[gimp] app: store the snap offsets in GimpToolWidget



commit 84e1f757ce7e9a09dbc97080ed7c776bcb9ac528
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jun 24 21:09:18 2017 +0200

    app: store the snap offsets in GimpToolWidget
    
    Rename gimp_tool_widget_snap_offsets() to set_snap_offsets(),
    and add gimp_tool_widget_get_snap_offsets().
    
    Also rename gimp_tool_widget_status() to set_status(), and
    add new function and signal set_status_coords().

 app/core/gimpmarshal.list           |    1 +
 app/display/gimptoolcompass.c       |   11 +++--
 app/display/gimptoolhandlegrid.c    |    2 +-
 app/display/gimptoolpath.c          |    8 ++--
 app/display/gimptoolpolygon.c       |    4 +-
 app/display/gimptooltransformgrid.c |   17 ++++---
 app/display/gimptoolwidget.c        |   84 +++++++++++++++++++++++++++++++---
 app/display/gimptoolwidget.h        |   38 ++++++++++++----
 8 files changed, 127 insertions(+), 38 deletions(-)
---
diff --git a/app/core/gimpmarshal.list b/app/core/gimpmarshal.list
index 68cace7..d7c5fc8 100644
--- a/app/core/gimpmarshal.list
+++ b/app/core/gimpmarshal.list
@@ -61,6 +61,7 @@ VOID: POINTER, FLAGS, BOOLEAN
 VOID: POINTER, UINT, FLAGS
 VOID: STRING
 VOID: STRING, BOOLEAN, UINT, FLAGS
+VOID: STRING, DOUBLE, STRING, DOUBLE, STRING
 VOID: STRING, FLAGS
 VOID: STRING, STRING, STRING
 VOID: VOID
diff --git a/app/display/gimptoolcompass.c b/app/display/gimptoolcompass.c
index 2c04d6b..22e96cc 100644
--- a/app/display/gimptoolcompass.c
+++ b/app/display/gimptoolcompass.c
@@ -820,7 +820,7 @@ gimp_tool_compass_hover (GimpToolWidget   *widget,
                                                    NULL, NULL, NULL);
                 }
 
-              gimp_tool_widget_status (widget, status);
+              gimp_tool_widget_set_status (widget, status);
               g_free (status);
               break;
             }
@@ -831,7 +831,7 @@ gimp_tool_compass_hover (GimpToolWidget   *widget,
                                                  "vertical guide"),
                                                toggle_mask & ~state,
                                                NULL, NULL, NULL);
-              gimp_tool_widget_status (widget, status);
+              gimp_tool_widget_set_status (widget, status);
               g_free (status);
               break;
             }
@@ -857,7 +857,7 @@ gimp_tool_compass_hover (GimpToolWidget   *widget,
                                                NULL, NULL, NULL);
             }
 
-          gimp_tool_widget_status (widget, status);
+          gimp_tool_widget_set_status (widget, status);
           g_free (status);
           break;
         }
@@ -867,11 +867,12 @@ gimp_tool_compass_hover (GimpToolWidget   *widget,
     {
       if ((private->n_points > 1) && (state & GDK_MOD1_MASK))
         {
-          gimp_tool_widget_status (widget, _("Click-Drag to move all points"));
+          gimp_tool_widget_set_status (widget,
+                                       _("Click-Drag to move all points"));
         }
       else
         {
-          gimp_tool_widget_status (widget, NULL);
+          gimp_tool_widget_set_status (widget, NULL);
         }
     }
 
diff --git a/app/display/gimptoolhandlegrid.c b/app/display/gimptoolhandlegrid.c
index cf0c0d2..4da17e6 100644
--- a/app/display/gimptoolhandlegrid.c
+++ b/app/display/gimptoolhandlegrid.c
@@ -882,7 +882,7 @@ gimp_tool_handle_grid_hover (GimpToolWidget   *widget,
         }
     }
 
-  gimp_tool_widget_status (widget, status);
+  gimp_tool_widget_set_status (widget, status);
   g_free (status);
 
   gimp_tool_handle_grid_update_hilight (grid);
diff --git a/app/display/gimptoolpath.c b/app/display/gimptoolpath.c
index 2e79044..00b15b0 100644
--- a/app/display/gimptoolpath.c
+++ b/app/display/gimptoolpath.c
@@ -488,8 +488,8 @@ gimp_tool_path_check_writable (GimpToolPath *path)
   if (gimp_item_is_content_locked (GIMP_ITEM (private->vectors)) ||
       gimp_item_is_position_locked (GIMP_ITEM (private->vectors)))
     {
-      gimp_tool_widget_status (GIMP_TOOL_WIDGET (path),
-                               _("The active path is locked."));
+      gimp_tool_widget_set_status (GIMP_TOOL_WIDGET (path),
+                                   _("The active path is locked."));
 
       private->function = VECTORS_FINISHED;
 
@@ -1430,7 +1430,7 @@ gimp_tool_path_update_status (GimpToolPath    *path,
 
   if (! proximity)
     {
-      gimp_tool_widget_status (GIMP_TOOL_WIDGET (path), NULL);
+      gimp_tool_widget_set_status (GIMP_TOOL_WIDGET (path), NULL);
       return;
     }
 
@@ -1547,7 +1547,7 @@ gimp_tool_path_update_status (GimpToolPath    *path,
       break;
     }
 
-  gimp_tool_widget_status (GIMP_TOOL_WIDGET (path), status);
+  gimp_tool_widget_set_status (GIMP_TOOL_WIDGET (path), status);
 
   if (free_status)
     g_free ((gchar *) status);
diff --git a/app/display/gimptoolpolygon.c b/app/display/gimptoolpolygon.c
index e000ff1..007de57 100644
--- a/app/display/gimptoolpolygon.c
+++ b/app/display/gimptoolpolygon.c
@@ -963,12 +963,12 @@ gimp_tool_polygon_status_update (GimpToolPolygon  *polygon,
 
       if (status_text)
         {
-          gimp_tool_widget_status (widget, status_text);
+          gimp_tool_widget_set_status (widget, status_text);
         }
     }
   else
     {
-      gimp_tool_widget_status (widget, NULL);
+      gimp_tool_widget_set_status (widget, NULL);
     }
 }
 
diff --git a/app/display/gimptooltransformgrid.c b/app/display/gimptooltransformgrid.c
index 78f2605..436baea 100644
--- a/app/display/gimptooltransformgrid.c
+++ b/app/display/gimptooltransformgrid.c
@@ -1152,14 +1152,14 @@ gimp_tool_transform_grid_button_press (GimpToolWidget      *widget,
 
           gimp_canvas_handle_get_position (handle, &x, &y);
 
-          gimp_tool_widget_snap_offsets (widget,
-                                         SIGNED_ROUND (x - coords->x),
-                                         SIGNED_ROUND (y - coords->y),
-                                         0, 0);
+          gimp_tool_widget_set_snap_offsets (widget,
+                                             SIGNED_ROUND (x - coords->x),
+                                             SIGNED_ROUND (y - coords->y),
+                                             0, 0);
         }
       else
         {
-          gimp_tool_widget_snap_offsets (widget, 0, 0, 0, 0);
+          gimp_tool_widget_set_snap_offsets (widget, 0, 0, 0, 0);
         }
 
       private->prev_tx1 = private->tx1;
@@ -1178,7 +1178,7 @@ gimp_tool_transform_grid_button_press (GimpToolWidget      *widget,
       return private->handle;
     }
 
-  gimp_tool_widget_snap_offsets (widget, 0, 0, 0, 0);
+  gimp_tool_widget_set_snap_offsets (widget, 0, 0, 0, 0);
 
   return 0;
 }
@@ -1891,11 +1891,12 @@ gimp_tool_transform_grid_hover (GimpToolWidget   *widget,
 
   if (handle != GIMP_TRANSFORM_HANDLE_NONE && proximity)
     {
-      gimp_tool_widget_status (widget, get_friendly_operation_name (handle));
+      gimp_tool_widget_set_status (widget,
+                                   get_friendly_operation_name (handle));
     }
   else
     {
-      gimp_tool_widget_status (widget, NULL);
+      gimp_tool_widget_set_status (widget, NULL);
     }
 
   private->handle = handle;
diff --git a/app/display/gimptoolwidget.c b/app/display/gimptoolwidget.c
index cae5df4..1aaca20 100644
--- a/app/display/gimptoolwidget.c
+++ b/app/display/gimptoolwidget.c
@@ -49,6 +49,7 @@ enum
   CHANGED,
   SNAP_OFFSETS,
   STATUS,
+  STATUS_COORDS,
   LAST_SIGNAL
 };
 
@@ -57,6 +58,11 @@ struct _GimpToolWidgetPrivate
   GimpDisplayShell *shell;
   GimpCanvasItem   *item;
   GList            *group_stack;
+
+  gint              snap_offset_x;
+  gint              snap_offset_y;
+  gint              snap_width;
+  gint              snap_height;
 };
 
 
@@ -127,6 +133,20 @@ gimp_tool_widget_class_init (GimpToolWidgetClass *klass)
                   G_TYPE_NONE, 1,
                   G_TYPE_STRING);
 
+  widget_signals[STATUS_COORDS] =
+    g_signal_new ("status-coords",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GimpToolWidgetClass, status_coords),
+                  NULL, NULL,
+                  gimp_marshal_VOID__STRING_DOUBLE_STRING_DOUBLE_STRING,
+                  G_TYPE_NONE, 5,
+                  G_TYPE_STRING,
+                  G_TYPE_DOUBLE,
+                  G_TYPE_STRING,
+                  G_TYPE_DOUBLE,
+                  G_TYPE_STRING);
+
   g_object_class_install_property (object_class, PROP_SHELL,
                                    g_param_spec_object ("shell",
                                                         NULL, NULL,
@@ -253,21 +273,55 @@ gimp_tool_widget_get_item (GimpToolWidget *widget)
 }
 
 void
-gimp_tool_widget_snap_offsets (GimpToolWidget *widget,
-                               gint            offset_x,
-                               gint            offset_y,
-                               gint            width,
-                               gint            height)
+gimp_tool_widget_set_snap_offsets (GimpToolWidget *widget,
+                                   gint            offset_x,
+                                   gint            offset_y,
+                                   gint            width,
+                                   gint            height)
 {
+  GimpToolWidgetPrivate *private;
+
   g_return_if_fail (GIMP_IS_TOOL_WIDGET (widget));
 
-  g_signal_emit (widget, widget_signals[SNAP_OFFSETS], 0,
+  private = widget->private;
+
+  if (offset_x != private->snap_offset_x ||
+      offset_y != private->snap_offset_y ||
+      width    != private->snap_width    ||
+      height   != private->snap_height)
+    {
+      private->snap_offset_x = offset_x;
+      private->snap_offset_y = offset_y;
+      private->snap_width    = width;
+      private->snap_height   = height;
+
+      g_signal_emit (widget, widget_signals[SNAP_OFFSETS], 0,
                  offset_x, offset_y, width, height);
+    }
 }
 
 void
-gimp_tool_widget_status (GimpToolWidget *widget,
-                         const gchar    *status)
+gimp_tool_widget_get_snap_offsets (GimpToolWidget *widget,
+                                   gint           *offset_x,
+                                   gint           *offset_y,
+                                   gint           *width,
+                                   gint           *height)
+{
+  GimpToolWidgetPrivate *private;
+
+  g_return_if_fail (GIMP_IS_TOOL_WIDGET (widget));
+
+  private = widget->private;
+
+  if (offset_x) *offset_x = private->snap_offset_x;
+  if (offset_y) *offset_y = private->snap_offset_y;
+  if (width)    *width    = private->snap_width;
+  if (height)   *height   = private->snap_height;
+}
+
+void
+gimp_tool_widget_set_status (GimpToolWidget *widget,
+                             const gchar    *status)
 {
   g_return_if_fail (GIMP_IS_TOOL_WIDGET (widget));
 
@@ -276,6 +330,20 @@ gimp_tool_widget_status (GimpToolWidget *widget,
 }
 
 void
+gimp_tool_widget_set_status_coords (GimpToolWidget *widget,
+                                    const gchar    *title,
+                                    gdouble         x,
+                                    const gchar    *separator,
+                                    gdouble         y,
+                                    const gchar    *help)
+{
+  g_return_if_fail (GIMP_IS_TOOL_WIDGET (widget));
+
+  g_signal_emit (widget, widget_signals[STATUS_COORDS], 0,
+                 title, x, separator, y, help);
+}
+
+void
 gimp_tool_widget_add_item (GimpToolWidget *widget,
                            GimpCanvasItem *item)
 {
diff --git a/app/display/gimptoolwidget.h b/app/display/gimptoolwidget.h
index 108f4a7..b61d625 100644
--- a/app/display/gimptoolwidget.h
+++ b/app/display/gimptoolwidget.h
@@ -56,6 +56,12 @@ struct _GimpToolWidgetClass
                                 gint                   height);
   void     (* status)          (GimpToolWidget        *widget,
                                 const gchar           *status);
+  void     (* status_coords)   (GimpToolWidget        *widget,
+                                const gchar           *title,
+                                gdouble                x,
+                                const gchar           *separator,
+                                gdouble                y,
+                                const gchar           *help);
 
   /*  virtual functions  */
   gint     (* button_press)    (GimpToolWidget        *widget,
@@ -101,20 +107,32 @@ struct _GimpToolWidgetClass
 };
 
 
-GType              gimp_tool_widget_get_type         (void) G_GNUC_CONST;
+GType              gimp_tool_widget_get_type          (void) G_GNUC_CONST;
 
-GimpDisplayShell * gimp_tool_widget_get_shell        (GimpToolWidget  *widget);
-GimpCanvasItem   * gimp_tool_widget_get_item         (GimpToolWidget  *widget);
+GimpDisplayShell * gimp_tool_widget_get_shell         (GimpToolWidget  *widget);
+GimpCanvasItem   * gimp_tool_widget_get_item          (GimpToolWidget  *widget);
 
 /*  for subclasses, to notify the handling tool
  */
-void               gimp_tool_widget_snap_offsets     (GimpToolWidget  *widget,
-                                                      gint             offset_x,
-                                                      gint             offset_y,
-                                                      gint             width,
-                                                      gint             height);
-void               gimp_tool_widget_status           (GimpToolWidget  *widget,
-                                                      const gchar     *status);
+void               gimp_tool_widget_set_snap_offsets  (GimpToolWidget  *widget,
+                                                       gint             offset_x,
+                                                       gint             offset_y,
+                                                       gint             width,
+                                                       gint             height);
+void               gimp_tool_widget_get_snap_offsets  (GimpToolWidget  *widget,
+                                                       gint            *offset_x,
+                                                       gint            *offset_y,
+                                                       gint            *width,
+                                                       gint            *height);
+
+void               gimp_tool_widget_set_status        (GimpToolWidget  *widget,
+                                                       const gchar     *status);
+void               gimp_tool_widget_set_status_coords (GimpToolWidget  *widget,
+                                                       const gchar     *title,
+                                                       gdouble          x,
+                                                       const gchar     *separator,
+                                                       gdouble          y,
+                                                       const gchar     *help);
 
 /*  for subclasses, to add and manage their items
  */


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