mirror of https://github.com/GNOME/gimp.git
app: factor out widget creation to start() functions
in crop, free select and rectangle select.
This commit is contained in:
parent
0e4d31937a
commit
4b103eb966
|
@ -82,6 +82,8 @@ static void gimp_crop_tool_rectangle_response (GimpToolWidget
|
|||
static void gimp_crop_tool_rectangle_change_complete (GimpToolRectangle *rectangle,
|
||||
GimpCropTool *crop_tool);
|
||||
|
||||
static void gimp_crop_tool_start (GimpCropTool *crop_tool,
|
||||
GimpDisplay *display);
|
||||
static void gimp_crop_tool_commit (GimpCropTool *crop_tool);
|
||||
static void gimp_crop_tool_halt (GimpCropTool *crop_tool);
|
||||
|
||||
|
@ -215,61 +217,7 @@ gimp_crop_tool_button_press (GimpTool *tool,
|
|||
|
||||
if (! tool->display)
|
||||
{
|
||||
static const gchar *properties[] =
|
||||
{
|
||||
"highlight",
|
||||
"guide",
|
||||
"x",
|
||||
"y",
|
||||
"width",
|
||||
"height",
|
||||
"fixed-rule-active",
|
||||
"fixed-rule",
|
||||
"desired-fixed-width",
|
||||
"desired-fixed-height",
|
||||
"desired-fixed-size-width",
|
||||
"desired-fixed-size-height",
|
||||
"aspect-numerator",
|
||||
"aspect-denominator",
|
||||
"fixed-center"
|
||||
};
|
||||
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
||||
GimpCropOptions *options = GIMP_CROP_TOOL_GET_OPTIONS (crop_tool);
|
||||
GimpToolWidget *widget;
|
||||
gint i;
|
||||
|
||||
tool->display = display;
|
||||
|
||||
crop_tool->rectangle = widget = gimp_tool_rectangle_new (shell);
|
||||
|
||||
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), widget);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (properties); i++)
|
||||
g_object_bind_property (G_OBJECT (options), properties[i],
|
||||
G_OBJECT (widget), properties[i],
|
||||
G_BINDING_SYNC_CREATE |
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
|
||||
g_signal_connect (widget, "changed",
|
||||
G_CALLBACK (gimp_crop_tool_rectangle_changed),
|
||||
crop_tool);
|
||||
g_signal_connect (widget, "response",
|
||||
G_CALLBACK (gimp_crop_tool_rectangle_response),
|
||||
crop_tool);
|
||||
g_signal_connect (widget, "change-complete",
|
||||
G_CALLBACK (gimp_crop_tool_rectangle_change_complete),
|
||||
crop_tool);
|
||||
|
||||
gimp_rectangle_options_connect (GIMP_RECTANGLE_OPTIONS (options),
|
||||
gimp_display_get_image (shell->display),
|
||||
G_CALLBACK (gimp_crop_tool_auto_shrink),
|
||||
crop_tool);
|
||||
|
||||
gimp_tool_rectangle_set_constraint (GIMP_TOOL_RECTANGLE (widget),
|
||||
gimp_crop_tool_get_constraint (crop_tool));
|
||||
|
||||
gimp_crop_tool_update_option_defaults (crop_tool, FALSE);
|
||||
gimp_crop_tool_start (crop_tool, display);
|
||||
|
||||
gimp_tool_widget_hover (crop_tool->rectangle, coords, state, TRUE);
|
||||
|
||||
|
@ -279,8 +227,6 @@ gimp_crop_tool_button_press (GimpTool *tool,
|
|||
*/
|
||||
gimp_tool_rectangle_set_function (GIMP_TOOL_RECTANGLE (crop_tool->rectangle),
|
||||
GIMP_TOOL_RECTANGLE_CREATING);
|
||||
|
||||
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
||||
}
|
||||
|
||||
if (gimp_tool_widget_button_press (crop_tool->rectangle, coords, time, state,
|
||||
|
@ -401,6 +347,70 @@ gimp_crop_tool_rectangle_change_complete (GimpToolRectangle *rectangle,
|
|||
gimp_crop_tool_update_option_defaults (crop_tool, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_crop_tool_start (GimpCropTool *crop_tool,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
static const gchar *properties[] =
|
||||
{
|
||||
"highlight",
|
||||
"guide",
|
||||
"x",
|
||||
"y",
|
||||
"width",
|
||||
"height",
|
||||
"fixed-rule-active",
|
||||
"fixed-rule",
|
||||
"desired-fixed-width",
|
||||
"desired-fixed-height",
|
||||
"desired-fixed-size-width",
|
||||
"desired-fixed-size-height",
|
||||
"aspect-numerator",
|
||||
"aspect-denominator",
|
||||
"fixed-center"
|
||||
};
|
||||
|
||||
GimpTool *tool = GIMP_TOOL (crop_tool);
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
||||
GimpCropOptions *options = GIMP_CROP_TOOL_GET_OPTIONS (crop_tool);
|
||||
GimpToolWidget *widget;
|
||||
gint i;
|
||||
|
||||
tool->display = display;
|
||||
|
||||
crop_tool->rectangle = widget = gimp_tool_rectangle_new (shell);
|
||||
|
||||
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), widget);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (properties); i++)
|
||||
g_object_bind_property (G_OBJECT (options), properties[i],
|
||||
G_OBJECT (widget), properties[i],
|
||||
G_BINDING_SYNC_CREATE |
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
|
||||
g_signal_connect (widget, "changed",
|
||||
G_CALLBACK (gimp_crop_tool_rectangle_changed),
|
||||
crop_tool);
|
||||
g_signal_connect (widget, "response",
|
||||
G_CALLBACK (gimp_crop_tool_rectangle_response),
|
||||
crop_tool);
|
||||
g_signal_connect (widget, "change-complete",
|
||||
G_CALLBACK (gimp_crop_tool_rectangle_change_complete),
|
||||
crop_tool);
|
||||
|
||||
gimp_rectangle_options_connect (GIMP_RECTANGLE_OPTIONS (options),
|
||||
gimp_display_get_image (shell->display),
|
||||
G_CALLBACK (gimp_crop_tool_auto_shrink),
|
||||
crop_tool);
|
||||
|
||||
gimp_tool_rectangle_set_constraint (GIMP_TOOL_RECTANGLE (widget),
|
||||
gimp_crop_tool_get_constraint (crop_tool));
|
||||
|
||||
gimp_crop_tool_update_option_defaults (crop_tool, FALSE);
|
||||
|
||||
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_crop_tool_commit (GimpCropTool *crop_tool)
|
||||
{
|
||||
|
|
|
@ -185,6 +185,36 @@ gimp_free_select_tool_finalize (GObject *object)
|
|||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_free_select_tool_start (GimpFreeSelectTool *fst,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (fst);
|
||||
GimpFreeSelectToolPrivate *private = fst->private;
|
||||
GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
||||
|
||||
tool->display = display;
|
||||
|
||||
/* We want to apply the selection operation that was current when
|
||||
* the tool was started, so we save this information
|
||||
*/
|
||||
private->operation_at_start = options->operation;
|
||||
|
||||
private->polygon = gimp_tool_polygon_new (shell);
|
||||
|
||||
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), private->polygon);
|
||||
|
||||
g_signal_connect (private->polygon, "changed",
|
||||
G_CALLBACK (gimp_free_select_tool_polygon_changed),
|
||||
fst);
|
||||
g_signal_connect (private->polygon, "response",
|
||||
G_CALLBACK (gimp_free_select_tool_polygon_response),
|
||||
fst);
|
||||
|
||||
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_free_select_tool_commit (GimpFreeSelectTool *fst,
|
||||
GimpDisplay *display)
|
||||
|
@ -302,18 +332,14 @@ gimp_free_select_tool_button_press (GimpTool *tool,
|
|||
GimpButtonPressType press_type,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
||||
GimpFreeSelectTool *fst = GIMP_FREE_SELECT_TOOL (tool);
|
||||
GimpFreeSelectToolPrivate *private = fst->private;
|
||||
GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
|
||||
GimpFreeSelectTool *fst = GIMP_FREE_SELECT_TOOL (tool);
|
||||
GimpFreeSelectToolPrivate *private = fst->private;
|
||||
|
||||
if (tool->display && tool->display != display)
|
||||
gimp_tool_control (tool, GIMP_TOOL_ACTION_COMMIT, tool->display);
|
||||
|
||||
if (! private->polygon) /* not tool->display, we have a subclass */
|
||||
{
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
||||
|
||||
/* First of all handle delegation to the selection mask edit logic
|
||||
* if appropriate.
|
||||
*/
|
||||
|
@ -323,36 +349,18 @@ gimp_free_select_tool_button_press (GimpTool *tool,
|
|||
return;
|
||||
}
|
||||
|
||||
tool->display = display;
|
||||
|
||||
/* We want to apply the selection operation that was current when
|
||||
* the tool was started, so we save this information
|
||||
*/
|
||||
private->operation_at_start = options->operation;
|
||||
|
||||
private->polygon = gimp_tool_polygon_new (shell);
|
||||
|
||||
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), private->polygon);
|
||||
|
||||
g_signal_connect (private->polygon, "changed",
|
||||
G_CALLBACK (gimp_free_select_tool_polygon_changed),
|
||||
fst);
|
||||
g_signal_connect (private->polygon, "response",
|
||||
G_CALLBACK (gimp_free_select_tool_polygon_response),
|
||||
fst);
|
||||
|
||||
gimp_draw_tool_start (draw_tool, display);
|
||||
gimp_free_select_tool_start (fst, display);
|
||||
|
||||
gimp_tool_widget_hover (private->polygon, coords, state, TRUE);
|
||||
}
|
||||
|
||||
gimp_tool_control_activate (tool->control);
|
||||
|
||||
if (gimp_tool_widget_button_press (private->polygon, coords, time, state,
|
||||
press_type))
|
||||
{
|
||||
private->grab_widget = private->polygon;
|
||||
}
|
||||
|
||||
gimp_tool_control_activate (tool->control);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -119,6 +119,8 @@ static void gimp_rectangle_select_tool_rectangle_change_complete
|
|||
(GimpToolWidget *widget,
|
||||
GimpRectangleSelectTool *rect_tool);
|
||||
|
||||
static void gimp_rectangle_select_tool_start (GimpRectangleSelectTool *rect_tool,
|
||||
GimpDisplay *display);
|
||||
static void gimp_rectangle_select_tool_commit (GimpRectangleSelectTool *rect_tool);
|
||||
static void gimp_rectangle_select_tool_halt (GimpRectangleSelectTool *rect_tool);
|
||||
|
||||
|
@ -246,74 +248,16 @@ gimp_rectangle_select_tool_button_press (GimpTool *tool,
|
|||
|
||||
if (! tool->display)
|
||||
{
|
||||
static const gchar *properties[] =
|
||||
{
|
||||
"highlight",
|
||||
"guide",
|
||||
"round-corners",
|
||||
"corner-radius",
|
||||
"x",
|
||||
"y",
|
||||
"width",
|
||||
"height",
|
||||
"fixed-rule-active",
|
||||
"fixed-rule",
|
||||
"desired-fixed-width",
|
||||
"desired-fixed-height",
|
||||
"desired-fixed-size-width",
|
||||
"desired-fixed-size-height",
|
||||
"aspect-numerator",
|
||||
"aspect-denominator",
|
||||
"fixed-center"
|
||||
};
|
||||
gimp_rectangle_select_tool_start (rect_tool, display);
|
||||
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
||||
GimpRectangleSelectOptions *options;
|
||||
GimpToolWidget *widget;
|
||||
gint i;
|
||||
|
||||
options = GIMP_RECTANGLE_SELECT_TOOL_GET_OPTIONS (rect_tool);
|
||||
|
||||
tool->display = display;
|
||||
|
||||
private->rectangle = widget = gimp_tool_rectangle_new (shell);
|
||||
|
||||
g_object_set (widget,
|
||||
"draw-ellipse", GIMP_RECTANGLE_SELECT_TOOL_GET_CLASS (rect_tool)->draw_ellipse,
|
||||
NULL);
|
||||
|
||||
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), widget);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (properties); i++)
|
||||
g_object_bind_property (G_OBJECT (options), properties[i],
|
||||
G_OBJECT (widget), properties[i],
|
||||
G_BINDING_SYNC_CREATE |
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
|
||||
g_signal_connect (widget, "response",
|
||||
G_CALLBACK (gimp_rectangle_select_tool_rectangle_response),
|
||||
rect_tool);
|
||||
g_signal_connect (widget, "change-complete",
|
||||
G_CALLBACK (gimp_rectangle_select_tool_rectangle_change_complete),
|
||||
rect_tool);
|
||||
|
||||
gimp_rectangle_options_connect (GIMP_RECTANGLE_OPTIONS (options),
|
||||
gimp_display_get_image (shell->display),
|
||||
G_CALLBACK (gimp_rectangle_select_tool_auto_shrink),
|
||||
rect_tool);
|
||||
|
||||
gimp_rectangle_select_tool_update_option_defaults (rect_tool, FALSE);
|
||||
|
||||
gimp_tool_widget_hover (widget, coords, state, TRUE);
|
||||
gimp_tool_widget_hover (private->rectangle, coords, state, TRUE);
|
||||
|
||||
/* HACK: force CREATING on a newly created rectangle; otherwise,
|
||||
* the above binding of properties would cause the rectangle to
|
||||
* start with the size from tool options.
|
||||
*/
|
||||
gimp_tool_rectangle_set_function (GIMP_TOOL_RECTANGLE (widget),
|
||||
gimp_tool_rectangle_set_function (GIMP_TOOL_RECTANGLE (private->rectangle),
|
||||
GIMP_TOOL_RECTANGLE_CREATING);
|
||||
|
||||
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
||||
}
|
||||
|
||||
private->saved_show_selection = gimp_display_shell_get_show_selection (shell);
|
||||
|
@ -688,6 +632,74 @@ gimp_rectangle_select_tool_rectangle_change_complete (GimpToolWidget *w
|
|||
gimp_rectangle_select_tool_update_option_defaults (rect_tool, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_rectangle_select_tool_start (GimpRectangleSelectTool *rect_tool,
|
||||
GimpDisplay *display)
|
||||
{
|
||||
static const gchar *properties[] =
|
||||
{
|
||||
"highlight",
|
||||
"guide",
|
||||
"round-corners",
|
||||
"corner-radius",
|
||||
"x",
|
||||
"y",
|
||||
"width",
|
||||
"height",
|
||||
"fixed-rule-active",
|
||||
"fixed-rule",
|
||||
"desired-fixed-width",
|
||||
"desired-fixed-height",
|
||||
"desired-fixed-size-width",
|
||||
"desired-fixed-size-height",
|
||||
"aspect-numerator",
|
||||
"aspect-denominator",
|
||||
"fixed-center"
|
||||
};
|
||||
|
||||
GimpTool *tool = GIMP_TOOL (rect_tool);
|
||||
GimpRectangleSelectToolPrivate *private = rect_tool->private;
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
||||
GimpRectangleSelectOptions *options;
|
||||
GimpToolWidget *widget;
|
||||
gint i;
|
||||
|
||||
options = GIMP_RECTANGLE_SELECT_TOOL_GET_OPTIONS (rect_tool);
|
||||
|
||||
tool->display = display;
|
||||
|
||||
private->rectangle = widget = gimp_tool_rectangle_new (shell);
|
||||
|
||||
g_object_set (widget,
|
||||
"draw-ellipse",
|
||||
GIMP_RECTANGLE_SELECT_TOOL_GET_CLASS (rect_tool)->draw_ellipse,
|
||||
NULL);
|
||||
|
||||
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), widget);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (properties); i++)
|
||||
g_object_bind_property (G_OBJECT (options), properties[i],
|
||||
G_OBJECT (widget), properties[i],
|
||||
G_BINDING_SYNC_CREATE |
|
||||
G_BINDING_BIDIRECTIONAL);
|
||||
|
||||
g_signal_connect (widget, "response",
|
||||
G_CALLBACK (gimp_rectangle_select_tool_rectangle_response),
|
||||
rect_tool);
|
||||
g_signal_connect (widget, "change-complete",
|
||||
G_CALLBACK (gimp_rectangle_select_tool_rectangle_change_complete),
|
||||
rect_tool);
|
||||
|
||||
gimp_rectangle_options_connect (GIMP_RECTANGLE_OPTIONS (options),
|
||||
gimp_display_get_image (shell->display),
|
||||
G_CALLBACK (gimp_rectangle_select_tool_auto_shrink),
|
||||
rect_tool);
|
||||
|
||||
gimp_rectangle_select_tool_update_option_defaults (rect_tool, FALSE);
|
||||
|
||||
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
||||
}
|
||||
|
||||
/* This function is called if the user clicks and releases the left
|
||||
* button without moving it. There are the things we might want
|
||||
* to do here:
|
||||
|
|
Loading…
Reference in New Issue