Commit ba6aa825 authored by Michael Natterer's avatar Michael Natterer 😴

app: implement the "points" property using GimpArray

instead of poking into private from new(). This way the item is
properly subclassable.
parent dbce9d49
......@@ -138,6 +138,19 @@ gimp_canvas_polygon_set_property (GObject *object,
switch (property_id)
{
case PROP_POINTS:
{
GimpArray *array = g_value_get_boxed (value);
g_free (private->points);
private->points = NULL;
private->n_points = 0;
if (array)
{
private->points = g_memdup (array->data, array->length);
private->n_points = array->length / sizeof (GimpVector2);
}
}
break;
case PROP_FILLED:
private->filled = g_value_get_boolean (value);
......@@ -151,15 +164,28 @@ gimp_canvas_polygon_set_property (GObject *object,
static void
gimp_canvas_polygon_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GimpCanvasPolygonPrivate *private = GET_PRIVATE (object);
switch (property_id)
{
case PROP_POINTS:
if (private->points)
{
GimpArray *array;
array = gimp_array_new ((const guint8 *) private->points,
private->n_points * sizeof (GimpVector2),
FALSE);
g_value_take_boxed (value, array);
}
else
{
g_value_set_boxed (value, NULL);
}
break;
case PROP_FILLED:
g_value_set_boolean (value, private->filled);
......@@ -268,53 +294,58 @@ gimp_canvas_polygon_new (GimpDisplayShell *shell,
gint n_points,
gboolean filled)
{
GimpCanvasItem *item;
GimpCanvasPolygonPrivate *private;
GimpCanvasItem *item;
GimpArray *array;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
g_return_val_if_fail (points != NULL && n_points > 1, NULL);
array = gimp_array_new ((const guint8 *) points,
n_points * sizeof (GimpVector2), TRUE);
item = g_object_new (GIMP_TYPE_CANVAS_POLYGON,
"shell", shell,
"filled", filled,
"points", array,
NULL);
private = GET_PRIVATE (item);
/* puke */
private->points = g_memdup (points, n_points * sizeof (GimpVector2));
private->n_points = n_points;
gimp_array_free (array);
return item;
}
GimpCanvasItem *
gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
const GimpCoords *points,
gint n_points,
const GimpCoords *coords,
gint n_coords,
gboolean filled)
{
GimpCanvasItem *item;
GimpCanvasPolygonPrivate *private;
gint i;
GimpCanvasItem *item;
GimpVector2 *points;
GimpArray *array;
gint i;
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
g_return_val_if_fail (points != NULL && n_points > 1, NULL);
g_return_val_if_fail (coords != NULL && n_coords > 1, NULL);
points = g_new (GimpVector2, n_coords);
for (i = 0; i < n_coords; i++)
{
points[i].x = coords[i].x;
points[i].y = coords[i].y;
}
array = gimp_array_new ((const guint8 *) points,
n_coords * sizeof (GimpVector2), FALSE);
item = g_object_new (GIMP_TYPE_CANVAS_POLYGON,
"shell", shell,
"filled", filled,
"points", array,
NULL);
private = GET_PRIVATE (item);
/* puke */
private->points = g_new (GimpVector2, n_points);
private->n_points = n_points;
for (i = 0; i < n_points; i++)
{
private->points[i].x = points[i].x;
private->points[i].y = points[i].y;
}
gimp_array_free (array);
return item;
}
......@@ -54,8 +54,8 @@ GimpCanvasItem * gimp_canvas_polygon_new (GimpDisplayShell *shell,
gint n_points,
gboolean filled);
GimpCanvasItem * gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
const GimpCoords *points,
gint n_points,
const GimpCoords *coords,
gint n_coords,
gboolean filled);
......
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