[gimp] app: make layer picking a generic modifier of the shell.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: make layer picking a generic modifier of the shell.
- Date: Mon, 7 Jan 2019 22:25:35 +0000 (UTC)
commit 4c337353a034a1de779e9fc01b26192d47a0ced5
Author: Jehan <jehan girinstud io>
Date: Sat Dec 22 19:09:34 2018 +0100
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).
app/display/gimpdisplayshell-tool-events.c | 54 +++++++++++++++++++++--
app/display/gimpdisplayshell.h | 2 +
app/tools/gimppainttool.c | 71 +++---------------------------
app/tools/gimppainttool.h | 3 --
4 files changed, 59 insertions(+), 71 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index 23db94bbad..a12609e405 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -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"
@@ -991,6 +992,12 @@ gimp_display_shell_canvas_tool_events (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:
@@ -1500,13 +1507,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);
@@ -1528,6 +1569,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.
@@ -1563,6 +1605,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,
diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h
index 2435c8e9f3..a96f67aa76 100644
--- a/app/display/gimpdisplayshell.h
+++ b/app/display/gimpdisplayshell.h
@@ -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;
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index 968cc0c90c..b303831019 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -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);
diff --git a/app/tools/gimppainttool.h b/app/tools/gimppainttool.h
index f927807009..387239e7f4 100644
--- a/app/tools/gimppainttool.h
+++ b/app/tools/gimppainttool.h
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]