From 842cbf0f1023f798362ab77aef34da23a24490b7 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sun, 21 Feb 2021 18:08:33 +0100 Subject: [PATCH] Fix for issue #192: focus box drawing incorrectly on OSX (e.g. 10.10.5) at scales >100% --- src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H | 1 + .../Quartz/Fl_Quartz_Graphics_Driver_rect.cxx | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H index 76edc4134..b61761d6f 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H @@ -95,6 +95,7 @@ protected: // --- implementation is in src/fl_rect.cxx which includes src/cfg_gfx/quartz_rect.cxx void point(int x, int y); void rect(int x, int y, int w, int h); + void focus_rect(int x, int y, int w, int h); void rectf(int x, int y, int w, int h); void line(int x, int y, int x1, int y1); void line(int x, int y, int x1, int y1, int x2, int y2); diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx index b238e9a9b..52b8c7f65 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_rect.cxx @@ -17,6 +17,7 @@ #include #include +#include /** @@ -42,6 +43,19 @@ void Fl_Quartz_Graphics_Driver::rect(int x, int y, int w, int h) { if ( (!has_feature(PRINTER)) && quartz_line_width_ > 1.5f) CGContextSetShouldAntialias(gc_, false); } +void Fl_Quartz_Graphics_Driver::focus_rect(int x, int y, int w, int h) +{ + CGContextSaveGState(gc_); + float s = scale(); + CGContextScaleCTM(gc_, 1/s, 1/s); + CGFloat lw = (s >= 1 ? floor(s) : 1); + CGContextSetLineWidth(gc_, lw); + CGFloat dots[2] = {lw, lw}; + CGContextSetLineDash(gc_, 0, dots, 2); + CGContextStrokeRect(gc_, CGRectMake(x*s, y*s, (w-1)*s, (h-1)*s)); + CGContextRestoreGState(gc_); +} + void Fl_Quartz_Graphics_Driver::rectf(int x, int y, int w, int h) { if (w<=0 || h<=0) return; CGRect rect = CGRectMake(x - 0.5, y - 0.5, w , h);