From c472d5d8b76e17e4dd537ca20c9bfb144b06189c Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Fri, 9 Feb 2018 13:48:22 +0000 Subject: Fix fl_read_image() under MacOS platform when GUI is rescaled. This commit also simplifies the platform-dependent support of fl_read_image(): only Fl_XXX_Screen_Driver::read_win_rectangle() contains platform-specific code to capture pixels from the current window or from an offscreen buffer. Platform-independent function Fl_Screen_Driver::traverse_to_gl_subwindows() captures subwindows that intersect with the area fl_read_image() targets. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12653 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H | 2 ++ .../Quartz/Fl_Quartz_Graphics_Driver_rect.cxx | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'src/drivers/Quartz') diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H index 60a261e94..b23817d46 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H @@ -184,6 +184,8 @@ protected: #else void descriptor_init(const char* name, Fl_Fontsize Size, Fl_Quartz_Font_Descriptor *d); #endif + virtual bool overlay_rect_unscaled() {return false; } + virtual void overlay_rect(int x, int y, int w , int h); }; class Fl_Quartz_Printer_Graphics_Driver : public Fl_Quartz_Graphics_Driver { diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx index 3a83b94d6..8153f4e78 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx @@ -173,6 +173,30 @@ void Fl_Quartz_Graphics_Driver::loop(int x, int y, int x1, int y1, int x2, int y if (quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } +// returns y of horizontal line corresponding to pixels of current window +// read by Fl_Cocoa_Screen_Driver::read_win_rectangle( -, y, -, 1) +// when GUI is scaled by s +static float overlay_y(int y, float s, int H) { + int a, b, c; + a = int(H*s) - (y+1)*s; // in Cocoa units from window bottom + c = (s > 1 ? s : 1); // height of pixels read in Cocoa units + b = H*s - (a+c); // top of read image from window top in Cocoa units + return b/s; // top of read image from window top in FLTK units +} + +void Fl_Quartz_Graphics_Driver::overlay_rect(int x, int y, int w , int h) { + float s = scale(); + CGContextSetLineWidth(gc_, 0.01); + int H = Fl_Window::current()->h(); + CGContextMoveToPoint(gc_, x, overlay_y(y, s, H)); + CGContextAddLineToPoint(gc_, x+w-1, overlay_y(y, s, H)); + CGContextAddLineToPoint(gc_, x+w-1, overlay_y(y+h-1, s, H)); + CGContextAddLineToPoint(gc_, x, overlay_y(y+h-1, s, H)); + CGContextClosePath(gc_); + CGContextStrokePath(gc_); + CGContextSetLineWidth(gc_, quartz_line_width_); +} + void Fl_Quartz_Graphics_Driver::polygon(int x, int y, int x1, int y1, int x2, int y2) { CGContextSetShouldAntialias(gc_, true); CGContextMoveToPoint(gc_, x, y); -- cgit v1.2.3