diff options
| author | Manolo Gouy <Manolo> | 2016-08-27 15:54:51 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-08-27 15:54:51 +0000 |
| commit | fd2da982b625109efe50a0c9351bf6dd5abc8aae (patch) | |
| tree | 6606b6d9d16ded16444ad74de8211d80b8a66439 /src/drivers | |
| parent | f551d538f23ddf810e7401a2d25de54dc5f15f75 (diff) | |
Fix Fl_Copy_Surface under Windows 10 when the desktop scaling factor value is > 100 %
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11899 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx | 5 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx | 24 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx | 28 |
4 files changed, 31 insertions, 27 deletions
diff --git a/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx b/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx index 1a7a88b27..2d0ab4760 100644 --- a/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx +++ b/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx @@ -22,6 +22,7 @@ #include <FL/Fl_Copy_Surface.H> #include <FL/x.H> #include "Fl_GDI_Graphics_Driver.H" +#include "../WinAPI/Fl_WinAPI_Screen_Driver.H" #include <windows.h> class Fl_GDI_Copy_Surface_Driver : public Fl_Copy_Surface_Driver { @@ -58,8 +59,10 @@ Fl_GDI_Copy_Surface_Driver::Fl_GDI_Copy_Surface_Driver(int w, int h) : Fl_Copy_S ReleaseDC(NULL, hdc); float factorw = (100.f * hmm) / hdots; float factorh = (100.f * vmm) / vdots; + // Global display scaling factor: 1, 1.25, 1.5, 1.75, etc... + float scaling = Fl_WinAPI_Screen_Driver::desktop_scaling_factor(); - RECT rect; rect.left = 0; rect.top = 0; rect.right = (LONG)(w * factorw); rect.bottom = (LONG)(h * factorh); + RECT rect; rect.left = 0; rect.top = 0; rect.right = (LONG)((w/scaling) * factorw); rect.bottom = (LONG)((h/scaling) * factorh); gc = CreateEnhMetaFile (NULL, NULL, &rect, NULL); if (gc != NULL) { SetTextAlign(gc, TA_BASELINE|TA_LEFT); diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H index 61a34dd2d..80529138f 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H @@ -52,6 +52,7 @@ public: virtual int h(); virtual void screen_xywh(int &X, int &Y, int &W, int &H, int n); virtual void screen_dpi(float &h, float &v, int n=0); + static float desktop_scaling_factor(); virtual void screen_work_area(int &X, int &Y, int &W, int &H, int n); // --- audible output virtual void beep(int type); diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx index b89d18881..52e3f5287 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx @@ -656,6 +656,30 @@ Fl_WinAPI_Screen_Driver::read_win_rectangle(uchar *p, // I - Pixel buffer or NU return rgb; } +/** Returns the current desktop scaling factor (1.75 for example) + */ +float Fl_WinAPI_Screen_Driver::desktop_scaling_factor() { + // Compute the global desktop scaling factor: 1, 1.25, 1.5, 1.75, etc... + // This factor can be set in Windows 10 by + // "Change the size of text, apps and other items" in display settings. + // We don't cache this value because it can change while the app is running. + HDC hdc = GetDC(NULL); + int hr = GetDeviceCaps(hdc, HORZRES); // pixels visible to the app +#ifndef DESKTOPHORZRES +#define DESKTOPHORZRES 118 + /* As of 27 august 2016, the DESKTOPHORZRES flag for GetDeviceCaps() + has disappeared from Microsoft online doc, but is quoted in numerous coding examples + e.g., https://social.msdn.microsoft.com/Forums/en-US/6acc3b21-23a4-4a00-90b4-968a43e1ccc8/capture-screen-with-high-dpi?forum=vbgeneral + It is necessary for the computation of the scaling factor at runtime as done here. + */ +#endif + int dhr = GetDeviceCaps(hdc, DESKTOPHORZRES); // true number of pixels on display + ReleaseDC(NULL, hdc); + float scaling = dhr/float(hr); + scaling = int(scaling * 100 + 0.5)/100.; // round to 2 digits after decimal point + return scaling; +} + // // End of "$Id$". //
\ No newline at end of file diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx index be0bb5cf6..88afaecbf 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx @@ -27,6 +27,7 @@ #include <FL/Fl_Overlay_Window.H> #include <FL/x.H> #include "Fl_WinAPI_Window_Driver.H" +#include "Fl_WinAPI_Screen_Driver.H" #include <windows.h> #if USE_COLORMAP @@ -82,32 +83,7 @@ RECT // frame of the decorated window in screen coordinates const DWORD DWMWA_EXTENDED_FRAME_BOUNDS = 9; if ( DwmGetWindowAttribute(fl_xid(win), DWMWA_EXTENDED_FRAME_BOUNDS, &r, sizeof(RECT)) == S_OK ) { need_r = 0; - // Compute the global display scaling factor: 1, 1.25, 1.5, 1.75, etc... - // This factor can be set in Windows 10 by - // "Change the size of text, apps and other items" in display settings. - HDC hdc = GetDC(NULL); - //int hs = GetDeviceCaps(hdc, HORZSIZE); - int hr = GetDeviceCaps(hdc, HORZRES); // pixels visible to the app - //int px = GetDeviceCaps(hdc, LOGPIXELSX); -#ifndef DESKTOPHORZRES -#define DESKTOPHORZRES 118 - /* As of 27 august 2016, the DESKTOPHORZRES flag for GetDeviceCaps() - has disappeared from Microsoft online doc, but is quoted in numerous coding examples - e.g., https://social.msdn.microsoft.com/Forums/en-US/6acc3b21-23a4-4a00-90b4-968a43e1ccc8/capture-screen-with-high-dpi?forum=vbgeneral - It is necessary for the computation of the scaling factor at runtime as done here. - */ -#endif - int dhr = GetDeviceCaps(hdc, DESKTOPHORZRES); // true number of pixels on display - //int vs = GetDeviceCaps(hdc, VERTSIZE); - //int vr = GetDeviceCaps(hdc, VERTRES); - //int py = GetDeviceCaps(hdc, LOGPIXELSY); - //int dvr = GetDeviceCaps(hdc, DESKTOPVERTRES); - ReleaseDC(NULL, hdc); - scaling = dhr/float(hr); - scaling = int(scaling * 100 + 0.5)/100.; // round to 2 digits after decimal point - //fprintf(LOG, - // "HORZSIZE=%d %d, HORZRES=%d %d, LOGPIXELSX=%d %d, DESKTOPHORZRES=%d %d scaling=%f bx=%d bt=%d ", - // hs,vs,hr,vr,px,py,dhr,dvr,scaling);fflush(LOG); + scaling = Fl_WinAPI_Screen_Driver::desktop_scaling_factor(); } } if (need_r) { |
