From b75b7de0647d1ab63e4b1465dcdcbfb2cea86b0a Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 10 Apr 2011 03:46:02 +0200 Subject: [PATCH] app: fix drawing artifacts in GimpCanvasRectangle The width/height returned by gimp_canvas_rectangle_transform() were off-by-one if the rectangle's width/height were exactly 0.0 and its x/y exact integers, causing too much drawing and/or too little invalidation. --- app/display/gimpcanvasrectangle.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/display/gimpcanvasrectangle.c b/app/display/gimpcanvasrectangle.c index 114eb636f8..6381101fc2 100644 --- a/app/display/gimpcanvasrectangle.c +++ b/app/display/gimpcanvasrectangle.c @@ -206,36 +206,43 @@ gimp_canvas_rectangle_transform (GimpCanvasItem *item, gdouble *h) { GimpCanvasRectanglePrivate *private = GET_PRIVATE (item); + gdouble x1, y1; + gdouble x2, y2; gimp_display_shell_transform_xy_f (shell, MIN (private->x, private->x + private->width), MIN (private->y, private->y + private->height), - x, y); + &x1, &y1); gimp_display_shell_transform_xy_f (shell, MAX (private->x, private->x + private->width), MAX (private->y, private->y + private->height), - w, h); + &x2, &y2); - *w -= *x; - *h -= *y; + x1 = floor (x1); + y1 = floor (y1); + x2 = ceil (x2); + y2 = ceil (y2); if (private->filled) { - *x = floor (*x); - *y = floor (*y); - *w = ceil (*w); - *h = ceil (*h); + *x = x1; + *y = y1; + *w = x2 - x1; + *h = y2 - y1; } else { - *x = floor (*x) + 0.5; - *y = floor (*y) + 0.5; - *w = ceil (*w) - 1.0; - *h = ceil (*h) - 1.0; + *x = x1 + 0.5; + *y = y1 + 0.5; + *w = x2 - 0.5 - *x; + *h = y2 - 0.5 - *y; + + *w = MAX (0.0, *w); + *h = MAX (0.0, *h); } }