diff options
Diffstat (limited to 'src/drivers/WinAPI')
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H | 5 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx | 44 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx | 29 |
4 files changed, 54 insertions, 26 deletions
diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H index 503eb308d..e81120fea 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H @@ -40,6 +40,8 @@ protected: static BOOL CALLBACK screen_cb(HMONITOR mon, HDC, LPRECT r, LPARAM); BOOL screen_cb(HMONITOR mon, HDC, LPRECT r); + int screen_num_unscaled(int x, int y); + int get_mouse_unscaled(int &mx, int &my); public: Fl_WinAPI_Screen_Driver() : Fl_Screen_Driver() { scale_ = 1; } @@ -53,7 +55,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(); + float DWM_scaling_factor(int screen_num); virtual void screen_work_area(int &X, int &Y, int &W, int &H, int n); // --- audible output virtual void beep(int type); @@ -74,6 +76,7 @@ public: virtual int dnd(int unused); virtual int compose(int &del); virtual Fl_RGB_Image *read_win_rectangle(uchar *p, int X, int Y, int w, int h, int alpha); + Fl_RGB_Image *read_win_rectangle_unscaled(uchar *p, int X, int Y, int w, int h, int alpha); virtual int get_mouse(int &x, int &y); virtual void enable_im(); virtual void disable_im(); diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx index e9ca9d2fb..e4a3361f5 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx @@ -159,10 +159,10 @@ void Fl_WinAPI_Screen_Driver::screen_work_area(int &X, int &Y, int &W, int &H, i { if (num_screens < 0) init(); if (n < 0 || n >= num_screens) n = 0; - X = work_area[n].left; - Y = work_area[n].top; - W = work_area[n].right - X; - H = work_area[n].bottom - Y; + X = work_area[n].left/scale_; + Y = work_area[n].top/scale_; + W = (work_area[n].right - X)/scale_; + H = (work_area[n].bottom - Y)/scale_; } @@ -174,10 +174,10 @@ void Fl_WinAPI_Screen_Driver::screen_xywh(int &X, int &Y, int &W, int &H, int n) n = 0; if (num_screens > 0) { - X = screens[n].left; - Y = screens[n].top; - W = screens[n].right - screens[n].left; - H = screens[n].bottom - screens[n].top; + X = screens[n].left/scale_; + Y = screens[n].top/scale_; + W = (screens[n].right - screens[n].left)/scale_; + H = (screens[n].bottom - screens[n].top)/scale_; } else { /* Fallback if something is broken... */ X = 0; @@ -512,7 +512,7 @@ int Fl_WinAPI_Screen_Driver::compose(int &del) { } -Fl_RGB_Image * // O - image or NULL if failed +Fl_RGB_Image * // O - image or NULL if failed Fl_WinAPI_Screen_Driver::read_win_rectangle(uchar *p, // I - Pixel buffer or NULL to allocate int X, // I - Left position int Y, // I - Top position @@ -520,6 +520,12 @@ Fl_WinAPI_Screen_Driver::read_win_rectangle(uchar *p, // I - Pixel buffer or NU int h, // I - Height of area to read int alpha) // I - Alpha value for image (0 for none) { + float s = Fl_Surface_Device::surface()->driver()->scale(); + return read_win_rectangle_unscaled(p, X*s, Y*s, w*s, h*s, alpha); +} + +Fl_RGB_Image *Fl_WinAPI_Screen_Driver::read_win_rectangle_unscaled(uchar *p, int X, int Y, int w, int h, int alpha) +{ int d; // Depth of image // Allocate the image data array as needed... @@ -614,11 +620,11 @@ 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) +/* Returns the current desktop scaling factor for screen_num (1.75 for example) */ -float Fl_WinAPI_Screen_Driver::desktop_scaling_factor() { +float Fl_WinAPI_Screen_Driver::DWM_scaling_factor(int screen_num) { #ifdef FLTK_HIDPI_SUPPORT - return 1;// this becomes useless if FLTK app are made DPI-aware by calling SetProcessDpiAwareness() + return scale(screen_num); #else // Compute the global desktop scaling factor: 1, 1.25, 1.5, 1.75, etc... // This factor can be set in Windows 10 by @@ -651,6 +657,20 @@ void Fl_WinAPI_Screen_Driver::offscreen_size(Fl_Offscreen off, int &width, int & } } +int Fl_WinAPI_Screen_Driver::screen_num_unscaled(int x, int y) +{ + int screen = 0; + if (num_screens < 0) init(); + for (int i = 0; i < num_screens; i ++) { + if (x >= screens[i].left && x < screens[i].right && + y >= screens[i].top && y < screens[i].bottom) { + screen = i; + break; + } + } + return screen; +} + // // End of "$Id$". // diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H index 59ced3e37..acd8f7603 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H @@ -62,7 +62,6 @@ class FL_EXPORT Fl_WinAPI_Window_Driver : public Fl_Window_Driver HICON small_icon; }; private: - RECT border_width_title_bar_height(int &bx, int &by, int &bt, float *pscaling = NULL); void shape_bitmap_(Fl_Image* b); void shape_alpha_(Fl_Image* img, int offset); public: @@ -70,6 +69,7 @@ public: ~Fl_WinAPI_Window_Driver(); static inline Fl_WinAPI_Window_Driver* driver(Fl_Window *w) {return (Fl_WinAPI_Window_Driver*)w->driver();} HDC private_dc; // used for OpenGL + RECT border_width_title_bar_height(int &bx, int &by, int &bt); struct icon_data *icon_; HCURSOR cursor; diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx index 1d496edff..e39a2ed5a 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx @@ -59,14 +59,11 @@ Fl_WinAPI_Window_Driver::~Fl_WinAPI_Window_Driver() } -// --- private - RECT // frame of the decorated window in screen coordinates Fl_WinAPI_Window_Driver::border_width_title_bar_height( int &bx, // left and right border width int &by, // bottom border height (=bx) - int &bt, // height of window title bar - float *pscaling // display scaling factor + int &bt // height of window title bar ) { Fl_Window *win = pWindow; @@ -83,14 +80,12 @@ 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; - scaling = Fl_WinAPI_Screen_Driver::desktop_scaling_factor(); + scaling = ((Fl_WinAPI_Screen_Driver*)Fl::screen_driver())->DWM_scaling_factor(screen_num()); } } if (need_r) { GetWindowRect(fl_xid(win), &r); } - if (pscaling) *pscaling = scaling; - bx = (r.right - r.left - int(win->w() * scaling))/2; if (bx < 1) bx = 1; by = bx; @@ -105,16 +100,24 @@ RECT // frame of the decorated window in screen coordinates int Fl_WinAPI_Window_Driver::decorated_w() { int bt, bx, by; + float s = Fl::screen_driver()->scale(screen_num()); border_width_title_bar_height(bx, by, bt); - return w() + 2 * bx; + int mini_bx = bx/s; if (mini_bx < 1) mini_bx = 1; + return w() + 2 * mini_bx; } int Fl_WinAPI_Window_Driver::decorated_h() { int bt, bx, by; - float scaling = 1; - border_width_title_bar_height(bx, by, bt, &scaling); - return h() + bt/scaling + 2 * by; + border_width_title_bar_height(bx, by, bt); +#ifdef FLTK_HIDPI_SUPPORT + float s = Fl::screen_driver()->scale(screen_num()); + int mini_by = by/s; if (mini_by < 1) mini_by = 1; + return h() + (bt + by)/s + mini_by; +#else + float scaling = ((Fl_WinAPI_Screen_Driver*)Fl::screen_driver())->DWM_scaling_factor(0); + return h() + bt/scaling + 2 * by +1; +#endif } @@ -596,7 +599,7 @@ int Fl_WinAPI_Window_Driver::scroll(int src_x, int src_y, int src_w, int src_h, static fl_GetRandomRgn_func fl_GetRandomRgn = 0L; static char first_time = 1; // We will have to do some Region magic now, so let's see if the - // required function is available (and it should be staring w/Win95) + // required function is available (and it should be starting w/Win95) if (first_time) { HMODULE hMod = GetModuleHandle("GDI32.DLL"); if (hMod) { @@ -604,6 +607,8 @@ int Fl_WinAPI_Window_Driver::scroll(int src_x, int src_y, int src_w, int src_h, } first_time = 0; } + float s = Fl::screen_driver()->scale(screen_num()); + src_x *= s; src_y *= s; src_w *= s; src_h *= s; dest_x *= s; dest_y *= s; // Now check if the source scrolling area is fully visible. // If it is, we will do a quick scroll and just update the // newly exposed area. If it is not, we go the safe route and |
