[gimp] app: add gimp_canvas_polygon_set_points()



commit 9d8f94375e664d57496b8ba9466d42b559c0f86c
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jun 23 01:40:35 2017 +0200

    app: add gimp_canvas_polygon_set_points()
    
    and allow NULL points in both this function and new().

 app/display/gimpcanvaspolygon.c |   32 ++++++++++++++++++++++++++++++--
 app/display/gimpcanvaspolygon.h |    4 ++++
 2 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/app/display/gimpcanvaspolygon.c b/app/display/gimpcanvaspolygon.c
index 9af307f..c6df1ab 100644
--- a/app/display/gimpcanvaspolygon.c
+++ b/app/display/gimpcanvaspolygon.c
@@ -274,6 +274,9 @@ gimp_canvas_polygon_draw (GimpCanvasItem *item,
   GimpVector2              *points;
   gint                      i;
 
+  if (! private->points)
+    return;
+
   points = g_new0 (GimpVector2, private->n_points);
 
   gimp_canvas_polygon_transform (item, points);
@@ -302,6 +305,9 @@ gimp_canvas_polygon_get_extents (GimpCanvasItem *item)
   gint                      x1, y1, x2, y2;
   gint                      i;
 
+  if (! private->points)
+    return NULL;
+
   points = g_new0 (GimpVector2, private->n_points);
 
   gimp_canvas_polygon_transform (item, points);
@@ -345,7 +351,7 @@ gimp_canvas_polygon_new (GimpDisplayShell  *shell,
   GimpArray      *array;
 
   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 (points == NULL || n_points > 0, NULL);
 
   array = gimp_array_new ((const guint8 *) points,
                           n_points * sizeof (GimpVector2), TRUE);
@@ -375,7 +381,7 @@ gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
   gint            i;
 
   g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL);
-  g_return_val_if_fail (coords != NULL && n_coords > 1, NULL);
+  g_return_val_if_fail (coords == NULL || n_coords > 0, NULL);
 
   points = g_new (GimpVector2, n_coords);
 
@@ -400,3 +406,25 @@ gimp_canvas_polygon_new_from_coords (GimpDisplayShell *shell,
 
   return item;
 }
+
+void
+gimp_canvas_polygon_set_points (GimpCanvasItem    *polygon,
+                                const GimpVector2 *points,
+                                gint               n_points)
+{
+  GimpArray *array;
+
+  g_return_if_fail (GIMP_IS_CANVAS_POLYGON (polygon));
+  g_return_if_fail (points == NULL || n_points > 0);
+
+  array = gimp_array_new ((const guint8 *) points,
+                          n_points * sizeof (GimpVector2), TRUE);
+
+  gimp_canvas_item_begin_change (polygon);
+  g_object_set (polygon,
+                "points", array,
+                NULL);
+  gimp_canvas_item_end_change (polygon);
+
+  gimp_array_free (array);
+}
diff --git a/app/display/gimpcanvaspolygon.h b/app/display/gimpcanvaspolygon.h
index b4902d8..eec333a 100644
--- a/app/display/gimpcanvaspolygon.h
+++ b/app/display/gimpcanvaspolygon.h
@@ -60,5 +60,9 @@ GimpCanvasItem * gimp_canvas_polygon_new_from_coords (GimpDisplayShell  *shell,
                                                       GimpMatrix3       *transform,
                                                       gboolean           filled);
 
+void             gimp_canvas_polygon_set_points      (GimpCanvasItem    *polygon,
+                                                      const GimpVector2 *points,
+                                                      gint               n_points);
+
 
 #endif /* __GIMP_CANVAS_POLYGON_H__ */


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