[gtk/wip/otte/lottie: 78/82] path: Add gsk_path_builder_add_ellipse()




commit aa2f6345c811597bea768ab920438cad5ad14c9e
Author: Benjamin Otte <otte redhat com>
Date:   Fri Dec 25 21:31:06 2020 +0100

    path: Add gsk_path_builder_add_ellipse()

 docs/reference/gsk/gsk4-sections.txt |  1 +
 gsk/gskpathbuilder.c                 | 46 ++++++++++++++++++++++++++++++++++++
 gsk/gskpathbuilder.h                 |  4 ++++
 3 files changed, 51 insertions(+)
---
diff --git a/docs/reference/gsk/gsk4-sections.txt b/docs/reference/gsk/gsk4-sections.txt
index 7c1f1488a1..809a7db44e 100644
--- a/docs/reference/gsk/gsk4-sections.txt
+++ b/docs/reference/gsk/gsk4-sections.txt
@@ -355,6 +355,7 @@ gsk_path_builder_get_current_point
 gsk_path_builder_add_rect
 gsk_path_builder_add_rounded_rect
 gsk_path_builder_add_circle
+gsk_path_builder_add_ellipse
 gsk_path_builder_add_path
 gtk_path_builder_add_segment
 <SUBSECTION>
diff --git a/gsk/gskpathbuilder.c b/gsk/gskpathbuilder.c
index c5e9533686..3b578627a0 100644
--- a/gsk/gskpathbuilder.c
+++ b/gsk/gskpathbuilder.c
@@ -457,6 +457,52 @@ gsk_path_builder_add_circle (GskPathBuilder         *builder,
   gsk_path_builder_add_contour (builder, contour);
 }
 
+/**
+ * gsk_path_builder_add_ellipse:
+ * @builder: a #GskPathBuilder
+ * @center: the center point of the ellipse
+ * @radius: the radius of the ellipse in x/y direction
+ *
+ * Adds an ellipse with the given @center and the @radius in
+ * x/y direction.
+ **/
+void
+gsk_path_builder_add_ellipse (GskPathBuilder         *self,
+                              const graphene_point_t *center,
+                              const graphene_size_t  *radius)
+{
+  const float weight = sqrt(0.5f);
+  graphene_point_t pts[8];
+
+  g_return_if_fail (self != NULL);
+  g_return_if_fail (center != NULL);
+  g_return_if_fail (radius != NULL);
+
+  pts[0] = GRAPHENE_POINT_INIT (center->x + radius->width / 2,
+                                center->y);
+  pts[1] = GRAPHENE_POINT_INIT (center->x + radius->width / 2,
+                                center->y + radius->height / 2);
+  pts[2] = GRAPHENE_POINT_INIT (center->x,
+                                center->y + radius->height / 2);
+  pts[3] = GRAPHENE_POINT_INIT (center->x - radius->width / 2,
+                                center->y + radius->height / 2);
+  pts[4] = GRAPHENE_POINT_INIT (center->x - radius->width / 2,
+                                center->y);
+  pts[5] = GRAPHENE_POINT_INIT (center->x - radius->width / 2,
+                                center->y - radius->height / 2);
+  pts[6] = GRAPHENE_POINT_INIT (center->x,
+                                center->y - radius->height / 2);
+  pts[7] = GRAPHENE_POINT_INIT (center->x + radius->width / 2,
+                                center->y - radius->height / 2);
+
+  gsk_path_builder_move_to (self, pts[0].x, pts[0].y);
+  gsk_path_builder_conic_to (self, pts[1].x, pts[1].y, pts[2].x, pts[2].y, weight);
+  gsk_path_builder_conic_to (self, pts[3].x, pts[3].y, pts[4].x, pts[4].y, weight);
+  gsk_path_builder_conic_to (self, pts[5].x, pts[5].y, pts[6].x, pts[6].y, weight);
+  gsk_path_builder_conic_to (self, pts[7].x, pts[7].y, pts[0].x, pts[0].y, weight);
+  gsk_path_builder_close (self);
+}
+
 /**
  * gsk_path_builder_move_to:
  * @builder: a #GskPathBuilder
diff --git a/gsk/gskpathbuilder.h b/gsk/gskpathbuilder.h
index 750f8133b8..0a4024b60e 100644
--- a/gsk/gskpathbuilder.h
+++ b/gsk/gskpathbuilder.h
@@ -62,6 +62,10 @@ GDK_AVAILABLE_IN_ALL
 void                    gsk_path_builder_add_circle             (GskPathBuilder         *builder,
                                                                  const graphene_point_t *center,
                                                                  float                   radius);
+GDK_AVAILABLE_IN_ALL
+void                    gsk_path_builder_add_ellipse            (GskPathBuilder         *self,
+                                                                 const graphene_point_t *center,
+                                                                 const graphene_size_t  *radius);
 /* next function implemented in gskpathmeasure.c */
 GDK_AVAILABLE_IN_ALL
 void                    gsk_path_builder_add_segment            (GskPathBuilder         *builder,


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