[gimp] app: add a transform matrix to GimpCanvasPolygon and all API using it
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add a transform matrix to GimpCanvasPolygon and all API using it
- Date: Mon, 19 Jun 2017 20:14:30 +0000 (UTC)
commit 546bbe1e14d984b8dab181a3d4aecb756d408518
Author: Michael Natterer <mitch gimp org>
Date: Mon Jun 19 21:53:49 2017 +0200
app: add a transform matrix to GimpCanvasPolygon and all API using it
app/display/gimpcanvaspolygon.c | 92 ++++++++++++++++++++++++++------
app/display/gimpcanvaspolygon.h | 2 +
app/tools/gimpdrawtool.c | 6 ++-
app/tools/gimpdrawtool.h | 2 +
app/tools/gimpfreeselecttool.c | 2 +-
app/tools/gimpiscissorstool.c | 2 +-
app/tools/gimpnpointdeformationtool.c | 2 +-
app/tools/gimptransformtool.c | 2 +-
8 files changed, 86 insertions(+), 24 deletions(-)
---
diff --git a/app/display/gimpcanvaspolygon.c b/app/display/gimpcanvaspolygon.c
index 69deb96..9af307f 100644
--- a/app/display/gimpcanvaspolygon.c
+++ b/app/display/gimpcanvaspolygon.c
@@ -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);
diff --git a/app/display/gimpcanvaspolygon.h b/app/display/gimpcanvaspolygon.h
index 0812129..b4902d8 100644
--- a/app/display/gimpcanvaspolygon.h
+++ b/app/display/gimpcanvaspolygon.h
@@ -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);
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index 89113a8..2a751a9 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -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);
diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h
index 5d67f72..940e9c3 100644
--- a/app/tools/gimpdrawtool.h
+++ b/app/tools/gimpdrawtool.h
@@ -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,
diff --git a/app/tools/gimpfreeselecttool.c b/app/tools/gimpfreeselecttool.c
index e3d016a..aabe9ff 100644
--- a/app/tools/gimpfreeselecttool.c
+++ b/app/tools/gimpfreeselecttool.c
@@ -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
diff --git a/app/tools/gimpiscissorstool.c b/app/tools/gimpiscissorstool.c
index e7a7156..c6d25bb 100644
--- a/app/tools/gimpiscissorstool.c
+++ b/app/tools/gimpiscissorstool.c
@@ -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);
diff --git a/app/tools/gimpnpointdeformationtool.c b/app/tools/gimpnpointdeformationtool.c
index e2a6d3e..0471142 100644
--- a/app/tools/gimpnpointdeformationtool.c
+++ b/app/tools/gimpnpointdeformationtool.c
@@ -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
diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c
index 99687c2..3793921 100644
--- a/app/tools/gimptransformtool.c
+++ b/app/tools/gimptransformtool.c
@@ -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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]