[gtk/wip/otte/lottie: 27/51] WIP: pathbuilder: Add gsk_path_builder_add_rounded_rect()




commit 042d87ea7f6d270bc577c022f7ff57f83c7b205d
Author: Benjamin Otte <otte redhat com>
Date:   Wed Dec 2 08:36:47 2020 +0100

    WIP: pathbuilder: Add gsk_path_builder_add_rounded_rect()
    
    It works, but does not use a custom contour yet.

 docs/reference/gsk/gsk4-sections.txt |  1 +
 gsk/gskpathbuilder.c                 | 67 ++++++++++++++++++++++++++++++++++++
 gsk/gskpathbuilder.h                 |  4 +++
 3 files changed, 72 insertions(+)
---
diff --git a/docs/reference/gsk/gsk4-sections.txt b/docs/reference/gsk/gsk4-sections.txt
index 947bee04af..4a5d8c39c0 100644
--- a/docs/reference/gsk/gsk4-sections.txt
+++ b/docs/reference/gsk/gsk4-sections.txt
@@ -352,6 +352,7 @@ gsk_path_builder_free_to_path
 gsk_path_builder_get_current_point
 <SUBSECTION>
 gsk_path_builder_add_rect
+gsk_path_builder_add_rounded_rect
 gsk_path_builder_add_circle
 gsk_path_builder_add_path
 gtk_path_builder_add_segment
diff --git a/gsk/gskpathbuilder.c b/gsk/gskpathbuilder.c
index d7d53c8441..a28898159f 100644
--- a/gsk/gskpathbuilder.c
+++ b/gsk/gskpathbuilder.c
@@ -353,6 +353,73 @@ gsk_path_builder_add_rect (GskPathBuilder        *builder,
   gsk_contour_get_start_end (contour, NULL, &builder->current_point);
 }
 
+/**
+ * gsk_path_builder_add_rounded_rect:
+ * @self: a #GskPathBuilder
+ * @rect: the rounded rect
+ *
+ * Adds @rect as a new contour to the path built in @self.
+ **/
+void
+gsk_path_builder_add_rounded_rect (GskPathBuilder       *self,
+                                   const GskRoundedRect *rect)
+{
+  const float weight = sqrt(0.5f);
+
+  g_return_if_fail (self != NULL);
+  g_return_if_fail (rect != NULL);
+
+  gsk_path_builder_move_to (self,
+                            rect->bounds.origin.x + rect->corner[GSK_CORNER_TOP_LEFT].width,
+                            rect->bounds.origin.y);
+  /* top */
+  gsk_path_builder_line_to (self,
+                            rect->bounds.origin.x + rect->bounds.size.width - 
rect->corner[GSK_CORNER_TOP_RIGHT].width,
+                            rect->bounds.origin.y);
+  /* topright corner */
+  gsk_path_builder_conic_to (self,
+                             rect->bounds.origin.x + rect->bounds.size.width,
+                             rect->bounds.origin.y,
+                             rect->bounds.origin.x + rect->bounds.size.width,
+                             rect->bounds.origin.y + rect->corner[GSK_CORNER_TOP_RIGHT].height,
+                             weight);
+  /* right */
+  gsk_path_builder_line_to (self,
+                            rect->bounds.origin.x + rect->bounds.size.width,
+                            rect->bounds.origin.y + rect->bounds.size.height - 
rect->corner[GSK_CORNER_BOTTOM_RIGHT].height);
+  /* bottomright corner */
+  gsk_path_builder_conic_to (self,
+                             rect->bounds.origin.x + rect->bounds.size.width,
+                             rect->bounds.origin.y + rect->bounds.size.height,
+                             rect->bounds.origin.x + rect->bounds.size.width - 
rect->corner[GSK_CORNER_BOTTOM_RIGHT].width,
+                             rect->bounds.origin.y + rect->bounds.size.height,
+                             weight);
+  /* bottom */
+  gsk_path_builder_line_to (self,
+                            rect->bounds.origin.x + rect->corner[GSK_CORNER_BOTTOM_LEFT].width,
+                            rect->bounds.origin.y + rect->bounds.size.height);
+  /* bottomleft corner */
+  gsk_path_builder_conic_to (self,
+                             rect->bounds.origin.x,
+                             rect->bounds.origin.y + rect->bounds.size.height,
+                             rect->bounds.origin.x,
+                             rect->bounds.origin.y + rect->bounds.size.height - 
rect->corner[GSK_CORNER_BOTTOM_LEFT].height,
+                             weight);
+  /* left */
+  gsk_path_builder_line_to (self,
+                            rect->bounds.origin.x,
+                            rect->bounds.origin.y + rect->corner[GSK_CORNER_TOP_LEFT].height);
+  /* topleft corner */
+  gsk_path_builder_conic_to (self,
+                             rect->bounds.origin.x,
+                             rect->bounds.origin.y,
+                             rect->bounds.origin.x + rect->corner[GSK_CORNER_TOP_LEFT].width,
+                             rect->bounds.origin.y,
+                             weight);
+  /* done */
+  gsk_path_builder_close (self);
+}
+
 /**
  * gsk_path_builder_add_circle:
  * @builder: a #GskPathBuilder
diff --git a/gsk/gskpathbuilder.h b/gsk/gskpathbuilder.h
index fbcac022fa..750f8133b8 100644
--- a/gsk/gskpathbuilder.h
+++ b/gsk/gskpathbuilder.h
@@ -25,6 +25,7 @@
 #endif
 
 
+#include <gsk/gskroundedrect.h>
 #include <gsk/gsktypes.h>
 
 G_BEGIN_DECLS
@@ -55,6 +56,9 @@ GDK_AVAILABLE_IN_ALL
 void                    gsk_path_builder_add_rect               (GskPathBuilder         *builder,
                                                                  const graphene_rect_t  *rect);
 GDK_AVAILABLE_IN_ALL
+void                    gsk_path_builder_add_rounded_rect       (GskPathBuilder         *builder,
+                                                                 const GskRoundedRect   *rect);
+GDK_AVAILABLE_IN_ALL
 void                    gsk_path_builder_add_circle             (GskPathBuilder         *builder,
                                                                  const graphene_point_t *center,
                                                                  float                   radius);


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