[gimp/wip/gradient-edit: 40/42] app: add prepare-to-remove-slider signal to GimpToolLine



commit 75eced642481e33a8d1e9973374dadad940d156a
Author: Ell <ell_se yahoo com>
Date:   Fri Oct 6 12:04:01 2017 -0400

    app: add prepare-to-remove-slider signal to GimpToolLine
    
    The signal is emitted when a slider is dragged away from the line,
    and will be removed when the button is released, and when the
    slider is dragged back to the vicinity of the line, and won't be
    removed.  The last parameter of the signal is a boolean flag
    differentiating between the two cases.
    
    Note that a remove-slider signal may be emitted without a preceeding
    prepare-to-remove-slider signal, however, is a prepare-to-remove-
    slider signal is emitted with a TRUE last parameter, it must be
    eventually followed by a remove-slider signal, or by another
    prepare-to-remove-slider signal with a FALSE last parameter.

 app/core/gimpmarshal.list  |    1 +
 app/display/gimptoolline.c |   67 +++++++++++++++++++++++++++++++++----------
 app/display/gimptoolline.h |   25 +++++++++-------
 3 files changed, 66 insertions(+), 27 deletions(-)
---
diff --git a/app/core/gimpmarshal.list b/app/core/gimpmarshal.list
index 477702d..a79ef9b 100644
--- a/app/core/gimpmarshal.list
+++ b/app/core/gimpmarshal.list
@@ -48,6 +48,7 @@ VOID: ENUM, OBJECT
 VOID: ENUM, POINTER
 VOID: FLAGS
 VOID: INT
+VOID: INT, BOOLEAN
 VOID: INT, INT
 VOID: INT, INT, INT, INT
 VOID: INT, INT, BOOLEAN, BOOLEAN
diff --git a/app/display/gimptoolline.c b/app/display/gimptoolline.c
index 031ee25..db8dcf4 100644
--- a/app/display/gimptoolline.c
+++ b/app/display/gimptoolline.c
@@ -85,6 +85,7 @@ enum
 {
   CAN_ADD_SLIDER,
   ADD_SLIDER,
+  PREPARE_TO_REMOVE_SLIDER,
   REMOVE_SLIDER,
   SELECTION_CHANGED,
   HANDLE_CLICKED,
@@ -244,6 +245,17 @@ gimp_tool_line_class_init (GimpToolLineClass *klass)
                   G_TYPE_INT, 1,
                   G_TYPE_DOUBLE);
 
+  line_signals[PREPARE_TO_REMOVE_SLIDER] =
+    g_signal_new ("prepare-to-remove-slider",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GimpToolLineClass, prepare_to_remove_slider),
+                  NULL, NULL,
+                  gimp_marshal_VOID__INT_BOOLEAN,
+                  G_TYPE_NONE, 2,
+                  G_TYPE_INT,
+                  G_TYPE_BOOLEAN);
+
   line_signals[REMOVE_SLIDER] =
     g_signal_new ("remove-slider",
                   G_TYPE_FROM_CLASS (klass),
@@ -714,6 +726,14 @@ gimp_tool_line_button_release (GimpToolWidget        *widget,
             {
               gimp_tool_line_get_slider (line, private->selection)->value =
                 private->saved_slider_value;
+
+              if (private->remove_slider)
+                {
+                  private->remove_slider = FALSE;
+
+                  g_signal_emit (line, line_signals[PREPARE_TO_REMOVE_SLIDER], 0,
+                                 private->selection, FALSE);
+                }
             }
 
           g_object_set (line,
@@ -728,6 +748,8 @@ gimp_tool_line_button_release (GimpToolWidget        *widget,
     {
       if (private->remove_slider)
         {
+          private->remove_slider = FALSE;
+
           g_signal_emit (line, line_signals[REMOVE_SLIDER], 0,
                          private->selection);
         }
@@ -1211,6 +1233,7 @@ gimp_tool_line_selection_motion (GimpToolLine *line,
         GimpControllerSlider *slider;
         gdouble               value;
         gdouble               dist;
+        gboolean              remove_slider;
 
         shell = gimp_tool_widget_get_shell (GIMP_TOOL_WIDGET (line));
 
@@ -1235,26 +1258,36 @@ gimp_tool_line_selection_motion (GimpToolLine *line,
           }
 
         /* slider tearing */
-        private->remove_slider = slider->removable &&
-                                 dist > SLIDER_TEAR_DISTANCE;
+        remove_slider = slider->removable && dist > SLIDER_TEAR_DISTANCE;
 
-        /* eek! */
-        {
-          GimpCursorType     cursor;
-          GimpToolCursorType tool_cursor;
-          GimpCursorModifier modifier;
+        if (remove_slider != private->remove_slider)
+          {
+            private->remove_slider = remove_slider;
 
-          cursor      = shell->current_cursor;
-          tool_cursor = shell->tool_cursor;
-          modifier    = GIMP_CURSOR_MODIFIER_NONE;
+            g_signal_emit (line, line_signals[PREPARE_TO_REMOVE_SLIDER], 0,
+                           private->selection, remove_slider);
 
-          gimp_tool_line_get_cursor (GIMP_TOOL_WIDGET (line), NULL, 0,
-                                     &cursor, &tool_cursor, &modifier);
+            /* set the cursor modifier to a minus by talking to the shell
+             * directly -- eek!
+             */
+            {
+              GimpCursorType     cursor;
+              GimpToolCursorType tool_cursor;
+              GimpCursorModifier modifier;
 
-          gimp_display_shell_set_cursor (shell, cursor, tool_cursor, modifier);
-        }
+              cursor      = shell->current_cursor;
+              tool_cursor = shell->tool_cursor;
+              modifier    = GIMP_CURSOR_MODIFIER_NONE;
 
-        gimp_tool_line_update_circle (line);
+              gimp_tool_line_get_cursor (GIMP_TOOL_WIDGET (line), NULL, 0,
+                                         &cursor, &tool_cursor, &modifier);
+
+              gimp_display_shell_set_cursor (shell, cursor, tool_cursor, modifier);
+            }
+
+            gimp_tool_line_update_handles (line);
+            gimp_tool_line_update_circle (line);
+          }
 
         return TRUE;
       }
@@ -1304,7 +1337,9 @@ gimp_tool_line_update_handles (GimpToolLine *line)
                          value >= slider->min                          &&
                          value <= slider->max);
 
-      visible = slider->visible && (! slider->autohide || show_autohidden);
+      visible = slider->visible                         &&
+                (! slider->autohide || show_autohidden) &&
+                ! (private->selection == i && private->remove_slider);
 
       handle = gimp_tool_line_get_handle (line, i);
 
diff --git a/app/display/gimptoolline.h b/app/display/gimptoolline.h
index d66d762..6ed3727 100644
--- a/app/display/gimptoolline.h
+++ b/app/display/gimptoolline.h
@@ -60,17 +60,20 @@ struct _GimpToolLineClass
   GimpToolWidgetClass  parent_class;
 
   /*  signals  */
-  gboolean (* can_add_slider)    (GimpToolLine        *line,
-                                  gdouble              value);
-  gint     (* add_slider)        (GimpToolLine        *line,
-                                  gdouble              value);
-  void     (* remove_slider)     (GimpToolLine        *line,
-                                  gint                 slider);
-  void     (* selection_changed) (GimpToolLine        *line);
-  gboolean (* handle_clicked)    (GimpToolLine        *line,
-                                  gint                 handle,
-                                  GdkModifierType      state,
-                                  GimpButtonPressType  press_type);
+  gboolean (* can_add_slider)           (GimpToolLine        *line,
+                                         gdouble              value);
+  gint     (* add_slider)               (GimpToolLine        *line,
+                                         gdouble              value);
+  void     (* prepare_to_remove_slider) (GimpToolLine        *line,
+                                         gint                 slider,
+                                         gboolean             remove);
+  void     (* remove_slider)            (GimpToolLine        *line,
+                                         gint                 slider);
+  void     (* selection_changed)        (GimpToolLine        *line);
+  gboolean (* handle_clicked)           (GimpToolLine        *line,
+                                         gint                 handle,
+                                         GdkModifierType      state,
+                                         GimpButtonPressType  press_type);
 };
 
 


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