[gimp] app: gimp_rectangle_tool_auto_shrink(): honor the drawable's offset



commit b26216f1d3600bf596ee82c23ef273f3b60ebf4d
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jan 14 21:28:34 2012 +0100

    app: gimp_rectangle_tool_auto_shrink(): honor the drawable's offset

 app/tools/gimprectangletool.c |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/app/tools/gimprectangletool.c b/app/tools/gimprectangletool.c
index b299011..666d53a 100644
--- a/app/tools/gimprectangletool.c
+++ b/app/tools/gimprectangletool.c
@@ -2502,8 +2502,6 @@ gimp_rectangle_tool_auto_shrink (GimpRectangleTool *rect_tool)
   GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
   GimpDisplay              *display = tool->display;
   GimpImage                *image;
-  gint                      width;
-  gint                      height;
   gint                      offset_x = 0;
   gint                      offset_y = 0;
   gint                      x1, y1;
@@ -2519,17 +2517,32 @@ gimp_rectangle_tool_auto_shrink (GimpRectangleTool *rect_tool)
 
   image = gimp_display_get_image (display);
 
-  width  = gimp_image_get_width  (image);
-  height = gimp_image_get_height (image);
-
   g_object_get (gimp_tool_get_options (tool),
                 "shrink-merged", &shrink_merged,
                 NULL);
 
-  x1 = private->x1 - offset_x  > 0      ? private->x1 - offset_x : 0;
-  x2 = private->x2 - offset_x  < width  ? private->x2 - offset_x : width;
-  y1 = private->y1 - offset_y  > 0      ? private->y1 - offset_y : 0;
-  y2 = private->y2 - offset_y  < height ? private->y2 - offset_y : height;
+  if (shrink_merged)
+    {
+      x1 = MAX (private->x1, 0);
+      y1 = MAX (private->y1, 0);
+      x2 = MIN (private->x2, gimp_image_get_width  (image));
+      y2 = MIN (private->y2, gimp_image_get_height (image));
+    }
+  else
+    {
+      GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+      GimpItem     *item     = GIMP_ITEM (drawable);
+
+      if (! drawable)
+        return;
+
+      gimp_item_get_offset (item, &offset_x, &offset_y);
+
+      x1 = MAX (private->x1 - offset_x, 0);
+      y1 = MAX (private->y1 - offset_y, 0);
+      x2 = MIN (private->x2 - offset_x, gimp_item_get_width  (item));
+      y2 = MIN (private->y2 - offset_y, gimp_item_get_height (item));
+    }
 
   if (gimp_image_crop_auto_shrink (image,
                                    x1, y1, x2, y2,
@@ -2545,9 +2558,9 @@ gimp_rectangle_tool_auto_shrink (GimpRectangleTool *rect_tool)
       private->function = GIMP_RECTANGLE_TOOL_AUTO_SHRINK;
 
       private->x1 = offset_x + shrunk_x1;
-      private->y1 = offset_x + shrunk_y1;
+      private->y1 = offset_y + shrunk_y1;
       private->x2 = offset_x + shrunk_x2;
-      private->y2 = offset_x + shrunk_y2;
+      private->y2 = offset_y + shrunk_y2;
 
       gimp_rectangle_tool_update_int_rect (rect_tool);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]