diff options
| author | Manolo Gouy <Manolo> | 2017-07-07 14:31:40 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2017-07-07 14:31:40 +0000 |
| commit | 7847c2d87ab85b54f846f8ab240b5e866e9a6593 (patch) | |
| tree | 88d7687b30eeaad6681fa28e27a8c70b95f9970a /src | |
| parent | 22d90078bd81c94cc3b7dce4fd7ca000eed03087 (diff) | |
WIN32 HiDPI support: fix copy and paste of image data when rescaling is applied.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12297 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_win32.cxx | 33 | ||||
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx | 4 |
2 files changed, 24 insertions, 13 deletions
diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 92a02dd3f..df43f59a5 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -65,6 +65,7 @@ void fl_cleanup_dc_list(void); #include <FL/Fl_Tooltip.H> #include <FL/Fl_Paged_Device.H> #include <FL/Fl_Shared_Image.H> +#include <FL/Fl_Image_Surface.H> #include "flstring.h" #include "drivers/GDI/Fl_Font.H" #include <stdio.h> @@ -755,6 +756,7 @@ void Fl_WinAPI_System_Driver::paste(Fl_Widget &receiver, int clipboard, const ch } else if (strcmp(type, Fl::clipboard_image) == 0) { // we want an image from clipboard uchar *rgb = NULL; + Fl_RGB_Image *image = NULL; int width = 0, height = 0, depth = 0; if ( (h = GetClipboardData(CF_DIB)) ) { // if there's a DIB in clipboard LPBITMAPINFO lpBI = (LPBITMAPINFO)GlobalLock(h) ; @@ -806,22 +808,31 @@ void Fl_WinAPI_System_Driver::paste(Fl_Widget &receiver, int clipboard, const ch int hdots = GetDeviceCaps(hdc, HORZRES); ReleaseDC(NULL, hdc); float factor = (100.f * hmm) / hdots; - float scaling = ((Fl_WinAPI_Screen_Driver*)Fl::screen_driver())->DWM_scaling_factor(receiver.top_window()->driver()->screen_num()); - width = int(width * scaling / factor); // convert to screen pixel unit +#ifdef FLTK_HIDPI_SUPPORT + float scaling = Fl::screen_driver()->scale( receiver.top_window()->driver()->screen_num() ); + width = int(width / (scaling * factor)); // convert to screen pixel unit + height = int(height / (scaling * factor)); +#else + float scaling = ((Fl_WinAPI_Screen_Driver*)Fl::screen_driver())->DWM_scaling_factor(0); + width = int(width * scaling / factor); // convert to screen pixel unit height = int(height * scaling / factor); + scaling = 1; +#endif RECT rect = {0, 0, width, height}; - Fl_Offscreen off = fl_create_offscreen(width, height); - fl_begin_offscreen(off); + Fl_Image_Surface *surf = new Fl_Image_Surface(width, height, 1); + Fl_Surface_Device::push_current(surf); fl_color(FL_WHITE); fl_rectf(0,0,width, height); // draw white background + rect.right *= scaling; rect.bottom *= scaling; // apply scaling to the metafile draw operation PlayEnhMetaFile((HDC)fl_graphics_driver->gc(), (HENHMETAFILE)h, &rect); // draw metafile to offscreen buffer - rgb = fl_read_image(NULL, 0, 0, width, height); // read pixels from offscreen buffer - depth = 3; - fl_end_offscreen(); - fl_delete_offscreen(off); + image = surf->image(); + Fl_Surface_Device::pop_current(); + delete surf; } - if (rgb) { - Fl_RGB_Image *image = new Fl_RGB_Image(rgb, width, height, depth); // create new image from pixel data - image->alloc_array = 1; + if (rgb || image) { + if (!image) { + Fl_RGB_Image *image = new Fl_RGB_Image(rgb, width, height, depth); // create new image from pixel data + image->alloc_array = 1; + } Fl::e_clipboard_data = image; Fl::e_clipboard_type = Fl::clipboard_image; // indicates that the paste event is for image data int done = receiver.handle(FL_PASTE); // send FL_PASTE event to widget diff --git a/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx b/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx index 1a1152de5..3369545a4 100644 --- a/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx +++ b/src/drivers/GDI/Fl_GDI_Copy_Surface_Driver.cxx @@ -62,10 +62,10 @@ Fl_GDI_Copy_Surface_Driver::Fl_GDI_Copy_Surface_Driver(int w, int h) : Fl_Copy_S // Global display scaling factor: 1, 1.25, 1.5, 1.75, etc... #ifdef FLTK_HIDPI_SUPPORT float scaling = Fl_Graphics_Driver::default_driver().scale(); + driver()->scale(scaling); #else - float scaling = ((Fl_WinAPI_Screen_Driver*)Fl::screen_driver())->DWM_scaling_factor(0); + float scaling = 1/((Fl_WinAPI_Screen_Driver*)Fl::screen_driver())->DWM_scaling_factor(0); #endif - driver()->scale(scaling); 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) { |
