app: add a transform matrix to GimpCanvasPolygon and all API using it

This commit is contained in:
Michael Natterer 2017-06-19 21:53:49 +02:00
parent 3ddfd107b9
commit 546bbe1e14
8 changed files with 85 additions and 23 deletions

View File

@ -38,6 +38,7 @@ enum
{ {
PROP_0, PROP_0,
PROP_POINTS, PROP_POINTS,
PROP_TRANSFORM,
PROP_FILLED PROP_FILLED
}; };
@ -48,6 +49,7 @@ struct _GimpCanvasPolygonPrivate
{ {
GimpVector2 *points; GimpVector2 *points;
gint n_points; gint n_points;
GimpMatrix3 *transform;
gboolean filled; gboolean filled;
}; };
@ -96,6 +98,10 @@ gimp_canvas_polygon_class_init (GimpCanvasPolygonClass *klass)
gimp_param_spec_array ("points", NULL, NULL, gimp_param_spec_array ("points", NULL, NULL,
GIMP_PARAM_READWRITE)); GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_TRANSFORM,
g_param_spec_pointer ("transform", NULL, NULL,
GIMP_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_FILLED, g_object_class_install_property (object_class, PROP_FILLED,
g_param_spec_boolean ("filled", NULL, NULL, g_param_spec_boolean ("filled", NULL, NULL,
FALSE, FALSE,
@ -121,6 +127,12 @@ gimp_canvas_polygon_finalize (GObject *object)
private->n_points = 0; private->n_points = 0;
} }
if (private->transform)
{
g_free (private->transform);
private->transform = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
@ -149,6 +161,19 @@ gimp_canvas_polygon_set_property (GObject *object,
} }
} }
break; break;
case PROP_TRANSFORM:
{
GimpMatrix3 *transform = g_value_get_pointer (value);
if (private->transform)
g_free (private->transform);
if (transform)
private->transform = g_memdup (transform, sizeof (GimpMatrix3));
else
private->transform = NULL;
}
break;
case PROP_FILLED: case PROP_FILLED:
private->filled = g_value_get_boolean (value); private->filled = g_value_get_boolean (value);
break; break;
@ -184,6 +209,11 @@ gimp_canvas_polygon_get_property (GObject *object,
g_value_set_boxed (value, NULL); g_value_set_boxed (value, NULL);
} }
break; break;
case PROP_TRANSFORM:
g_value_set_pointer (value, private->transform);
break;
case PROP_FILLED: case PROP_FILLED:
g_value_set_boolean (value, private->filled); g_value_set_boolean (value, private->filled);
break; break;
@ -201,6 +231,27 @@ gimp_canvas_polygon_transform (GimpCanvasItem *item,
GimpCanvasPolygonPrivate *private = GET_PRIVATE (item); GimpCanvasPolygonPrivate *private = GET_PRIVATE (item);
gint i; gint i;
if (private->transform)
{
for (i = 0; i < private->n_points; i++)
{
gdouble tx, ty;
gimp_matrix3_transform_point (private->transform,
private->points[i].x,
private->points[i].y,
&tx, &ty);
gimp_canvas_item_transform_xy_f (item,
tx, ty,
&points[i].x,
&points[i].y);
points[i].x = floor (points[i].x) + 0.5;
points[i].y = floor (points[i].y) + 0.5;
}
}
else
{
for (i = 0; i < private->n_points; i++) for (i = 0; i < private->n_points; i++)
{ {
gimp_canvas_item_transform_xy_f (item, gimp_canvas_item_transform_xy_f (item,
@ -213,6 +264,7 @@ gimp_canvas_polygon_transform (GimpCanvasItem *item,
points[i].y = floor (points[i].y) + 0.5; points[i].y = floor (points[i].y) + 0.5;
} }
} }
}
static void static void
gimp_canvas_polygon_draw (GimpCanvasItem *item, gimp_canvas_polygon_draw (GimpCanvasItem *item,
@ -286,6 +338,7 @@ GimpCanvasItem *
gimp_canvas_polygon_new (GimpDisplayShell *shell, gimp_canvas_polygon_new (GimpDisplayShell *shell,
const GimpVector2 *points, const GimpVector2 *points,
gint n_points, gint n_points,
GimpMatrix3 *transform,
gboolean filled) gboolean filled)
{ {
GimpCanvasItem *item; GimpCanvasItem *item;
@ -299,6 +352,7 @@ gimp_canvas_polygon_new (GimpDisplayShell *shell,
item = g_object_new (GIMP_TYPE_CANVAS_POLYGON, item = g_object_new (GIMP_TYPE_CANVAS_POLYGON,
"shell", shell, "shell", shell,
"transform", transform,
"filled", filled, "filled", filled,
"points", array, "points", array,
NULL); NULL);
@ -312,6 +366,7 @@ GimpCanvasItem *
gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell, gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
const GimpCoords *coords, const GimpCoords *coords,
gint n_coords, gint n_coords,
GimpMatrix3 *transform,
gboolean filled) gboolean filled)
{ {
GimpCanvasItem *item; GimpCanvasItem *item;
@ -335,6 +390,7 @@ gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
item = g_object_new (GIMP_TYPE_CANVAS_POLYGON, item = g_object_new (GIMP_TYPE_CANVAS_POLYGON,
"shell", shell, "shell", shell,
"transform", transform,
"filled", filled, "filled", filled,
"points", array, "points", array,
NULL); NULL);

View File

@ -52,10 +52,12 @@ GType gimp_canvas_polygon_get_type (void) G_GNUC_CONST;
GimpCanvasItem * gimp_canvas_polygon_new (GimpDisplayShell *shell, GimpCanvasItem * gimp_canvas_polygon_new (GimpDisplayShell *shell,
const GimpVector2 *points, const GimpVector2 *points,
gint n_points, gint n_points,
GimpMatrix3 *transform,
gboolean filled); gboolean filled);
GimpCanvasItem * gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell, GimpCanvasItem * gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
const GimpCoords *coords, const GimpCoords *coords,
gint n_coords, gint n_coords,
GimpMatrix3 *transform,
gboolean filled); gboolean filled);

View File

@ -809,6 +809,7 @@ GimpCanvasItem *
gimp_draw_tool_add_lines (GimpDrawTool *draw_tool, gimp_draw_tool_add_lines (GimpDrawTool *draw_tool,
const GimpVector2 *points, const GimpVector2 *points,
gint n_points, gint n_points,
GimpMatrix3 *transform,
gboolean filled) gboolean filled)
{ {
GimpCanvasItem *item; GimpCanvasItem *item;
@ -819,7 +820,7 @@ gimp_draw_tool_add_lines (GimpDrawTool *draw_tool,
return NULL; return NULL;
item = gimp_canvas_polygon_new (gimp_display_get_shell (draw_tool->display), item = gimp_canvas_polygon_new (gimp_display_get_shell (draw_tool->display),
points, n_points, filled); points, n_points, transform, filled);
gimp_draw_tool_add_item (draw_tool, item); gimp_draw_tool_add_item (draw_tool, item);
g_object_unref (item); g_object_unref (item);
@ -831,6 +832,7 @@ GimpCanvasItem *
gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool, gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool,
const GimpCoords *points, const GimpCoords *points,
gint n_points, gint n_points,
GimpMatrix3 *transform,
gboolean filled) gboolean filled)
{ {
GimpCanvasItem *item; GimpCanvasItem *item;
@ -841,7 +843,7 @@ gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool,
return NULL; return NULL;
item = gimp_canvas_polygon_new_from_coords (gimp_display_get_shell (draw_tool->display), item = gimp_canvas_polygon_new_from_coords (gimp_display_get_shell (draw_tool->display),
points, n_points, filled); points, n_points, transform, filled);
gimp_draw_tool_add_item (draw_tool, item); gimp_draw_tool_add_item (draw_tool, item);
g_object_unref (item); g_object_unref (item);

View File

@ -174,11 +174,13 @@ GimpCanvasItem * gimp_draw_tool_add_corner (GimpDrawTool *draw_too
GimpCanvasItem * gimp_draw_tool_add_lines (GimpDrawTool *draw_tool, GimpCanvasItem * gimp_draw_tool_add_lines (GimpDrawTool *draw_tool,
const GimpVector2 *points, const GimpVector2 *points,
gint n_points, gint n_points,
GimpMatrix3 *transform,
gboolean filled); gboolean filled);
GimpCanvasItem * gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool, GimpCanvasItem * gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool,
const GimpCoords *points, const GimpCoords *points,
gint n_points, gint n_points,
GimpMatrix3 *transform,
gboolean filled); gboolean filled);
GimpCanvasItem * gimp_draw_tool_add_path (GimpDrawTool *draw_tool, GimpCanvasItem * gimp_draw_tool_add_path (GimpDrawTool *draw_tool,
const GimpBezierDesc *desc, const GimpBezierDesc *desc,

View File

@ -1316,7 +1316,7 @@ gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
gimp_draw_tool_push_group (draw_tool, stroke_group); gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_lines (draw_tool, gimp_draw_tool_add_lines (draw_tool,
priv->points, priv->n_points, priv->points, priv->n_points,
FALSE); NULL, FALSE);
gimp_draw_tool_pop_group (draw_tool); gimp_draw_tool_pop_group (draw_tool);
/* We always show the handle for the first point, even with button1 /* We always show the handle for the first point, even with button1

View File

@ -875,7 +875,7 @@ iscissors_draw_segment (GimpDrawTool *draw_tool,
points[i].y = (coords >> 16); points[i].y = (coords >> 16);
} }
item = gimp_draw_tool_add_lines (draw_tool, points, len, FALSE); item = gimp_draw_tool_add_lines (draw_tool, points, len, NULL, FALSE);
g_free (points); g_free (points);

View File

@ -764,7 +764,7 @@ gimp_n_point_deformation_tool_draw_lattice (GimpNPointDeformationTool *npd_tool)
for (i = 0; i < n_squares; i++) for (i = 0; i < n_squares; i++)
gimp_draw_tool_add_lines (GIMP_DRAW_TOOL (npd_tool), gimp_draw_tool_add_lines (GIMP_DRAW_TOOL (npd_tool),
&points[5 * i], 5, FALSE); &points[5 * i], 5, NULL, FALSE);
} }
static void static void

View File

@ -888,7 +888,7 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
gimp_draw_tool_add_strokes (draw_tool, gimp_draw_tool_add_strokes (draw_tool,
&g_array_index (coords, &g_array_index (coords,
GimpCoords, 0), GimpCoords, 0),
coords->len, FALSE); coords->len, NULL, FALSE);
} }
if (coords) if (coords)