[gtk+/wip/css: 95/97] gradient: Allow resolving with contexts
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 95/97] gradient: Allow resolving with contexts
- Date: Mon, 2 Jan 2012 15:01:27 +0000 (UTC)
commit 3098f5a58aaa71e2330fe250ba2c9571eb09eb71
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]