Commit 546bbe1e authored by Michael Natterer's avatar Michael Natterer 😴

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

parent 3ddfd107
......@@ -38,6 +38,7 @@ enum
{
PROP_0,
PROP_POINTS,
PROP_TRANSFORM,
PROP_FILLED
};
......@@ -46,9 +47,10 @@ typedef struct _GimpCanvasPolygonPrivate GimpCanvasPolygonPrivate;
struct _GimpCanvasPolygonPrivate
{
GimpVector2 *points;
gint n_points;
gboolean filled;
GimpVector2 *points;
gint n_points;
GimpMatrix3 *transform;
gboolean filled;
};
#define GET_PRIVATE(polygon) \
......@@ -96,6 +98,10 @@ gimp_canvas_polygon_class_init (GimpCanvasPolygonClass *klass)
gimp_param_spec_array ("points", NULL, NULL,
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_param_spec_boolean ("filled", NULL, NULL,
FALSE,
......@@ -121,6 +127,12 @@ gimp_canvas_polygon_finalize (GObject *object)
private->n_points = 0;
}
if (private->transform)
{
g_free (private->transform);
private->transform = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
......@@ -149,6 +161,19 @@ gimp_canvas_polygon_set_property (GObject *object,
}
}
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:
private->filled = g_value_get_boolean (value);
break;
......@@ -184,6 +209,11 @@ gimp_canvas_polygon_get_property (GObject *object,
g_value_set_boxed (value, NULL);
}
break;
case PROP_TRANSFORM:
g_value_set_pointer (value, private->transform);
break;
case PROP_FILLED:
g_value_set_boolean (value, private->filled);
break;
......@@ -201,16 +231,38 @@ gimp_canvas_polygon_transform (GimpCanvasItem *item,
GimpCanvasPolygonPrivate *private = GET_PRIVATE (item);
gint i;
for (i = 0; i < private->n_points; 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
{
gimp_canvas_item_transform_xy_f (item,
private->points[i].x,
private->points[i].y,
&points[i].x,
&points[i].y);
points[i].x = floor (points[i].x) + 0.5;
points[i].y = floor (points[i].y) + 0.5;
for (i = 0; i < private->n_points; i++)
{
gimp_canvas_item_transform_xy_f (item,
private->points[i].x,
private->points[i].y,
&points[i].x,
&points[i].y);
points[i].x = floor (points[i].x) + 0.5;
points[i].y = floor (points[i].y) + 0.5;
}
}
}
......@@ -286,6 +338,7 @@ GimpCanvasItem *
gimp_canvas_polygon_new (GimpDisplayShell *shell,
const GimpVector2 *points,
gint n_points,
GimpMatrix3 *transform,
gboolean filled)
{
GimpCanvasItem *item;
......@@ -298,9 +351,10 @@ gimp_canvas_polygon_new (GimpDisplayShell *shell,
n_points * sizeof (GimpVector2), TRUE);
item = g_object_new (GIMP_TYPE_CANVAS_POLYGON,
"shell", shell,
"filled", filled,
"points", array,
"shell", shell,
"transform", transform,
"filled", filled,
"points", array,
NULL);
gimp_array_free (array);
......@@ -312,6 +366,7 @@ GimpCanvasItem *
gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
const GimpCoords *coords,
gint n_coords,
GimpMatrix3 *transform,
gboolean filled)
{
GimpCanvasItem *item;
......@@ -334,9 +389,10 @@ gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
n_coords * sizeof (GimpVector2), TRUE);
item = g_object_new (GIMP_TYPE_CANVAS_POLYGON,
"shell", shell,
"filled", filled,
"points", array,
"shell", shell,
"transform", transform,
"filled", filled,
"points", array,
NULL);
gimp_array_free (array);
......
......@@ -52,10 +52,12 @@ GType gimp_canvas_polygon_get_type (void) G_GNUC_CONST;
GimpCanvasItem * gimp_canvas_polygon_new (GimpDisplayShell *shell,
const GimpVector2 *points,
gint n_points,
GimpMatrix3 *transform,
gboolean filled);
GimpCanvasItem * gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
const GimpCoords *coords,
gint n_coords,
GimpMatrix3 *transform,
gboolean filled);
......
......@@ -809,6 +809,7 @@ GimpCanvasItem *
gimp_draw_tool_add_lines (GimpDrawTool *draw_tool,
const GimpVector2 *points,
gint n_points,
GimpMatrix3 *transform,
gboolean filled)
{
GimpCanvasItem *item;
......@@ -819,7 +820,7 @@ gimp_draw_tool_add_lines (GimpDrawTool *draw_tool,
return NULL;
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);
g_object_unref (item);
......@@ -831,6 +832,7 @@ GimpCanvasItem *
gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool,
const GimpCoords *points,
gint n_points,
GimpMatrix3 *transform,
gboolean filled)
{
GimpCanvasItem *item;
......@@ -841,7 +843,7 @@ gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool,
return NULL;
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);
g_object_unref (item);
......
......@@ -174,11 +174,13 @@ GimpCanvasItem * gimp_draw_tool_add_corner (GimpDrawTool *draw_too
GimpCanvasItem * gimp_draw_tool_add_lines (GimpDrawTool *draw_tool,
const GimpVector2 *points,
gint n_points,
GimpMatrix3 *transform,
gboolean filled);
GimpCanvasItem * gimp_draw_tool_add_strokes (GimpDrawTool *draw_tool,
const GimpCoords *points,
gint n_points,
GimpMatrix3 *transform,
gboolean filled);
GimpCanvasItem * gimp_draw_tool_add_path (GimpDrawTool *draw_tool,
const GimpBezierDesc *desc,
......
......@@ -1316,7 +1316,7 @@ gimp_free_select_tool_draw (GimpDrawTool *draw_tool)
gimp_draw_tool_push_group (draw_tool, stroke_group);
gimp_draw_tool_add_lines (draw_tool,
priv->points, priv->n_points,
FALSE);
NULL, FALSE);
gimp_draw_tool_pop_group (draw_tool);
/* We always show the handle for the first point, even with button1
......
......@@ -875,7 +875,7 @@ iscissors_draw_segment (GimpDrawTool *draw_tool,
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);
......
......@@ -764,7 +764,7 @@ gimp_n_point_deformation_tool_draw_lattice (GimpNPointDeformationTool *npd_tool)
for (i = 0; i < n_squares; i++)
gimp_draw_tool_add_lines (GIMP_DRAW_TOOL (npd_tool),
&points[5 * i], 5, FALSE);
&points[5 * i], 5, NULL, FALSE);
}
static void
......
......@@ -888,7 +888,7 @@ gimp_transform_tool_draw (GimpDrawTool *draw_tool)
gimp_draw_tool_add_strokes (draw_tool,
&g_array_index (coords,
GimpCoords, 0),
coords->len, FALSE);
coords->len, NULL, FALSE);
}
if (coords)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment