[gimp/soc-2012-unified-transformation: 40/51] transformtool: Add a pick_function method to the TransformTool class and remove some more hack dupli



commit 501c15f910eab8dd9b05c0de667fa9287ba86583
Author: Mikael Magnusson <mikachu src gnome org>
Date:   Tue Aug 7 18:45:55 2012 +0200

    transformtool: Add a pick_function method to the TransformTool class and remove some more hack duplication

 app/tools/gimptransformtool.c        |  141 ++++++++++++++++++----------------
 app/tools/gimptransformtool.h        |   36 +++++----
 app/tools/gimpunifiedtransformtool.c |   92 ++++++----------------
 3 files changed, 118 insertions(+), 151 deletions(-)
---
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index d975d8e..59f545d 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -530,83 +530,90 @@ gimp_transform_tool_oper_update (GimpTool         *tool,
       return;
     }
 
-  if (tr_tool->use_handles)
+  if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->pick_function)
     {
-      gdouble closest_dist;
-      gdouble dist;
-
-      dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
-                                                  coords->x, coords->y,
-                                                  tr_tool->tx1, tr_tool->ty1);
-      closest_dist = dist;
-      function = TRANSFORM_HANDLE_NW;
-
-      dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
-                                                  coords->x, coords->y,
-                                                  tr_tool->tx2, tr_tool->ty2);
-      if (dist < closest_dist)
+      function = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->pick_function (tr_tool, coords, state, display);
+    }
+  else
+    {
+      if (tr_tool->use_handles)
         {
-          closest_dist = dist;
-          function = TRANSFORM_HANDLE_NE;
-        }
+            gdouble closest_dist;
+            gdouble dist;
+
+            dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
+                                                        coords->x, coords->y,
+                                                        tr_tool->tx1, tr_tool->ty1);
+            closest_dist = dist;
+            function = TRANSFORM_HANDLE_NW;
+
+            dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
+                                                        coords->x, coords->y,
+                                                        tr_tool->tx2, tr_tool->ty2);
+            if (dist < closest_dist)
+              {
+                closest_dist = dist;
+                function = TRANSFORM_HANDLE_NE;
+              }
 
-      dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
-                                                  coords->x, coords->y,
-                                                  tr_tool->tx3, tr_tool->ty3);
-      if (dist < closest_dist)
-        {
-          closest_dist = dist;
-          function = TRANSFORM_HANDLE_SW;
-        }
+            dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
+                                                        coords->x, coords->y,
+                                                        tr_tool->tx3, tr_tool->ty3);
+            if (dist < closest_dist)
+              {
+                closest_dist = dist;
+                function = TRANSFORM_HANDLE_SW;
+              }
 
-      dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
-                                                  coords->x, coords->y,
-                                                  tr_tool->tx4, tr_tool->ty4);
-      if (dist < closest_dist)
-        {
-          closest_dist = dist;
-          function = TRANSFORM_HANDLE_SE;
+            dist = gimp_draw_tool_calc_distance_square (draw_tool, display,
+                                                        coords->x, coords->y,
+                                                        tr_tool->tx4, tr_tool->ty4);
+            if (dist < closest_dist)
+              {
+                closest_dist = dist;
+                function = TRANSFORM_HANDLE_SE;
+              }
+
+            if (tr_tool->use_mid_handles)
+              {
+                if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_N],
+                                          coords->x, coords->y))
+                  {
+                    function = TRANSFORM_HANDLE_N;
+                  }
+                else if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_E],
+                                               coords->x, coords->y))
+                  {
+                    function = TRANSFORM_HANDLE_E;
+                  }
+                else if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_S],
+                                               coords->x, coords->y))
+                  {
+                    function = TRANSFORM_HANDLE_S;
+                  }
+                else if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_W],
+                                               coords->x, coords->y))
+                  {
+                    function = TRANSFORM_HANDLE_W;
+                  }
+              }
         }
 
-      if (tr_tool->use_mid_handles)
-        {
-          if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_N],
-                                    coords->x, coords->y))
-            {
-              function = TRANSFORM_HANDLE_N;
-            }
-          else if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_E],
-                                         coords->x, coords->y))
-            {
-              function = TRANSFORM_HANDLE_E;
-            }
-          else if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_S],
-                                         coords->x, coords->y))
-            {
-              function = TRANSFORM_HANDLE_S;
-            }
-          else if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_W],
-                                         coords->x, coords->y))
+          if (tr_tool->use_pivot)
             {
-              function = TRANSFORM_HANDLE_W;
+              if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_PIVOT],
+                                        coords->x, coords->y))
+                {
+                  function = TRANSFORM_HANDLE_PIVOT;
+                }
             }
-        }
-    }
 
-    if (tr_tool->use_pivot)
-      {
-        if (gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_PIVOT],
+        if (tr_tool->use_center &&
+            gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_CENTER],
                                   coords->x, coords->y))
           {
-            function = TRANSFORM_HANDLE_PIVOT;
+            function = TRANSFORM_HANDLE_CENTER;
           }
-      }
-
-  if (tr_tool->use_center &&
-      gimp_canvas_item_hit (tr_tool->handles[TRANSFORM_HANDLE_CENTER],
-                            coords->x, coords->y))
-    {
-      function = TRANSFORM_HANDLE_CENTER;
     }
 
   gimp_transform_tool_set_function (tr_tool, function);
diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h
index 2fdaa06..adbbc0a 100644
--- a/app/tools/gimptransformtool.h
+++ b/app/tools/gimptransformtool.h
@@ -128,22 +128,26 @@ struct _GimpTransformToolClass
   GimpDrawToolClass  parent_class;
 
   /*  virtual functions  */
-  void          (* dialog)        (GimpTransformTool *tool);
-  void          (* dialog_update) (GimpTransformTool *tool);
-  void          (* prepare)       (GimpTransformTool *tool);
-  void          (* motion)        (GimpTransformTool *tool);
-  void          (* recalc_matrix) (GimpTransformTool *tool);
-  gchar       * (* get_undo_desc) (GimpTransformTool *tool);
-  void          (* draw_gui)      (GimpTransformTool *tool,
-                                   gint               handle_w,
-                                   gint               handle_h);
-  GeglBuffer  * (* transform)     (GimpTransformTool *tool,
-                                   GimpItem          *item,
-                                   GeglBuffer        *orig_buffer,
-                                   gint               orig_offset_x,
-                                   gint               orig_offset_y,
-                                   gint              *new_offset_x,
-                                   gint              *new_offset_y);
+  void            (* dialog)        (GimpTransformTool *tool);
+  void            (* dialog_update) (GimpTransformTool *tool);
+  void            (* prepare)       (GimpTransformTool *tool);
+  void            (* motion)        (GimpTransformTool *tool);
+  void            (* recalc_matrix) (GimpTransformTool *tool);
+  gchar         * (* get_undo_desc) (GimpTransformTool *tool);
+  TransformAction (* pick_function) (GimpTransformTool *tool,
+                                     const GimpCoords  *coords,
+                                     GdkModifierType    state,
+                                     GimpDisplay       *display);
+  void            (* draw_gui)      (GimpTransformTool *tool,
+                                     gint               handle_w,
+                                     gint               handle_h);
+  GeglBuffer    * (* transform)     (GimpTransformTool *tool,
+                                     GimpItem          *item,
+                                     GeglBuffer        *orig_buffer,
+                                     gint               orig_offset_x,
+                                     gint               orig_offset_y,
+                                     gint              *new_offset_x,
+                                     gint              *new_offset_y);
 };
 
 
diff --git a/app/tools/gimpunifiedtransformtool.c b/app/tools/gimpunifiedtransformtool.c
index b4946b5..c5a7243 100644
--- a/app/tools/gimpunifiedtransformtool.c
+++ b/app/tools/gimpunifiedtransformtool.c
@@ -68,20 +68,19 @@ enum
 
 /*  local function prototypes  */
 
-static void    gimp_transform_tool_oper_update           (GimpTool              *tool,
-                                                          const GimpCoords      *coords,
-                                                          GdkModifierType        state,
-                                                          gboolean               proximity,
-                                                          GimpDisplay           *display);
-static void    gimp_unified_transform_tool_dialog        (GimpTransformTool *tr_tool);
-static void    gimp_unified_transform_tool_dialog_update (GimpTransformTool *tr_tool);
-static void    gimp_unified_transform_tool_prepare       (GimpTransformTool *tr_tool);
-static void    gimp_unified_transform_tool_motion        (GimpTransformTool *tr_tool);
-static void    gimp_unified_transform_tool_recalc_matrix (GimpTransformTool *tr_tool);
-static gchar * gimp_unified_transform_tool_get_undo_desc (GimpTransformTool *tr_tool);
-static void    gimp_unified_transform_tool_draw_gui      (GimpTransformTool *draw_tool,
-                                                          gint               handle_w,
-                                                          gint               handle_h);
+static void            gimp_unified_transform_tool_dialog        (GimpTransformTool *tr_tool);
+static void            gimp_unified_transform_tool_dialog_update (GimpTransformTool *tr_tool);
+static void            gimp_unified_transform_tool_prepare       (GimpTransformTool *tr_tool);
+static void            gimp_unified_transform_tool_motion        (GimpTransformTool *tr_tool);
+static void            gimp_unified_transform_tool_recalc_matrix (GimpTransformTool *tr_tool);
+static gchar *         gimp_unified_transform_tool_get_undo_desc (GimpTransformTool *tr_tool);
+static TransformAction gimp_unified_transform_tool_pick_function (GimpTransformTool *tr_tool,
+                                                                  const GimpCoords  *coords,
+                                                                  GdkModifierType    state,
+                                                                  GimpDisplay       *display);
+static void            gimp_unified_transform_tool_draw_gui      (GimpTransformTool *tr_tool,
+                                                                  gint               handle_w,
+                                                                  gint               handle_h);
 
 
 G_DEFINE_TYPE (GimpUnifiedTransformTool, gimp_unified_transform_tool,
@@ -110,7 +109,6 @@ static void
 gimp_unified_transform_tool_class_init (GimpUnifiedTransformToolClass *klass)
 {
   GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
-  GimpToolClass          *tool_class  = GIMP_TOOL_CLASS (klass);
 
   trans_class->dialog        = gimp_unified_transform_tool_dialog;
   trans_class->dialog_update = gimp_unified_transform_tool_dialog_update;
@@ -118,9 +116,8 @@ gimp_unified_transform_tool_class_init (GimpUnifiedTransformToolClass *klass)
   trans_class->motion        = gimp_unified_transform_tool_motion;
   trans_class->recalc_matrix = gimp_unified_transform_tool_recalc_matrix;
   trans_class->get_undo_desc = gimp_unified_transform_tool_get_undo_desc;
+  trans_class->pick_function = gimp_unified_transform_tool_pick_function;
   trans_class->draw_gui      = gimp_unified_transform_tool_draw_gui;
-
-  tool_class->oper_update = gimp_transform_tool_oper_update;
 }
 
 static void
@@ -134,67 +131,26 @@ gimp_unified_transform_tool_init (GimpUnifiedTransformTool *unified_tool)
 
   tr_tool->progress_text = _("Unified transform");
 
-  tr_tool->use_grid        = TRUE;
-  tr_tool->use_handles     = TRUE;
-  tr_tool->use_center      = TRUE;
-  tr_tool->use_mid_handles = TRUE;
-  tr_tool->use_pivot       = TRUE;
+  tr_tool->use_grid    = TRUE;
+  tr_tool->use_handles = TRUE;
 }
 
-/*hack*/
-static void
-gimp_transform_tool_set_function (GimpTransformTool *tr_tool,
-                                  TransformAction    function)
-{
-  GimpTool *tool = GIMP_TOOL (tr_tool);
-  if (function != tr_tool->function)
-    {
-      if (tr_tool->handles[tr_tool->function] &&
-          gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tr_tool)))
-        {
-          gimp_canvas_item_set_highlight (tr_tool->handles[tr_tool->function],
-                                          FALSE);
-          gimp_tool_pop_status (tool, tool->display);
-        }
-
-      tr_tool->function = function;
-
-      if (tr_tool->handles[tr_tool->function] &&
-          gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tr_tool)))
-        {
-          gimp_canvas_item_set_highlight (tr_tool->handles[tr_tool->function],
-                                          TRUE);
-          gimp_tool_push_status (tool, tool->display, "%i", tr_tool->function);
-        }
-    }
-}
-static void
-gimp_transform_tool_oper_update (GimpTool         *tool,
-                                 const GimpCoords *coords,
-                                 GdkModifierType   state,
-                                 gboolean          proximity,
-                                 GimpDisplay      *display)
+static TransformAction
+gimp_unified_transform_tool_pick_function (GimpTransformTool *tr_tool,
+                                           const GimpCoords  *coords,
+                                           GdkModifierType    state,
+                                           GimpDisplay       *display)
 {
-  GimpTransformTool *tr_tool   = GIMP_TRANSFORM_TOOL (tool);
-  GimpDrawTool      *draw_tool = GIMP_DRAW_TOOL (tool);
-  TransformAction    function  = TRANSFORM_HANDLE_NONE;
-  TransformAction    i;
-
-  if (display != tool->display || draw_tool->item == NULL)
-    {
-      gimp_transform_tool_set_function (tr_tool, TRANSFORM_HANDLE_NONE);
-      return;
-    }
+  TransformAction i;
 
   for (i = TRANSFORM_HANDLE_NONE + 1; i < TRANSFORM_HANDLE_NUM; i++) {
     if (gimp_canvas_item_hit (tr_tool->handles[i], coords->x, coords->y))
       {
-        function = i;
-        break;
+        return i;
       }
   }
 
-  gimp_transform_tool_set_function (tr_tool, function);
+  return TRANSFORM_HANDLE_NONE;
 }
 
 static void



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