From dd9826c817928cbc87d6506608bf6591838959ec Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Tue, 19 Aug 2014 02:28:42 -0700 Subject: [PATCH] MGR: On MS Windows, make DPI setting detection more efficient and DPI adjustments more general. --- clientgui/BOINCTaskCtrl.cpp | 4 ++-- clientgui/DlgDiagnosticLogFlags.cpp | 20 +++++++++++--------- clientgui/DlgEventLog.cpp | 8 ++++---- clientgui/MainDocument.cpp | 27 +++++++++++++++++++++++---- clientgui/MainDocument.h | 9 ++++++--- 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/clientgui/BOINCTaskCtrl.cpp b/clientgui/BOINCTaskCtrl.cpp index 9269afd873..064e59b9ef 100644 --- a/clientgui/BOINCTaskCtrl.cpp +++ b/clientgui/BOINCTaskCtrl.cpp @@ -24,8 +24,8 @@ #include "BOINCTaskCtrl.h" #include "MainDocument.h" -#define TASKPANEWIDTH ADJUSTFORDPI(200) -#define TASKBUTTONWIDTH ADJUSTFORDPI(TASKPANEWIDTH - 55) +#define TASKPANEWIDTH ADJUSTFORXDPI(200) +#define TASKBUTTONWIDTH ADJUSTFORXDPI(TASKPANEWIDTH - 55) IMPLEMENT_DYNAMIC_CLASS(CBOINCTaskCtrl, wxScrolledWindow) diff --git a/clientgui/DlgDiagnosticLogFlags.cpp b/clientgui/DlgDiagnosticLogFlags.cpp index 8b77230705..816da45ef5 100755 --- a/clientgui/DlgDiagnosticLogFlags.cpp +++ b/clientgui/DlgDiagnosticLogFlags.cpp @@ -30,8 +30,10 @@ #include "SkinManager.h" -#define DLGDIAGNOSTICS_INITIAL_SIZE ADJUSTFORDPI(480) -#define DLGDIAGNOSTICS_MIN_SIZE ADJUSTFORDPI(400) +#define DLGDIAGNOSTICS_INITIAL_WIDTH ADJUSTFORXDPI(480) +#define DLGDIAGNOSTICS_INITIAL_HEIGHT ADJUSTFORYDPI(480) +#define DLGDIAGNOSTICS_MIN_WIDTH ADJUSTFORXDPI(400) +#define DLGDIAGNOSTICS_MIN_HEIGHT ADJUSTFORYDPI(400) IMPLEMENT_DYNAMIC_CLASS(CDlgDiagnosticLogFlags, wxDialog) @@ -45,7 +47,7 @@ END_EVENT_TABLE() /* Constructor */ CDlgDiagnosticLogFlags::CDlgDiagnosticLogFlags(wxWindow* parent) : wxDialog( parent, ID_ANYDIALOG, wxEmptyString, wxDefaultPosition, - wxSize( DLGDIAGNOSTICS_INITIAL_SIZE,DLGDIAGNOSTICS_INITIAL_SIZE ), + wxSize( DLGDIAGNOSTICS_INITIAL_WIDTH,DLGDIAGNOSTICS_INITIAL_HEIGHT ), wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ) { @@ -71,7 +73,7 @@ CDlgDiagnosticLogFlags::CDlgDiagnosticLogFlags(wxWindow* parent) : m_cc_config.defaults(); pDoc->rpc.get_cc_config(m_cc_config, log_flags); - SetSizeHints(DLGDIAGNOSTICS_MIN_SIZE, DLGDIAGNOSTICS_MIN_SIZE); + SetSizeHints(DLGDIAGNOSTICS_MIN_WIDTH, DLGDIAGNOSTICS_MIN_HEIGHT); SetExtraStyle( GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY ); wxBoxSizer* bSizer1 = new wxBoxSizer( wxVERTICAL ); @@ -198,15 +200,15 @@ bool CDlgDiagnosticLogFlags::RestoreState() { pConfig->SetPath("/DlgDiagnosticLogFlags/"); - pConfig->Read(wxT("Width"), &iWidth, DLGDIAGNOSTICS_INITIAL_SIZE); - pConfig->Read(wxT("Height"), &iHeight, DLGDIAGNOSTICS_INITIAL_SIZE); + pConfig->Read(wxT("Width"), &iWidth, DLGDIAGNOSTICS_INITIAL_WIDTH); + pConfig->Read(wxT("Height"), &iHeight, DLGDIAGNOSTICS_INITIAL_HEIGHT); // Guard against a rare situation where registry values are zero - if ((iWidth < 50) && (iWidth != wxDefaultCoord)) iWidth = DLGDIAGNOSTICS_INITIAL_SIZE; - if ((iHeight < 50) && (iHeight != wxDefaultCoord)) iHeight = DLGDIAGNOSTICS_INITIAL_SIZE; + if ((iWidth < 50) && (iWidth != wxDefaultCoord)) iWidth = DLGDIAGNOSTICS_INITIAL_WIDTH; + if ((iHeight < 50) && (iHeight != wxDefaultCoord)) iHeight = DLGDIAGNOSTICS_INITIAL_HEIGHT; // Set size to saved values or defaults if no saved values - SetSize(std::max(iWidth, DLGDIAGNOSTICS_MIN_SIZE), std::max(iHeight, DLGDIAGNOSTICS_MIN_SIZE)); + SetSize(std::max(iWidth, DLGDIAGNOSTICS_MIN_WIDTH), std::max(iHeight, DLGDIAGNOSTICS_MIN_HEIGHT)); return true; } diff --git a/clientgui/DlgEventLog.cpp b/clientgui/DlgEventLog.cpp index 2ab5fa4594..e0b1c8c26a 100644 --- a/clientgui/DlgEventLog.cpp +++ b/clientgui/DlgEventLog.cpp @@ -49,10 +49,10 @@ ////@begin XPM images ////@end XPM images -#define DLGEVENTLOG_INITIAL_WIDTH ADJUSTFORDPI(640) -#define DLGEVENTLOG_INITIAL_HEIGHT ADJUSTFORDPI(480) -#define DLGEVENTLOG_MIN_WIDTH ADJUSTFORDPI(600) -#define DLGEVENTLOG_MIN_HEIGHT ADJUSTFORDPI(250) +#define DLGEVENTLOG_INITIAL_WIDTH ADJUSTFORXDPI(640) +#define DLGEVENTLOG_INITIAL_HEIGHT ADJUSTFORYDPI(480) +#define DLGEVENTLOG_MIN_WIDTH ADJUSTFORXDPI(600) +#define DLGEVENTLOG_MIN_HEIGHT ADJUSTFORYDPI(250) #define COLUMN_PROJECT 0 #define COLUMN_TIME 1 diff --git a/clientgui/MainDocument.cpp b/clientgui/MainDocument.cpp index c9a52c19d8..21744aef74 100644 --- a/clientgui/MainDocument.cpp +++ b/clientgui/MainDocument.cpp @@ -2637,8 +2637,13 @@ void color_cycle(int i, int n, wxColour& color) { } #ifdef __WXMSW__ -float GetDPIScaling() { - float fScale = 1.0; +static float XDPIScaleFactor = 0.0; +static float YDPIScaleFactor = 0.0; + +void GetDPIScaling() { + XDPIScaleFactor = 1.0; + YDPIScaleFactor = 1.0; + // SetProcessDPIAware() requires Windows Vista or later HMODULE hUser32 = LoadLibrary(_T("user32.dll")); typedef BOOL (*SetProcessDPIAwareFunc)(); SetProcessDPIAwareFunc setDPIAware = (SetProcessDPIAwareFunc)GetProcAddress(hUser32, "SetProcessDPIAware"); @@ -2646,10 +2651,24 @@ float GetDPIScaling() { setDPIAware(); HWND hWnd = GetForegroundWindow(); HDC hdc = GetDC(hWnd); - fScale = GetDeviceCaps(hdc, LOGPIXELSX) / 96.0f; + XDPIScaleFactor = GetDeviceCaps(hdc, LOGPIXELSX) / 96.0f; + YDPIScaleFactor = GetDeviceCaps(hdc, LOGPIXELSY) / 96.0f; ReleaseDC(hWnd, hdc); } FreeLibrary(hUser32); - return fScale; +} + +float GetXDPIScaling() { + if (XDPIScaleFactor == 0.0) { + GetDPIScaling(); + } + return XDPIScaleFactor; +} + +float GetYDPIScaling() { + if (YDPIScaleFactor == 0.0) { + GetDPIScaling(); + } + return YDPIScaleFactor; } #endif diff --git a/clientgui/MainDocument.h b/clientgui/MainDocument.h index 5c75020b9a..2a85710ccb 100644 --- a/clientgui/MainDocument.h +++ b/clientgui/MainDocument.h @@ -418,10 +418,13 @@ extern void https_to_http(wxString& strMessage); extern void color_cycle(int i, int n, wxColour& color); #ifdef __WXMSW__ -#define ADJUSTFORDPI(x) (int)(x * GetDPIScaling()) -extern float GetDPIScaling(); +#define ADJUSTFORXDPI(x) (int)(x * GetXDPIScaling()) +#define ADJUSTFORYDPI(y) (int)(y * GetYDPIScaling()) +extern float GetXDPIScaling(); +extern float GetYDPIScaling(); #else -#define ADJUSTFORDPI(x) x +#define ADJUSTFORXDPI(x) x +#define ADJUSTFORYDPI(y) y #endif #ifdef SANDBOX