[gimp/wip/gradient-edit: 41/42] app: handle prepare-to-remove-slider signal in the blend tool



commit 27a2554947b66368e1b78aecad45c83666ec698c
Author: Ell <ell_se yahoo com>
Date:   Fri Oct 6 12:11:45 2017 -0400

    app: handle prepare-to-remove-slider signal in the blend tool
    
    Add a tentative_gradient member to GimpBlendTool, which, when set,
    is displayed instead of the current gradient.
    
    Use this to show a version of the gradient with the currently
    selected stop deleted, upon receiving a prepare-to-remove-slider
    signal, i.e., when the slider is about to be removed.

 app/tools/gimpblendtool-editor.c |   42 ++++++++++++++++++++++++++++++++++
 app/tools/gimpblendtool.c        |   46 +++++++++++++++++++++++++++++++++-----
 app/tools/gimpblendtool.h        |   13 ++++++++--
 3 files changed, 92 insertions(+), 9 deletions(-)
---
diff --git a/app/tools/gimpblendtool-editor.c b/app/tools/gimpblendtool-editor.c
index 0417690..0b2d188 100644
--- a/app/tools/gimpblendtool-editor.c
+++ b/app/tools/gimpblendtool-editor.c
@@ -91,6 +91,10 @@ static gboolean              gimp_blend_tool_editor_line_can_add_slider
 static gint                  gimp_blend_tool_editor_line_add_slider                   (GimpToolLine          
*line,
                                                                                        gdouble               
 value,
                                                                                        GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_line_prepare_to_remove_slider     (GimpToolLine          
*line,
+                                                                                       gint                  
 slider,
+                                                                                       gboolean              
 remove,
+                                                                                       GimpBlendTool         
*blend_tool);
 static void                  gimp_blend_tool_editor_line_remove_slider                (GimpToolLine          
*line,
                                                                                        gint                  
 slider,
                                                                                        GimpBlendTool         
*blend_tool);
@@ -231,11 +235,46 @@ gimp_blend_tool_editor_line_add_slider (GimpToolLine  *line,
 }
 
 static void
+gimp_blend_tool_editor_line_prepare_to_remove_slider (GimpToolLine  *line,
+                                                      gint           slider,
+                                                      gboolean       remove,
+                                                      GimpBlendTool *blend_tool)
+{
+  if (remove)
+    {
+      GimpGradient        *tentative_gradient;
+      GimpGradientSegment *seg;
+      gint                 i;
+
+      tentative_gradient =
+        GIMP_GRADIENT (gimp_data_duplicate (GIMP_DATA (blend_tool->gradient)));
+
+      seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, slider);
+
+      i = gimp_gradient_segment_range_get_n_segments (blend_tool->gradient,
+                                                      blend_tool->gradient->segments,
+                                                      seg) - 1;
+
+      seg = gimp_gradient_segment_get_nth (tentative_gradient->segments, i);
+
+      gimp_gradient_segment_range_merge (tentative_gradient,
+                                         seg, seg->next, NULL, NULL);
+
+      gimp_blend_tool_set_tentative_gradient (blend_tool, tentative_gradient);
+    }
+  else
+    {
+      gimp_blend_tool_set_tentative_gradient (blend_tool, NULL);
+    }
+}
+
+static void
 gimp_blend_tool_editor_line_remove_slider (GimpToolLine  *line,
                                            gint           slider,
                                            GimpBlendTool *blend_tool)
 {
   gimp_blend_tool_editor_delete_stop (blend_tool, slider);
+  gimp_blend_tool_set_tentative_gradient (blend_tool, NULL);
 }
 
 static void
@@ -2042,6 +2081,9 @@ gimp_blend_tool_editor_start (GimpBlendTool *blend_tool)
   g_signal_connect (blend_tool->widget, "add-slider",
                     G_CALLBACK (gimp_blend_tool_editor_line_add_slider),
                     blend_tool);
+  g_signal_connect (blend_tool->widget, "prepare-to-remove-slider",
+                    G_CALLBACK (gimp_blend_tool_editor_line_prepare_to_remove_slider),
+                    blend_tool);
   g_signal_connect (blend_tool->widget, "remove-slider",
                     G_CALLBACK (gimp_blend_tool_editor_line_remove_slider),
                     blend_tool);
diff --git a/app/tools/gimpblendtool.c b/app/tools/gimpblendtool.c
index e40e84d..72c656a 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -889,13 +889,16 @@ gimp_blend_tool_gradient_dirty (GimpBlendTool *blend_tool)
   if (! blend_tool->filter)
     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);
+  if (! blend_tool->tentative_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);
+      /* Update the filter */
+      gimp_drawable_filter_apply (blend_tool->filter, NULL);
+    }
 
   gimp_blend_tool_editor_gradient_dirty (blend_tool);
 }
@@ -982,3 +985,34 @@ gimp_blend_tool_filter_flush (GimpDrawableFilter *filter,
 
   gimp_projection_flush (gimp_image_get_projection (image));
 }
+
+
+/*  protected functions  */
+
+
+void
+gimp_blend_tool_set_tentative_gradient (GimpBlendTool *blend_tool,
+                                        GimpGradient  *gradient)
+{
+  g_return_if_fail (GIMP_IS_BLEND_TOOL (blend_tool));
+  g_return_if_fail (gradient == NULL || GIMP_IS_GRADIENT (gradient));
+
+  if (gradient != blend_tool->tentative_gradient)
+    {
+      g_clear_object (&blend_tool->tentative_gradient);
+
+      blend_tool->tentative_gradient = gradient;
+
+      if (gradient)
+        g_object_ref (gradient);
+
+      if (blend_tool->render_node)
+        {
+          gegl_node_set (blend_tool->render_node,
+                         "gradient", gradient ? gradient : blend_tool->gradient,
+                         NULL);
+
+          gimp_drawable_filter_apply (blend_tool->filter, NULL);
+        }
+    }
+}
diff --git a/app/tools/gimpblendtool.h b/app/tools/gimpblendtool.h
index 4494284..63b1e5e 100644
--- a/app/tools/gimpblendtool.h
+++ b/app/tools/gimpblendtool.h
@@ -40,6 +40,7 @@ struct _GimpBlendTool
   GimpDrawTool        parent_instance;
 
   GimpGradient       *gradient;
+  GimpGradient       *tentative_gradient;
 
   gdouble             start_x;    /*  starting x coord  */
   gdouble             start_y;    /*  starting y coord  */
@@ -95,10 +96,16 @@ struct _GimpBlendToolClass
 };
 
 
-void    gimp_blend_tool_register (GimpToolRegisterCallback  callback,
-                                  gpointer                  data);
+void    gimp_blend_tool_register               (GimpToolRegisterCallback  callback,
+                                                gpointer                  data);
 
-GType   gimp_blend_tool_get_type (void) G_GNUC_CONST;
+GType   gimp_blend_tool_get_type               (void) G_GNUC_CONST;
+
+
+/*  protected functions  */
+
+void    gimp_blend_tool_set_tentative_gradient (GimpBlendTool            *blend_tool,
+                                                GimpGradient             *gradient);
 
 
 #endif  /*  __GIMP_BLEND_TOOL_H__  */


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