app: alt-click to pick a layer will loop through candidate layers.

If you click on a zone filled in several visible layers, you don't
necessarily want the top layer. You may want one below. With this
change, as long as you hold alt, you will loop through all candidate
layers from top to bottom (then looping back top when reaching the
bottom).
In a first alt-click, you will always end up to the top candidate.
This commit is contained in:
Jehan 2018-12-15 23:34:07 +01:00
parent 3b59e6f61e
commit 90e9eb3fca
8 changed files with 60 additions and 20 deletions

View file

@ -41,29 +41,55 @@
GimpLayer *
gimp_image_pick_layer (GimpImage *image,
gint x,
gint y)
gint y,
GimpLayer *previously_picked)
{
GList *all_layers;
GList *list;
gint off_x, off_y;
gint tries = 1;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
all_layers = gimp_image_get_layer_list (image);
for (list = all_layers; list; list = g_list_next (list))
if (previously_picked)
{
GimpLayer *layer = list->data;
gint off_x, off_y;
gimp_item_get_offset (GIMP_ITEM (previously_picked), &off_x, &off_y);
if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (previously_picked),
x - off_x, y - off_y) <= 0.25)
previously_picked = NULL;
else
tries++;
}
gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (layer),
x - off_x, y - off_y) > 0.25)
while (tries)
{
for (list = all_layers; list; list = g_list_next (list))
{
g_list_free (all_layers);
GimpLayer *layer = list->data;
return layer;
if (previously_picked)
{
/* Take the first layer with a pixel at given coordinates
* after the previously picked one.
*/
if (layer == previously_picked)
previously_picked = NULL;
continue;
}
gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (layer),
x - off_x, y - off_y) > 0.25)
{
g_list_free (all_layers);
return layer;
}
}
tries--;
}
g_list_free (all_layers);

View file

@ -21,7 +21,8 @@
GimpLayer * gimp_image_pick_layer (GimpImage *image,
gint x,
gint y);
gint y,
GimpLayer *previously_picked);
GimpLayer * gimp_image_pick_layer_by_bounds (GimpImage *image,
gint x,
gint y);

View file

@ -759,7 +759,7 @@ image_pick_correlate_layer_invoker (GimpProcedure *procedure,
if (success)
{
layer = gimp_image_pick_layer (image, x, y);
layer = gimp_image_pick_layer (image, x, y, NULL);
}
return_vals = gimp_procedure_get_return_values (procedure, success,

View file

@ -219,7 +219,8 @@ gimp_move_tool_button_press (GimpTool *tool,
}
else if ((layer = gimp_image_pick_layer (image,
coords->x,
coords->y)))
coords->y,
NULL)))
{
if (gimp_image_get_floating_selection (image) &&
! gimp_layer_is_floating_sel (layer))
@ -582,7 +583,8 @@ gimp_move_tool_cursor_update (GimpTool *tool,
modifier = GIMP_CURSOR_MODIFIER_MOVE;
}
else if ((layer = gimp_image_pick_layer (image,
coords->x, coords->y)))
coords->x, coords->y,
NULL)))
{
/* if there is a floating selection, and this aint it... */
if (gimp_image_get_floating_selection (image) &&

View file

@ -273,9 +273,17 @@ gimp_paint_tool_button_press (GimpTool *tool,
layer = gimp_image_pick_layer (image,
(gint) coords->x,
(gint) coords->y);
if (layer && layer != gimp_image_get_active_layer (image))
gimp_image_set_active_layer (image, layer);
(gint) coords->y,
paint_tool->picked_layer);
if (layer)
{
if (layer != gimp_image_get_active_layer (image))
{
paint_tool->picked_layer = layer;
gimp_image_set_active_layer (image, layer);
}
paint_tool->picked_layer = layer;
}
return;
}
else if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
@ -478,6 +486,7 @@ gimp_paint_tool_modifier_key (GimpTool *tool,
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) &&
! paint_tool->draw_line)
{
paint_tool->picked_layer = NULL;
if ((state & gimp_get_all_modifiers_mask ()) == GDK_MOD1_MASK)
paint_tool->picking_layer = TRUE;
else
@ -514,7 +523,8 @@ gimp_paint_tool_cursor_update (GimpTool *tool,
layer = gimp_image_pick_layer (image,
(gint) coords->x,
(gint) coords->y);
(gint) coords->y,
paint_tool->picked_layer);
modifier = GIMP_CURSOR_MODIFIER_NONE;
if (gimp_image_get_floating_selection (image))

View file

@ -45,6 +45,7 @@ struct _GimpPaintTool
gboolean draw_line;
gboolean picking_layer; /* pick layer in progress (alt pressed) */
GimpLayer *picked_layer;
gboolean show_cursor;
gboolean draw_brush;

View file

@ -180,7 +180,7 @@ gimp_selection_tool_oper_update (GimpTool *tool,
image = gimp_display_get_image (display);
selection = gimp_image_get_mask (image);
drawable = gimp_image_get_active_drawable (image);
layer = gimp_image_pick_layer (image, coords->x, coords->y);
layer = gimp_image_pick_layer (image, coords->x, coords->y, NULL);
floating_sel = gimp_image_get_floating_selection (image);
extend_mask = gimp_get_extend_selection_mask ();

View file

@ -507,7 +507,7 @@ HELP
headers => [ qw("core/gimpimage-pick-item.h") ],
code => <<'CODE'
{
layer = gimp_image_pick_layer (image, x, y);
layer = gimp_image_pick_layer (image, x, y, NULL);
}
CODE
);