app: redraw handles when needed.

There were various cases when the reference's on-canvas handles were not
redrawn, or drawn at all:

- When the reference is an image, we now draw them. It may seem redundant as
  it's the image bounds, but it's still useful to see what are the reference
  bounds in a glimpse. Moreover in "Show All" mode, it's even more useful.
- Start the tool, hence draw the reference handles, in oper_update() if not
  started yet.
- When the "align-reference" property changes.
- When the display (active image) changes.
This commit is contained in:
Jehan 2022-11-08 12:39:00 +01:00
parent 4c09f194d1
commit 63dc7dee8a
1 changed files with 75 additions and 0 deletions

View File

@ -102,11 +102,15 @@ static gboolean gimp_align_tool_undo (GimpTool *tool,
GimpDisplay *display);
static void gimp_align_tool_draw (GimpDrawTool *draw_tool);
static void gimp_align_tool_redraw (GimpAlignTool *align_tool);
static void gimp_align_tool_align (GimpAlignTool *align_tool,
GimpAlignmentType align_type);
static gint gimp_align_tool_undo_idle (gpointer data);
static void gimp_align_tool_display_changed (GimpContext *context,
GimpDisplay *display,
GimpAlignTool *align_tool);
G_DEFINE_TYPE (GimpAlignTool, gimp_align_tool, GIMP_TYPE_DRAW_TOOL)
@ -179,6 +183,13 @@ gimp_align_tool_constructed (GObject *object)
g_signal_connect_object (options, "align-button-clicked",
G_CALLBACK (gimp_align_tool_align),
align_tool, G_CONNECT_SWAPPED);
g_signal_connect_object (options, "notify::align-reference",
G_CALLBACK (gimp_align_tool_redraw),
align_tool, G_CONNECT_SWAPPED);
g_signal_connect_object (gimp_get_user_context (GIMP_CONTEXT (options)->gimp),
"display-changed",
G_CALLBACK (gimp_align_tool_display_changed),
align_tool, 0);
}
static void
@ -457,6 +468,9 @@ gimp_align_tool_oper_update (GimpTool *tool,
}
gimp_align_tool_status_update (tool, display, state, proximity);
if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
}
static void
@ -677,6 +691,33 @@ gimp_align_tool_draw (GimpDrawTool *draw_tool)
break;
}
}
else if (GIMP_IS_IMAGE (reference))
{
GimpImage *image = GIMP_IMAGE (reference);
gint width = gimp_image_get_width (image);
gint height = gimp_image_get_height (image);
gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
0, 0,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_HANDLE_ANCHOR_NORTH_WEST);
gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
width, 0,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_HANDLE_ANCHOR_NORTH_EAST);
gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
0, height,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_HANDLE_ANCHOR_SOUTH_WEST);
gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
width, height,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_TOOL_HANDLE_SIZE_SMALL,
GIMP_HANDLE_ANCHOR_SOUTH_EAST);
}
/* Highlight picked guides, similarly to how they are highlighted in Move
* tool.
@ -701,6 +742,19 @@ gimp_align_tool_draw (GimpDrawTool *draw_tool)
}
}
static void
gimp_align_tool_redraw (GimpAlignTool *align_tool)
{
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (align_tool);
gimp_draw_tool_pause (draw_tool);
if (! gimp_draw_tool_is_active (draw_tool) && draw_tool->display)
gimp_draw_tool_start (draw_tool, draw_tool->display);
gimp_draw_tool_resume (draw_tool);
}
static void
gimp_align_tool_align (GimpAlignTool *align_tool,
GimpAlignmentType align_type)
@ -785,3 +839,24 @@ gimp_align_tool_undo_idle (gpointer data)
return FALSE; /* remove idle */
}
static void
gimp_align_tool_display_changed (GimpContext *context,
GimpDisplay *display,
GimpAlignTool *align_tool)
{
GimpTool *tool = GIMP_TOOL (align_tool);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (align_tool);
gimp_draw_tool_pause (draw_tool);
if (display != tool->display)
gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
tool->display = display;
if (! gimp_draw_tool_is_active (draw_tool) && display)
gimp_draw_tool_start (draw_tool, display);
gimp_draw_tool_resume (draw_tool);
}