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



commit 73e3fe3fda73eca7926d2e6f8db4edf114e02f47
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 |  102 ++++++++++++++++++++++++++++++++------------
 app/display/gimptoolline.h |   18 +++++---
 3 files changed, 86 insertions(+), 35 deletions(-)
---
diff --git a/app/core/gimpmarshal.list b/app/core/gimpmarshal.list
index add1892..477702d 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 dfa3fba..f1b27f9 100644
--- a/app/display/gimptoolline.c
+++ b/app/display/gimptoolline.c
@@ -87,6 +87,7 @@ enum
   ADD_SLIDER,
   REMOVE_SLIDER,
   SELECTION_CHANGED,
+  HANDLE_CLICKED,
   LAST_SIGNAL
 };
 
@@ -261,6 +262,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,
@@ -590,6 +603,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;
@@ -599,43 +613,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;
-    }
+      g_signal_emit (line, line_signals[HANDLE_CLICKED], 0,
+                     private->selection, state, press_type, &result);
 
-  if (private->hover > GIMP_TOOL_LINE_HANDLE_NONE)
-    {
-      gimp_tool_line_set_selection (line, private->hover);
-
-      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;
 
@@ -645,7 +680,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
@@ -680,10 +715,21 @@ gimp_tool_line_button_release (GimpToolWidget        *widget,
                         NULL);
         }
     }
-  else if (grab == GRAB_SELECTION && private->remove_slider)
+  else if (grab == GRAB_SELECTION)
     {
-      g_signal_emit (line, line_signals[REMOVE_SLIDER], 0,
-                     private->selection);
+      if (private->remove_slider)
+        {
+          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[HANDLE_CLICKED], 0,
+                         private->selection, state, GIMP_BUTTON_PRESS_NORMAL,
+                         &result);
+        }
     }
 }
 
diff --git a/app/display/gimptoolline.h b/app/display/gimptoolline.h
index d9a557c..d66d762 100644
--- a/app/display/gimptoolline.h
+++ b/app/display/gimptoolline.h
@@ -60,13 +60,17 @@ 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 (* 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);
 };
 
 


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