[gtk/wip/baedert/for-master: 1/2] 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: 1/2] cssshadowvalue: Simplify inset shadow nodes to color nodes if possible
- Date: Fri, 29 Nov 2019 18:23:43 +0000 (UTC)
commit e8c7e182633a29ecdb0eb963dbd0888a47ed5be9
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 | 83 +++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 73 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index d2febe7522..13b4844407 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -386,23 +386,86 @@ 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;
+ const float h = 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 + h
+ ));
+ }
+ else if (dx < 0)
+ {
+ const float y = dy > 0 ? dy : 0;
+ const float h = 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 + h
+ ));
+ }
+
+ 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]