Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Clasen
21245a8729 Make gsk_path_builder_add_contour public
This allows to split a path into contours
without losing their closedness.
2023-08-21 21:19:13 -04:00
Matthias Clasen
45cacd25ce Make gsk_path_get_n_contours public
It is useful to know how many contours
a path consists of, for the API added
in the next commit.
2023-08-21 21:18:40 -04:00
5 changed files with 60 additions and 21 deletions

View File

@@ -302,7 +302,7 @@ gsk_path_to_cairo (GskPath *self,
cr);
}
/*< private >
/**
* gsk_path_get_n_contours:
* @path: a `GskPath`
*
@@ -311,8 +311,10 @@ gsk_path_to_cairo (GskPath *self,
* Returns: the number of contours in @path
*/
gsize
gsk_path_get_n_contours (const GskPath *self)
gsk_path_get_n_contours (GskPath *self)
{
g_return_val_if_fail (self != NULL, 0);
return self->n_contours;
}

View File

@@ -92,6 +92,9 @@ GDK_AVAILABLE_IN_4_14
void gsk_path_to_cairo (GskPath *self,
cairo_t *cr);
GDK_AVAILABLE_IN_4_14
gsize gsk_path_get_n_contours (GskPath *self);
GDK_AVAILABLE_IN_4_14
gboolean gsk_path_is_empty (GskPath *self);

View File

@@ -180,6 +180,9 @@ gsk_path_builder_append_current (GskPathBuilder *self,
self->current_point = points[n_points - 1];
}
static void add_contour (GskPathBuilder *self,
GskContour *contour);
static void
gsk_path_builder_end_current (GskPathBuilder *self)
{
@@ -199,7 +202,16 @@ gsk_path_builder_end_current (GskPathBuilder *self)
g_array_set_size (self->points, 0);
/* do this at the end to avoid inflooping when add_contour calls back here */
gsk_path_builder_add_contour (self, contour);
add_contour (self, contour);
}
static void
add_contour (GskPathBuilder *self,
GskContour *contour)
{
gsk_path_builder_end_current (self);
self->contours = g_slist_prepend (self->contours, contour);
}
static void
@@ -298,15 +310,6 @@ gsk_path_builder_to_path (GskPathBuilder *self)
return path;
}
void
gsk_path_builder_add_contour (GskPathBuilder *self,
GskContour *contour)
{
gsk_path_builder_end_current (self);
self->contours = g_slist_prepend (self->contours, contour);
}
/**
* gsk_path_builder_get_current_point:
* @self: a `GskPathBuilder`
@@ -350,7 +353,7 @@ gsk_path_builder_add_path (GskPathBuilder *self,
{
const GskContour *contour = gsk_path_get_contour (path, i);
gsk_path_builder_add_contour (self, gsk_contour_dup (contour));
add_contour (self, gsk_contour_dup (contour));
}
}
@@ -374,7 +377,7 @@ gsk_path_builder_add_reverse_path (GskPathBuilder *self,
{
const GskContour *contour = gsk_path_get_contour (path, i - 1);
gsk_path_builder_add_contour (self, gsk_contour_reverse (contour));
add_contour (self, gsk_contour_reverse (contour));
}
}
@@ -1115,7 +1118,8 @@ gsk_path_builder_add_layout (GskPathBuilder *self,
* will be connected.
*
* Note that this method always adds a path with the given start point
* and end point. To add a closed path, use [method@Gsk.PathBuilder.add_path].
* and end point. To add a closed path, use [method@Gsk.PathBuilder.add_path]
* of [method@Gsk.PathBuilder.add_contour].
*
* Since: 4.14
*/
@@ -1170,7 +1174,11 @@ gsk_path_builder_add_segment (GskPathBuilder *self,
&(GskRealPathPoint) { s->contour, n_ops - 1, 1. });
for (gsize i = (s->contour + 1) % n_contours; i != e->contour; i = (i + 1) % n_contours)
gsk_path_builder_add_contour (self, gsk_contour_dup (gsk_path_get_contour (path, i)));
{
const GskContour *contour = gsk_path_get_contour (path, i);
add_contour (self, gsk_contour_dup (contour));
}
contour = gsk_path_get_contour (path, e->contour);
n_ops = gsk_contour_get_n_ops (contour);
@@ -1184,3 +1192,28 @@ out:
gsk_path_builder_end_current (self);
self->current_point = current;
}
/**
* gsk_path_builder_add_contour:
* @self: a `GskPathBuilder`
* @path: the `GskPath` to take the contour from
* @contour: the index of the contour to take
*
* Adds one of the connected contours of @path to @self.
*
* Use [method@Gsk.Path.get_n_contours] to find out how
* many contours a path has.
*
* Since: 4.14
*/
void
gsk_path_builder_add_contour (GskPathBuilder *self,
GskPath *path,
gsize contour)
{
g_return_if_fail (self != NULL);
g_return_if_fail (path != NULL);
g_return_if_fail (contour < gsk_path_get_n_contours (path));
add_contour (self, gsk_contour_dup (gsk_path_get_contour (path, contour)));
}

View File

@@ -76,6 +76,12 @@ void gsk_path_builder_add_segment (GskPathBuilder
GskPath *path,
const GskPathPoint *start,
const GskPathPoint *end);
GDK_AVAILABLE_IN_4_14
void gsk_path_builder_add_contour (GskPathBuilder *self,
GskPath *path,
gsize contour);
GDK_AVAILABLE_IN_4_14
void gsk_path_builder_move_to (GskPathBuilder *self,
float x,

View File

@@ -40,7 +40,6 @@ typedef struct _GskRealPathPoint GskRealPathPoint;
GskPath * gsk_path_new_from_contours (const GSList *contours);
gsize gsk_path_get_n_contours (const GskPath *self);
const GskContour * gsk_path_get_contour (const GskPath *self,
gsize i);
@@ -52,10 +51,6 @@ gboolean gsk_path_foreach_with_tolerance (GskPath
GskPathForeachFunc func,
gpointer user_data);
void gsk_path_builder_add_contour (GskPathBuilder *builder,
GskContour *contour);
void gsk_path_builder_svg_arc_to (GskPathBuilder *builder,
float rx,
float ry,