Fixes of DPI scaling on Windows.
This commit is contained in:
parent
dad8a47741
commit
e8325a8e2d
@ -59,7 +59,7 @@ CopyrightsDialog::CopyrightsDialog()
|
||||
m_html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition,
|
||||
wxSize(40 * em_unit(), 20 * em_unit()), wxHW_SCROLLBAR_AUTO);
|
||||
|
||||
wxFont font = get_default_font_for_dpi(get_dpi_for_window(this));// GetFont();
|
||||
wxFont font = get_default_font(this);
|
||||
const int fs = font.GetPointSize();
|
||||
const int fs2 = static_cast<int>(1.2f*fs);
|
||||
int size[] = { fs, fs, fs, fs, fs2, fs2, fs2 };
|
||||
@ -269,7 +269,7 @@ AboutDialog::AboutDialog()
|
||||
m_html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO/*NEVER*/);
|
||||
{
|
||||
m_html->SetMinSize(wxSize(-1, 16 * wxGetApp().em_unit()));
|
||||
wxFont font = get_default_font_for_dpi(get_dpi_for_window(this));// GetFont();
|
||||
wxFont font = get_default_font(this);
|
||||
const auto text_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
auto text_clr_str = wxString::Format(wxT("#%02X%02X%02X"), text_clr.Red(), text_clr.Green(), text_clr.Blue());
|
||||
auto bgr_clr_str = wxString::Format(wxT("#%02X%02X%02X"), bgr_clr.Red(), bgr_clr.Green(), bgr_clr.Blue());
|
||||
|
@ -114,7 +114,7 @@ ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db
|
||||
// text
|
||||
html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO);
|
||||
{
|
||||
wxFont font = get_default_font_for_dpi(get_dpi_for_window(this));// wxGetApp().normal_font();//wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||
wxFont font = get_default_font(this);
|
||||
#ifdef __WXMSW__
|
||||
const int fs = font.GetPointSize();
|
||||
const int fs1 = static_cast<int>(0.8f*fs);
|
||||
@ -140,7 +140,7 @@ ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db
|
||||
|
||||
void ConfigSnapshotDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||
{
|
||||
wxFont font = get_default_font_for_dpi(get_dpi_for_window(this));// GetFont();
|
||||
wxFont font = get_default_font(this);
|
||||
const int fs = font.GetPointSize();
|
||||
const int fs1 = static_cast<int>(0.8f*fs);
|
||||
const int fs2 = static_cast<int>(1.1f*fs);
|
||||
|
@ -75,7 +75,7 @@ template<class F> typename F::FN winapi_get_function(const wchar_t *dll, const c
|
||||
#endif
|
||||
|
||||
// If called with nullptr, a DPI for the primary monitor is returned.
|
||||
int get_dpi_for_window(wxWindow *window)
|
||||
int get_dpi_for_window(const wxWindow *window)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
enum MONITOR_DPI_TYPE_ {
|
||||
@ -126,7 +126,7 @@ int get_dpi_for_window(wxWindow *window)
|
||||
#endif
|
||||
}
|
||||
|
||||
wxFont get_default_font_for_dpi(int dpi)
|
||||
wxFont get_default_font_for_dpi(const wxWindow *window, int dpi)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// First try to load the font with the Windows 10 specific way.
|
||||
@ -137,7 +137,7 @@ wxFont get_default_font_for_dpi(int dpi)
|
||||
memset(&nm, 0, sizeof(NONCLIENTMETRICS));
|
||||
nm.cbSize = sizeof(NONCLIENTMETRICS);
|
||||
if (SystemParametersInfoForDpi_fn(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nm, 0, dpi))
|
||||
return wxFont(wxNativeFontInfo(nm.lfMessageFont));
|
||||
return wxFont(wxNativeFontInfo(nm.lfMessageFont, window));
|
||||
}
|
||||
// Then try to guesstimate the font DPI scaling on Windows 8.
|
||||
// Let's hope that the font returned by the SystemParametersInfo(), which is used by wxWidgets internally, makes sense.
|
||||
|
@ -53,8 +53,9 @@ void on_window_geometry(wxTopLevelWindow *tlw, std::function<void()> callback);
|
||||
|
||||
enum { DPI_DEFAULT = 96 };
|
||||
|
||||
int get_dpi_for_window(wxWindow *window);
|
||||
wxFont get_default_font_for_dpi(int dpi);
|
||||
int get_dpi_for_window(const wxWindow *window);
|
||||
wxFont get_default_font_for_dpi(const wxWindow* window, int dpi);
|
||||
inline wxFont get_default_font(const wxWindow* window) { return get_default_font_for_dpi(window, get_dpi_for_window(window)); }
|
||||
|
||||
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
struct DpiChangedEvent : public wxEvent {
|
||||
@ -84,7 +85,7 @@ public:
|
||||
int dpi = get_dpi_for_window(this);
|
||||
m_scale_factor = (float)dpi / (float)DPI_DEFAULT;
|
||||
m_prev_scale_factor = m_scale_factor;
|
||||
m_normal_font = get_default_font_for_dpi(dpi);
|
||||
m_normal_font = get_default_font_for_dpi(this, dpi);
|
||||
|
||||
/* Because of default window font is a primary display font,
|
||||
* We should set correct font for window before getting em_unit value.
|
||||
@ -107,13 +108,8 @@ public:
|
||||
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||
this->Bind(wxEVT_DPI_CHANGED, [this](wxDPIChangedEvent& evt) {
|
||||
m_scale_factor = (float)evt.GetNewDPI().x / (float)DPI_DEFAULT;
|
||||
|
||||
m_new_font_point_size = get_default_font_for_dpi(evt.GetNewDPI().x).GetPointSize();
|
||||
|
||||
if (!m_can_rescale)
|
||||
return;
|
||||
|
||||
if (m_force_rescale || is_new_scale_factor())
|
||||
m_new_font_point_size = get_default_font_for_dpi(this, evt.GetNewDPI().x).GetPointSize();
|
||||
if (m_can_rescale && (m_force_rescale || is_new_scale_factor()))
|
||||
rescale(wxRect());
|
||||
});
|
||||
#else
|
||||
|
@ -129,7 +129,7 @@ SysInfoDialog::SysInfoDialog()
|
||||
}
|
||||
|
||||
// main_info_text
|
||||
wxFont font = get_default_font_for_dpi(get_dpi_for_window(this));// wxGetApp().normal_font();
|
||||
wxFont font = get_default_font(this);
|
||||
const auto text_clr = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
auto text_clr_str = wxString::Format(wxT("#%02X%02X%02X"), text_clr.Red(), text_clr.Green(), text_clr.Blue());
|
||||
auto bgr_clr_str = wxString::Format(wxT("#%02X%02X%02X"), bgr_clr.Red(), bgr_clr.Green(), bgr_clr.Blue());
|
||||
@ -195,7 +195,7 @@ void SysInfoDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||
m_logo_bmp.msw_rescale();
|
||||
m_logo->SetBitmap(m_logo_bmp.bmp());
|
||||
|
||||
wxFont font = get_default_font_for_dpi(get_dpi_for_window(this));// GetFont();
|
||||
wxFont font = get_default_font(this);
|
||||
const int fs = font.GetPointSize() - 1;
|
||||
int font_size[] = { static_cast<int>(fs*1.5), static_cast<int>(fs*1.4), static_cast<int>(fs*1.3), fs, fs, fs, fs };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user