path: Add gsk_path_builder_add_ellipse()

This commit is contained in:
Benjamin Otte
2020-12-25 21:31:06 +01:00
parent 5c77b02bac
commit 98bad2ea08
3 changed files with 51 additions and 0 deletions

View File

@@ -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>

View File

@@ -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

View File

@@ -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,