From 8706d69e60bd0dd63aa720cee2522626eb3e3806 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 3 Dec 2020 01:15:53 +0100 Subject: [PATCH] snapshot: Add gsk_snapshot_append_conic_gradient() --- docs/reference/gtk/gtk4-sections.txt | 1 + gtk/gtksnapshot.c | 60 ++++++++++++++++++++++++++++ gtk/gtksnapshot.h | 7 ++++ 3 files changed, 68 insertions(+) diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index c6e8f87a58..a13864c7d1 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -4329,6 +4329,7 @@ gtk_snapshot_append_color gtk_snapshot_append_layout gtk_snapshot_append_linear_gradient gtk_snapshot_append_repeating_linear_gradient +gtk_snapshot_append_conic_gradient gtk_snapshot_append_border gtk_snapshot_append_inset_shadow gtk_snapshot_append_outset_shadow diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 40122f6338..7c5c744842 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -2249,6 +2249,66 @@ gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot *snapshot, gtk_snapshot_append_node_internal (snapshot, node); } +/** + * 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 diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h index 19e0045b17..6125e44ecc 100644 --- a/gtk/gtksnapshot.h +++ b/gtk/gtksnapshot.h @@ -191,6 +191,13 @@ void gtk_snapshot_append_repeating_radial_gradient (GtkSnapshot const GskColorStop *stops, gsize n_stops); GDK_AVAILABLE_IN_ALL +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); +GDK_AVAILABLE_IN_ALL void gtk_snapshot_append_border (GtkSnapshot *snapshot, const GskRoundedRect *outline, const float border_width[4],