Commit 2dc3e181 authored by Jehan's avatar Jehan

app: make layer picking a generic modifier of the shell.

Instead of having layer picking only on paint tools with alt-click, make
it available everywhere with alt-middle click. Moving through layers is
also a way to navigate an image, so it actually makes sense to be with
other modifiers (panning, zooming, rotating), while making the feature
more generic (this is definitely useful whatever the selected tool).

(cherry picked from commit 4c337353)
parent e0be9bde
......@@ -32,6 +32,7 @@
#include "core/gimp-filter-history.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-pick-item.h"
#include "core/gimpitem.h"
#include "widgets/gimpcontrollers.h"
......@@ -1239,6 +1240,12 @@ gimp_display_shell_canvas_tool_events_internal (GtkWidget *canvas,
return FALSE;
}
if (gimp_display_shell_key_to_state (kevent->keyval) == GDK_MOD1_MASK)
/* We reset the picked layer only when hitting the Alt
* key.
*/
shell->picked_layer = NULL;
switch (kevent->keyval)
{
case GDK_KEY_Left:
......@@ -1537,13 +1544,47 @@ gimp_display_shell_start_scrolling (GimpDisplayShell *shell,
shell->rotating = (state & gimp_get_extend_selection_mask ()) ? TRUE : FALSE;
shell->rotate_drag_angle = shell->rotate_angle;
shell->scaling = (state & gimp_get_toggle_behavior_mask ()) ? TRUE : FALSE;
shell->layer_picking = (state & GDK_MOD1_MASK) ? TRUE : FALSE;
if (shell->rotating)
gimp_display_shell_set_override_cursor (shell,
(GimpCursorType) GDK_EXCHANGE);
{
gimp_display_shell_set_override_cursor (shell,
(GimpCursorType) GDK_EXCHANGE);
}
else if (shell->scaling)
gimp_display_shell_set_override_cursor (shell,
(GimpCursorType) GIMP_CURSOR_ZOOM);
{
gimp_display_shell_set_override_cursor (shell,
(GimpCursorType) GIMP_CURSOR_ZOOM);
}
else if (shell->layer_picking)
{
GimpImage *image = gimp_display_get_image (shell->display);
GimpLayer *layer;
GimpCoords image_coords;
GimpCoords display_coords;
guint32 time;
gimp_display_shell_set_override_cursor (shell,
(GimpCursorType) GIMP_CURSOR_CROSSHAIR);
gimp_display_shell_get_event_coords (shell, event,
&display_coords,
&state, &time);
gimp_display_shell_untransform_event_coords (shell,
&display_coords, &image_coords,
NULL);
layer = gimp_image_pick_layer (image,
(gint) image_coords.x,
(gint) image_coords.y,
shell->picked_layer);
if (layer && ! gimp_image_get_floating_selection (image))
{
if (layer != gimp_image_get_active_layer (image))
gimp_image_set_active_layer (image, layer);
shell->picked_layer = layer;
}
}
else
gimp_display_shell_set_override_cursor (shell,
(GimpCursorType) GDK_FLEUR);
......@@ -1565,6 +1606,7 @@ gimp_display_shell_stop_scrolling (GimpDisplayShell *shell,
shell->rotating = FALSE;
shell->rotate_drag_angle = 0.0;
shell->scaling = FALSE;
shell->layer_picking = FALSE;
/* We may have ungrabbed the pointer when space was released while
* mouse was down, to be able to catch a GDK_BUTTON_RELEASE event.
......@@ -1600,6 +1642,10 @@ gimp_display_shell_handle_scrolling (GimpDisplayShell *shell,
shell->scroll_last_x - x,
shell->scroll_last_y - y);
}
else if (shell->layer_picking)
{
/* Do nothing. We only pick the layer on click. */
}
else
{
gimp_display_shell_scroll (shell,
......
......@@ -208,6 +208,8 @@ struct _GimpDisplayShell
gdouble rotate_drag_angle;
gboolean scaling;
gpointer scroll_info;
gboolean layer_picking;
GimpLayer *picked_layer;
GeglBuffer *mask;
gint mask_offset_x;
......
......@@ -32,7 +32,6 @@
#include "core/gimpdrawable.h"
#include "core/gimperror.h"
#include "core/gimpimage.h"
#include "core/gimpimage-pick-item.h"
#include "core/gimplayer.h"
#include "core/gimppaintinfo.h"
#include "core/gimpprojection.h"
......@@ -267,26 +266,7 @@ gimp_paint_tool_button_press (GimpTool *tool,
gboolean constrain;
GError *error = NULL;
if (paint_tool->picking_layer)
{
GimpLayer *layer;
layer = gimp_image_pick_layer (image,
(gint) coords->x,
(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)))
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
{
GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
press_type, display);
......@@ -385,7 +365,7 @@ gimp_paint_tool_button_release (GimpTool *tool,
GimpImage *image = gimp_display_get_image (display);
gboolean cancel;
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) || paint_tool->picking_layer)
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
{
GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time,
state, release_type,
......@@ -420,7 +400,7 @@ gimp_paint_tool_motion (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display);
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) || paint_tool->picking_layer)
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
return;
gimp_paint_tool_paint_motion (paint_tool, coords, time);
......@@ -483,15 +463,6 @@ 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
paint_tool->picking_layer = FALSE;
}
}
static void
......@@ -501,41 +472,18 @@ gimp_paint_tool_cursor_update (GimpTool *tool,
GimpDisplay *display)
{
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
GimpToolCursorType tool_cursor;
GimpCursorModifier modifier;
GimpCursorModifier toggle_modifier;
GimpToolCursorType old_tool_cursor;
GimpCursorModifier old_modifier;
GimpCursorModifier old_toggle_modifier;
tool_cursor = tool->control->tool_cursor;
modifier = tool->control->cursor_modifier;
toggle_modifier = tool->control->toggle_cursor_modifier;
old_tool_cursor = tool_cursor;
old_modifier = modifier;
old_toggle_modifier = toggle_modifier;
if (paint_tool->picking_layer)
{
GimpImage *image = gimp_display_get_image (display);
GimpLayer *layer;
layer = gimp_image_pick_layer (image,
(gint) coords->x,
(gint) coords->y,
paint_tool->picked_layer);
modifier = GIMP_CURSOR_MODIFIER_NONE;
if (gimp_image_get_floating_selection (image))
modifier = GIMP_CURSOR_MODIFIER_BAD;
else if (layer && layer != gimp_image_get_active_layer (image))
modifier = GIMP_CURSOR_MODIFIER_SELECT;
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_HAND);
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
}
else if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
{
GimpImage *image = gimp_display_get_image (display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
......@@ -571,8 +519,6 @@ gimp_paint_tool_cursor_update (GimpTool *tool,
/* reset old stuff here so we are not interfering with the modifiers
* set by our subclasses
*/
gimp_tool_control_set_tool_cursor (tool->control,
old_tool_cursor);
gimp_tool_control_set_cursor_modifier (tool->control,
old_modifier);
gimp_tool_control_set_toggle_cursor_modifier (tool->control,
......@@ -594,8 +540,7 @@ gimp_paint_tool_oper_update (GimpTool *tool,
GimpImage *image = gimp_display_get_image (display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) ||
paint_tool->picking_layer)
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
{
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state,
proximity, display);
......@@ -712,11 +657,9 @@ gimp_paint_tool_oper_update (GimpTool *tool,
static void
gimp_paint_tool_draw (GimpDrawTool *draw_tool)
{
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (draw_tool);
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)) &&
! paint_tool->picking_layer)
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
{
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (draw_tool);
GimpPaintCore *core = paint_tool->core;
GimpImage *image = gimp_display_get_image (draw_tool->display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
......
......@@ -44,9 +44,6 @@ struct _GimpPaintTool
gboolean pick_colors; /* pick color if ctrl is pressed */
gboolean draw_line;
gboolean picking_layer; /* pick layer in progress (alt pressed) */
GimpLayer *picked_layer;
gboolean show_cursor;
gboolean draw_brush;
gboolean draw_fallback;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment