[gtk+/wip/css: 113/154] styleproperty: Convert background-image from pattern to GtkCssImage
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 113/154] styleproperty: Convert background-image from pattern to GtkCssImage
- Date: Sat, 7 Jan 2012 14:57:25 +0000 (UTC)
commit 17e93caaaaaecc2c9a0a9658c765ff2ad10b2039
Author: Benjamin Otte <otte redhat com>
Date: Mon Jan 2 22:22:25 2012 +0100
styleproperty: Convert background-image from pattern to GtkCssImage
gtk/gtkcssstyleproperty.c | 34 +++++++++++++++++++++-
gtk/gtkcssstylepropertyimpl.c | 64 +++++++++++++++++++++++++++++++++++++---
2 files changed, 92 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index 4791857..da1a6b7 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -28,6 +28,9 @@
#include "gtkprivatetypebuiltins.h"
#include "gtkstylepropertiesprivate.h"
+#include "gtkcssimagegradientprivate.h"
+#include "gtkcssimageprivate.h"
+
enum {
PROP_0,
PROP_ID,
@@ -131,7 +134,36 @@ _gtk_css_style_property_query (GtkStyleProperty *property,
val = _gtk_style_properties_peek_property (props, GTK_CSS_STYLE_PROPERTY (property), state);
if (val)
- g_value_copy (val, value);
+ {
+ /* Somebody make this a vfunc */
+ if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_IMAGE)
+ {
+ GtkCssImage *image = g_value_get_object (val);
+ cairo_pattern_t *pattern;
+ cairo_surface_t *surface;
+ cairo_matrix_t matrix;
+
+ if (image == NULL)
+ g_value_set_boxed (value, NULL);
+ else if (GTK_IS_CSS_IMAGE_GRADIENT (image))
+ g_value_set_boxed (value, GTK_CSS_IMAGE_GRADIENT (image)->pattern);
+ else
+ {
+ double width, height;
+
+ /* the 100, 100 is rather random */
+ _gtk_css_image_get_concrete_size (image, 0, 0, 100, 100, &width, &height);
+ surface = _gtk_css_image_get_surface (image, NULL, width, height);
+ pattern = cairo_pattern_create_for_surface (surface);
+ cairo_matrix_init_scale (&matrix, width, height);
+ cairo_pattern_set_matrix (pattern, &matrix);
+ cairo_surface_destroy (surface);
+ g_value_take_boxed (value, pattern);
+ }
+ }
+ else
+ g_value_copy (val, value);
+ }
else
_gtk_style_property_default_value (property, props, state, value);
}
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 57e01a4..b3f4965 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -36,6 +36,7 @@
/* the actual parsers we have */
#include "gtkanimationdescription.h"
#include "gtkbindings.h"
+#include "gtkcssimageprivate.h"
#include "gtkgradient.h"
#include "gtkshadowprivate.h"
#include "gtkthemingengine.h"
@@ -339,6 +340,57 @@ border_corner_radius_value_print (GtkCssStyleProperty *property,
}
}
+static gboolean
+css_image_value_parse (GtkCssStyleProperty *property,
+ GValue *value,
+ GtkCssParser *parser,
+ GFile *base)
+{
+ GtkCssImage *image;
+
+ if (_gtk_css_parser_try (parser, "none", TRUE))
+ image = NULL;
+ else
+ {
+ image = _gtk_css_image_new_parse (parser, base);
+ if (image == NULL)
+ return FALSE;
+ }
+
+ g_value_unset (value);
+ g_value_init (value, GTK_TYPE_CSS_IMAGE);
+ g_value_take_object (value, image);
+ return TRUE;
+}
+
+static void
+css_image_value_print (GtkCssStyleProperty *property,
+ const GValue *value,
+ GString *string)
+{
+ GtkCssImage *image = g_value_get_object (value);
+
+ if (image)
+ _gtk_css_image_print (image, string);
+ else
+ g_string_append (string, "none");
+}
+
+static void
+css_image_value_compute (GtkCssStyleProperty *property,
+ GValue *computed,
+ GtkStyleContext *context,
+ const GValue *specified)
+{
+ GtkCssImage *image = g_value_get_object (specified);
+
+ if (image)
+ image = _gtk_css_image_compute (image, context);
+
+ g_value_init (computed, GTK_TYPE_CSS_IMAGE);
+ g_value_take_object (computed, image);
+}
+
/*** REGISTRATION ***/
#define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
@@ -608,13 +660,15 @@ _gtk_css_style_property_init_properties (void)
&value);
g_value_unset (&value);
- gtk_style_property_register ("background-image",
+ g_value_init (&value, GTK_TYPE_CSS_IMAGE);
+ _gtk_style_property_register ("background-image",
CAIRO_GOBJECT_TYPE_PATTERN,
0,
- NULL,
- NULL,
- NULL,
- NULL);
+ css_image_value_parse,
+ css_image_value_print,
+ css_image_value_compute,
+ &value);
+ g_value_unset (&value);
gtk_style_property_register ("background-repeat",
GTK_TYPE_CSS_BACKGROUND_REPEAT,
0,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]