From 5ad07b7b4bc18c7565202d21118a78cbad242927 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sun, 18 Aug 2024 14:40:43 +0200 Subject: Fix fl_overlay_rect smearing on macOS (#735) If fl_overlay_rect crosses window bounds, reading the window contents would fail and restoring the contents would fail, generating a smear effect. --- src/fl_overlay.cxx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/fl_overlay.cxx') diff --git a/src/fl_overlay.cxx b/src/fl_overlay.cxx index 31b79b5e4..d4077afc5 100644 --- a/src/fl_overlay.cxx +++ b/src/fl_overlay.cxx @@ -133,12 +133,26 @@ void fl_overlay_clear() { \see fl_overlay_clear() */ void fl_overlay_rect(int x, int y, int w, int h) { - if (w < 0) {x += w; w = -w;} else if (!w) w = 1; - if (h < 0) {y += h; h = -h;} else if (!h) h = 1; + // If there is already another overlay rect, erase it now if (pw > 0) { if (x==px && y==py && w==pw && h==ph) return; erase_current_rect(); } + // Width and hight must be positive, swap with coordinates if needed + if (w < 0) {x += w; w = -w;} + if (h < 0) {y += h; h = -h;} + // Clip the overlay to the window rect, or reading the background will fail + Fl_Window *win = Fl_Window::current(); + if (win) { + int d; + d = -x; if (d>0) { x += d; w -= d; } + d = (x+w)-win->w(); if (d>0) { w -= d; } + d = -y; if (d>0) { y += d; h -= d; } + d = (y+h)-win->h(); if (d>0) { h -= d; } + } + if (w<1) w = 1; + if (h<1) h = 1; + // Store the rect so we can erase it later, and draw it now px = x; py = y; pw = w; ph = h; draw_current_rect(); } -- cgit v1.2.3