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



commit 7e45d4374f5a3c9cf89e5768b9427b8c286c9a6d
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 |  260 ++++++++++++++++++++++----------------
 app/tools/gimpblendtool.c        |   46 ++++++-
 app/tools/gimpblendtool.h        |   13 ++-
 3 files changed, 201 insertions(+), 118 deletions(-)
---
diff --git a/app/tools/gimpblendtool-editor.c b/app/tools/gimpblendtool-editor.c
index cd18bbe..b8b9fd4 100644
--- a/app/tools/gimpblendtool-editor.c
+++ b/app/tools/gimpblendtool-editor.c
@@ -85,115 +85,119 @@ typedef struct
 
 /*  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 void                  gimp_blend_tool_editor_line_selection_changed     (GimpToolLine          *line,
-                                                                                GimpBlendTool         
*blend_tool);
-static gboolean              gimp_blend_tool_editor_line_handle_clicked        (GimpToolLine          *line,
-                                                                                gint                   
handle,
-                                                                                GdkModifierType        state,
-                                                                                GimpButtonPressType    
press_type,
-                                                                                GimpBlendTool         
*blend_tool);
-                                                                               
-static void                  gimp_blend_tool_editor_gui_response               (GimpToolGui           *gui,
-                                                                                gint                   
response_id,
-                                                                                GimpBlendTool         
*blend_tool);
-                                                                               
-static void                  gimp_blend_tool_editor_color_entry_color_clicked  (GimpColorButton       
*button,
-                                                                                GimpBlendTool         
*blend_tool);
-static void                  gimp_blend_tool_editor_color_entry_color_changed  (GimpColorButton       
*button,
-                                                                                GimpBlendTool         
*blend_tool);
-static void                  gimp_blend_tool_editor_color_entry_color_response (GimpColorButton       
*button,
-                                                                                GimpColorDialogState   state,
-                                                                                GimpBlendTool         
*blend_tool);
-                                                                               
-static void                  gimp_blend_tool_editor_color_entry_type_changed   (GtkComboBox           *combo,
-                                                                                GimpBlendTool         
*blend_tool);
-                                                                               
-static void                  gimp_blend_tool_editor_endpoint_se_value_changed  (GimpSizeEntry         *se,
-                                                                                GimpBlendTool         
*blend_tool);
-
-static void                  gimp_blend_tool_editor_stop_se_value_changed      (GimpSizeEntry        *se,
-                                                                                GimpBlendTool        
*blend_tool);
-                                                                               
-static void                  gimp_blend_tool_editor_stop_delete_clicked        (GtkWidget             
*button,
-                                                                                GimpBlendTool         
*blend_tool);
-                                                                               
-static void                  gimp_blend_tool_editor_midpoint_se_value_changed  (GimpSizeEntry        *se,
-                                                                                GimpBlendTool        
*blend_tool);
-
-static void                  gimp_blend_tool_editor_midpoint_type_changed      (GtkComboBox           *combo,
-                                                                                GimpBlendTool         
*blend_tool);
-                                                                              
-static void                  gimp_blend_tool_editor_midpoint_color_changed     (GtkComboBox           *combo,
-                                                                                GimpBlendTool         
*blend_tool);
-                                                                              
-static void                  gimp_blend_tool_editor_midpoint_new_stop_clicked  (GtkWidget             
*button,
-                                                                                GimpBlendTool         
*blend_tool);
-static void                  gimp_blend_tool_editor_midpoint_center_clicked    (GtkWidget             
*button,
-                                                                                GimpBlendTool         
*blend_tool);
-                                                                              
-static gboolean              gimp_blend_tool_editor_flush_idle                 (GimpBlendTool         
*blend_tool);
-                                                                              
-static gboolean              gimp_blend_tool_editor_is_gradient_editable       (GimpBlendTool         
*blend_tool);
-                                                                              
-static gboolean              gimp_blend_tool_editor_handle_is_endpoint         (GimpBlendTool         
*blend_tool,
-                                                                                gint                   
handle);
-static gboolean              gimp_blend_tool_editor_handle_is_stop             (GimpBlendTool         
*blend_tool,
-                                                                                gint                   
handle);
-static gboolean              gimp_blend_tool_editor_handle_is_midpoint         (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_freeze_gradient            (GimpBlendTool         
*blend_tool);
-static void                  gimp_blend_tool_editor_thaw_gradient              (GimpBlendTool         
*blend_tool);
-                                                                              
-static gint                  gimp_blend_tool_editor_add_stop                   (GimpBlendTool         
*blend_tool,
-                                                                                gdouble                
value);
-static void                  gimp_blend_tool_editor_delete_stop                (GimpBlendTool         
*blend_tool,
-                                                                                gint                   
slider);
-static gint                  gimp_blend_tool_editor_midpoint_to_stop           (GimpBlendTool         
*blend_tool,
-                                                                                gint                   
slider);
-                                                                              
-static void                  gimp_blend_tool_editor_update_sliders             (GimpBlendTool         
*blend_tool);
-                                                                              
-static void                  gimp_blend_tool_editor_purge_gradient_history     (GSList               
**stack);
-static void                  gimp_blend_tool_editor_purge_gradient             (GimpBlendTool         
*blend_tool);
-                                                                              
-static GtkWidget           * gimp_blend_tool_editor_color_entry_new            (GimpBlendTool         
*blend_tool,
-                                                                                const gchar           *title,
-                                                                                Direction              
direction,
-                                                                                GtkWidget             
*chain_button,
-                                                                                GtkWidget            
**color_panel,
-                                                                                GtkWidget            
**type_combo);
-static void                  gimp_blend_tool_editor_init_endpoint_gui          (GimpBlendTool         
*blend_tool);
-static void                  gimp_blend_tool_editor_init_stop_gui              (GimpBlendTool         
*blend_tool);
-static void                  gimp_blend_tool_editor_init_midpoint_gui          (GimpBlendTool         
*blend_tool);
-static void                  gimp_blend_tool_editor_update_endpoint_gui        (GimpBlendTool         
*blend_tool,
-                                                                                gint                   
selection);
-static void                  gimp_blend_tool_editor_update_stop_gui            (GimpBlendTool         
*blend_tool,
-                                                                                gint                   
selection);
-static void                  gimp_blend_tool_editor_update_midpoint_gui        (GimpBlendTool         
*blend_tool,
-                                                                                gint                   
selection);
-static void                  gimp_blend_tool_editor_update_gui                 (GimpBlendTool         
*blend_tool);
-                                                                              
-static BlendInfo           * gimp_blend_tool_editor_blend_info_new             (GimpBlendTool         
*blend_tool);
-static void                  gimp_blend_tool_editor_blend_info_free            (BlendInfo             *info);
-static void                  gimp_blend_tool_editor_blend_info_apply           (GimpBlendTool         
*blend_tool,
-                                                                                const BlendInfo       *info,
-                                                                                gboolean               
set_selection);
+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 void                  gimp_blend_tool_editor_line_selection_changed        (GimpToolLine          
*line,
+                                                                                   GimpBlendTool         
*blend_tool);
+static gboolean              gimp_blend_tool_editor_line_handle_clicked           (GimpToolLine          
*line,
+                                                                                   gint                   
handle,
+                                                                                   GdkModifierType        
state,
+                                                                                   GimpButtonPressType    
press_type,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_gui_response                  (GimpToolGui           
*gui,
+                                                                                   gint                   
response_id,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_color_entry_color_clicked     (GimpColorButton       
*button,
+                                                                                   GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_color_entry_color_changed     (GimpColorButton       
*button,
+                                                                                   GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_color_entry_color_response    (GimpColorButton       
*button,
+                                                                                   GimpColorDialogState   
state,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_color_entry_type_changed      (GtkComboBox           
*combo,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_endpoint_se_value_changed     (GimpSizeEntry         *se,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_stop_se_value_changed         (GimpSizeEntry        *se,
+                                                                                   GimpBlendTool        
*blend_tool);
+
+static void                  gimp_blend_tool_editor_stop_delete_clicked           (GtkWidget             
*button,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_midpoint_se_value_changed     (GimpSizeEntry        *se,
+                                                                                   GimpBlendTool        
*blend_tool);
+
+static void                  gimp_blend_tool_editor_midpoint_type_changed         (GtkComboBox           
*combo,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_midpoint_color_changed        (GtkComboBox           
*combo,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_midpoint_new_stop_clicked     (GtkWidget             
*button,
+                                                                                   GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_midpoint_center_clicked       (GtkWidget             
*button,
+                                                                                   GimpBlendTool         
*blend_tool);
+
+static gboolean              gimp_blend_tool_editor_flush_idle                    (GimpBlendTool         
*blend_tool);
+
+static gboolean              gimp_blend_tool_editor_is_gradient_editable          (GimpBlendTool         
*blend_tool);
+
+static gboolean              gimp_blend_tool_editor_handle_is_endpoint            (GimpBlendTool         
*blend_tool,
+                                                                                   gint                   
handle);
+static gboolean              gimp_blend_tool_editor_handle_is_stop                (GimpBlendTool         
*blend_tool,
+                                                                                   gint                   
handle);
+static gboolean              gimp_blend_tool_editor_handle_is_midpoint            (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_freeze_gradient               (GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_thaw_gradient                 (GimpBlendTool         
*blend_tool);
+
+static gint                  gimp_blend_tool_editor_add_stop                      (GimpBlendTool         
*blend_tool,
+                                                                                   gdouble                
value);
+static void                  gimp_blend_tool_editor_delete_stop                   (GimpBlendTool         
*blend_tool,
+                                                                                   gint                   
slider);
+static gint                  gimp_blend_tool_editor_midpoint_to_stop              (GimpBlendTool         
*blend_tool,
+                                                                                   gint                   
slider);
+
+static void                  gimp_blend_tool_editor_update_sliders                (GimpBlendTool         
*blend_tool);
+
+static void                  gimp_blend_tool_editor_purge_gradient_history        (GSList               
**stack);
+static void                  gimp_blend_tool_editor_purge_gradient                (GimpBlendTool         
*blend_tool);
+
+static GtkWidget           * gimp_blend_tool_editor_color_entry_new               (GimpBlendTool         
*blend_tool,
+                                                                                   const gchar           
*title,
+                                                                                   Direction              
direction,
+                                                                                   GtkWidget             
*chain_button,
+                                                                                   GtkWidget            
**color_panel,
+                                                                                   GtkWidget            
**type_combo);
+static void                  gimp_blend_tool_editor_init_endpoint_gui             (GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_init_stop_gui                 (GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_init_midpoint_gui             (GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_update_endpoint_gui           (GimpBlendTool         
*blend_tool,
+                                                                                   gint                   
selection);
+static void                  gimp_blend_tool_editor_update_stop_gui               (GimpBlendTool         
*blend_tool,
+                                                                                   gint                   
selection);
+static void                  gimp_blend_tool_editor_update_midpoint_gui           (GimpBlendTool         
*blend_tool,
+                                                                                   gint                   
selection);
+static void                  gimp_blend_tool_editor_update_gui                    (GimpBlendTool         
*blend_tool);
+
+static BlendInfo           * gimp_blend_tool_editor_blend_info_new                (GimpBlendTool         
*blend_tool);
+static void                  gimp_blend_tool_editor_blend_info_free               (BlendInfo             
*info);
+static void                  gimp_blend_tool_editor_blend_info_apply              (GimpBlendTool         
*blend_tool,
+                                                                                   const BlendInfo       
*info,
+                                                                                   gboolean               
set_selection);
 
 
 /*  private functions  */
@@ -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 0231c45..08862bc 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]