[gimp/soc-2012-unified-transformation: 12/52] transformtool: Enable hit detection for new handles



commit d42d62d6e52af6ce8f632cf93d30ce598b1c8bec
Author: Mikael Magnusson <mikachu src gnome org>
Date:   Thu Jun 14 04:29:37 2012 +0200

    transformtool: Enable hit detection for new handles

 app/tools/gimptransformtool.c        |    2 +-
 app/tools/gimptransformtool.h        |    2 +-
 app/tools/gimpunifiedtransformtool.c |   62 +++++++++++++++++++++++++++++++++-
 3 files changed, 63 insertions(+), 3 deletions(-)
---
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index e1d28b3..c198178 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -339,7 +339,7 @@ gimp_transform_tool_button_press (GimpTool            *tool,
   GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
 
   if (tr_tool->function == TRANSFORM_CREATING)
-    gimp_transform_tool_oper_update (tool, coords, state, TRUE, display);
+    GIMP_TOOL_GET_CLASS (tool)->oper_update (tool, coords, state, TRUE, display);
 
   tr_tool->lastx = tr_tool->mousex = coords->x;
   tr_tool->lasty = tr_tool->mousey = coords->y;
diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h
index b6fbef1..a4bbbef 100644
--- a/app/tools/gimptransformtool.h
+++ b/app/tools/gimptransformtool.h
@@ -34,8 +34,8 @@ typedef enum
   TRANSFORM_HANDLE_S,  /* south      */
   TRANSFORM_HANDLE_E,  /* east       */
   TRANSFORM_HANDLE_W,  /* west       */
-  TRANSFORM_HANDLE_PIVOT,  /* pivot for rotation and scaling */
   TRANSFORM_HANDLE_CENTER, /* for moving */
+  TRANSFORM_HANDLE_PIVOT,  /* pivot for rotation and scaling */
   /* extra handles for unified tool */
   TRANSFORM_HANDLE_NW_P, /* perspective handles */
   TRANSFORM_HANDLE_NE_P,
diff --git a/app/tools/gimpunifiedtransformtool.c b/app/tools/gimpunifiedtransformtool.c
index d6ff14a..50a3031 100644
--- a/app/tools/gimpunifiedtransformtool.c
+++ b/app/tools/gimpunifiedtransformtool.c
@@ -70,6 +70,11 @@ 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_draw          (GimpDrawTool      *draw_tool);
 static void    gimp_unified_transform_tool_dialog        (GimpTransformTool *tr_tool);
 static void    gimp_unified_transform_tool_dialog_update (GimpTransformTool *tr_tool);
@@ -105,7 +110,8 @@ static void
 gimp_unified_transform_tool_class_init (GimpUnifiedTransformToolClass *klass)
 {
   GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
-  GimpDrawToolClass *draw_class = GIMP_DRAW_TOOL_CLASS (klass);
+  GimpToolClass          *tool_class  = GIMP_TOOL_CLASS (klass);
+  GimpDrawToolClass      *draw_class  = GIMP_DRAW_TOOL_CLASS (klass);
 
   trans_class->dialog        = gimp_unified_transform_tool_dialog;
   trans_class->dialog_update = gimp_unified_transform_tool_dialog_update;
@@ -114,6 +120,8 @@ gimp_unified_transform_tool_class_init (GimpUnifiedTransformToolClass *klass)
   trans_class->recalc_matrix = gimp_unified_transform_tool_recalc_matrix;
   trans_class->get_undo_desc = gimp_unified_transform_tool_get_undo_desc;
 
+  tool_class->oper_update = gimp_transform_tool_oper_update;
+
   draw_class->draw = gimp_unified_transform_tool_draw;
 }
 
@@ -135,6 +143,58 @@ gimp_unified_transform_tool_init (GimpUnifiedTransformTool *unified_tool)
   tr_tool->use_pivot       = TRUE;
 }
 
+/*hack*/
+static void
+gimp_transform_tool_set_function (GimpTransformTool *tr_tool,
+                                  TransformAction    function)
+{
+  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);
+        }
+
+      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);
+        }
+    }
+}
+static void
+gimp_transform_tool_oper_update (GimpTool         *tool,
+                                 const GimpCoords *coords,
+                                 GdkModifierType   state,
+                                 gboolean          proximity,
+                                 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;
+    }
+
+  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;
+      }
+  }
+
+  gimp_transform_tool_set_function (tr_tool, function);
+}
 /* hack */
 static void
 gimp_transform_tool_handles_recalc (GimpTransformTool *tr_tool,



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