[gimp] app: add gimp_transform_tool_set_type()



commit f651db52fb7de28608b8566c2482968c45e33335
Author: Ell <ell_se yahoo com>
Date:   Sat Aug 10 23:55:56 2019 +0300

    app: add gimp_transform_tool_set_type()
    
    ... which temporarily changes the transform-type of the tool,
    restoring the original type once it's halted.  To be used when
    activating a transform tool through an action for a specific
    transform type.

 app/tools/gimptransformtool.c | 75 +++++++++++++++++++++++++++++++++++++++++++
 app/tools/gimptransformtool.h | 18 +++++++----
 2 files changed, 87 insertions(+), 6 deletions(-)
---
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index e6223317be..6ba1675d9b 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -64,6 +64,10 @@
 
 /*  local function prototypes  */
 
+static void                     gimp_transform_tool_control            (GimpTool           *tool,
+                                                                        GimpToolAction      action,
+                                                                        GimpDisplay        *display);
+
 static gchar                  * gimp_transform_tool_real_get_undo_desc (GimpTransformTool  *tr_tool);
 static GimpTransformDirection   gimp_transform_tool_real_get_direction (GimpTransformTool  *tr_tool);
 static GeglBuffer             * gimp_transform_tool_real_transform     (GimpTransformTool  *tr_tool,
@@ -75,6 +79,8 @@ static GeglBuffer             * gimp_transform_tool_real_transform     (GimpTran
                                                                         gint               *new_offset_x,
                                                                         gint               *new_offset_y);
 
+static void                     gimp_transform_tool_halt               (GimpTransformTool  *tr_tool);
+
 static gboolean                 gimp_transform_tool_confirm            (GimpTransformTool  *tr_tool,
                                                                         GimpDisplay        *display);
 
@@ -90,6 +96,10 @@ G_DEFINE_TYPE (GimpTransformTool, gimp_transform_tool, GIMP_TYPE_DRAW_TOOL)
 static void
 gimp_transform_tool_class_init (GimpTransformToolClass *klass)
 {
+  GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
+
+  tool_class->control  = gimp_transform_tool_control;
+
   klass->recalc_matrix = NULL;
   klass->get_undo_desc = gimp_transform_tool_real_get_undo_desc;
   klass->get_direction = gimp_transform_tool_real_get_direction;
@@ -104,6 +114,34 @@ gimp_transform_tool_init (GimpTransformTool *tr_tool)
 {
   gimp_matrix3_identity (&tr_tool->transform);
   tr_tool->transform_valid = TRUE;
+
+  tr_tool->restore_type = FALSE;
+}
+
+static void
+gimp_transform_tool_control (GimpTool       *tool,
+                             GimpToolAction  action,
+                             GimpDisplay    *display)
+{
+  GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
+
+  switch (action)
+    {
+    case GIMP_TOOL_ACTION_PAUSE:
+      break;
+
+    case GIMP_TOOL_ACTION_RESUME:
+      break;
+
+    case GIMP_TOOL_ACTION_HALT:
+      gimp_transform_tool_halt (tr_tool);
+      break;
+
+    case GIMP_TOOL_ACTION_COMMIT:
+      break;
+    }
+
+  GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
 }
 
 static gchar *
@@ -216,6 +254,21 @@ gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
   return ret;
 }
 
+static void
+gimp_transform_tool_halt (GimpTransformTool *tr_tool)
+{
+  GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
+
+  if (tr_tool->restore_type)
+    {
+      g_object_set (options,
+                    "type", tr_tool->saved_type,
+                    NULL);
+
+      tr_tool->restore_type = FALSE;
+    }
+}
+
 static gboolean
 gimp_transform_tool_confirm (GimpTransformTool *tr_tool,
                              GimpDisplay       *display)
@@ -830,3 +883,25 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
 
   return TRUE;
 }
+
+void
+gimp_transform_tool_set_type (GimpTransformTool *tr_tool,
+                              GimpTransformType  type)
+{
+  GimpTransformOptions *options;
+
+  g_return_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool));
+
+  options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
+
+  if (! tr_tool->restore_type)
+    tr_tool->saved_type = options->type;
+
+  tr_tool->restore_type = FALSE;
+
+  g_object_set (options,
+                "type", type,
+                NULL);
+
+  tr_tool->restore_type = TRUE;
+}
diff --git a/app/tools/gimptransformtool.h b/app/tools/gimptransformtool.h
index acd04a356c..afe17e3bd4 100644
--- a/app/tools/gimptransformtool.h
+++ b/app/tools/gimptransformtool.h
@@ -45,15 +45,18 @@ typedef struct _GimpTransformToolClass GimpTransformToolClass;
 
 struct _GimpTransformTool
 {
-  GimpDrawTool  parent_instance;
+  GimpDrawTool       parent_instance;
 
-  GimpObject   *object;
+  GimpObject        *object;
 
-  gint          x1, y1;             /*  upper left hand coordinate         */
-  gint          x2, y2;             /*  lower right hand coords            */
+  gint               x1, y1;             /*  upper left hand coordinate   */
+  gint               x2, y2;             /*  lower right hand coords      */
 
-  GimpMatrix3   transform;          /*  transformation matrix              */
-  gboolean      transform_valid;    /*  whether the matrix is valid        */
+  GimpMatrix3        transform;          /*  transformation matrix        */
+  gboolean           transform_valid;    /*  whether the matrix is valid  */
+
+  gboolean           restore_type;
+  GimpTransformType  saved_type;
 };
 
 struct _GimpTransformToolClass
@@ -94,5 +97,8 @@ void         gimp_transform_tool_recalc_matrix       (GimpTransformTool  *tr_too
 gboolean     gimp_transform_tool_transform           (GimpTransformTool  *tr_tool,
                                                       GimpDisplay        *display);
 
+void         gimp_transform_tool_set_type            (GimpTransformTool  *tr_tool,
+                                                      GimpTransformType   type);
+
 
 #endif  /*  __GIMP_TRANSFORM_TOOL_H__  */


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