[gtk/wip/baedert/for-master: 15/15] cssshadowvalue: Simplify inset shadow nodes to color nodes if possible
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/for-master: 15/15] cssshadowvalue: Simplify inset shadow nodes to color nodes if possible
- Date: Fri, 29 Nov 2019 12:40:45 +0000 (UTC)
commit 3f6b6ee3fa6cb3cc1ed62bd33d808fdb2cc0d4eb
Author: Timm Bäder <mail baedert org>
Date: Fri Nov 29 13:34:22 2019 +0100
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.
gtk/gtkcssshadowvalue.c | 79 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 69 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index d2febe7522..1ae1b3d9cc 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -386,23 +386,82 @@ 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;
+
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);
+
+ /* 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 (dy > 0)
+ {
+ gtk_snapshot_append_color (snapshot,
+ _gtk_css_rgba_value_get_rgba (shadow->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,
+ _gtk_css_rgba_value_get_rgba (shadow->color),
+ &GRAPHENE_RECT_INIT (
+ padding_bounds->origin.x,
+ padding_bounds->origin.y + padding_bounds->size.height + dy,
+ padding_bounds->size.width,
+ - dy
+ ));
+ }
+
+ if (dx > 0)
+ {
+ gtk_snapshot_append_color (snapshot,
+ _gtk_css_rgba_value_get_rgba (shadow->color),
+ &GRAPHENE_RECT_INIT (
+ padding_bounds->origin.x,
+ padding_bounds->origin.y,
+ dx,
+ padding_bounds->size.height
+ ));
+ }
+ else if (dx < 0)
+ {
+ gtk_snapshot_append_color (snapshot,
+ _gtk_css_rgba_value_get_rgba (shadow->color),
+ &GRAPHENE_RECT_INIT (
+ padding_bounds->origin.x + padding_bounds->size.width + dx,
+ padding_bounds->origin.y,
+ - dx,
+ padding_bounds->size.height
+ ));
+ }
+ }
+ else
+ {
+ gtk_snapshot_append_inset_shadow (snapshot,
+ padding_box,
+ _gtk_css_rgba_value_get_rgba (shadow->color),
+ dx, dy, spread, radius);
+ }
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]