app: add support for color picking in "show all" mode

Add a show_all parameter to gimp_image_pick_color(), which, when
TRUE, allows picking colors outside the canvas bounds in sample-
merged mode.  Forward the display's "show all" mode through this
parameter where applicable (in particular, in the color-picker tool
and the pointer dockable).
This commit is contained in:
Ell 2019-09-04 18:10:24 +03:00
parent 02943e22f6
commit cf3638391d
14 changed files with 74 additions and 17 deletions

View file

@ -20,8 +20,12 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpmath/gimpmath.h"
#include "core-types.h"
#include "gegl/gimp-gegl-loops.h"
#include "gimpchannel.h"
#include "gimpdrawable.h"
#include "gimpimage.h"
@ -35,6 +39,7 @@ gimp_image_pick_color (GimpImage *image,
GimpDrawable *drawable,
gint x,
gint y,
gboolean show_all,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,
@ -43,6 +48,7 @@ gimp_image_pick_color (GimpImage *image,
GimpRGB *color)
{
GimpPickable *pickable;
gboolean result;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), FALSE);
@ -80,7 +86,10 @@ gimp_image_pick_color (GimpImage *image,
if (sample_merged)
{
pickable = GIMP_PICKABLE (image);
if (! show_all)
pickable = GIMP_PICKABLE (image);
else
pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
}
else
{
@ -101,7 +110,38 @@ gimp_image_pick_color (GimpImage *image,
if (sample_format)
*sample_format = gimp_pickable_get_format (pickable);
return gimp_pickable_pick_color (pickable, x, y,
sample_average, average_radius,
pixel, color);
result = gimp_pickable_pick_color (pickable, x, y,
sample_average &&
! (show_all && sample_merged),
average_radius,
pixel, color);
if (show_all && sample_merged)
{
const Babl *format = babl_format ("RaGaBaA double");
gdouble sample[4] = {};
if (! result)
memset (pixel, 0, babl_format_get_bytes_per_pixel (*sample_format));
if (sample_average)
{
GeglBuffer *buffer = gimp_pickable_get_buffer (pickable);
gint radius = floor (average_radius);
gimp_gegl_average_color (buffer,
GEGL_RECTANGLE (x - radius,
y - radius,
2 * radius + 1,
2 * radius + 1),
FALSE, GEGL_ABYSS_NONE, format, sample);
}
if (! result || sample_average)
gimp_pickable_pixel_to_srgb (pickable, format, sample, color);
result = TRUE;
}
return result;
}

View file

@ -23,6 +23,7 @@ gboolean gimp_image_pick_color (GimpImage *image,
GimpDrawable *drawable,
gint x,
gint y,
gboolean show_all,
gboolean sample_merged,
gboolean sample_average,
gdouble average_radius,

View file

@ -4968,6 +4968,7 @@ gimp_image_remove_vectors (GimpImage *image,
gboolean
gimp_image_coords_in_active_pickable (GimpImage *image,
const GimpCoords *coords,
gboolean show_all,
gboolean sample_merged,
gboolean selected_only)
{
@ -4981,9 +4982,11 @@ gimp_image_coords_in_active_pickable (GimpImage *image,
if (sample_merged)
{
if (x >= 0 && x < gimp_image_get_width (image) &&
y >= 0 && y < gimp_image_get_height (image))
in_pickable = TRUE;
if (show_all || (x >= 0 && x < gimp_image_get_width (image) &&
y >= 0 && y < gimp_image_get_height (image)))
{
in_pickable = TRUE;
}
}
else
{

View file

@ -450,6 +450,7 @@ void gimp_image_remove_vectors (GimpImage *image,
gboolean gimp_image_coords_in_active_pickable (GimpImage *image,
const GimpCoords *coords,
gboolean show_all,
gboolean sample_merged,
gboolean selected_only);

View file

@ -761,6 +761,7 @@ gimp_cursor_view_cursor_idle (GimpCursorView *view)
if (gimp_image_pick_color (image, NULL,
int_x, int_y,
view->priv->shell->show_all,
view->priv->sample_merged,
FALSE, 0.0,
&sample_format, pixel, &color))

View file

@ -721,6 +721,7 @@ image_pick_color_invoker (GimpProcedure *procedure,
success = gimp_image_pick_color (image,
drawable,
(gint) x, (gint) y,
FALSE,
sample_merged,
sample_average,
average_radius,

View file

@ -521,7 +521,8 @@ gimp_bucket_fill_tool_button_press (GimpTool *tool,
options->line_art_source == GIMP_LINE_ART_SOURCE_SAMPLE_MERGED :
options->sample_merged);
if (press_type == GIMP_BUTTON_PRESS_NORMAL &&
gimp_image_coords_in_active_pickable (image, coords, sample_merged, TRUE))
gimp_image_coords_in_active_pickable (image, coords,
FALSE, sample_merged, TRUE))
{
GimpContext *context = GIMP_CONTEXT (options);
GimpFillOptions *fill_options;
@ -588,7 +589,8 @@ gimp_bucket_fill_tool_motion (GimpTool *tool,
sample_merged = (options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
options->line_art_source == GIMP_LINE_ART_SOURCE_SAMPLE_MERGED :
options->sample_merged);
if (gimp_image_coords_in_active_pickable (image, coords, sample_merged, TRUE) &&
if (gimp_image_coords_in_active_pickable (image, coords,
FALSE, sample_merged, TRUE) &&
/* Fill selection only needs to happen once. */
options->fill_area != GIMP_BUCKET_FILL_SELECTION)
{
@ -770,7 +772,8 @@ gimp_bucket_fill_tool_cursor_update (GimpTool *tool,
sample_merged = (options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
options->line_art_source == GIMP_LINE_ART_SOURCE_SAMPLE_MERGED :
options->sample_merged);
if (gimp_image_coords_in_active_pickable (image, coords, sample_merged, TRUE))
if (gimp_image_coords_in_active_pickable (image, coords,
FALSE, sample_merged, TRUE))
{
GimpDrawable *drawable = gimp_image_get_active_drawable (image);

View file

@ -443,9 +443,11 @@ gimp_color_tool_real_can_pick (GimpColorTool *color_tool,
const GimpCoords *coords,
GimpDisplay *display)
{
GimpImage *image = gimp_display_get_image (display);
GimpDisplayShell *shell = gimp_display_get_shell (display);
GimpImage *image = gimp_display_get_image (display);
return gimp_image_coords_in_active_pickable (image, coords,
shell->show_all,
color_tool->options->sample_merged,
FALSE);
}
@ -458,13 +460,15 @@ gimp_color_tool_real_pick (GimpColorTool *color_tool,
gpointer pixel,
GimpRGB *color)
{
GimpImage *image = gimp_display_get_image (display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GimpDisplayShell *shell = gimp_display_get_shell (display);
GimpImage *image = gimp_display_get_image (display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
g_return_val_if_fail (drawable != NULL, FALSE);
return gimp_image_pick_color (image, drawable,
coords->x, coords->y,
shell->show_all,
color_tool->options->sample_merged,
color_tool->options->sample_average,
color_tool->options->average_radius,

View file

@ -526,7 +526,7 @@ gimp_perspective_clone_tool_cursor_update (GimpTool *tool,
image = gimp_display_get_image (display);
if (gimp_image_coords_in_active_pickable (image, coords,
FALSE, TRUE))
FALSE, FALSE, TRUE))
{
cursor = GIMP_CURSOR_MOUSE;
}

View file

@ -283,7 +283,8 @@ gimp_region_select_tool_cursor_update (GimpTool *tool,
GimpImage *image = gimp_display_get_image (display);
if (! gimp_image_coords_in_active_pickable (image, coords,
options->sample_merged, FALSE))
FALSE, options->sample_merged,
FALSE))
modifier = GIMP_CURSOR_MODIFIER_BAD;
gimp_tool_control_set_cursor_modifier (tool->control, modifier);

View file

@ -502,7 +502,7 @@ gimp_text_tool_button_press (GimpTool *tool,
}
}
if (gimp_image_coords_in_active_pickable (image, coords, FALSE, FALSE))
if (gimp_image_coords_in_active_pickable (image, coords, FALSE, FALSE, FALSE))
{
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GimpItem *item = GIMP_ITEM (drawable);

View file

@ -564,6 +564,7 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
if (gimp_image_pick_color (image_editor->image, NULL,
x, y,
FALSE,
editor->sample_merged,
FALSE, 0.0,
&format,

View file

@ -275,7 +275,7 @@ gimp_selection_view_button_press (GtkWidget *widget,
y = gimp_image_get_height (image_editor->image) * bevent->y / renderer->height;
if (gimp_image_pick_color (image_editor->image, drawable, x, y,
options->sample_merged,
FALSE, options->sample_merged,
FALSE, 0.0,
NULL,
NULL, &color))

View file

@ -465,6 +465,7 @@ HELP
success = gimp_image_pick_color (image,
drawable,
(gint) x, (gint) y,
FALSE,
sample_merged,
sample_average,
average_radius,