[gimp/blend-tool-fun: 8/8] app: In GimpBlendTool, sync the operation properties with GimpBlendOptions



commit fe0bc3da6988e70f9c6551ee614dba61edeac78f
Author: Michael Henning <drawoc darkrefraction com>
Date:   Sun Jun 22 21:53:38 2014 -0400

    app: In GimpBlendTool, sync the operation properties with GimpBlendOptions

 app/tools/gimpblendtool.c |   66 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index f0bcac8..fec49bc 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -41,6 +41,8 @@
 #include "core/gimpprogress.h"
 #include "core/gimpprojection.h"
 
+#include "gegl/gimp-gegl-config-proxy.h"
+
 #include "widgets/gimphelp-ids.h"
 #include "widgets/gimpwidgets-utils.h"
 
@@ -120,6 +122,12 @@ 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_start_op_sync       (GimpBlendTool         *blend_tool);
+static void   gimp_blend_tool_options_notify      (GimpBlendOptions      *options,
+                                                   GParamSpec            *pspec,
+                                                   GimpBlendTool         *blend_tool);
+static void   gimp_blend_tool_stop_op_sync        (GimpBlendTool         *blend_tool);
+
 static void   gimp_blend_tool_create_image_map    (GimpBlendTool         *blend_tool,
                                                    GimpDrawable          *drawable);
 static void   gimp_blend_tool_image_map_flush     (GimpImageMap          *image_map,
@@ -641,6 +649,8 @@ gimp_blend_tool_start (GimpBlendTool         *blend_tool,
 
   gimp_blend_tool_create_image_map (blend_tool, drawable);
 
+  gimp_blend_tool_start_op_sync (blend_tool);
+
   if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (blend_tool)))
     gimp_draw_tool_start (GIMP_DRAW_TOOL (blend_tool), display);
 }
@@ -650,6 +660,8 @@ gimp_blend_tool_halt (GimpBlendTool *blend_tool)
 {
   GimpTool *tool = GIMP_TOOL (blend_tool);
 
+  gimp_blend_tool_stop_op_sync (blend_tool);
+
   if (blend_tool->graph)
     {
       g_object_unref (blend_tool->graph);
@@ -785,6 +797,60 @@ gimp_blend_tool_update_preview_coords (GimpBlendTool *blend_tool)
                  NULL);
 }
 
+static void
+gimp_blend_tool_start_op_sync (GimpBlendTool *blend_tool)
+{
+  GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GParamSpec      **pspecs;
+  guint             n_pspecs;
+  gint              i;
+
+  /* Listen for any property changes on the config object that match the op */
+  pspecs = gegl_operation_list_properties ("gimp:blend", &n_pspecs);
+
+  for (i = 0; i < n_pspecs; i++)
+    {
+      GParamSpec *pspec = pspecs[i];
+      gchar *signal_name = g_strdup_printf ("notify::%s", pspec->name);
+
+      g_signal_connect (options, signal_name,
+                        G_CALLBACK (gimp_blend_tool_options_notify),
+                        blend_tool);
+
+      g_free (signal_name);
+    }
+
+  g_free (pspecs);
+
+  /* Initially sync all of the properties */
+  gimp_gegl_config_proxy_sync (GIMP_OBJECT (options), blend_tool->render_node);
+}
+
+static void
+gimp_blend_tool_options_notify (GimpBlendOptions *options,
+                                GParamSpec       *pspec,
+                                GimpBlendTool    *blend_tool)
+{
+  GValue value = G_VALUE_INIT;
+  g_value_init (&value, pspec->value_type);
+
+  g_object_get_property (G_OBJECT (options), pspec->name, &value);
+  gegl_node_set_property (blend_tool->render_node, pspec->name, &value);
+
+  g_value_unset (&value);
+
+  gimp_image_map_apply (blend_tool->image_map, NULL);
+}
+
+static void
+gimp_blend_tool_stop_op_sync (GimpBlendTool *blend_tool)
+{
+  GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  g_signal_handlers_disconnect_by_func (options,
+                                        G_CALLBACK (gimp_blend_tool_options_notify),
+                                        blend_tool);
+}
+
 /* Image map stuff */
 
 static void


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