diff options
| author | Matthias Melcher <github@matthiasm.com> | 2024-08-18 14:40:43 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2024-08-18 14:42:21 +0200 |
| commit | 5ad07b7b4bc18c7565202d21118a78cbad242927 (patch) | |
| tree | 9214eb513079bff890aad398c44d94e2d368bc7c /src/fl_overlay.cxx | |
| parent | afc2072878a422c10815ab7b2f20da4e4052b68c (diff) | |
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.
Diffstat (limited to 'src/fl_overlay.cxx')
| -rw-r--r-- | src/fl_overlay.cxx | 18 |
1 files changed, 16 insertions, 2 deletions
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(); } |
