app: reset GimpFilterTool widget when resetting settings

Add a gimp_filter_tool_reset_widget() function, which resets the
tool widget associated with the filter's controller -- i.e., it
resets those properties of the widget that aren't controlled by the
op's properties to some "default" state.  For most controller types
this is a NOP; for transform-grid controllers, we move the pivot
back to the center of the drawable, w.r.t. the current transform.

Call gimp_filter_tool_reset_widget() after resetting or reloading
the tool's config.
This commit is contained in:
Ell 2018-03-18 14:14:53 -04:00
parent 7ca38c54f6
commit cada28e91e
3 changed files with 71 additions and 0 deletions

View File

@ -189,6 +189,68 @@ gimp_filter_tool_create_widget (GimpFilterTool *filter_tool,
return controller->widget;
}
void
gimp_filter_tool_reset_widget (GimpFilterTool *filter_tool,
GimpToolWidget *widget)
{
Controller *controller;
g_return_if_fail (GIMP_IS_FILTER_TOOL (filter_tool));
g_return_if_fail (GIMP_IS_TOOL_WIDGET (widget));
controller = g_object_get_data (G_OBJECT (filter_tool->widget),
"controller");
g_return_if_fail (controller != NULL);
switch (controller->controller_type)
{
case GIMP_CONTROLLER_TYPE_TRANSFORM_GRID:
{
GimpMatrix3 *transform;
gint off_x, off_y;
GeglRectangle area;
gdouble x1, y1;
gdouble x2, y2;
gdouble pivot_x, pivot_y;
g_object_get (controller->widget,
"transform", &transform,
NULL);
gimp_filter_tool_get_drawable_area (filter_tool, &off_x, &off_y, &area);
x1 = off_x + area.x;
y1 = off_y + area.y;
x2 = x1 + area.width;
y2 = y1 + area.height;
gimp_matrix3_transform_point (transform,
(x1 + x2) / 2.0, (y1 + y2) / 2.0,
&pivot_x, &pivot_y);
g_signal_handlers_block_by_func (controller->widget,
gimp_filter_tool_transform_grid_changed,
controller);
g_object_set (controller->widget,
"pivot-x", pivot_x,
"pivot-y", pivot_y,
NULL);
g_signal_handlers_unblock_by_func (controller->widget,
gimp_filter_tool_transform_grid_changed,
controller);
g_free (transform);
}
break;
default:
break;
}
}
/* private functions */

View File

@ -29,5 +29,8 @@ GimpToolWidget * gimp_filter_tool_create_widget (GimpFilterTool *filter_tool
GCallback *set_func,
gpointer *set_func_data);
void gimp_filter_tool_reset_widget (GimpFilterTool *filter_tool,
GimpToolWidget *widget);
#endif /* __GIMP_FILTER_TOOL_WIDGETS_H__ */

View File

@ -1034,6 +1034,9 @@ gimp_filter_tool_reset (GimpFilterTool *filter_tool)
if (filter_tool->config)
g_object_thaw_notify (filter_tool->config);
if (filter_tool->widget)
gimp_filter_tool_reset_widget (filter_tool, filter_tool->widget);
}
static void
@ -1453,6 +1456,9 @@ gimp_filter_tool_set_config (GimpFilterTool *filter_tool,
g_return_if_fail (GIMP_IS_SETTINGS (config));
GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->set_config (filter_tool, config);
if (filter_tool->widget)
gimp_filter_tool_reset_widget (filter_tool, filter_tool->widget);
}
void