app: some cleanup in GimpTransformTool

- add utility function gimp_transform_tool_get_widget()
- reorder some functions
- cleanup in draw()
This commit is contained in:
Michael Natterer 2017-06-20 00:19:21 +02:00
parent 99dee5860d
commit 956477831f
1 changed files with 78 additions and 72 deletions

View File

@ -117,8 +117,6 @@ static void gimp_transform_tool_options_notify (GimpTool
static void gimp_transform_tool_draw (GimpDrawTool *draw_tool);
static void gimp_transform_tool_dialog_update (GimpTransformTool *tr_tool);
static GeglBuffer *
gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
GimpItem *item,
@ -145,8 +143,11 @@ static void gimp_transform_tool_halt (GimpTransformTool
static gboolean gimp_transform_tool_bounds (GimpTransformTool *tr_tool,
GimpDisplay *display);
static void gimp_transform_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_transform_tool_dialog_update (GimpTransformTool *tr_tool);
static void gimp_transform_tool_prepare (GimpTransformTool *tr_tool,
GimpDisplay *display);
static GimpToolWidget *
gimp_transform_tool_get_widget (GimpTransformTool *tr_tool);
static void gimp_transform_tool_transform (GimpTransformTool *tr_tool,
GimpDisplay *display);
@ -262,7 +263,6 @@ gimp_transform_tool_initialize (GimpTool *tool,
GError **error)
{
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
GimpImage *image = gimp_display_get_image (display);
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
GimpItem *item;
@ -308,52 +308,7 @@ gimp_transform_tool_initialize (GimpTool *tool,
gimp_transform_tool_recalc_matrix (tr_tool, NULL);
/* Get the on-canvas gui */
if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->get_widget)
{
static const gchar *properties[] =
{
"constrain-move",
"constrain-scale",
"constrain-rotate",
"constrain-shear",
"constrain-perspective",
"frompivot-scale",
"frompivot-shear",
"frompivot-perspective",
"cornersnap",
"fixedpivot"
};
gint i;
tr_tool->widget =
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->get_widget (tr_tool);
g_object_bind_property (G_OBJECT (options), "grid-type",
G_OBJECT (tr_tool->widget), "guide-type",
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
g_object_bind_property (G_OBJECT (options), "grid-size",
G_OBJECT (tr_tool->widget), "n-guides",
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
for (i = 0; i < G_N_ELEMENTS (properties); i++)
g_object_bind_property (G_OBJECT (options), properties[i],
G_OBJECT (tr_tool->widget), properties[i],
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
g_signal_connect (tr_tool->widget, "changed",
G_CALLBACK (gimp_transform_tool_widget_changed),
tr_tool);
g_signal_connect (tr_tool->widget, "snap-offsets",
G_CALLBACK (gimp_transform_tool_widget_snap_offsets),
tr_tool);
g_signal_connect (tr_tool->widget, "status",
G_CALLBACK (gimp_transform_tool_widget_status),
tr_tool);
}
tr_tool->widget = gimp_transform_tool_get_widget (tr_tool);
gimp_transform_tool_hide_active_item (tr_tool, item);
@ -760,8 +715,6 @@ gimp_transform_tool_options_notify (GimpTool *tool,
return;
if (! strcmp (pspec->name, "direction"))
{
if (tool->display)
{
/* reget the selection bounds */
gimp_transform_tool_bounds (tr_tool, tool->display);
@ -769,9 +722,7 @@ gimp_transform_tool_options_notify (GimpTool *tool,
/* recalculate the tool's transformation matrix */
gimp_transform_tool_recalc_matrix (tr_tool, tr_tool->widget);
}
}
if (! strcmp (pspec->name, "show-preview"))
else if (! strcmp (pspec->name, "show-preview"))
{
if (tr_tool->preview)
{
@ -902,16 +853,6 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
}
}
static void
gimp_transform_tool_dialog_update (GimpTransformTool *tr_tool)
{
if (tr_tool->gui &&
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update)
{
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update (tr_tool);
}
}
static GeglBuffer *
gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
GimpItem *active_item,
@ -1367,6 +1308,16 @@ gimp_transform_tool_dialog (GimpTransformTool *tr_tool)
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog (tr_tool);
}
static void
gimp_transform_tool_dialog_update (GimpTransformTool *tr_tool)
{
if (tr_tool->gui &&
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update)
{
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->dialog_update (tr_tool);
}
}
static void
gimp_transform_tool_prepare (GimpTransformTool *tr_tool,
GimpDisplay *display)
@ -1384,6 +1335,61 @@ gimp_transform_tool_prepare (GimpTransformTool *tr_tool,
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->prepare (tr_tool);
}
static GimpToolWidget *
gimp_transform_tool_get_widget (GimpTransformTool *tr_tool)
{
static const gchar *properties[] =
{
"constrain-move",
"constrain-scale",
"constrain-rotate",
"constrain-shear",
"constrain-perspective",
"frompivot-scale",
"frompivot-shear",
"frompivot-perspective",
"cornersnap",
"fixedpivot"
};
GimpToolWidget *widget = NULL;
if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->get_widget)
{
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
gint i;
widget = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->get_widget (tr_tool);
g_object_bind_property (G_OBJECT (options), "grid-type",
G_OBJECT (widget), "guide-type",
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
g_object_bind_property (G_OBJECT (options), "grid-size",
G_OBJECT (widget), "n-guides",
G_BINDING_SYNC_CREATE |
G_BINDING_BIDIRECTIONAL);
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_transform_tool_widget_changed),
tr_tool);
g_signal_connect (widget, "snap-offsets",
G_CALLBACK (gimp_transform_tool_widget_snap_offsets),
tr_tool);
g_signal_connect (widget, "status",
G_CALLBACK (gimp_transform_tool_widget_status),
tr_tool);
}
return widget;
}
void
gimp_transform_tool_recalc_matrix (GimpTransformTool *tr_tool,
GimpToolWidget *widget)