mirror of
https://github.com/fltk/fltk.git
synced 2026-05-25 17:42:14 +08:00
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.
This commit is contained in:
+16
-2
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user