[gimp] app: add gimp_image_pick_vectors(), remove gimp_draw_tool_on_vectors()



commit 96b80230914275ea312a5e84ac4a68cb18f1e0f6
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jun 22 11:35:57 2017 +0200

    app: add gimp_image_pick_vectors(), remove gimp_draw_tool_on_vectors()

 app/core/gimpimage-pick-item.c |   53 ++++++++++++++++++++++++
 app/core/gimpimage-pick-item.h |    6 +++
 app/tools/gimpaligntool.c      |   46 +++++++++------------
 app/tools/gimpdrawtool.c       |   88 ----------------------------------------
 app/tools/gimpdrawtool.h       |    6 ---
 app/tools/gimpmovetool.c       |   29 ++++++++-----
 app/tools/gimpvectortool.c     |   12 ++++--
 7 files changed, 103 insertions(+), 137 deletions(-)
---
diff --git a/app/core/gimpimage-pick-item.c b/app/core/gimpimage-pick-item.c
index 330211d..5e06f04 100644
--- a/app/core/gimpimage-pick-item.c
+++ b/app/core/gimpimage-pick-item.c
@@ -34,6 +34,9 @@
 
 #include "text/gimptextlayer.h"
 
+#include "vectors/gimpstroke.h"
+#include "vectors/gimpvectors.h"
+
 
 GimpLayer *
 gimp_image_pick_layer (GimpImage *image,
@@ -156,6 +159,56 @@ gimp_image_pick_text_layer (GimpImage *image,
   return NULL;
 }
 
+GimpVectors *
+gimp_image_pick_vectors (GimpImage *image,
+                         gdouble    x,
+                         gdouble    y,
+                         gdouble    epsilon_x,
+                         gdouble    epsilon_y)
+{
+  GimpVectors *ret = NULL;
+  GList       *all_vectors;
+  GList       *list;
+  gdouble      mindist = G_MAXDOUBLE;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  all_vectors = gimp_image_get_vectors_list (image);
+
+  for (list = all_vectors; list; list = g_list_next (list))
+    {
+      GimpVectors *vectors = list->data;
+
+      if (gimp_item_is_visible (GIMP_ITEM (vectors)))
+        {
+          GimpStroke *stroke = NULL;
+          GimpCoords  coords = GIMP_COORDS_DEFAULT_VALUES;
+
+          while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
+            {
+              gdouble dist;
+
+              coords.x = x;
+              coords.y = y;
+
+              dist = gimp_stroke_nearest_point_get (stroke, &coords, 1.0,
+                                                    NULL, NULL, NULL, NULL);
+
+              if (dist >= 0.0 &&
+                  dist <  MIN (epsilon_y, mindist))
+                {
+                  mindist = dist;
+                  ret     = vectors;
+                }
+            }
+        }
+    }
+
+  g_list_free (all_vectors);
+
+  return ret;
+}
+
 GimpGuide *
 gimp_image_pick_guide (GimpImage *image,
                        gdouble    x,
diff --git a/app/core/gimpimage-pick-item.h b/app/core/gimpimage-pick-item.h
index e97fbc9..1c0f533 100644
--- a/app/core/gimpimage-pick-item.h
+++ b/app/core/gimpimage-pick-item.h
@@ -29,6 +29,12 @@ GimpTextLayer   * gimp_image_pick_text_layer      (GimpImage *image,
                                                    gint       x,
                                                    gint       y);
 
+GimpVectors     * gimp_image_pick_vectors         (GimpImage *image,
+                                                   gdouble    x,
+                                                   gdouble    y,
+                                                   gdouble    epsilon_x,
+                                                   gdouble    epsilon_y);
+
 GimpGuide       * gimp_image_pick_guide           (GimpImage *image,
                                                    gdouble    x,
                                                    gdouble    y,
diff --git a/app/tools/gimpaligntool.c b/app/tools/gimpaligntool.c
index 674444d..d5c79bb 100644
--- a/app/tools/gimpaligntool.c
+++ b/app/tools/gimpaligntool.c
@@ -283,10 +283,10 @@ gimp_align_tool_button_release (GimpTool              *tool,
       GimpLayer   *layer;
       gint         snap_distance = display->config->snap_distance;
 
-      vectors = gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
-                                           coords,
-                                           snap_distance, snap_distance);
-      if (vectors)
+      if ((vectors = gimp_image_pick_vectors (image,
+                                              coords->x, coords->y,
+                                              FUNSCALEX (shell, snap_distance),
+                                              FUNSCALEY (shell, snap_distance))))
         {
           object = G_OBJECT (vectors);
         }
@@ -298,13 +298,10 @@ gimp_align_tool_button_release (GimpTool              *tool,
         {
           object = G_OBJECT (guide);
         }
-      else
+      else if ((layer = gimp_image_pick_layer_by_bounds (image,
+                                                         coords->x, coords->y)))
         {
-          if ((layer = gimp_image_pick_layer_by_bounds (image,
-                                                        coords->x, coords->y)))
-            {
-              object = G_OBJECT (layer);
-            }
+          object = G_OBJECT (layer);
         }
 
       if (object)
@@ -433,8 +430,10 @@ gimp_align_tool_oper_update (GimpTool         *tool,
   add = ((state & gimp_get_extend_selection_mask ()) &&
          align_tool->selected_objects);
 
-  if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
-                                 coords, snap_distance, snap_distance))
+  if (gimp_image_pick_vectors (image,
+                               coords->x, coords->y,
+                               FUNSCALEX (shell, snap_distance),
+                               FUNSCALEY (shell, snap_distance)))
     {
       if (add)
         align_tool->function = ALIGN_TOOL_ADD_PATH;
@@ -452,23 +451,16 @@ gimp_align_tool_oper_update (GimpTool         *tool,
       else
         align_tool->function = ALIGN_TOOL_PICK_GUIDE;
     }
-  else
+  else if (gimp_image_pick_layer_by_bounds (image, coords->x, coords->y))
     {
-      GimpLayer *layer;
-
-      layer = gimp_image_pick_layer_by_bounds (image, coords->x, coords->y);
-
-      if (layer)
-        {
-          if (add)
-            align_tool->function = ALIGN_TOOL_ADD_LAYER;
-          else
-            align_tool->function = ALIGN_TOOL_PICK_LAYER;
-        }
+      if (add)
+        align_tool->function = ALIGN_TOOL_ADD_LAYER;
       else
-        {
-          align_tool->function = ALIGN_TOOL_IDLE;
-        }
+        align_tool->function = ALIGN_TOOL_PICK_LAYER;
+    }
+  else
+    {
+      align_tool->function = ALIGN_TOOL_IDLE;
     }
 
   gimp_align_tool_status_update (tool, display, state, proximity);
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index 1c8838e..db321a7 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -29,10 +29,6 @@
 #include "core/gimpdrawable.h"
 #include "core/gimpimage.h"
 
-#include "vectors/gimpanchor.h"
-#include "vectors/gimpstroke.h"
-#include "vectors/gimpvectors.h"
-
 #include "display/gimpcanvas.h"
 #include "display/gimpcanvasarc.h"
 #include "display/gimpcanvasboundary.h"
@@ -1021,87 +1017,3 @@ gimp_draw_tool_on_handle (GimpDrawTool     *draw_tool,
 
   return FALSE;
 }
-
-static gboolean
-gimp_draw_tool_on_vectors_curve (GimpDrawTool     *draw_tool,
-                                 GimpDisplay      *display,
-                                 GimpVectors      *vectors,
-                                 const GimpCoords *coords,
-                                 gint              width,
-                                 gint              height)
-{
-  GimpStroke *stroke     = NULL;
-  GimpCoords  min_coords = GIMP_COORDS_DEFAULT_VALUES;
-  GimpCoords  cur_coords;
-  gdouble     min_dist   = -1;
-  gdouble     cur_dist;
-  gdouble     cur_pos;
-
-  while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
-    {
-      cur_dist = gimp_stroke_nearest_point_get (stroke, coords, 1.0,
-                                                &cur_coords,
-                                                NULL, NULL,
-                                                &cur_pos);
-
-      if (cur_dist >= 0.0 && (min_dist < 0.0 || cur_dist < min_dist))
-        {
-          min_dist   = cur_dist;
-          min_coords = cur_coords;
-        }
-    }
-
-  if (min_dist >= 0 &&
-      gimp_draw_tool_on_handle (draw_tool, display,
-                                coords->x,
-                                coords->y,
-                                GIMP_HANDLE_CIRCLE,
-                                min_coords.x,
-                                min_coords.y,
-                                width, height,
-                                GIMP_HANDLE_ANCHOR_CENTER))
-    {
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-GimpVectors *
-gimp_draw_tool_on_vectors (GimpDrawTool      *draw_tool,
-                           GimpDisplay       *display,
-                           const GimpCoords  *coords,
-                           gint               width,
-                           gint               height)
-{
-  GList *all_vectors;
-  GList *list;
-
-  g_return_val_if_fail (GIMP_IS_DRAW_TOOL (draw_tool), NULL);
-  g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
-  g_return_val_if_fail (coords != NULL, NULL);
-
-  all_vectors = gimp_image_get_vectors_list (gimp_display_get_image (display));
-
-  for (list = all_vectors; list; list = g_list_next (list))
-    {
-      GimpVectors *vectors = list->data;
-
-      if (! gimp_item_get_visible (GIMP_ITEM (vectors)))
-        continue;
-
-      if (gimp_draw_tool_on_vectors_curve (draw_tool,
-                                           display,
-                                           vectors, coords,
-                                           width, height))
-        {
-          g_list_free (all_vectors);
-
-          return vectors;
-        }
-    }
-
-  g_list_free (all_vectors);
-
-  return NULL;
-}
diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h
index 78efcd1..a5eee94 100644
--- a/app/tools/gimpdrawtool.h
+++ b/app/tools/gimpdrawtool.h
@@ -211,11 +211,5 @@ gboolean         gimp_draw_tool_on_handle            (GimpDrawTool     *draw_too
                                                       gint              height,
                                                       GimpHandleAnchor  anchor);
 
-GimpVectors    * gimp_draw_tool_on_vectors           (GimpDrawTool     *draw_tool,
-                                                      GimpDisplay      *display,
-                                                      const GimpCoords *coord,
-                                                      gint              width,
-                                                      gint              height);
-
 
 #endif  /*  __GIMP_DRAW_TOOL_H__  */
diff --git a/app/tools/gimpmovetool.c b/app/tools/gimpmovetool.c
index 1e22788..0868067 100644
--- a/app/tools/gimpmovetool.c
+++ b/app/tools/gimpmovetool.c
@@ -175,12 +175,16 @@ gimp_move_tool_button_press (GimpTool            *tool,
 
   if (! options->move_current)
     {
+      const gint snap_distance = display->config->snap_distance;
+
       if (options->move_type == GIMP_TRANSFORM_TYPE_PATH)
         {
           GimpVectors *vectors;
 
-          vectors = gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
-                                               coords, 7, 7);
+          vectors = gimp_image_pick_vectors (image,
+                                             coords->x, coords->y,
+                                             FUNSCALEX (shell, snap_distance),
+                                             FUNSCALEY (shell, snap_distance));
           if (vectors)
             {
               move->old_active_vectors =
@@ -198,7 +202,6 @@ gimp_move_tool_button_press (GimpTool            *tool,
         {
           GimpGuide  *guide;
           GimpLayer  *layer;
-          const gint  snap_distance = display->config->snap_distance;
 
           if (gimp_display_shell_get_show_guides (shell) &&
               (guide = gimp_image_pick_guide (image,
@@ -516,12 +519,13 @@ gimp_move_tool_cursor_update (GimpTool         *tool,
                               GdkModifierType   state,
                               GimpDisplay      *display)
 {
-  GimpMoveOptions    *options     = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
-  GimpDisplayShell   *shell       = gimp_display_get_shell (display);
-  GimpImage          *image       = gimp_display_get_image (display);
-  GimpCursorType      cursor      = GIMP_CURSOR_MOUSE;
-  GimpToolCursorType  tool_cursor = GIMP_TOOL_CURSOR_MOVE;
-  GimpCursorModifier  modifier    = GIMP_CURSOR_MODIFIER_NONE;
+  GimpMoveOptions    *options       = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
+  GimpDisplayShell   *shell         = gimp_display_get_shell (display);
+  GimpImage          *image         = gimp_display_get_image (display);
+  GimpCursorType      cursor        = GIMP_CURSOR_MOUSE;
+  GimpToolCursorType  tool_cursor   = GIMP_TOOL_CURSOR_MOVE;
+  GimpCursorModifier  modifier      = GIMP_CURSOR_MODIFIER_NONE;
+  gint                snap_distance = display->config->snap_distance;
 
   if (options->move_type == GIMP_TRANSFORM_TYPE_PATH)
     {
@@ -537,8 +541,10 @@ gimp_move_tool_cursor_update (GimpTool         *tool,
         }
       else
         {
-          if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
-                                         coords, 7, 7))
+          if (gimp_image_pick_vectors (image,
+                                       coords->x, coords->y,
+                                       FUNSCALEX (shell, snap_distance),
+                                       FUNSCALEY (shell, snap_distance)))
             {
               tool_cursor = GIMP_TOOL_CURSOR_HAND;
             }
@@ -566,7 +572,6 @@ gimp_move_tool_cursor_update (GimpTool         *tool,
   else
     {
       GimpLayer  *layer;
-      const gint  snap_distance = display->config->snap_distance;
 
       if (gimp_display_shell_get_show_guides (shell) &&
           gimp_image_pick_guide (image, coords->x, coords->y,
diff --git a/app/tools/gimpvectortool.c b/app/tools/gimpvectortool.c
index eda26bf..865c13d 100644
--- a/app/tools/gimpvectortool.c
+++ b/app/tools/gimpvectortool.c
@@ -32,6 +32,7 @@
 
 #include "core/gimp.h"
 #include "core/gimpimage.h"
+#include "core/gimpimage-pick-item.h"
 #include "core/gimpimage-undo.h"
 #include "core/gimpimage-undo-push.h"
 #include "core/gimptoolinfo.h"
@@ -403,6 +404,7 @@ gimp_vector_tool_cursor_update (GimpTool         *tool,
                                 GimpDisplay      *display)
 {
   GimpVectorTool     *vector_tool = GIMP_VECTOR_TOOL (tool);
+  GimpDisplayShell   *shell       = gimp_display_get_shell (display);
   GimpToolCursorType  tool_cursor = GIMP_TOOL_CURSOR_PATHS;
   GimpCursorModifier  modifier    = GIMP_CURSOR_MODIFIER_NONE;
 
@@ -412,10 +414,12 @@ gimp_vector_tool_cursor_update (GimpTool         *tool,
                                    coords, state,
                                    NULL, &tool_cursor, &modifier);
     }
-  else if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
-                                      coords,
-                                      GIMP_TOOL_HANDLE_SIZE_CIRCLE,
-                                      GIMP_TOOL_HANDLE_SIZE_CIRCLE))
+  else if (gimp_image_pick_vectors (gimp_display_get_image (display),
+                                    coords->x, coords->y,
+                                    FUNSCALEX (shell,
+                                               GIMP_TOOL_HANDLE_SIZE_CIRCLE / 2),
+                                    FUNSCALEY (shell,
+                                               GIMP_TOOL_HANDLE_SIZE_CIRCLE / 2)))
     {
       tool_cursor = GIMP_TOOL_CURSOR_HAND;
     }


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