[gimp/wip/gradient-edit: 36/36] app: fix fg/bg color change handling in the blend tool



commit cb5f8c11869509c24940b37fd09cee1da1aab12c
Author: Ell <ell_se yahoo com>
Date:   Fri Aug 4 08:44:32 2017 -0400

    app: fix fg/bg color change handling in the blend tool
    
    Separate the handling of changes to the FG/BG color from the gradient
    dirty signal handling, so that the gradient editor doesn't purge the
    history in response.  Additionally, correctly respond to such changes
    whenever the gradient has segments that depend on the FG/BG colors,
    even if the dependency is introduced after the gradient is selected.

 app/tools/gimpblendtool-editor.c |    6 ++++
 app/tools/gimpblendtool-editor.h |    2 +
 app/tools/gimpblendtool.c        |   53 +++++++++++++++++++++++++-------------
 3 files changed, 43 insertions(+), 18 deletions(-)
---
diff --git a/app/tools/gimpblendtool-editor.c b/app/tools/gimpblendtool-editor.c
index 6be48eb..51ff676 100644
--- a/app/tools/gimpblendtool-editor.c
+++ b/app/tools/gimpblendtool-editor.c
@@ -2186,6 +2186,12 @@ gimp_blend_tool_editor_line_changed (GimpBlendTool *blend_tool)
 }
 
 void
+gimp_blend_tool_editor_fg_bg_changed (GimpBlendTool *blend_tool)
+{
+  gimp_blend_tool_editor_update_gui (blend_tool);
+}
+
+void
 gimp_blend_tool_editor_gradient_dirty (GimpBlendTool *blend_tool)
 {
   if (blend_tool->widget && ! blend_tool->modifying)
diff --git a/app/tools/gimpblendtool-editor.h b/app/tools/gimpblendtool-editor.h
index c72fa47..b9bbda4 100644
--- a/app/tools/gimpblendtool-editor.h
+++ b/app/tools/gimpblendtool-editor.h
@@ -28,6 +28,8 @@ void          gimp_blend_tool_editor_halt             (GimpBlendTool    *blend_t
 
 void          gimp_blend_tool_editor_line_changed     (GimpBlendTool    *blend_tool);
 
+void          gimp_blend_tool_editor_fg_bg_changed    (GimpBlendTool    *blend_tool);
+
 void          gimp_blend_tool_editor_gradient_dirty   (GimpBlendTool    *blend_tool);
 
 void          gimp_blend_tool_editor_gradient_changed (GimpBlendTool    *blend_tool);
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index 3c6f6b4..edef56a 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -121,6 +121,8 @@ static void   gimp_blend_tool_precalc_shapeburst  (GimpBlendTool         *blend_
 static void   gimp_blend_tool_create_graph        (GimpBlendTool         *blend_tool);
 static void   gimp_blend_tool_update_graph        (GimpBlendTool         *blend_tool);
 
+static void   gimp_blend_tool_fg_bg_changed       (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);
@@ -297,8 +299,7 @@ gimp_blend_tool_button_press (GimpTool            *tool,
                               GimpButtonPressType  press_type,
                               GimpDisplay         *display)
 {
-  GimpBlendTool    *blend_tool = GIMP_BLEND_TOOL (tool);
-  GimpBlendOptions *options    = GIMP_BLEND_TOOL_GET_OPTIONS (tool);
+  GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
 
   if (tool->display && display != tool->display)
     gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, tool->display);
@@ -575,6 +576,13 @@ gimp_blend_tool_start (GimpBlendTool    *blend_tool,
                     G_CALLBACK (gimp_blend_tool_line_response),
                     blend_tool);
 
+  g_signal_connect_swapped (context, "background-changed",
+                            G_CALLBACK (gimp_blend_tool_fg_bg_changed),
+                            blend_tool);
+  g_signal_connect_swapped (context, "foreground-changed",
+                            G_CALLBACK (gimp_blend_tool_fg_bg_changed),
+                            blend_tool);
+
   gimp_blend_tool_create_filter (blend_tool, drawable);
 
   /* Initially sync all of the properties */
@@ -597,6 +605,7 @@ gimp_blend_tool_halt (GimpBlendTool *blend_tool)
 {
   GimpTool         *tool    = GIMP_TOOL (blend_tool);
   GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool);
+  GimpContext      *context = GIMP_CONTEXT (options);
 
   gimp_blend_tool_editor_halt (blend_tool);
 
@@ -626,6 +635,10 @@ gimp_blend_tool_halt (GimpBlendTool *blend_tool)
       gimp_image_flush (gimp_display_get_image (tool->display));
     }
 
+  g_signal_handlers_disconnect_by_func (context,
+                                        G_CALLBACK (gimp_blend_tool_fg_bg_changed),
+                                        blend_tool);
+
   if (tool->display)
     gimp_tool_pop_status (tool, tool->display);
 
@@ -825,6 +838,26 @@ gimp_blend_tool_update_graph (GimpBlendTool *blend_tool)
 }
 
 static void
+gimp_blend_tool_fg_bg_changed (GimpBlendTool *blend_tool)
+{
+  if (! blend_tool->filter || ! blend_tool->gradient)
+    return;
+
+  if (gimp_gradient_has_fg_bg_segments (blend_tool->gradient))
+    {
+      /* 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 filter */
+      gimp_drawable_filter_apply (blend_tool->filter, NULL);
+
+      gimp_blend_tool_editor_fg_bg_changed (blend_tool);
+    }
+}
+
+static void
 gimp_blend_tool_gradient_dirty (GimpBlendTool *blend_tool)
 {
   if (! blend_tool->filter)
@@ -845,17 +878,11 @@ 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);
     }
@@ -870,16 +897,6 @@ gimp_blend_tool_set_gradient (GimpBlendTool *blend_tool,
                                 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]