Commit 0bc170cd authored by Benjamin Otte's avatar Benjamin Otte

styleproperty: Convert background-image from pattern to GtkCssImage

parent 2bb899b5
......@@ -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);
}
......
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment