[gimp] Bug 785781 - Additional Free Selection step (hitting Enter)...



commit d60c237805ac2d4018a20cf7acbad6bf4e33b622
Author: Michael Natterer <mitch gimp org>
Date:   Fri Dec 1 22:19:42 2017 +0100

    Bug 785781 - Additional Free Selection step (hitting Enter)...
    
    ...is a regression in common cases
    
    Commit the free select tool on double click inside the polygon.
    
    Done by implementing GimpCanvasItem::hit() in GimpCanvasPolygon, using
    ugly code.

 app/display/gimpcanvaspolygon.c |   46 +++++++++++++++++++++++++++++++++++++++
 app/display/gimptoolpolygon.c   |    6 +++++
 app/tools/gimpfreeselecttool.c  |   22 ++++++++++--------
 3 files changed, 64 insertions(+), 10 deletions(-)
---
diff --git a/app/display/gimpcanvaspolygon.c b/app/display/gimpcanvaspolygon.c
index c6df1ab..cf7b2ee 100644
--- a/app/display/gimpcanvaspolygon.c
+++ b/app/display/gimpcanvaspolygon.c
@@ -73,6 +73,9 @@ static void             gimp_canvas_polygon_get_property (GObject        *object
 static void             gimp_canvas_polygon_draw         (GimpCanvasItem *item,
                                                           cairo_t        *cr);
 static cairo_region_t * gimp_canvas_polygon_get_extents  (GimpCanvasItem *item);
+static gboolean         gimp_canvas_polygon_hit          (GimpCanvasItem *item,
+                                                          gdouble         x,
+                                                          gdouble         y);
 
 
 G_DEFINE_TYPE (GimpCanvasPolygon, gimp_canvas_polygon,
@@ -93,6 +96,7 @@ gimp_canvas_polygon_class_init (GimpCanvasPolygonClass *klass)
 
   item_class->draw           = gimp_canvas_polygon_draw;
   item_class->get_extents    = gimp_canvas_polygon_get_extents;
+  item_class->hit            = gimp_canvas_polygon_hit;
 
   g_object_class_install_property (object_class, PROP_POINTS,
                                    gimp_param_spec_array ("points", NULL, NULL,
@@ -340,6 +344,48 @@ gimp_canvas_polygon_get_extents (GimpCanvasItem *item)
   return cairo_region_create_rectangle (&rectangle);
 }
 
+static gboolean
+gimp_canvas_polygon_hit (GimpCanvasItem *item,
+                         gdouble         x,
+                         gdouble         y)
+{
+  GimpCanvasPolygonPrivate *private = GET_PRIVATE (item);
+  GimpVector2              *points;
+  gdouble                   tx, ty;
+  cairo_surface_t          *surface;
+  cairo_t                  *cr;
+  gboolean                  hit;
+  gint                      i;
+
+  if (! private->points)
+    return FALSE;
+
+  gimp_canvas_item_transform_xy_f (item, x, y, &tx, &ty);
+
+  points = g_new0 (GimpVector2, private->n_points);
+
+  gimp_canvas_polygon_transform (item, points);
+
+  surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1);
+  cr = cairo_create (surface);
+  cairo_surface_destroy (surface);
+
+  cairo_move_to (cr, points[0].x, points[0].y);
+
+  for (i = 1; i < private->n_points; i++)
+    {
+      cairo_line_to (cr, points[i].x, points[i].y);
+    }
+
+  g_free (points);
+
+  hit = cairo_in_fill (cr, tx, ty);
+
+  cairo_destroy (cr);
+
+  return hit;
+}
+
 GimpCanvasItem *
 gimp_canvas_polygon_new (GimpDisplayShell  *shell,
                          const GimpVector2 *points,
diff --git a/app/display/gimptoolpolygon.c b/app/display/gimptoolpolygon.c
index 618f60b..c836fa4 100644
--- a/app/display/gimptoolpolygon.c
+++ b/app/display/gimptoolpolygon.c
@@ -1038,6 +1038,12 @@ gimp_tool_polygon_button_press (GimpToolWidget      *widget,
     }
   else if (priv->polygon_closed)
     {
+      if (press_type == GIMP_BUTTON_PRESS_DOUBLE &&
+          gimp_canvas_item_hit (priv->polygon, coords->x, coords->y))
+        {
+          gimp_tool_widget_response (widget, GIMP_TOOL_WIDGET_RESPONSE_CONFIRM);
+        }
+
       return 0;
     }
   else
diff --git a/app/tools/gimpfreeselecttool.c b/app/tools/gimpfreeselecttool.c
index f74f2ea..302e19d 100644
--- a/app/tools/gimpfreeselecttool.c
+++ b/app/tools/gimpfreeselecttool.c
@@ -166,15 +166,16 @@ gimp_free_select_tool_init (GimpFreeSelectTool *fst)
                                               GIMP_TYPE_FREE_SELECT_TOOL,
                                               GimpFreeSelectToolPrivate);
 
-  gimp_tool_control_set_motion_mode      (tool->control,
-                                          GIMP_MOTION_MODE_EXACT);
-  gimp_tool_control_set_wants_click      (tool->control, TRUE);
-  gimp_tool_control_set_active_modifiers (tool->control,
-                                          GIMP_TOOL_ACTIVE_MODIFIERS_SEPARATE);
-  gimp_tool_control_set_precision        (tool->control,
-                                          GIMP_CURSOR_PRECISION_SUBPIXEL);
-  gimp_tool_control_set_tool_cursor      (tool->control,
-                                          GIMP_TOOL_CURSOR_FREE_SELECT);
+  gimp_tool_control_set_motion_mode        (tool->control,
+                                            GIMP_MOTION_MODE_EXACT);
+  gimp_tool_control_set_wants_click        (tool->control, TRUE);
+  gimp_tool_control_set_wants_double_click (tool->control, TRUE);
+  gimp_tool_control_set_active_modifiers   (tool->control,
+                                            GIMP_TOOL_ACTIVE_MODIFIERS_SEPARATE);
+  gimp_tool_control_set_precision          (tool->control,
+                                            GIMP_CURSOR_PRECISION_SUBPIXEL);
+  gimp_tool_control_set_tool_cursor        (tool->control,
+                                            GIMP_TOOL_CURSOR_FREE_SELECT);
 }
 
 static void
@@ -364,7 +365,8 @@ gimp_free_select_tool_button_press (GimpTool            *tool,
       private->grab_widget = private->widget;
     }
 
-  gimp_tool_control_activate (tool->control);
+  if (press_type == GIMP_BUTTON_PRESS_NORMAL)
+    gimp_tool_control_activate (tool->control);
 }
 
 static void


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