[gimp] app: Update the gradient tool preview when the gradient is modified.



commit 0388d41528c715682d963a1537e6fc6a67f1dd42
Author: Michael Henning <drawoc darkrefraction com>
Date:   Sat Jun 28 22:53:38 2014 -0400

    app: Update the gradient tool preview when the gradient is modified.

 app/tools/gimpblendtool.c |   76 +++++++++++++++++++++++++++++++++++++++++++--
 app/tools/gimpblendtool.h |    2 +
 2 files changed, 75 insertions(+), 3 deletions(-)
---
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index 5d8fe95..ba48a6a 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -64,6 +64,7 @@
 static gboolean gimp_blend_tool_initialize        (GimpTool              *tool,
                                                    GimpDisplay           *display,
                                                    GError               **error);
+static void   gimp_blend_tool_dispose             (GObject               *object);
 static void   gimp_blend_tool_control             (GimpTool              *tool,
                                                    GimpToolAction         action,
                                                    GimpDisplay           *display);
@@ -121,6 +122,10 @@ static void   gimp_blend_tool_push_status         (GimpBlendTool         *blend_
 
 static void   gimp_blend_tool_create_graph        (GimpBlendTool         *blend_tool);
 static void   gimp_blend_tool_update_preview_coords (GimpBlendTool       *blend_tool);
+static void   gimp_blend_tool_gradient_dirty      (GimpGradient          *curve,
+                                                   GimpBlendTool         *blend_tool);
+static void   gimp_blend_tool_set_gradient        (GimpBlendTool         *blend_tool,
+                                                   GimpGradient          *gradient);
 static void   gimp_blend_tool_options_notify      (GimpTool              *tool,
                                                    GimpToolOptions       *options,
                                                    const GParamSpec      *pspec);
@@ -161,9 +166,12 @@ gimp_blend_tool_register (GimpToolRegisterCallback  callback,
 static void
 gimp_blend_tool_class_init (GimpBlendToolClass *klass)
 {
+  GObjectClass      *object_class    = G_OBJECT_CLASS (klass);
   GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
   GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
 
+  object_class->dispose           = gimp_blend_tool_dispose;
+
   tool_class->initialize          = gimp_blend_tool_initialize;
   tool_class->control             = gimp_blend_tool_control;
   tool_class->oper_update         = gimp_blend_tool_oper_update;
@@ -240,6 +248,15 @@ gimp_blend_tool_initialize (GimpTool     *tool,
 }
 
 static void
+gimp_blend_tool_dispose (GObject *object)
+{
+  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (object);
+  gimp_blend_tool_set_gradient (blend_tool, NULL);
+
+  G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
 gimp_blend_tool_control (GimpTool       *tool,
                          GimpToolAction  action,
                          GimpDisplay    *display)
@@ -633,6 +650,7 @@ gimp_blend_tool_start (GimpBlendTool         *blend_tool,
   GimpImage        *image    = gimp_display_get_image (display);
   GimpDrawable     *drawable = gimp_image_get_active_drawable (image);
   GimpBlendOptions *options  = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GimpContext      *context  = GIMP_CONTEXT (options);
 
   tool->display  = display;
   tool->drawable = drawable;
@@ -642,6 +660,9 @@ gimp_blend_tool_start (GimpBlendTool         *blend_tool,
   /* Initially sync all of the properties */
   gimp_gegl_config_proxy_sync (GIMP_OBJECT (options), blend_tool->render_node);
 
+  /* Connect signal handlers for the gradient */
+  gimp_blend_tool_set_gradient (blend_tool, context->gradient);
+
   if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (blend_tool)))
     gimp_draw_tool_start (GIMP_DRAW_TOOL (blend_tool), display);
 }
@@ -787,6 +808,48 @@ gimp_blend_tool_update_preview_coords (GimpBlendTool *blend_tool)
 }
 
 static void
+gimp_blend_tool_gradient_dirty (GimpGradient  *curve,
+                                GimpBlendTool *blend_tool)
+{
+  if (!blend_tool->image_map)
+    return;
+
+  /* Set a property on the node. Otherwise it will cache and refuse to update */
+  gegl_node_set (blend_tool->render_node,
+                 "gradient", blend_tool->gradient,
+                 NULL);
+
+  /* Update the image_map */
+  gimp_image_map_apply (blend_tool->image_map, NULL);
+}
+
+static void
+gimp_blend_tool_set_gradient (GimpBlendTool *blend_tool,
+                              GimpGradient  *gradient)
+{
+  if (blend_tool->gradient)
+    {
+      g_signal_handlers_disconnect_by_func (blend_tool->gradient,
+                                            G_CALLBACK (gimp_blend_tool_gradient_dirty),
+                                            blend_tool);
+      g_object_unref (blend_tool->gradient);
+      blend_tool->gradient = NULL;
+    }
+
+  if (gradient)
+    {
+      blend_tool->gradient = g_object_ref (gradient);
+      g_signal_connect (blend_tool->gradient, "dirty",
+                        G_CALLBACK (gimp_blend_tool_gradient_dirty),
+                        blend_tool);
+      if (blend_tool->render_node)
+        gegl_node_set (blend_tool->render_node,
+                       "gradient", blend_tool->gradient,
+                       NULL);
+    }
+}
+
+static void
 gimp_blend_tool_options_notify (GimpTool         *tool,
                                 GimpToolOptions  *options,
                                 const GParamSpec *pspec)
@@ -794,10 +857,17 @@ gimp_blend_tool_options_notify (GimpTool         *tool,
   GimpContext   *context    = GIMP_CONTEXT (options);
   GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
 
-  /* Sync any property changes on the config object that match the op */
-  if (blend_tool->render_node &&
-      gegl_node_find_property (blend_tool->render_node, pspec->name))
+  if (! strcmp (pspec->name, "gradient"))
+    {
+      gimp_blend_tool_set_gradient (blend_tool, context->gradient);
+
+      if (blend_tool->image_map)
+        gimp_image_map_apply (blend_tool->image_map, NULL);
+    }
+  else if (blend_tool->render_node &&
+           gegl_node_find_property (blend_tool->render_node, pspec->name))
     {
+      /* Sync any property changes on the config object that match the op */
       GValue value = G_VALUE_INIT;
       g_value_init (&value, pspec->value_type);
 
diff --git a/app/tools/gimpblendtool.h b/app/tools/gimpblendtool.h
index 6f35d04..353ac34 100644
--- a/app/tools/gimpblendtool.h
+++ b/app/tools/gimpblendtool.h
@@ -48,6 +48,8 @@ struct _GimpBlendTool
 
   GimpBlendToolPoint grabbed_point;
 
+  GimpGradient   *gradient;
+
   gdouble         start_x;    /*  starting x coord  */
   gdouble         start_y;    /*  starting y coord  */
   gdouble         end_x;      /*  ending x coord    */


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