Bug 784802 - Crop and rectangle-select tools incorrectly detect ...

... current aspect ratio

When updating the default aspect ratio of a widget-less crop tool,
construct a temporary GimpToolRectangle widget, so that we can use
it to call gimp_tool_rectangle_constraint_size_set() and pick the
correct ratio, instead of just bailing.

When halting the crop tool, update the default aspect ratio, which
now does the right thing, as per the above.

Update the default aspect ratio upon changes to the active layer of
the current image, and to the size of the active layer, which
affect the default aspect ratio when "current layer only" is
toggled.
This commit is contained in:
Ell 2018-02-15 16:56:05 -05:00
parent 547d3149d5
commit 49b3695e46
2 changed files with 136 additions and 54 deletions

View File

@ -92,6 +92,8 @@ static void gimp_crop_tool_image_changed (GimpCropTool
GimpImage *image,
GimpContext *context);
static void gimp_crop_tool_image_size_changed (GimpCropTool *crop_tool);
static void gimp_crop_tool_image_active_layer_changed (GimpCropTool *crop_tool);
static void gimp_crop_tool_layer_size_changed (GimpCropTool *crop_tool);
static void gimp_crop_tool_auto_shrink (GimpCropTool *crop_tool);
@ -285,14 +287,18 @@ gimp_crop_tool_options_notify (GimpTool *tool,
{
GimpCropTool *crop_tool = GIMP_CROP_TOOL (tool);
if (crop_tool->widget)
{
if (! strcmp (pspec->name, "layer-only") ||
! strcmp (pspec->name, "allow-growing"))
{
if (crop_tool->widget)
{
gimp_tool_rectangle_set_constraint (GIMP_TOOL_RECTANGLE (crop_tool->widget),
gimp_crop_tool_get_constraint (crop_tool));
}
else
{
gimp_crop_tool_update_option_defaults (crop_tool, FALSE);
}
}
}
@ -497,6 +503,8 @@ gimp_crop_tool_halt (GimpCropTool *crop_tool)
tool->display = NULL;
tool->drawable = NULL;
gimp_crop_tool_update_option_defaults (crop_tool, TRUE);
}
/**
@ -517,10 +525,7 @@ gimp_crop_tool_update_option_defaults (GimpCropTool *crop_tool,
options = GIMP_RECTANGLE_OPTIONS (GIMP_TOOL_GET_OPTIONS (tool));
if (! rectangle)
return;
if (tool->display && ! ignore_pending)
if (rectangle && ! ignore_pending)
{
/* There is a pending rectangle and we should not ignore it, so
* set default Fixed: Aspect ratio to the same as the current
@ -542,11 +547,38 @@ gimp_crop_tool_update_option_defaults (GimpCropTool *crop_tool,
* ratio to that of the current image/layer.
*/
if (! rectangle)
{
/* ugly hack: if we don't have a widget, construct a temporary one
* so that we can use it to call
* gimp_tool_rectangle_constraint_size_set().
*/
GimpContext *context = gimp_get_user_context (tool->tool_info->gimp);
GimpDisplay *display = gimp_context_get_display (context);
if (display)
{
GimpDisplayShell *shell = gimp_display_get_shell (display);
rectangle = GIMP_TOOL_RECTANGLE (gimp_tool_rectangle_new (shell));
gimp_tool_rectangle_set_constraint (
rectangle, gimp_crop_tool_get_constraint (crop_tool));
}
}
if (rectangle)
{
gimp_tool_rectangle_constraint_size_set (rectangle,
G_OBJECT (options),
"default-aspect-numerator",
"default-aspect-denominator");
if (! crop_tool->widget)
g_object_unref (rectangle);
}
g_object_set (G_OBJECT (options),
"use-string-current", FALSE,
NULL);
@ -579,6 +611,9 @@ gimp_crop_tool_image_changed (GimpCropTool *crop_tool,
g_signal_handlers_disconnect_by_func (crop_tool->current_image,
gimp_crop_tool_image_size_changed,
NULL);
g_signal_handlers_disconnect_by_func (crop_tool->current_image,
gimp_crop_tool_image_active_layer_changed,
NULL);
}
crop_tool->current_image = image;
@ -589,8 +624,17 @@ gimp_crop_tool_image_changed (GimpCropTool *crop_tool,
G_CALLBACK (gimp_crop_tool_image_size_changed),
crop_tool,
G_CONNECT_SWAPPED);
g_signal_connect_object (crop_tool->current_image, "active-layer-changed",
G_CALLBACK (gimp_crop_tool_image_active_layer_changed),
crop_tool,
G_CONNECT_SWAPPED);
}
/* Make sure we are connected to "size-changed" for the initial
* layer.
*/
gimp_crop_tool_image_active_layer_changed (crop_tool);
gimp_crop_tool_update_option_defaults (GIMP_CROP_TOOL (crop_tool), FALSE);
}
@ -600,6 +644,43 @@ gimp_crop_tool_image_size_changed (GimpCropTool *crop_tool)
gimp_crop_tool_update_option_defaults (crop_tool, FALSE);
}
static void
gimp_crop_tool_image_active_layer_changed (GimpCropTool *crop_tool)
{
if (crop_tool->current_layer)
{
g_signal_handlers_disconnect_by_func (crop_tool->current_layer,
gimp_crop_tool_layer_size_changed,
NULL);
}
if (crop_tool->current_image)
{
crop_tool->current_layer =
gimp_image_get_active_layer (crop_tool->current_image);
}
else
{
crop_tool->current_layer = NULL;
}
if (crop_tool->current_layer)
{
g_signal_connect_object (crop_tool->current_layer, "size-changed",
G_CALLBACK (gimp_crop_tool_layer_size_changed),
crop_tool,
G_CONNECT_SWAPPED);
}
gimp_crop_tool_update_option_defaults (crop_tool, FALSE);
}
static void
gimp_crop_tool_layer_size_changed (GimpCropTool *crop_tool)
{
gimp_crop_tool_update_option_defaults (crop_tool, FALSE);
}
static void
gimp_crop_tool_auto_shrink (GimpCropTool *crop_tool)
{

View File

@ -40,6 +40,7 @@ struct _GimpCropTool
GimpDrawTool parent_instance;
GimpImage *current_image;
GimpLayer *current_layer;
GimpToolWidget *widget;
GimpToolWidget *grab_widget;