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.
This commit is contained in:
Matthias Clasen 2024-08-02 09:33:34 -04:00
parent ea28dc8cff
commit abefa0ab00
2 changed files with 90 additions and 13 deletions

View File

@ -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);
}

View File

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