summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx9
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver.H2
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx32
-rw-r--r--src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx10
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H5
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx44
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H2
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx29
8 files changed, 93 insertions, 40 deletions
diff --git a/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx b/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx
index 1e7584fa8..e3d43664c 100644
--- a/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx
+++ b/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx
@@ -60,8 +60,13 @@ Fl_GDI_Copy_Surface_Driver::Fl_GDI_Copy_Surface_Driver(int w, int h) : Fl_Copy_S
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();
-
+#ifdef FLTK_HIDPI_SUPPORT
+ float scaling = Fl_Graphics_Driver::default_driver().scale();
+ factorw *= scaling;
+ factorh *= scaling;
+#else
+ float scaling = ((Fl_WinAPI_Screen_Driver*)Fl::screen_driver())->DWM_scaling_factor(0);
+#endif
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) {
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H
index a641e4c89..0ab48418b 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H
@@ -89,7 +89,7 @@ public:
void XDestroyRegion(Fl_Region r);
void translate_all(int x, int y);
void untranslate_all(void);
- static HRGN scale_region(HRGN r, float f, bool keep, bool inflate=false);
+ static HRGN scale_region(HRGN r, float f, Fl_GDI_Graphics_Driver *dr, bool keep/*, bool inflate=false*/);
virtual void scale(float f);
virtual float scale();
protected:
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
index 00bade1b1..41948b83a 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
@@ -146,7 +146,7 @@ void Fl_GDI_Graphics_Driver::translate_all(int x, int y) {
depth = stack_height - 1;
}
GetWindowOrgEx((HDC)gc(), origins+depth);
- SetWindowOrgEx((HDC)gc(), origins[depth].x - x, origins[depth].y - y, NULL);
+ SetWindowOrgEx((HDC)gc(), origins[depth].x - x*scale_, origins[depth].y - y*scale_, NULL);
depth++;
}
@@ -243,24 +243,44 @@ float Fl_GDI_Graphics_Driver::scale() {
/* Rescale region r with factor f and returns the scaled region.
The input region is deleted if keep is false.
- The input region is inflated by 1 unit before rescaling if inflate is true.
+ //The input region is inflated by 1 unit before rescaling if inflate is true.
Region r is returned unchanged if r is null or f is 1.
*/
-HRGN Fl_GDI_Graphics_Driver::scale_region(HRGN r, float f, bool keep, bool inflate) {
+HRGN Fl_GDI_Graphics_Driver::scale_region(HRGN r, float f, Fl_GDI_Graphics_Driver *dr, bool keep/*, bool inflate*/) {
if (r && f != 1) {
DWORD size = GetRegionData(r, 0, NULL);
RGNDATA *pdata = (RGNDATA*)malloc(size);
GetRegionData(r, size, pdata);
if (!keep) DeleteObject(r);
- if (inflate) {
+ /*if (inflate) { // seems no longer useful
RECT *rects = (RECT*)&(pdata->Buffer);
for (DWORD i = 0; i < pdata->rdh.nCount; i++) {
InflateRect(rects+i, 1, 1);
}
+ }*/
+ POINT pt = {0, 0};
+ if (dr && dr->depth >= 1) { // account for both scaling and translation
+ GetWindowOrgEx((HDC)dr->gc(), &pt);
+ pt.x *= (f - 1);
+ pt.y *= (f - 1);
}
- XFORM xform = {f, 0, 0, f, 0, 0};
+ XFORM xform = {f, 0, 0, f, (FLOAT)pt.x , (FLOAT)pt.y};
r = ExtCreateRegion(&xform, size, pdata);
free(pdata);
+
+ if (dr && int(f) != f && f > 1) { // needed for clean checkers demo
+ DWORD size = GetRegionData(r, 0, NULL);
+ RGNDATA *pdata = (RGNDATA*)malloc(size);
+ GetRegionData(r, size, pdata);
+ DeleteObject(r);
+ RECT *rects = (RECT*)&(pdata->Buffer);
+ for (DWORD i = 0; i < pdata->rdh.nCount; i++) {
+ InflateRect(rects+i, 1, 1);
+ }
+ r = ExtCreateRegion(NULL, size, pdata);
+ free(pdata);
+ }
+
}
return r;
}
@@ -268,7 +288,7 @@ HRGN Fl_GDI_Graphics_Driver::scale_region(HRGN r, float f, bool keep, bool infla
Fl_Region Fl_GDI_Graphics_Driver::scale_clip(float f) {
HRGN r = rstack[rstackptr];
- HRGN r2 = scale_region(r, f, true);
+ HRGN r2 = scale_region(r, f, this, true);
return (r == r2 ? NULL : (rstack[rstackptr] = r2, r));
}
diff --git a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx
index e55e69583..904511fe0 100644
--- a/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx
+++ b/src/drivers/GDI/Fl_GDI_Image_Surface_Driver.cxx
@@ -21,6 +21,7 @@
#ifdef FL_CFG_GFX_GDI
#include "Fl_GDI_Graphics_Driver.H"
+#include "../WinAPI/Fl_WinAPI_Screen_Driver.H"
#include <FL/Fl_Image_Surface.H>
#include <FL/fl_draw.H>
#include <FL/x.H>
@@ -55,7 +56,9 @@ Fl_GDI_Image_Surface_Driver::Fl_GDI_Image_Surface_Driver(int w, int h, int high_
w = int(w*d);
h = int(h*d);
}
- offscreen = off ? off : CreateCompatibleBitmap( (fl_graphics_driver->gc() ? (HDC)fl_graphics_driver->gc() : fl_GetDC(0) ) , w, h);
+ HDC gc = (HDC)Fl_Graphics_Driver::default_driver().gc();
+ offscreen = off ? off : CreateCompatibleBitmap( (gc ? gc : fl_GetDC(0) ) , w, h);
+ if (!offscreen) offscreen = CreateCompatibleBitmap(fl_GetDC(0), w, h);
driver(new Fl_GDI_Graphics_Driver);
if (d != 1 && high_res) driver()->scale(d);
_sgc = NULL;
@@ -93,11 +96,8 @@ void Fl_GDI_Image_Surface_Driver::untranslate() {
Fl_RGB_Image* Fl_GDI_Image_Surface_Driver::image()
{
- unsigned char *data;
- data = fl_read_image(NULL, 0, 0, width, height, 0);
+ Fl_RGB_Image *image = Fl::screen_driver()->read_win_rectangle(NULL, 0, 0, width, height, 0);
previous->driver()->gc(_sgc);
- Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height);
- image->alloc_array = 1;
return image;
}
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