From abefa0ab0051362f5a4492d6470e0b127ea5ab28 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 2 Aug 2024 09:33:34 -0400 Subject: [PATCH] gtk: Add gtk_snapshot_append_{in,out}set_shadow2 These are private snapshot functions that use the new constructors to create a box shadow nodes with a given color state. --- gtk/gtksnapshot.c | 87 ++++++++++++++++++++++++++++++++++------ gtk/gtksnapshotprivate.h | 16 ++++++++ 2 files changed, 90 insertions(+), 13 deletions(-) diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 34c8f1eb8d..0dcd181779 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -2880,6 +2880,37 @@ gtk_snapshot_append_inset_shadow (GtkSnapshot *snapshot, float dy, float spread, float blur_radius) +{ + GdkColor color2; + + gdk_color_init_from_rgba (&color2, color); + gtk_snapshot_append_inset_shadow2 (snapshot, + outline, + &color2, + dx, dy, spread, blur_radius); + gdk_color_finish (&color2); +} + +/*< private > + * gtk_snapshot_append_inset_shadow2: + * @snapshot: a `GtkSnapshot` + * @outline: outline of the region surrounded by shadow + * @color: color of the shadow + * @dx: horizontal offset of shadow + * @dy: vertical offset of shadow + * @spread: how far the shadow spreads towards the inside + * @blur_radius: how much blur to apply to the shadow + * + * Appends an inset shadow into the box given by @outline. + */ +void +gtk_snapshot_append_inset_shadow2 (GtkSnapshot *snapshot, + const GskRoundedRect *outline, + const GdkColor *color, + float dx, + float dy, + float spread, + float blur_radius) { GskRenderNode *node; GskRoundedRect real_outline; @@ -2892,12 +2923,12 @@ gtk_snapshot_append_inset_shadow (GtkSnapshot *snapshot, gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &x, &y); gsk_rounded_rect_scale_affine (&real_outline, outline, scale_x, scale_y, x, y); - node = gsk_inset_shadow_node_new (&real_outline, - color, - scale_x * dx, - scale_y * dy, - spread, - blur_radius); + node = gsk_inset_shadow_node_new2 (&real_outline, + color, + scale_x * dx, + scale_y * dy, + spread, + blur_radius); gtk_snapshot_append_node_internal (snapshot, node); } @@ -2922,6 +2953,37 @@ gtk_snapshot_append_outset_shadow (GtkSnapshot *snapshot, float dy, float spread, float blur_radius) +{ + GdkColor color2; + + gdk_color_init_from_rgba (&color2, color); + gtk_snapshot_append_outset_shadow2 (snapshot, + outline, + &color2, + dx, dy, spread, blur_radius); + gdk_color_finish (&color2); +} + +/*< private > + * gtk_snapshot_append_outset_shadow2: + * @snapshot: a `GtkSnapshot` + * @outline: outline of the region surrounded by shadow + * @color: color of the shadow + * @dx: horizontal offset of shadow + * @dy: vertical offset of shadow + * @spread: how far the shadow spreads towards the outside + * @blur_radius: how much blur to apply to the shadow + * + * Appends an outset shadow node around the box given by @outline. + */ +void +gtk_snapshot_append_outset_shadow2 (GtkSnapshot *snapshot, + const GskRoundedRect *outline, + const GdkColor *color, + float dx, + float dy, + float spread, + float blur_radius) { GskRenderNode *node; GskRoundedRect real_outline; @@ -2934,13 +2996,12 @@ gtk_snapshot_append_outset_shadow (GtkSnapshot *snapshot, gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &x, &y); gsk_rounded_rect_scale_affine (&real_outline, outline, scale_x, scale_y, x, y); - node = gsk_outset_shadow_node_new (&real_outline, - color, - scale_x * dx, - scale_y * dy, - spread, - blur_radius); - + node = gsk_outset_shadow_node_new2 (&real_outline, + color, + scale_x * dx, + scale_y * dy, + spread, + blur_radius); gtk_snapshot_append_node_internal (snapshot, node); } diff --git a/gtk/gtksnapshotprivate.h b/gtk/gtksnapshotprivate.h index 177b0065b1..0e96f61714 100644 --- a/gtk/gtksnapshotprivate.h +++ b/gtk/gtksnapshotprivate.h @@ -45,5 +45,21 @@ void gtk_snapshot_append_border2 (GtkSnapshot const float border_width[4], const GdkColor border_color[4]); +void gtk_snapshot_append_inset_shadow2 (GtkSnapshot *snapshot, + const GskRoundedRect *outline, + const GdkColor *color, + float dx, + float dy, + float spread, + float blur_radius); + +void gtk_snapshot_append_outset_shadow2 (GtkSnapshot *snapshot, + const GskRoundedRect *outline, + const GdkColor *color, + float dx, + float dy, + float spread, + float blur_radius); + G_END_DECLS