cssshadowvalue: Simplify inset shadow nodes to color nodes if possible
inset shadows like this are frequently used to implement highlights in CSS without crowing them min size of the element.
This commit is contained in:
@@ -386,23 +386,84 @@ gtk_css_shadow_value_snapshot_outset (const GtkCssValue *shadow,
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_shadow_value_snapshot_inset (const GtkCssValue *shadow,
|
||||
GtkSnapshot *snapshot,
|
||||
const GskRoundedRect*padding_box)
|
||||
gtk_css_shadow_value_snapshot_inset (const GtkCssValue *shadow,
|
||||
GtkSnapshot *snapshot,
|
||||
const GskRoundedRect *padding_box)
|
||||
{
|
||||
double dx, dy, spread, radius;
|
||||
const GdkRGBA *color;
|
||||
|
||||
g_return_if_fail (shadow->class == >K_CSS_VALUE_SHADOW);
|
||||
|
||||
/* We don't need to draw invisible shadows */
|
||||
if (gdk_rgba_is_clear (_gtk_css_rgba_value_get_rgba (shadow->color)))
|
||||
return;
|
||||
|
||||
gtk_snapshot_append_inset_shadow (snapshot,
|
||||
padding_box,
|
||||
_gtk_css_rgba_value_get_rgba (shadow->color),
|
||||
_gtk_css_number_value_get (shadow->hoffset, 0),
|
||||
_gtk_css_number_value_get (shadow->voffset, 0),
|
||||
_gtk_css_number_value_get (shadow->spread, 0),
|
||||
_gtk_css_number_value_get (shadow->radius, 0));
|
||||
dx = _gtk_css_number_value_get (shadow->hoffset, 0);
|
||||
dy = _gtk_css_number_value_get (shadow->voffset, 0);
|
||||
spread = _gtk_css_number_value_get (shadow->spread, 0);
|
||||
radius = _gtk_css_number_value_get (shadow->radius, 0);
|
||||
color = _gtk_css_rgba_value_get_rgba (shadow->color);
|
||||
|
||||
/* These are trivial to do with a color node */
|
||||
if (spread == 0 && radius == 0 &&
|
||||
gsk_rounded_rect_is_rectilinear (padding_box))
|
||||
{
|
||||
const graphene_rect_t *padding_bounds = &padding_box->bounds;
|
||||
|
||||
if (dx > 0)
|
||||
{
|
||||
const float y = dy > 0 ? dy : 0;
|
||||
|
||||
gtk_snapshot_append_color (snapshot, color,
|
||||
&GRAPHENE_RECT_INIT (
|
||||
padding_bounds->origin.x,
|
||||
padding_bounds->origin.y + y,
|
||||
dx,
|
||||
padding_bounds->size.height - ABS (dy)
|
||||
));
|
||||
}
|
||||
else if (dx < 0)
|
||||
{
|
||||
const float y = dy > 0 ? dy : 0;
|
||||
|
||||
gtk_snapshot_append_color (snapshot, color,
|
||||
&GRAPHENE_RECT_INIT (
|
||||
padding_bounds->origin.x + padding_bounds->size.width + dx,
|
||||
padding_bounds->origin.y + y,
|
||||
- dx,
|
||||
padding_bounds->size.height - ABS (dy)
|
||||
));
|
||||
}
|
||||
|
||||
if (dy > 0)
|
||||
{
|
||||
gtk_snapshot_append_color (snapshot, color,
|
||||
&GRAPHENE_RECT_INIT (
|
||||
padding_bounds->origin.x,
|
||||
padding_bounds->origin.y,
|
||||
padding_bounds->size.width,
|
||||
dy
|
||||
));
|
||||
}
|
||||
else if (dy < 0)
|
||||
{
|
||||
gtk_snapshot_append_color (snapshot, color,
|
||||
&GRAPHENE_RECT_INIT (
|
||||
padding_bounds->origin.x,
|
||||
padding_bounds->origin.y + padding_bounds->size.height + dy,
|
||||
padding_bounds->size.width,
|
||||
- dy
|
||||
));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_snapshot_append_inset_shadow (snapshot,
|
||||
padding_box,
|
||||
color,
|
||||
dx, dy, spread, radius);
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
||||
Reference in New Issue
Block a user