[gimp] app: fix conditions for guide and sample point moving/removing



commit 62c5a737fd53457c85a4c4bd7acee06638138671
Author: Michael Natterer <mitch gimp org>
Date:   Thu Apr 25 09:30:46 2013 +0200

    app: fix conditions for guide and sample point moving/removing
    
    Simply check the transfomred coords against the canvas extents and the
    untransformed against the image contents instead of using
    untransform_viewport(). The code is easier to read now, and
    untransform_viewport() is still broken and can't really be implemented
    properly when the canvas is rotated.

 app/tools/gimpcolortool.c |   32 ++++++++++++++++----------------
 app/tools/gimpmovetool.c  |   30 +++++++++++++++---------------
 2 files changed, 31 insertions(+), 31 deletions(-)
---
diff --git a/app/tools/gimpcolortool.c b/app/tools/gimpcolortool.c
index 74d406f..78bb291 100644
--- a/app/tools/gimpcolortool.c
+++ b/app/tools/gimpcolortool.c
@@ -255,7 +255,6 @@ gimp_color_tool_button_release (GimpTool              *tool,
 {
   GimpColorTool    *color_tool = GIMP_COLOR_TOOL (tool);
   GimpDisplayShell *shell      = gimp_display_get_shell (display);
-  GimpImage        *image      = gimp_display_get_image (display);
 
   /*  Chain up to halt the tool  */
   GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
@@ -266,7 +265,9 @@ gimp_color_tool_button_release (GimpTool              *tool,
 
   if (color_tool->moving_sample_point)
     {
-      gint x, y, width, height;
+      GimpImage *image  = gimp_display_get_image (display);
+      gint       width  = gimp_image_get_width  (image);
+      gint       height = gimp_image_get_height (image);
 
       gimp_tool_pop_status (tool, display);
 
@@ -283,12 +284,12 @@ gimp_color_tool_button_release (GimpTool              *tool,
           return;
         }
 
-      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
-
-      if ((color_tool->sample_point_x <  x              ||
-           color_tool->sample_point_x > (x + width - 1) ||
-           color_tool->sample_point_y < y               ||
-           color_tool->sample_point_y > (y + height - 1)))
+      if (color_tool->sample_point_x == SAMPLE_POINT_POSITION_INVALID ||
+          color_tool->sample_point_x <  0                             ||
+          color_tool->sample_point_x >= width                         ||
+          color_tool->sample_point_y == SAMPLE_POINT_POSITION_INVALID ||
+          color_tool->sample_point_y <  0                             ||
+          color_tool->sample_point_y >= height)
         {
           if (color_tool->sample_point)
             {
@@ -367,18 +368,17 @@ gimp_color_tool_motion (GimpTool         *tool,
         }
       else
         {
-          gint x, y, width, height;
+          GimpImage *image  = gimp_display_get_image (display);
+          gint       width  = gimp_image_get_width  (image);
+          gint       height = gimp_image_get_height (image);
 
           color_tool->sample_point_x = floor (coords->x);
           color_tool->sample_point_y = floor (coords->y);
 
-          gimp_display_shell_untransform_viewport (shell, &x, &y,
-                                                   &width, &height);
-
-          if ((color_tool->sample_point_x <  x              ||
-               color_tool->sample_point_x > (x + width - 1) ||
-               color_tool->sample_point_y < y               ||
-               color_tool->sample_point_y > (y + height - 1)))
+          if (color_tool->sample_point_x <  0     ||
+              color_tool->sample_point_x >= width ||
+              color_tool->sample_point_y <  0     ||
+              color_tool->sample_point_y >= height)
             {
               delete_point = TRUE;
             }
diff --git a/app/tools/gimpmovetool.c b/app/tools/gimpmovetool.c
index e71daf0..f9320d0 100644
--- a/app/tools/gimpmovetool.c
+++ b/app/tools/gimpmovetool.c
@@ -409,7 +409,8 @@ gimp_move_tool_button_release (GimpTool              *tool,
   if (move->moving_guide)
     {
       gboolean delete_guide = FALSE;
-      gint     x, y, width, height;
+      gint     width  = gimp_image_get_width  (image);
+      gint     height = gimp_image_get_height (image);
 
       gimp_tool_pop_status (tool, display);
 
@@ -429,19 +430,19 @@ gimp_move_tool_button_release (GimpTool              *tool,
           return;
         }
 
-      gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
-
       switch (move->guide_orientation)
         {
         case GIMP_ORIENTATION_HORIZONTAL:
-          if ((move->guide_position < y) ||
-              (move->guide_position > (y + height)))
+          if (move->guide_position == GUIDE_POSITION_INVALID ||
+              move->guide_position <  0                      ||
+              move->guide_position >= height)
             delete_guide = TRUE;
           break;
 
         case GIMP_ORIENTATION_VERTICAL:
-          if ((move->guide_position < x) ||
-              (move->guide_position > (x + width)))
+          if (move->guide_position == GUIDE_POSITION_INVALID ||
+              move->guide_position <  0                      ||
+              move->guide_position >= width)
             delete_guide = TRUE;
           break;
 
@@ -566,27 +567,26 @@ gimp_move_tool_motion (GimpTool         *tool,
         }
       else
         {
-          gint x, y, width, height;
+          GimpImage *image  = gimp_display_get_image (display);
+          gint       width  = gimp_image_get_width  (image);
+          gint       height = gimp_image_get_height (image);
 
           if (move->guide_orientation == GIMP_ORIENTATION_HORIZONTAL)
             move->guide_position = RINT (coords->y);
           else
             move->guide_position = RINT (coords->x);
 
-          gimp_display_shell_untransform_viewport (shell, &x, &y,
-                                                   &width, &height);
-
           switch (move->guide_orientation)
             {
             case GIMP_ORIENTATION_HORIZONTAL:
-              if ((move->guide_position < y) ||
-                  (move->guide_position > (y + height)))
+              if (move->guide_position <  0 ||
+                  move->guide_position >= height)
                 delete_guide = TRUE;
               break;
 
             case GIMP_ORIENTATION_VERTICAL:
-              if ((move->guide_position < x) ||
-                  (move->guide_position > (x + width)))
+              if (move->guide_position <  0 ||
+                  move->guide_position >= width)
                 delete_guide = TRUE;
               break;
 


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