[gimp/wip/gradient-edit: 19/52] app: add handle-clicked signal to GimpToolLine



commit 7d64589b8bd901d0ecf1608cbc1e09aa8812f6f1
Author: Ell <ell_se yahoo com>
Date:   Sun Jul 23 19:49:15 2017 -0400

    app: add handle-clicked signal to GimpToolLine
    
    ... which is emitted when a handle is single/double/tripple clicked.
    
    The signal handler returns a boolean value.  A return value of TRUE
    stops further event processing, while a return value of FALSE allows
    it.

 app/core/gimpmarshal.list  |    1 +
 app/display/gimptoolline.c |  104 +++++++++++++++++++++++++++++++------------
 app/display/gimptoolline.h |   24 ++++++----
 3 files changed, 90 insertions(+), 39 deletions(-)
---
diff --git a/app/core/gimpmarshal.list b/app/core/gimpmarshal.list
index f44c1c7..a79ef9b 100644
--- a/app/core/gimpmarshal.list
+++ b/app/core/gimpmarshal.list
@@ -25,6 +25,7 @@
 BOOLEAN: BOOLEAN
 BOOLEAN: DOUBLE
 BOOLEAN: ENUM, INT
+BOOLEAN: INT, UINT, ENUM
 BOOLEAN: OBJECT
 BOOLEAN: OBJECT, POINTER
 BOOLEAN: OBJECT, POINTER, STRING
diff --git a/app/display/gimptoolline.c b/app/display/gimptoolline.c
index 4c6664e..eeee562 100644
--- a/app/display/gimptoolline.c
+++ b/app/display/gimptoolline.c
@@ -88,6 +88,7 @@ enum
   PREPARE_TO_REMOVE_SLIDER,
   REMOVE_SLIDER,
   SELECTION_CHANGED,
+  HANDLE_CLICKED,
   LAST_SIGNAL
 };
 
@@ -273,6 +274,18 @@ gimp_tool_line_class_init (GimpToolLineClass *klass)
                   g_cclosure_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
 
+  line_signals[HANDLE_CLICKED] =
+    g_signal_new ("handle-clicked",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GimpToolLineClass, handle_clicked),
+                  NULL, NULL,
+                  gimp_marshal_BOOLEAN__INT_UINT_ENUM,
+                  G_TYPE_BOOLEAN, 3,
+                  G_TYPE_INT,
+                  G_TYPE_UINT,
+                  GIMP_TYPE_BUTTON_PRESS_TYPE);
+
   g_object_class_install_property (object_class, PROP_X1,
                                    g_param_spec_double ("x1", NULL, NULL,
                                                         -GIMP_MAX_IMAGE_SIZE,
@@ -602,6 +615,7 @@ gimp_tool_line_button_press (GimpToolWidget      *widget,
 {
   GimpToolLine        *line    = GIMP_TOOL_LINE (widget);
   GimpToolLinePrivate *private = line->private;
+  gboolean             result  = FALSE;
 
   private->grab          = GRAB_NONE;
   private->remove_slider = FALSE;
@@ -611,43 +625,64 @@ gimp_tool_line_button_press (GimpToolWidget      *widget,
   private->saved_x2 = private->x2;
   private->saved_y2 = private->y2;
 
-  if (GIMP_TOOL_LINE_HANDLE_IS_SLIDER (private->hover))
+  if (press_type         != GIMP_BUTTON_PRESS_NORMAL   &&
+      private->hover      > GIMP_TOOL_LINE_HANDLE_NONE &&
+      private->selection  > GIMP_TOOL_LINE_HANDLE_NONE)
     {
-      private->saved_slider_value =
-        gimp_tool_line_get_slider (line, private->hover)->value;
-    }
-
-  if (private->hover > GIMP_TOOL_LINE_HANDLE_NONE)
-    {
-      gimp_tool_line_set_selection (line, private->hover);
+      g_signal_emit (line, line_signals[HANDLE_CLICKED], 0,
+                     private->selection, state, press_type, &result);
 
-      private->grab = GRAB_SELECTION;
+      if (! result)
+        gimp_tool_widget_hover (widget, coords, state, TRUE);
     }
-  else if (private->hover == HOVER_NEW_SLIDER)
+
+  if (press_type == GIMP_BUTTON_PRESS_NORMAL || ! result)
     {
-      gint slider;
+      private->saved_x1 = private->x1;
+      private->saved_y1 = private->y1;
+      private->saved_x2 = private->x2;
+      private->saved_y2 = private->y2;
 
-      g_signal_emit (line, line_signals[ADD_SLIDER], 0,
-                     private->new_slider_value, &slider);
+      if (GIMP_TOOL_LINE_HANDLE_IS_SLIDER (private->hover))
+        {
+          private->saved_slider_value =
+            gimp_tool_line_get_slider (line, private->hover)->value;
+        }
 
-      g_return_val_if_fail (slider < (gint) private->sliders->len, FALSE);
+      if (private->hover > GIMP_TOOL_LINE_HANDLE_NONE)
+        {
+          gimp_tool_line_set_selection (line, private->hover);
 
-      if (slider >= 0)
+          private->grab = GRAB_SELECTION;
+        }
+      else if (private->hover == HOVER_NEW_SLIDER)
         {
-          gimp_tool_line_set_selection (line, slider);
+          gint slider;
 
-          private->saved_slider_value =
-            gimp_tool_line_get_slider (line, private->selection)->value;
+          g_signal_emit (line, line_signals[ADD_SLIDER], 0,
+                         private->new_slider_value, &slider);
 
-          private->grab = GRAB_SELECTION;
+          g_return_val_if_fail (slider < (gint) private->sliders->len, FALSE);
+
+          if (slider >= 0)
+            {
+              gimp_tool_line_set_selection (line, slider);
+
+              private->saved_slider_value =
+                gimp_tool_line_get_slider (line, private->selection)->value;
+
+              private->grab = GRAB_SELECTION;
+            }
         }
-    }
-  else if (state & GRAB_LINE_MASK)
-    {
-      private->grab = GRAB_LINE;
+      else if (state & GRAB_LINE_MASK)
+        {
+          private->grab = GRAB_LINE;
+        }
+
+      result = (private->grab != GRAB_NONE);
     }
 
-  if (grab == GRAB_NONE)
+  if (! result)
     {
       private->hover = GIMP_TOOL_LINE_HANDLE_NONE;
 
@@ -657,7 +692,7 @@ gimp_tool_line_button_press (GimpToolWidget      *widget,
   gimp_tool_line_update_handles (line);
   gimp_tool_line_update_status (line, state, TRUE);
 
-  return private->grab != GRAB_NONE;
+  return result;
 }
 
 void
@@ -700,12 +735,23 @@ gimp_tool_line_button_release (GimpToolWidget        *widget,
                         NULL);
         }
     }
-  else if (grab == GRAB_SELECTION && private->remove_slider)
+  else if (grab == GRAB_SELECTION)
     {
-      private->remove_slider = FALSE;
+      if (private->remove_slider)
+        {
+          private->remove_slider = FALSE;
+
+          g_signal_emit (line, line_signals[REMOVE_SLIDER], 0,
+                         private->selection);
+        }
+      else if (release_type == GIMP_BUTTON_RELEASE_CLICK)
+        {
+          gboolean result;
 
-      g_signal_emit (line, line_signals[REMOVE_SLIDER], 0,
-                     private->selection);
+          g_signal_emit (line, line_signals[HANDLE_CLICKED], 0,
+                         private->selection, state, GIMP_BUTTON_PRESS_NORMAL,
+                         &result);
+        }
     }
 }
 
diff --git a/app/display/gimptoolline.h b/app/display/gimptoolline.h
index 8642a35..6ed3727 100644
--- a/app/display/gimptoolline.h
+++ b/app/display/gimptoolline.h
@@ -60,16 +60,20 @@ struct _GimpToolLineClass
   GimpToolWidgetClass  parent_class;
 
   /*  signals  */
-  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 (* 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]