[gtk/matthiasc/for-master: 3/7] cssshadowvalue: Add a 'filter mode'




commit 069516ddb71560a1d8ce486a8de580e55d9957df
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Feb 6 09:44:16 2021 -0500

    cssshadowvalue: Add a 'filter mode'
    
    Shadow values created by gtk_css_shadow_value_new_filter or
    gtk_css_shadow_value_parse_filter interpret their radius value
    as standard deviation. Add a flag for this mode, and use it
    where necessary.

 gtk/gtkcssshadowvalue.c | 53 +++++++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index e75f4a95a4..ee4ede137d 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -44,12 +44,14 @@ typedef struct {
 
 struct _GtkCssValue {
   GTK_CSS_VALUE_BASE
+  guint use_std_dev : 1; /* values stored in radius are std_dev, for drop-shadow */
   guint n_shadows;
   ShadowValue shadows[1];
 };
 
 static GtkCssValue *    gtk_css_shadow_value_new     (ShadowValue *shadows,
-                                                      guint        n_shadows);
+                                                      guint        n_shadows,
+                                                      gboolean     use_std_dev);
 
 static void
 shadow_value_for_transition (ShadowValue *result,
@@ -133,7 +135,7 @@ gtk_css_value_shadow_compute (GtkCssValue      *value,
       shadows[i].inset = shadow->inset;
     }
 
-  return gtk_css_shadow_value_new (shadows, value->n_shadows);
+  return gtk_css_shadow_value_new (shadows, value->n_shadows, value->use_std_dev);
 }
 
 static gboolean
@@ -227,7 +229,7 @@ gtk_css_value_shadow_transition (GtkCssValue *start,
         }
     }
 
-  return gtk_css_shadow_value_new (shadows, len);
+  return gtk_css_shadow_value_new (shadows, len, start->use_std_dev);
 }
 
 static void
@@ -284,7 +286,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
   gtk_css_value_shadow_print
 };
 
-static GtkCssValue shadow_none_singleton = { &GTK_CSS_VALUE_SHADOW, 1, TRUE, 0 };
+static GtkCssValue shadow_none_singleton = { &GTK_CSS_VALUE_SHADOW, 1, TRUE, FALSE, 0 };
 
 GtkCssValue *
 gtk_css_shadow_value_new_none (void)
@@ -294,7 +296,8 @@ gtk_css_shadow_value_new_none (void)
 
 static GtkCssValue *
 gtk_css_shadow_value_new (ShadowValue *shadows,
-                          guint        n_shadows)
+                          guint        n_shadows,
+                          gboolean     use_std_dev)
 {
   GtkCssValue *retval;
   guint i;
@@ -304,11 +307,11 @@ gtk_css_shadow_value_new (ShadowValue *shadows,
 
   retval = _gtk_css_value_alloc (&GTK_CSS_VALUE_SHADOW, sizeof (GtkCssValue) + sizeof (ShadowValue) * 
(n_shadows - 1));
   retval->n_shadows = n_shadows;
+  retval->use_std_dev = use_std_dev;
 
   memcpy (retval->shadows, shadows, sizeof (ShadowValue) * n_shadows);
 
   retval->is_computed = TRUE;
-
   for (i = 0; i < n_shadows; i++)
     {
       const ShadowValue *shadow = &retval->shadows[i];
@@ -339,7 +342,7 @@ gtk_css_shadow_value_new_filter (void)
   value.spread = _gtk_css_number_value_new (0, GTK_CSS_NUMBER);
   value.color = _gtk_css_color_value_new_current_color ();
 
-  return gtk_css_shadow_value_new (&value, 1);
+  return gtk_css_shadow_value_new (&value, 1, TRUE);
 }
 
 enum {
@@ -501,7 +504,7 @@ _gtk_css_shadow_value_parse (GtkCssParser *parser,
       }
   } while (gtk_css_parser_try_token (parser, GTK_CSS_TOKEN_COMMA));
 
-  return gtk_css_shadow_value_new (shadows, n_shadows);
+  return gtk_css_shadow_value_new (shadows, n_shadows, FALSE);
 
 fail:
   for (i = 0; i < n_shadows; i++)
@@ -519,7 +522,7 @@ _gtk_css_shadow_value_parse_filter (GtkCssParser *parser)
   ShadowValue shadow;
 
   if (_gtk_css_shadow_value_parse_one (parser, FALSE, &shadow))
-    return gtk_css_shadow_value_new (&shadow, 1);
+    return gtk_css_shadow_value_new (&shadow, 1, TRUE);
   else
     return NULL;
 }
@@ -539,6 +542,8 @@ gtk_css_shadow_value_get_extents (const GtkCssValue *value,
 
       spread = _gtk_css_number_value_get (shadow->spread, 0);
       radius = _gtk_css_number_value_get (shadow->radius, 0);
+      if (value->use_std_dev)
+        radius = radius * 2;
       clip_radius = gsk_cairo_blur_compute_pixels (radius);
       hoffset = _gtk_css_number_value_get (shadow->hoffset, 0);
       voffset = _gtk_css_number_value_get (shadow->voffset, 0);
@@ -556,6 +561,8 @@ gtk_css_shadow_value_snapshot_outset (const GtkCssValue    *value,
                                       const GskRoundedRect *border_box)
 {
   guint i;
+  double dx, dy, spread, radius;
+  const GdkRGBA *color;
 
   g_return_if_fail (value->class == &GTK_CSS_VALUE_SHADOW);
 
@@ -566,17 +573,20 @@ gtk_css_shadow_value_snapshot_outset (const GtkCssValue    *value,
       if (shadow->inset)
         continue;
 
+      color = gtk_css_color_value_get_rgba (shadow->color);
+
       /* We don't need to draw invisible shadows */
-      if (gdk_rgba_is_clear (gtk_css_color_value_get_rgba (shadow->color)))
+      if (gdk_rgba_is_clear (color))
         continue;
 
-      gtk_snapshot_append_outset_shadow (snapshot,
-                                         border_box,
-                                         gtk_css_color_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);
+      if (value->use_std_dev)
+        radius = 2 * radius;
+
+      gtk_snapshot_append_outset_shadow (snapshot, border_box, color, dx, dy, spread, radius);
     }
 }
 
@@ -598,15 +608,18 @@ gtk_css_shadow_value_snapshot_inset (const GtkCssValue    *value,
       if (!shadow->inset)
         continue;
 
+      color = gtk_css_color_value_get_rgba (shadow->color);
+
       /* We don't need to draw invisible shadows */
-      if (gdk_rgba_is_clear (gtk_css_color_value_get_rgba (shadow->color)))
+      if (gdk_rgba_is_clear (color))
         continue;
 
       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_color_value_get_rgba (shadow->color);
+      if (value->use_std_dev)
+        radius = 2 * radius;
 
       /* These are trivial to do with a color node */
       if (spread == 0 && radius == 0 &&
@@ -725,6 +738,8 @@ gtk_css_shadow_value_push_snapshot (const GtkCssValue *value,
           shadows[i].dy = _gtk_css_number_value_get (shadow->voffset, 0);
           shadows[i].color = *gtk_css_color_value_get_rgba (shadow->color);
           shadows[i].radius = _gtk_css_number_value_get (shadow->radius, 0);
+          if (value->use_std_dev)
+            shadows[i].radius *= 2;
         }
 
       gtk_snapshot_push_shadow (snapshot, shadows, value->n_shadows);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]