[gimp] app: add gimp_canvas_polygon_new_from_coords()



commit 7c82f3dc09809fd184d92ec506d57e50165780bd
Author: Michael Natterer <mitch gimp org>
Date:   Thu Sep 23 00:40:32 2010 +0200

    app: add gimp_canvas_polygon_new_from_coords()
    
    and use it from gimp_draw_tool_draw_strokes().

 app/display/gimpcanvaspolygon.c |   27 +++++++++++++++++++++++++++
 app/display/gimpcanvaspolygon.h |   13 ++++++++-----
 app/tools/gimpdrawtool.c        |   13 ++++++++++++-
 3 files changed, 47 insertions(+), 6 deletions(-)
---
diff --git a/app/display/gimpcanvaspolygon.c b/app/display/gimpcanvaspolygon.c
index 0075b49..78a0d3c 100644
--- a/app/display/gimpcanvaspolygon.c
+++ b/app/display/gimpcanvaspolygon.c
@@ -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;
+}
diff --git a/app/display/gimpcanvaspolygon.h b/app/display/gimpcanvaspolygon.h
index 54dadcd..c1dfadf 100644
--- a/app/display/gimpcanvaspolygon.h
+++ b/app/display/gimpcanvaspolygon.h
@@ -47,11 +47,14 @@ struct _GimpCanvasPolygonClass
 };
 
 
-GType            gimp_canvas_polygon_get_type (void) G_GNUC_CONST;
-
-GimpCanvasItem * gimp_canvas_polygon_new      (const GimpVector2 *points,
-                                               gint               n_points,
-                                               gboolean           filled);
+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_from_coords (const GimpCoords  *points,
+                                                      gint               n_points,
+                                                      gboolean           filled);
 
 
 #endif /* __GIMP_CANVAS_POLYGON_H__ */
diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c
index e0b4ccf..4f56b55 100644
--- a/app/tools/gimpdrawtool.c
+++ b/app/tools/gimpdrawtool.c
@@ -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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]