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().
This commit is contained in:
Michael Natterer
2015-07-02 01:53:46 +02:00
parent 2ed749fd26
commit af1e86827f
3 changed files with 51 additions and 37 deletions

View File

@ -265,15 +265,14 @@ selection_draw (Selection *selection)
static void static void
selection_undraw (Selection *selection) selection_undraw (Selection *selection)
{ {
gint x1, y1, x2, y2; gint x, y, w, h;
selection_stop (selection); 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 */ /* expose will restart the selection */
gimp_display_shell_expose_area (selection->shell, gimp_display_shell_expose_area (selection->shell, x, y, w, h);
x1, y1, (x2 - x1), (y2 - y1));
} }
else else
{ {

View File

@ -1752,65 +1752,80 @@ gimp_display_shell_snap_coords (GimpDisplayShell *shell,
gboolean gboolean
gimp_display_shell_mask_bounds (GimpDisplayShell *shell, gimp_display_shell_mask_bounds (GimpDisplayShell *shell,
gint *x1, gint *x,
gint *y1, gint *y,
gint *x2, gint *width,
gint *y2) gint *height)
{ {
GimpImage *image; GimpImage *image;
GimpLayer *layer; GimpLayer *layer;
gint x1, y1;
gint x2, y2;
gdouble x1_f, y1_f; gdouble x1_f, y1_f;
gdouble x2_f, y2_f; gdouble x2_f, y2_f;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE); g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
g_return_val_if_fail (x1 != NULL, FALSE); g_return_val_if_fail (x != NULL, FALSE);
g_return_val_if_fail (y1 != NULL, FALSE); g_return_val_if_fail (y != NULL, FALSE);
g_return_val_if_fail (x2 != NULL, FALSE); g_return_val_if_fail (width != NULL, FALSE);
g_return_val_if_fail (y2 != NULL, FALSE); g_return_val_if_fail (height != NULL, FALSE);
image = gimp_display_get_image (shell->display); image = gimp_display_get_image (shell->display);
/* If there is a floating selection, handle things differently */ /* If there is a floating selection, handle things differently */
if ((layer = gimp_image_get_floating_selection (image))) if ((layer = gimp_image_get_floating_selection (image)))
{ {
gint off_x; gint fs_x;
gint off_y; 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), if (! gimp_item_bounds (GIMP_ITEM (gimp_image_get_mask (image)),
x1, y1, x2, y2)) x, y, width, height))
{ {
*x1 = off_x; *x = fs_x;
*y1 = off_y; *y = fs_y;
*x2 = off_x + gimp_item_get_width (GIMP_ITEM (layer)); *width = fs_width;
*y2 = off_y + gimp_item_get_height (GIMP_ITEM (layer)); *height = fs_height;
} }
else else
{ {
*x1 = MIN (off_x, *x1); gimp_rectangle_union (*x, *y, *width, *height,
*y1 = MIN (off_y, *y1); fs_x, fs_y, fs_width, fs_height,
*x2 = MAX (off_x + gimp_item_get_width (GIMP_ITEM (layer)), *x2); x, y, width, height);
*y2 = MAX (off_y + gimp_item_get_height (GIMP_ITEM (layer)), *y2);
} }
} }
else if (! gimp_channel_bounds (gimp_image_get_mask (image), else if (! gimp_item_bounds (GIMP_ITEM (gimp_image_get_mask (image)),
x1, y1, x2, y2)) x, y, width, height))
{ {
return FALSE; return FALSE;
} }
x1 = *x;
y1 = *y;
x2 = *x + *width;
y2 = *y + *height;
gimp_display_shell_transform_bounds (shell, gimp_display_shell_transform_bounds (shell,
*x1, *y1, *x2, *y2, x1, y1, x2, y2,
&x1_f, &y1_f, &x2_f, &y2_f); &x1_f, &y1_f, &x2_f, &y2_f);
/* Make sure the extents are within bounds */ /* Make sure the extents are within bounds */
*x1 = CLAMP (floor (x1_f), 0, shell->disp_width); x1 = CLAMP (floor (x1_f), 0, shell->disp_width);
*y1 = CLAMP (floor (y1_f), 0, shell->disp_height); y1 = CLAMP (floor (y1_f), 0, shell->disp_height);
*x2 = CLAMP (ceil (x2_f), 0, shell->disp_width); x2 = CLAMP (ceil (x2_f), 0, shell->disp_width);
*y2 = CLAMP (ceil (y2_f), 0, shell->disp_height); 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 void

View File

@ -276,10 +276,10 @@ gboolean gimp_display_shell_snap_coords (GimpDisplayShell *shell,
gint snap_height); gint snap_height);
gboolean gimp_display_shell_mask_bounds (GimpDisplayShell *shell, gboolean gimp_display_shell_mask_bounds (GimpDisplayShell *shell,
gint *x1, gint *x,
gint *y1, gint *y,
gint *x2, gint *width,
gint *y2); gint *height);
void gimp_display_shell_flush (GimpDisplayShell *shell, void gimp_display_shell_flush (GimpDisplayShell *shell,
gboolean now); gboolean now);