app: add gimp_canvas_polygon_new_from_coords()

and use it from gimp_draw_tool_draw_strokes().
This commit is contained in:
Michael Natterer
2010-09-23 00:40:32 +02:00
parent eeeea7c69b
commit 7c82f3dc09
3 changed files with 46 additions and 5 deletions

View File

@ -282,3 +282,30 @@ gimp_canvas_polygon_new (const GimpVector2 *points,
return item;
}
GimpCanvasItem *
gimp_canvas_polygon_new_from_coords (const GimpCoords *points,
gint n_points,
gboolean filled)
{
GimpCanvasItem *item;
GimpCanvasPolygonPrivate *private;
gint i;
item = g_object_new (GIMP_TYPE_CANVAS_POLYGON,
"filled", filled,
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;
}
return item;
}

View File

@ -47,11 +47,14 @@ struct _GimpCanvasPolygonClass
};
GType gimp_canvas_polygon_get_type (void) G_GNUC_CONST;
GType gimp_canvas_polygon_get_type (void) G_GNUC_CONST;
GimpCanvasItem * gimp_canvas_polygon_new (const GimpVector2 *points,
gint n_points,
gboolean filled);
GimpCanvasItem * gimp_canvas_polygon_new (const GimpVector2 *points,
gint n_points,
gboolean filled);
GimpCanvasItem * gimp_canvas_polygon_new_from_coords (const GimpCoords *points,
gint n_points,
gboolean filled);
#endif /* __GIMP_CANVAS_POLYGON_H__ */

View File

@ -1410,9 +1410,20 @@ gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool,
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
if (n_points == 0)
if (points == NULL || n_points < 2)
return;
if (draw_tool->use_cairo)
{
GimpCanvasItem *item;
item = gimp_canvas_polygon_new_from_coords (points, n_points, filled);
draw_tool->items = g_list_append (draw_tool->items, item);
return;
}
shell = gimp_display_get_shell (draw_tool->display);
coords = g_new (GdkPoint, n_points);