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.
This commit is contained in:
Michael Natterer
2017-12-01 22:19:42 +01:00
parent 568c147f8d
commit d60c237805
3 changed files with 64 additions and 10 deletions

View File

@ -73,6 +73,9 @@ static void gimp_canvas_polygon_get_property (GObject *object
static void gimp_canvas_polygon_draw (GimpCanvasItem *item, static void gimp_canvas_polygon_draw (GimpCanvasItem *item,
cairo_t *cr); cairo_t *cr);
static cairo_region_t * gimp_canvas_polygon_get_extents (GimpCanvasItem *item); 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, 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->draw = gimp_canvas_polygon_draw;
item_class->get_extents = gimp_canvas_polygon_get_extents; 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, g_object_class_install_property (object_class, PROP_POINTS,
gimp_param_spec_array ("points", NULL, NULL, gimp_param_spec_array ("points", NULL, NULL,
@ -340,6 +344,48 @@ gimp_canvas_polygon_get_extents (GimpCanvasItem *item)
return cairo_region_create_rectangle (&rectangle); 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 * GimpCanvasItem *
gimp_canvas_polygon_new (GimpDisplayShell *shell, gimp_canvas_polygon_new (GimpDisplayShell *shell,
const GimpVector2 *points, const GimpVector2 *points,

View File

@ -1038,6 +1038,12 @@ gimp_tool_polygon_button_press (GimpToolWidget *widget,
} }
else if (priv->polygon_closed) 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; return 0;
} }
else else

View File

@ -169,6 +169,7 @@ gimp_free_select_tool_init (GimpFreeSelectTool *fst)
gimp_tool_control_set_motion_mode (tool->control, gimp_tool_control_set_motion_mode (tool->control,
GIMP_MOTION_MODE_EXACT); GIMP_MOTION_MODE_EXACT);
gimp_tool_control_set_wants_click (tool->control, TRUE); 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_control_set_active_modifiers (tool->control,
GIMP_TOOL_ACTIVE_MODIFIERS_SEPARATE); GIMP_TOOL_ACTIVE_MODIFIERS_SEPARATE);
gimp_tool_control_set_precision (tool->control, gimp_tool_control_set_precision (tool->control,
@ -364,6 +365,7 @@ gimp_free_select_tool_button_press (GimpTool *tool,
private->grab_widget = private->widget; private->grab_widget = private->widget;
} }
if (press_type == GIMP_BUTTON_PRESS_NORMAL)
gimp_tool_control_activate (tool->control); gimp_tool_control_activate (tool->control);
} }