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



commit 24b924aeabd308682f9644135cf69ee26920e627
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 |   79 +++++++++++++++++++++++++++++---------
 app/tools/gimpblendtool.c        |   46 +++++++++++++++++++---
 app/tools/gimpblendtool.h        |   13 +++++-
 3 files changed, 111 insertions(+), 27 deletions(-)
---
diff --git a/app/tools/gimpblendtool-editor.c b/app/tools/gimpblendtool-editor.c
index 23d1b0e..6e7f2cd 100644
--- a/app/tools/gimpblendtool-editor.c
+++ b/app/tools/gimpblendtool-editor.c
@@ -49,29 +49,33 @@
 
 /*  local function prototypes  */
 
-static gboolean              gimp_blend_tool_editor_line_can_add_slider  (GimpToolLine  *line,
-                                                                          gdouble        value,
-                                                                          GimpBlendTool *blend_tool);
-static gint                  gimp_blend_tool_editor_line_add_slider      (GimpToolLine  *line,
-                                                                          gdouble        value,
-                                                                          GimpBlendTool *blend_tool);
-static void                  gimp_blend_tool_editor_line_remove_slider   (GimpToolLine  *line,
-                                                                          gint           slider,
-                                                                          GimpBlendTool *blend_tool);
+static gboolean              gimp_blend_tool_editor_line_can_add_slider           (GimpToolLine  *line,
+                                                                                   gdouble        value,
+                                                                                   GimpBlendTool 
*blend_tool);
+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);
 
-static gboolean              gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool);
+static gboolean              gimp_blend_tool_editor_is_gradient_editable          (GimpBlendTool 
*blend_tool);
 
-static GimpGradientSegment * gimp_blend_tool_editor_handle_get_segment   (GimpBlendTool *blend_tool,
-                                                                          gint           handle);
+static GimpGradientSegment * gimp_blend_tool_editor_handle_get_segment            (GimpBlendTool *blend_tool,
+                                                                                   gint           handle);
 
-static void                  gimp_blend_tool_editor_block_handlers       (GimpBlendTool *blend_tool);
-static void                  gimp_blend_tool_editor_unblock_handlers     (GimpBlendTool *blend_tool);
-static gboolean              gimp_blend_tool_editor_are_handlers_blocked (GimpBlendTool *blend_tool);
+static void                  gimp_blend_tool_editor_block_handlers                (GimpBlendTool 
*blend_tool);
+static void                  gimp_blend_tool_editor_unblock_handlers              (GimpBlendTool 
*blend_tool);
+static gboolean              gimp_blend_tool_editor_are_handlers_blocked          (GimpBlendTool 
*blend_tool);
 
-static void                  gimp_blend_tool_editor_freeze_gradient      (GimpBlendTool *blend_tool);
-static void                  gimp_blend_tool_editor_thaw_gradient        (GimpBlendTool *blend_tool);
+static void                  gimp_blend_tool_editor_freeze_gradient               (GimpBlendTool 
*blend_tool);
+static void                  gimp_blend_tool_editor_thaw_gradient                 (GimpBlendTool 
*blend_tool);
 
-static void                  gimp_blend_tool_editor_update_sliders       (GimpBlendTool *blend_tool);
+static void                  gimp_blend_tool_editor_update_sliders                (GimpBlendTool 
*blend_tool);
 
 
 /*  private functions  */
@@ -123,6 +127,40 @@ 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)
@@ -137,6 +175,8 @@ gimp_blend_tool_editor_line_remove_slider (GimpToolLine  *line,
                                      seg, seg->next, NULL, NULL);
 
   gimp_blend_tool_editor_thaw_gradient (blend_tool);
+
+  gimp_blend_tool_set_tentative_gradient (blend_tool, NULL);
 }
 
 static gboolean
@@ -404,6 +444,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 a00d920..ef9a1fc 100644
--- a/app/tools/gimpblendtool.c
+++ b/app/tools/gimpblendtool.c
@@ -908,13 +908,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);
 }
@@ -1039,3 +1042,34 @@ blend_info_free (BlendInfo *info)
 {
   g_slice_free (BlendInfo, info);
 }
+
+
+/*  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 1a0bc87..3a743d2 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  */
@@ -73,10 +74,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]