[gimp/blend-tool-fun: 11/12] app: Support gradients with fg/bg segments in the blend tool preview.



commit 0babeb4d7e897c84d6bd04b2f1cf4bd4c032ecdd
Author: Michael Henning <drawoc darkrefraction com>
Date:   Sun Jun 29 20:40:47 2014 -0400

    app: Support gradients with fg/bg segments in the blend tool preview.

 app/operations/gimpoperationblend.c |   44 ++++++++++++++++++++++++++--------
 app/operations/gimpoperationblend.h |    2 +
 app/tools/gimpblendtool.c           |   35 ++++++++++++++++++++++-----
 3 files changed, 63 insertions(+), 18 deletions(-)
---
diff --git a/app/operations/gimpoperationblend.c b/app/operations/gimpoperationblend.c
index f0e34d2..c5f3718 100644
--- a/app/operations/gimpoperationblend.c
+++ b/app/operations/gimpoperationblend.c
@@ -43,6 +43,7 @@
 enum
 {
   PROP_0,
+  PROP_CONTEXT,
   PROP_GRADIENT,
   PROP_START_X,
   PROP_START_Y,
@@ -190,6 +191,14 @@ gimp_operation_blend_class_init (GimpOperationBlendClass *klass)
                                  "description", "GIMP Blend operation",
                                  NULL);
 
+  g_object_class_install_property (object_class, PROP_CONTEXT,
+                                   g_param_spec_object ("context",
+                                                        "Context",
+                                                        "A GimpContext",
+                                                        GIMP_TYPE_OBJECT,
+                                                        G_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT));
+
   g_object_class_install_property (object_class, PROP_GRADIENT,
                                    g_param_spec_object ("gradient",
                                                         "Gradient",
@@ -307,7 +316,9 @@ static void
 gimp_operation_blend_dispose (GObject *object)
 {
   GimpOperationBlend *self = GIMP_OPERATION_BLEND (object);
+
   g_clear_object (&self->gradient);
+  g_clear_object (&self->context);
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -322,6 +333,10 @@ gimp_operation_blend_get_property (GObject    *object,
 
   switch (property_id)
     {
+    case PROP_CONTEXT:
+      g_value_set_object (value, self->context);
+      break;
+
     case PROP_GRADIENT:
       g_value_set_object (value, self->gradient);
       break;
@@ -390,22 +405,29 @@ gimp_operation_blend_set_property (GObject      *object,
 
   switch (property_id)
     {
+    case PROP_CONTEXT:
+      if (self->context)
+        g_object_unref (self->context);
+
+      self->context = g_value_dup_object (value);
+      break;
+
     case PROP_GRADIENT:
       {
-        GimpGradient *gradient = g_value_dup_object (value);
-        if (gradient && gimp_gradient_has_fg_bg_segments (gradient))
+        GimpGradient *gradient = g_value_get_object (value);
+
+        if (self->gradient)
           {
-            g_warning ("gimp:blend can't handle gradients with foreground or "
-                       "background segments. Call gimp_gradient_flatten on "
-                       "the gradient first");
-            g_object_unref (gradient);
+            g_object_unref (self->gradient);
+            self->gradient = NULL;
           }
-        else
-          {
-            if (self->gradient)
-              g_object_unref (self->gradient);
 
-            self->gradient = gradient;
+        if (gradient)
+          {
+            if (gimp_gradient_has_fg_bg_segments (gradient))
+              self->gradient = gimp_gradient_flatten (gradient, self->context);
+            else
+              self->gradient = g_object_ref (gradient);
           }
       }
       break;
diff --git a/app/operations/gimpoperationblend.h b/app/operations/gimpoperationblend.h
index f587ec8..c121651 100644
--- a/app/operations/gimpoperationblend.h
+++ b/app/operations/gimpoperationblend.h
@@ -40,6 +40,8 @@ struct _GimpOperationBlend
 {
   GeglOperationSource  parent_instance;
 
+  GimpContext         *context;
+
   GimpGradient        *gradient;
   gdouble              start_x, start_y, end_x, end_y;
   GimpGradientType     gradient_type;
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index ba48a6a..d8e9877 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -122,8 +122,7 @@ 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_gradient_dirty      (GimpBlendTool         *blend_tool);
 static void   gimp_blend_tool_set_gradient        (GimpBlendTool         *blend_tool,
                                                    GimpGradient          *gradient);
 static void   gimp_blend_tool_options_notify      (GimpTool              *tool,
@@ -776,6 +775,8 @@ gimp_blend_tool_push_status (GimpBlendTool   *blend_tool,
 static void
 gimp_blend_tool_create_graph (GimpBlendTool *blend_tool)
 {
+  GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GimpContext      *context = GIMP_CONTEXT (options);
   GeglNode *graph, *output, *render;
 
   /* render_node is not supposed to be recreated */
@@ -794,6 +795,10 @@ gimp_blend_tool_create_graph (GimpBlendTool *blend_tool)
 
   blend_tool->graph       = graph;
   blend_tool->render_node = render;
+
+  gegl_node_set (render,
+                 "context", context,
+                 NULL);
 }
 
 static void
@@ -808,8 +813,7 @@ gimp_blend_tool_update_preview_coords (GimpBlendTool *blend_tool)
 }
 
 static void
-gimp_blend_tool_gradient_dirty (GimpGradient  *curve,
-                                GimpBlendTool *blend_tool)
+gimp_blend_tool_gradient_dirty (GimpBlendTool *blend_tool)
 {
   if (!blend_tool->image_map)
     return;
@@ -827,11 +831,17 @@ static void
 gimp_blend_tool_set_gradient (GimpBlendTool *blend_tool,
                               GimpGradient  *gradient)
 {
+  GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GimpContext      *context = GIMP_CONTEXT (options);
+
   if (blend_tool->gradient)
     {
       g_signal_handlers_disconnect_by_func (blend_tool->gradient,
                                             G_CALLBACK (gimp_blend_tool_gradient_dirty),
                                             blend_tool);
+      g_signal_handlers_disconnect_by_func (context,
+                                            G_CALLBACK (gimp_blend_tool_gradient_dirty),
+                                            blend_tool);
       g_object_unref (blend_tool->gradient);
       blend_tool->gradient = NULL;
     }
@@ -839,9 +849,20 @@ gimp_blend_tool_set_gradient (GimpBlendTool *blend_tool,
   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);
+      g_signal_connect_swapped (blend_tool->gradient, "dirty",
+                                G_CALLBACK (gimp_blend_tool_gradient_dirty),
+                                blend_tool);
+
+      if (gimp_gradient_has_fg_bg_segments (blend_tool->gradient))
+        {
+          g_signal_connect_swapped (context, "background-changed",
+                                    G_CALLBACK (gimp_blend_tool_gradient_dirty),
+                                    blend_tool);
+          g_signal_connect_swapped (context, "foreground-changed",
+                                    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,


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