diff options
author | Benjamin Otte <otte@redhat.com> | 2020-12-03 01:15:53 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2020-12-03 01:15:53 +0100 |
commit | 8706d69e60bd0dd63aa720cee2522626eb3e3806 (patch) | |
tree | 744f0b9c531f165b65ae90c40435c1e4cf748d54 /gtk/gtksnapshot.c | |
parent | 55a242bd816893e8b3c777b053a3c5fc0266b5d6 (diff) | |
download | gtk+-8706d69e60bd0dd63aa720cee2522626eb3e3806.tar.gz |
snapshot: Add gsk_snapshot_append_conic_gradient()
Diffstat (limited to 'gtk/gtksnapshot.c')
-rw-r--r-- | gtk/gtksnapshot.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 40122f6338..7c5c744842 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -2250,6 +2250,66 @@ gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot *snapshot, } /** + * gtk_snapshot_append_conic_gradient: + * @snapshot: a #GtkSnapshot + * @bounds: the rectangle to render the gradient into + * @center: the center point of the conic gradient + * @rotation: the clockwise rotation in degrees of the starting angle. 0 means the + * starting angle is the top. + * @stops: (array length=n_stops): a pointer to an array of #GskColorStop defining the gradient + * @n_stops: the number of elements in @stops + * + * Appends a conic gradient node with the given stops to @snapshot. + */ +void +gtk_snapshot_append_conic_gradient (GtkSnapshot *snapshot, + const graphene_rect_t *bounds, + const graphene_point_t *center, + float rotation, + const GskColorStop *stops, + gsize n_stops) +{ + GskRenderNode *node; + graphene_rect_t real_bounds; + float dx, dy; + const GdkRGBA *first_color; + gboolean need_gradient = FALSE; + int i; + + g_return_if_fail (snapshot != NULL); + g_return_if_fail (center != NULL); + g_return_if_fail (stops != NULL); + g_return_if_fail (n_stops > 1); + + gtk_snapshot_ensure_translate (snapshot, &dx, &dy); + graphene_rect_offset_r (bounds, dx, dy, &real_bounds); + + first_color = &stops[0].color; + for (i = 0; i < n_stops; i ++) + { + if (!gdk_rgba_equal (first_color, &stops[i].color)) + { + need_gradient = TRUE; + break; + } + } + + if (need_gradient) + node = gsk_conic_gradient_node_new (&real_bounds, + &GRAPHENE_POINT_INIT( + center->x + dx, + center->y + dy + ), + rotation, + stops, + n_stops); + else + node = gsk_color_node_new (first_color, &real_bounds); + + gtk_snapshot_append_node_internal (snapshot, node); +} + +/** * gtk_snapshot_append_radial_gradient: * @snapshot: a #GtkSnapshot * @bounds: the rectangle to render the readial gradient into |