[gtk+/wip/css: 94/154] gradient: Allow resolving with contexts



commit da70d908caa52d114c4f0cb58d173cb0d454d54a
Author: Benjamin Otte <otte redhat com>
Date:   Mon Jan 2 15:44:27 2012 +0100

    gradient: Allow resolving with contexts

 gtk/gtkgradient.c |   39 +++++++++++++++++++++++++++++++++++++++
 gtk/gtkgradient.h |    5 +++++
 2 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkgradient.c b/gtk/gtkgradient.c
index 3815860..b3ba261 100644
--- a/gtk/gtkgradient.c
+++ b/gtk/gtkgradient.c
@@ -19,6 +19,7 @@
 
 #include "config.h"
 #include "gtkgradient.h"
+#include "gtkstylecontextprivate.h"
 #include "gtkstyleproperties.h"
 #include "gtkintl.h"
 
@@ -281,6 +282,44 @@ gtk_gradient_resolve (GtkGradient         *gradient,
   return TRUE;
 }
 
+cairo_pattern_t *
+gtk_gradient_resolve_for_context (GtkGradient     *gradient,
+                                  GtkStyleContext *context)
+{
+  cairo_pattern_t *pattern;
+  guint i;
+
+  g_return_val_if_fail (gradient != NULL, FALSE);
+  g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
+
+  if (gradient->radius0 == 0 && gradient->radius1 == 0)
+    pattern = cairo_pattern_create_linear (gradient->x0, gradient->y0,
+                                           gradient->x1, gradient->y1);
+  else
+    pattern = cairo_pattern_create_radial (gradient->x0, gradient->y0,
+                                           gradient->radius0,
+                                           gradient->x1, gradient->y1,
+                                           gradient->radius1);
+
+  for (i = 0; i < gradient->stops->len; i++)
+    {
+      ColorStop *stop;
+      GdkRGBA rgba;
+
+      stop = &g_array_index (gradient->stops, ColorStop, i);
+
+      /* if color resolving fails, assume transparency */
+      if (!_gtk_style_context_resolve_color (context, stop->color, &rgba))
+        rgba.red = rgba.green = rgba.blue = rgba.alpha = 0.0;
+
+      cairo_pattern_add_color_stop_rgba (pattern, stop->offset,
+                                         rgba.red, rgba.green,
+                                         rgba.blue, rgba.alpha);
+    }
+
+  return pattern;
+}
+
 static void
 append_number (GString    *str,
                double      d,
diff --git a/gtk/gtkgradient.h b/gtk/gtkgradient.h
index 7d54030..cb706bd 100644
--- a/gtk/gtkgradient.h
+++ b/gtk/gtkgradient.h
@@ -25,6 +25,7 @@
 #define __GTK_GRADIENT_H__
 
 #include <gdk/gdk.h>
+#include <gtk/gtkstylecontext.h>
 #include <gtk/gtkstyleproperties.h>
 #include <gtk/gtksymboliccolor.h>
 
@@ -55,6 +56,10 @@ void          gtk_gradient_unref          (GtkGradient         *gradient);
 gboolean      gtk_gradient_resolve        (GtkGradient         *gradient,
                                            GtkStyleProperties  *props,
                                            cairo_pattern_t    **resolved_gradient);
+cairo_pattern_t *
+              gtk_gradient_resolve_for_context
+                                          (GtkGradient         *gradient,
+                                           GtkStyleContext     *context);
 
 char *        gtk_gradient_to_string      (GtkGradient         *gradient);
 



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