From af1e86827ff1374d1b8be033cb10bc836a28e000 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 2 Jul 2015 01:53:46 +0200 Subject: [PATCH] app: make gimp_display_shell_mask_bounds() use x, y, width, height instead of x1, y1, x2, y2, and use gimp_item_bounds() instead of gimp_channel_bounds(). --- app/display/gimpdisplayshell-selection.c | 7 +-- app/display/gimpdisplayshell.c | 73 ++++++++++++++---------- app/display/gimpdisplayshell.h | 8 +-- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/app/display/gimpdisplayshell-selection.c b/app/display/gimpdisplayshell-selection.c index 172c01453b..774758196a 100644 --- a/app/display/gimpdisplayshell-selection.c +++ b/app/display/gimpdisplayshell-selection.c @@ -265,15 +265,14 @@ selection_draw (Selection *selection) static void selection_undraw (Selection *selection) { - gint x1, y1, x2, y2; + gint x, y, w, h; selection_stop (selection); - if (gimp_display_shell_mask_bounds (selection->shell, &x1, &y1, &x2, &y2)) + if (gimp_display_shell_mask_bounds (selection->shell, &x, &y, &w, &h)) { /* expose will restart the selection */ - gimp_display_shell_expose_area (selection->shell, - x1, y1, (x2 - x1), (y2 - y1)); + gimp_display_shell_expose_area (selection->shell, x, y, w, h); } else { diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 033bddc543..6dc404d098 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -1752,65 +1752,80 @@ gimp_display_shell_snap_coords (GimpDisplayShell *shell, gboolean gimp_display_shell_mask_bounds (GimpDisplayShell *shell, - gint *x1, - gint *y1, - gint *x2, - gint *y2) + gint *x, + gint *y, + gint *width, + gint *height) { GimpImage *image; GimpLayer *layer; + gint x1, y1; + gint x2, y2; gdouble x1_f, y1_f; gdouble x2_f, y2_f; g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE); - g_return_val_if_fail (x1 != NULL, FALSE); - g_return_val_if_fail (y1 != NULL, FALSE); - g_return_val_if_fail (x2 != NULL, FALSE); - g_return_val_if_fail (y2 != NULL, FALSE); + g_return_val_if_fail (x != NULL, FALSE); + g_return_val_if_fail (y != NULL, FALSE); + g_return_val_if_fail (width != NULL, FALSE); + g_return_val_if_fail (height != NULL, FALSE); image = gimp_display_get_image (shell->display); /* If there is a floating selection, handle things differently */ if ((layer = gimp_image_get_floating_selection (image))) { - gint off_x; - gint off_y; + gint fs_x; + gint fs_y; + gint fs_width; + gint fs_height; - gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y); + gimp_item_get_offset (GIMP_ITEM (layer), &fs_x, &fs_y); + fs_width = gimp_item_get_width (GIMP_ITEM (layer)); + fs_height = gimp_item_get_height (GIMP_ITEM (layer)); - if (! gimp_channel_bounds (gimp_image_get_mask (image), - x1, y1, x2, y2)) + if (! gimp_item_bounds (GIMP_ITEM (gimp_image_get_mask (image)), + x, y, width, height)) { - *x1 = off_x; - *y1 = off_y; - *x2 = off_x + gimp_item_get_width (GIMP_ITEM (layer)); - *y2 = off_y + gimp_item_get_height (GIMP_ITEM (layer)); + *x = fs_x; + *y = fs_y; + *width = fs_width; + *height = fs_height; } else { - *x1 = MIN (off_x, *x1); - *y1 = MIN (off_y, *y1); - *x2 = MAX (off_x + gimp_item_get_width (GIMP_ITEM (layer)), *x2); - *y2 = MAX (off_y + gimp_item_get_height (GIMP_ITEM (layer)), *y2); + gimp_rectangle_union (*x, *y, *width, *height, + fs_x, fs_y, fs_width, fs_height, + x, y, width, height); } } - else if (! gimp_channel_bounds (gimp_image_get_mask (image), - x1, y1, x2, y2)) + else if (! gimp_item_bounds (GIMP_ITEM (gimp_image_get_mask (image)), + x, y, width, height)) { return FALSE; } + x1 = *x; + y1 = *y; + x2 = *x + *width; + y2 = *y + *height; + gimp_display_shell_transform_bounds (shell, - *x1, *y1, *x2, *y2, + x1, y1, x2, y2, &x1_f, &y1_f, &x2_f, &y2_f); /* Make sure the extents are within bounds */ - *x1 = CLAMP (floor (x1_f), 0, shell->disp_width); - *y1 = CLAMP (floor (y1_f), 0, shell->disp_height); - *x2 = CLAMP (ceil (x2_f), 0, shell->disp_width); - *y2 = CLAMP (ceil (y2_f), 0, shell->disp_height); + x1 = CLAMP (floor (x1_f), 0, shell->disp_width); + y1 = CLAMP (floor (y1_f), 0, shell->disp_height); + x2 = CLAMP (ceil (x2_f), 0, shell->disp_width); + y2 = CLAMP (ceil (y2_f), 0, shell->disp_height); - return ((*x2 - *x1) > 0) && ((*y2 - *y1) > 0); + *x = x1; + *y = y1; + *width = x2 - x1; + *height = y2 - y1; + + return (*width > 0) && (*height > 0); } void diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index b62107257e..305ec82eb9 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -276,10 +276,10 @@ gboolean gimp_display_shell_snap_coords (GimpDisplayShell *shell, gint snap_height); gboolean gimp_display_shell_mask_bounds (GimpDisplayShell *shell, - gint *x1, - gint *y1, - gint *x2, - gint *y2); + gint *x, + gint *y, + gint *width, + gint *height); void gimp_display_shell_flush (GimpDisplayShell *shell, gboolean now);