app: add GimpColorTool::can_pick() virtual function

Determines if the tool can pick at a given coordinate, without
actually picking.  The default implementation uses
gimp_image_coords_in_active_pickable(); GimpFilterTool overrides
this function, to return TRUE whenever the active picker has
pick_abyss == TRUE.

Use this function when updating the cursor, and when determining
whether to draw the sample-average region indicator.
This commit is contained in:
Ell 2017-05-03 13:24:39 -04:00
parent bc4589968c
commit bfadac145b
3 changed files with 86 additions and 23 deletions

View File

@ -95,6 +95,10 @@ static void gimp_color_tool_cursor_update (GimpTool *tool,
static void gimp_color_tool_draw (GimpDrawTool *draw_tool); static void gimp_color_tool_draw (GimpDrawTool *draw_tool);
static gboolean
gimp_color_tool_real_can_pick (GimpColorTool *color_tool,
const GimpCoords *coords,
GimpDisplay *display);
static gboolean gimp_color_tool_real_pick (GimpColorTool *color_tool, static gboolean gimp_color_tool_real_pick (GimpColorTool *color_tool,
gint x, gint x,
gint y, gint y,
@ -109,6 +113,9 @@ static void gimp_color_tool_real_picked (GimpColorTool *color_tool,
gpointer pixel, gpointer pixel,
const GimpRGB *color); const GimpRGB *color);
static gboolean gimp_color_tool_can_pick (GimpColorTool *tool,
const GimpCoords *coords,
GimpDisplay *display);
static void gimp_color_tool_pick (GimpColorTool *tool, static void gimp_color_tool_pick (GimpColorTool *tool,
GimpColorPickState pick_state, GimpColorPickState pick_state,
gint x, gint x,
@ -154,6 +161,7 @@ gimp_color_tool_class_init (GimpColorToolClass *klass)
draw_class->draw = gimp_color_tool_draw; draw_class->draw = gimp_color_tool_draw;
klass->can_pick = gimp_color_tool_real_can_pick;
klass->pick = gimp_color_tool_real_pick; klass->pick = gimp_color_tool_real_pick;
klass->picked = gimp_color_tool_real_picked; klass->picked = gimp_color_tool_real_picked;
} }
@ -207,7 +215,7 @@ gimp_color_tool_button_press (GimpTool *tool,
gimp_sample_point_tool_start_edit (tool, display, gimp_sample_point_tool_start_edit (tool, display,
color_tool->sample_point); color_tool->sample_point);
} }
else else if (gimp_color_tool_can_pick (color_tool, coords, display))
{ {
gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_START, gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_START,
coords->x, coords->y); coords->x, coords->y);
@ -231,7 +239,8 @@ gimp_color_tool_button_release (GimpTool *tool,
if (! color_tool->enabled) if (! color_tool->enabled)
return; return;
if (! color_tool->sample_point) if (! color_tool->sample_point &&
gimp_color_tool_can_pick (color_tool, coords, display))
{ {
gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_END, gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_END,
coords->x, coords->y); coords->x, coords->y);
@ -254,13 +263,18 @@ gimp_color_tool_motion (GimpTool *tool,
{ {
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
color_tool->can_pick = gimp_color_tool_can_pick (color_tool,
coords, display);
color_tool->center_x = coords->x; color_tool->center_x = coords->x;
color_tool->center_y = coords->y; color_tool->center_y = coords->y;
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); if (color_tool->can_pick)
{
gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_UPDATE,
coords->x, coords->y);
}
gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_UPDATE, gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
coords->x, coords->y);
} }
} }
@ -303,6 +317,8 @@ gimp_color_tool_oper_update (GimpTool *tool,
color_tool->sample_point = sample_point; color_tool->sample_point = sample_point;
color_tool->can_pick = gimp_color_tool_can_pick (color_tool,
coords, display);
color_tool->center_x = coords->x; color_tool->center_x = coords->x;
color_tool->center_y = coords->y; color_tool->center_y = coords->y;
@ -323,7 +339,6 @@ gimp_color_tool_cursor_update (GimpTool *tool,
GimpDisplay *display) GimpDisplay *display)
{ {
GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool); GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool);
GimpImage *image = gimp_display_get_image (display);
if (color_tool->enabled) if (color_tool->enabled)
{ {
@ -338,9 +353,7 @@ gimp_color_tool_cursor_update (GimpTool *tool,
{ {
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_BAD; GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_BAD;
if (gimp_image_coords_in_active_pickable (image, coords, if (gimp_color_tool_can_pick (color_tool, coords, display))
color_tool->options->sample_merged,
FALSE))
{ {
switch (color_tool->pick_mode) switch (color_tool->pick_mode)
{ {
@ -394,7 +407,7 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
item = gimp_draw_tool_add_sample_point (draw_tool, x, y, index); item = gimp_draw_tool_add_sample_point (draw_tool, x, y, index);
gimp_canvas_item_set_highlight (item, TRUE); gimp_canvas_item_set_highlight (item, TRUE);
} }
else if (color_tool->options->sample_average) else if (color_tool->can_pick && color_tool->options->sample_average)
{ {
gdouble radius = color_tool->options->average_radius; gdouble radius = color_tool->options->average_radius;
@ -408,6 +421,19 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
} }
} }
static gboolean
gimp_color_tool_real_can_pick (GimpColorTool *color_tool,
const GimpCoords *coords,
GimpDisplay *display)
{
GimpImage *image = gimp_display_get_image (display);
return
gimp_image_coords_in_active_pickable (image, coords,
color_tool->options->sample_merged,
FALSE);
}
static gboolean static gboolean
gimp_color_tool_real_pick (GimpColorTool *color_tool, gimp_color_tool_real_pick (GimpColorTool *color_tool,
gint x, gint x,
@ -542,6 +568,18 @@ gimp_color_tool_real_picked (GimpColorTool *color_tool,
} }
} }
static gboolean
gimp_color_tool_can_pick (GimpColorTool *tool,
const GimpCoords *coords,
GimpDisplay *display)
{
GimpColorToolClass *klass;
klass = GIMP_COLOR_TOOL_GET_CLASS (tool);
return klass->can_pick && klass->can_pick (tool, coords, display);
}
static void static void
gimp_color_tool_pick (GimpColorTool *tool, gimp_color_tool_pick (GimpColorTool *tool,
GimpColorPickState pick_state, GimpColorPickState pick_state,

View File

@ -44,6 +44,7 @@ struct _GimpColorTool
GimpColorPickMode pick_mode; GimpColorPickMode pick_mode;
gboolean can_pick;
gint center_x; gint center_x;
gint center_y; gint center_y;
GimpSamplePoint *sample_point; GimpSamplePoint *sample_point;
@ -54,21 +55,24 @@ struct _GimpColorToolClass
GimpDrawToolClass parent_class; GimpDrawToolClass parent_class;
/* virtual functions */ /* virtual functions */
gboolean (* pick) (GimpColorTool *tool, gboolean (* can_pick) (GimpColorTool *tool,
gint x, const GimpCoords *coords,
gint y, GimpDisplay *display);
const Babl **sample_format, gboolean (* pick) (GimpColorTool *tool,
gpointer pixel, gint x,
GimpRGB *color); gint y,
const Babl **sample_format,
gpointer pixel,
GimpRGB *color);
/* signals */ /* signals */
void (* picked) (GimpColorTool *tool, void (* picked) (GimpColorTool *tool,
GimpColorPickState pick_state, GimpColorPickState pick_state,
gdouble x, gdouble x,
gdouble y, gdouble y,
const Babl *sample_format, const Babl *sample_format,
gpointer pixel, gpointer pixel,
const GimpRGB *color); const GimpRGB *color);
}; };

View File

@ -108,6 +108,9 @@ static void gimp_filter_tool_options_notify (GimpTool *tool,
GimpToolOptions *options, GimpToolOptions *options,
const GParamSpec *pspec); const GParamSpec *pspec);
static gboolean gimp_filter_tool_can_pick_color (GimpColorTool *color_tool,
const GimpCoords *coords,
GimpDisplay *display);
static gboolean gimp_filter_tool_pick_color (GimpColorTool *color_tool, static gboolean gimp_filter_tool_pick_color (GimpColorTool *color_tool,
gint x, gint x,
gint y, gint y,
@ -179,6 +182,7 @@ gimp_filter_tool_class_init (GimpFilterToolClass *klass)
tool_class->cursor_update = gimp_filter_tool_cursor_update; tool_class->cursor_update = gimp_filter_tool_cursor_update;
tool_class->options_notify = gimp_filter_tool_options_notify; tool_class->options_notify = gimp_filter_tool_options_notify;
color_tool_class->can_pick = gimp_filter_tool_can_pick_color;
color_tool_class->pick = gimp_filter_tool_pick_color; color_tool_class->pick = gimp_filter_tool_pick_color;
color_tool_class->picked = gimp_filter_tool_color_picked; color_tool_class->picked = gimp_filter_tool_color_picked;
@ -791,6 +795,23 @@ gimp_filter_tool_options_notify (GimpTool *tool,
} }
} }
static gboolean
gimp_filter_tool_can_pick_color (GimpColorTool *color_tool,
const GimpCoords *coords,
GimpDisplay *display)
{
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (color_tool);
gboolean pick_abyss;
pick_abyss =
GPOINTER_TO_INT (g_object_get_data (G_OBJECT (filter_tool->active_picker),
"picker-pick-abyss"));
return pick_abyss ||
GIMP_COLOR_TOOL_CLASS (parent_class)->can_pick (color_tool,
coords, display);
}
static gboolean static gboolean
gimp_filter_tool_pick_color (GimpColorTool *color_tool, gimp_filter_tool_pick_color (GimpColorTool *color_tool,
gint x, gint x,