[gtk+] GtkStyleSet: Handle GtkGradients as a replacement for cairo_pattern_t



commit cf87923d1bc3ef1e5fad75b969b91c64f6f56840
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Sep 2 02:11:12 2010 +0200

    GtkStyleSet: Handle GtkGradients as a replacement for cairo_pattern_t
    
    The former will handle GtkSymbolicColors, which will be resolved and
    cached at query time.

 gtk/gtkstyleset.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkstyleset.c b/gtk/gtkstyleset.c
index 755d66e..a7851ad 100644
--- a/gtk/gtkstyleset.c
+++ b/gtk/gtkstyleset.c
@@ -497,6 +497,12 @@ gtk_style_set_set_property (GtkStyleSet   *set,
       /* Allow GtkSymbolicColor as well */
       g_return_if_fail (value_type == GDK_TYPE_COLOR || value_type == GTK_TYPE_SYMBOLIC_COLOR);
     }
+  else if (node->property_type == GDK_TYPE_CAIRO_PATTERN)
+    {
+      /* Allow GtkGradient as a substitute */
+      g_return_if_fail (value_type == GDK_TYPE_CAIRO_PATTERN ||
+                        value_type == GTK_TYPE_GRADIENT);
+    }
   else
     g_return_if_fail (node->property_type == value_type);
 
@@ -618,6 +624,23 @@ resolve_color (GtkStyleSet *set,
   return TRUE;
 }
 
+static gboolean
+resolve_gradient (GtkStyleSet *set,
+                  GValue      *value)
+{
+  cairo_pattern_t *gradient;
+
+  if (!gtk_gradient_resolve (g_value_get_boxed (value), set, &gradient))
+    return FALSE;
+
+  /* Store it back, this is where cairo_pattern_t caching happens */
+  g_value_unset (value);
+  g_value_init (value, GDK_TYPE_CAIRO_PATTERN);
+  g_value_take_boxed (value, gradient);
+
+  return TRUE;
+}
+
 gboolean
 gtk_style_set_get_property (GtkStyleSet   *set,
                             const gchar   *property,
@@ -664,6 +687,13 @@ gtk_style_set_get_property (GtkStyleSet   *set,
       if (!resolve_color (set, val))
         return FALSE;
     }
+  else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
+    {
+      g_return_val_if_fail (node->property_type == GDK_TYPE_CAIRO_PATTERN, FALSE);
+
+      if (!resolve_gradient (set, val))
+        return FALSE;
+    }
 
   g_value_copy (val, value);
 
@@ -714,6 +744,13 @@ gtk_style_set_get_valist (GtkStyleSet   *set,
           if (!resolve_color (set, val))
             val = &node->default_value;
         }
+      else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
+        {
+          g_return_val_if_fail (node->property_type == GDK_TYPE_CAIRO_PATTERN, FALSE);
+
+          if (!resolve_gradient (set, val))
+            val = &node->default_value;
+        }
 
       G_VALUE_LCOPY (val, args, 0, &error);
 



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