app: add GimpFilterTool::region_changed() virtual function
Add a new GimpFilterTool::region_changed() virtual function, which gets called whenever the filter region changes, either due to a change to the tool's "region" option, or a change to the image mask. Override GimpFilterTool::region_changed() in GimpOperationTool and GimpOffsetTool, instead of listening to a change to the "region" option in GimpTool::options_notify(), so that the tools are properly updated when the image mask changes.
This commit is contained in:
parent
428ee0e2ad
commit
066827e23c
4 changed files with 69 additions and 70 deletions
|
|
@ -156,6 +156,8 @@ static void gimp_filter_tool_reset (GimpFilterTool *filter_to
|
|||
|
||||
static void gimp_filter_tool_create_filter (GimpFilterTool *filter_tool);
|
||||
|
||||
static void gimp_filter_tool_region_changed (GimpFilterTool *filter_tool);
|
||||
|
||||
static void gimp_filter_tool_flush (GimpDrawableFilter *filter,
|
||||
GimpFilterTool *filter_tool);
|
||||
static void gimp_filter_tool_config_notify (GObject *object,
|
||||
|
|
@ -446,14 +448,14 @@ gimp_filter_tool_initialize (GimpTool *tool,
|
|||
|
||||
gimp_tool_gui_show (filter_tool->gui);
|
||||
|
||||
gimp_filter_tool_create_filter (filter_tool);
|
||||
|
||||
g_signal_connect_object (image, "mask-changed",
|
||||
G_CALLBACK (gimp_filter_tool_mask_changed),
|
||||
filter_tool, 0);
|
||||
|
||||
gimp_filter_tool_mask_changed (image, filter_tool);
|
||||
|
||||
gimp_filter_tool_create_filter (filter_tool);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -796,6 +798,8 @@ gimp_filter_tool_options_notify (GimpTool *tool,
|
|||
{
|
||||
gimp_drawable_filter_set_region (filter_tool->filter,
|
||||
filter_options->region);
|
||||
|
||||
gimp_filter_tool_region_changed (filter_tool);
|
||||
}
|
||||
else if (! strcmp (pspec->name, "gamma-hack") &&
|
||||
filter_tool->filter)
|
||||
|
|
@ -1104,6 +1108,16 @@ gimp_filter_tool_create_filter (GimpFilterTool *filter_tool)
|
|||
gimp_drawable_filter_apply (filter_tool->filter, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_filter_tool_region_changed (GimpFilterTool *filter_tool)
|
||||
{
|
||||
if (filter_tool->filter &&
|
||||
GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->region_changed)
|
||||
{
|
||||
GIMP_FILTER_TOOL_GET_CLASS (filter_tool)->region_changed (filter_tool);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_filter_tool_flush (GimpDrawableFilter *filter,
|
||||
GimpFilterTool *filter_tool)
|
||||
|
|
@ -1128,6 +1142,8 @@ static void
|
|||
gimp_filter_tool_mask_changed (GimpImage *image,
|
||||
GimpFilterTool *filter_tool)
|
||||
{
|
||||
GimpFilterOptions *options = GIMP_FILTER_TOOL_GET_OPTIONS (filter_tool);
|
||||
|
||||
if (filter_tool->gui)
|
||||
{
|
||||
GimpChannel *mask = gimp_image_get_mask (image);
|
||||
|
|
@ -1135,6 +1151,9 @@ gimp_filter_tool_mask_changed (GimpImage *image,
|
|||
gtk_widget_set_sensitive (filter_tool->region_combo,
|
||||
! gimp_channel_is_empty (mask));
|
||||
}
|
||||
|
||||
if (options->region == GIMP_FILTER_REGION_SELECTION)
|
||||
gimp_filter_tool_region_changed (filter_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ struct _GimpFilterToolClass
|
|||
GOutputStream *output,
|
||||
GError **error);
|
||||
|
||||
void (* region_changed) (GimpFilterTool *filter_tool);
|
||||
void (* color_picked) (GimpFilterTool *filter_tool,
|
||||
gpointer identifier,
|
||||
gdouble x,
|
||||
|
|
|
|||
|
|
@ -78,9 +78,6 @@ static void gimp_offset_tool_cursor_update (GimpTool
|
|||
const GimpCoords *coords,
|
||||
GdkModifierType state,
|
||||
GimpDisplay *display);
|
||||
static void gimp_offset_tool_options_notify (GimpTool *tool,
|
||||
GimpToolOptions *options,
|
||||
const GParamSpec *pspec);
|
||||
|
||||
static gchar * gimp_offset_tool_get_operation (GimpFilterTool *filter_tool,
|
||||
gchar **description);
|
||||
|
|
@ -88,6 +85,7 @@ static void gimp_offset_tool_dialog (GimpFilterTool
|
|||
static void gimp_offset_tool_config_notify (GimpFilterTool *filter_tool,
|
||||
GimpConfig *config,
|
||||
const GParamSpec *pspec);
|
||||
static void gimp_offset_tool_region_changed (GimpFilterTool *filter_tool);
|
||||
|
||||
static void gimp_offset_tool_offset_changed (GimpSizeEntry *se,
|
||||
GimpOffsetTool *offset_tool);
|
||||
|
|
@ -142,18 +140,18 @@ gimp_offset_tool_class_init (GimpOffsetToolClass *klass)
|
|||
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
||||
GimpFilterToolClass *filter_tool_class = GIMP_FILTER_TOOL_CLASS (klass);
|
||||
|
||||
tool_class->initialize = gimp_offset_tool_initialize;
|
||||
tool_class->control = gimp_offset_tool_control;
|
||||
tool_class->button_press = gimp_offset_tool_button_press;
|
||||
tool_class->button_release = gimp_offset_tool_button_release;
|
||||
tool_class->motion = gimp_offset_tool_motion;
|
||||
tool_class->oper_update = gimp_offset_tool_oper_update;
|
||||
tool_class->cursor_update = gimp_offset_tool_cursor_update;
|
||||
tool_class->options_notify = gimp_offset_tool_options_notify;
|
||||
tool_class->initialize = gimp_offset_tool_initialize;
|
||||
tool_class->control = gimp_offset_tool_control;
|
||||
tool_class->button_press = gimp_offset_tool_button_press;
|
||||
tool_class->button_release = gimp_offset_tool_button_release;
|
||||
tool_class->motion = gimp_offset_tool_motion;
|
||||
tool_class->oper_update = gimp_offset_tool_oper_update;
|
||||
tool_class->cursor_update = gimp_offset_tool_cursor_update;
|
||||
|
||||
filter_tool_class->get_operation = gimp_offset_tool_get_operation;
|
||||
filter_tool_class->dialog = gimp_offset_tool_dialog;
|
||||
filter_tool_class->config_notify = gimp_offset_tool_config_notify;
|
||||
filter_tool_class->get_operation = gimp_offset_tool_get_operation;
|
||||
filter_tool_class->dialog = gimp_offset_tool_dialog;
|
||||
filter_tool_class->config_notify = gimp_offset_tool_config_notify;
|
||||
filter_tool_class->region_changed = gimp_offset_tool_region_changed;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -443,19 +441,6 @@ gimp_offset_tool_cursor_update (GimpTool *tool,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_offset_tool_options_notify (GimpTool *tool,
|
||||
GimpToolOptions *options,
|
||||
const GParamSpec *pspec)
|
||||
{
|
||||
GimpOffsetTool *offset_tool = GIMP_OFFSET_TOOL (tool);
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
|
||||
|
||||
if (! strcmp (pspec->name, "region"))
|
||||
gimp_offset_tool_update (offset_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_offset_tool_dialog (GimpFilterTool *filter_tool)
|
||||
{
|
||||
|
|
@ -574,6 +559,12 @@ gimp_offset_tool_config_notify (GimpFilterTool *filter_tool,
|
|||
config, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_offset_tool_region_changed (GimpFilterTool *filter_tool)
|
||||
{
|
||||
gimp_offset_tool_update (GIMP_OFFSET_TOOL (filter_tool));
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_offset_tool_offset_changed (GimpSizeEntry *se,
|
||||
GimpOffsetTool *offset_tool)
|
||||
|
|
|
|||
|
|
@ -78,9 +78,6 @@ static gboolean gimp_operation_tool_initialize (GimpTool *tool,
|
|||
static void gimp_operation_tool_control (GimpTool *tool,
|
||||
GimpToolAction action,
|
||||
GimpDisplay *display);
|
||||
static void gimp_operation_tool_options_notify (GimpTool *tool,
|
||||
GimpToolOptions *options,
|
||||
const GParamSpec *pspec);
|
||||
|
||||
static gchar * gimp_operation_tool_get_operation (GimpFilterTool *filter_tool,
|
||||
gchar **description);
|
||||
|
|
@ -88,6 +85,7 @@ static void gimp_operation_tool_dialog (GimpFilterTool *filte
|
|||
static void gimp_operation_tool_reset (GimpFilterTool *filter_tool);
|
||||
static void gimp_operation_tool_set_config (GimpFilterTool *filter_tool,
|
||||
GimpConfig *config);
|
||||
static void gimp_operation_tool_region_changed (GimpFilterTool *filter_tool);
|
||||
static void gimp_operation_tool_color_picked (GimpFilterTool *filter_tool,
|
||||
gpointer identifier,
|
||||
gdouble x,
|
||||
|
|
@ -146,17 +144,17 @@ gimp_operation_tool_class_init (GimpOperationToolClass *klass)
|
|||
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
||||
GimpFilterToolClass *filter_tool_class = GIMP_FILTER_TOOL_CLASS (klass);
|
||||
|
||||
object_class->finalize = gimp_operation_tool_finalize;
|
||||
object_class->finalize = gimp_operation_tool_finalize;
|
||||
|
||||
tool_class->initialize = gimp_operation_tool_initialize;
|
||||
tool_class->control = gimp_operation_tool_control;
|
||||
tool_class->options_notify = gimp_operation_tool_options_notify;
|
||||
tool_class->initialize = gimp_operation_tool_initialize;
|
||||
tool_class->control = gimp_operation_tool_control;
|
||||
|
||||
filter_tool_class->get_operation = gimp_operation_tool_get_operation;
|
||||
filter_tool_class->dialog = gimp_operation_tool_dialog;
|
||||
filter_tool_class->reset = gimp_operation_tool_reset;
|
||||
filter_tool_class->set_config = gimp_operation_tool_set_config;
|
||||
filter_tool_class->color_picked = gimp_operation_tool_color_picked;
|
||||
filter_tool_class->get_operation = gimp_operation_tool_get_operation;
|
||||
filter_tool_class->dialog = gimp_operation_tool_dialog;
|
||||
filter_tool_class->reset = gimp_operation_tool_reset;
|
||||
filter_tool_class->set_config = gimp_operation_tool_set_config;
|
||||
filter_tool_class->region_changed = gimp_operation_tool_region_changed;
|
||||
filter_tool_class->color_picked = gimp_operation_tool_color_picked;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -237,35 +235,6 @@ gimp_operation_tool_control (GimpTool *tool,
|
|||
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_operation_tool_options_notify (GimpTool *tool,
|
||||
GimpToolOptions *options,
|
||||
const GParamSpec *pspec)
|
||||
{
|
||||
GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (tool);
|
||||
|
||||
GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
|
||||
|
||||
if (! strcmp (pspec->name, "region"))
|
||||
{
|
||||
GimpFilterTool *filter_tool = GIMP_FILTER_TOOL (tool);
|
||||
|
||||
/* when the region changes, do we want the operation's on-canvas
|
||||
* controller to move to a new position, or the operation to
|
||||
* change its properties to match the on-canvas controller?
|
||||
*
|
||||
* decided to leave the on-canvas controller where it is and
|
||||
* pretend it has changed, so the operation is updated
|
||||
* accordingly...
|
||||
*/
|
||||
if (filter_tool->widget)
|
||||
g_signal_emit_by_name (filter_tool->widget, "changed");
|
||||
|
||||
if (filter_tool->config && tool->drawable)
|
||||
gimp_operation_tool_sync_op (op_tool, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static gchar *
|
||||
gimp_operation_tool_get_operation (GimpFilterTool *filter_tool,
|
||||
gchar **description)
|
||||
|
|
@ -346,6 +315,25 @@ gimp_operation_tool_set_config (GimpFilterTool *filter_tool,
|
|||
gimp_operation_tool_relink_chains (op_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_operation_tool_region_changed (GimpFilterTool *filter_tool)
|
||||
{
|
||||
GimpOperationTool *op_tool = GIMP_OPERATION_TOOL (filter_tool);
|
||||
|
||||
/* when the region changes, do we want the operation's on-canvas
|
||||
* controller to move to a new position, or the operation to
|
||||
* change its properties to match the on-canvas controller?
|
||||
*
|
||||
* decided to leave the on-canvas controller where it is and
|
||||
* pretend it has changed, so the operation is updated
|
||||
* accordingly...
|
||||
*/
|
||||
if (filter_tool->widget)
|
||||
g_signal_emit_by_name (filter_tool->widget, "changed");
|
||||
|
||||
gimp_operation_tool_sync_op (op_tool, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_operation_tool_color_picked (GimpFilterTool *filter_tool,
|
||||
gpointer identifier,
|
||||
|
|
|
|||
Loading…
Reference in a new issue