[gtk+] css: Implement repeating linear gradients
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] css: Implement repeating linear gradients
- Date: Thu, 2 Feb 2012 02:19:56 +0000 (UTC)
commit 811e848832c140b21fe711a0f377248aef040550
Author: Benjamin Otte <otte redhat com>
Date: Tue Jan 17 11:44:07 2012 +0100
css: Implement repeating linear gradients
gtk/gtkcssimage.c | 3 ++-
gtk/gtkcssimagelinear.c | 18 +++++++++++++++---
gtk/gtkcssimagelinearprivate.h | 1 +
3 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index 11f3a80..b8eda5f 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -324,7 +324,8 @@ gtk_css_image_get_parser_type (GtkCssParser *parser)
{ "url", _gtk_css_image_url_get_type },
{ "-gtk-gradient", _gtk_css_image_gradient_get_type },
{ "-gtk-win32-theme-part", _gtk_css_image_win32_get_type },
- { "linear-gradient", _gtk_css_image_linear_get_type }
+ { "linear-gradient", _gtk_css_image_linear_get_type },
+ { "repeating-linear-gradient", _gtk_css_image_linear_get_type }
};
guint i;
diff --git a/gtk/gtkcssimagelinear.c b/gtk/gtkcssimagelinear.c
index 890465c..130f9d9 100644
--- a/gtk/gtkcssimagelinear.c
+++ b/gtk/gtkcssimagelinear.c
@@ -168,7 +168,10 @@ gtk_css_image_linear_draw (GtkCssImage *image,
gtk_css_image_linear_get_start_end (linear, length, &start, &end);
pattern = cairo_pattern_create_linear (x * (start - 0.5), y * (start - 0.5),
x * (end - 0.5), y * (end - 0.5));
- cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
+ if (linear->repeating)
+ cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+ else
+ cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
offset = start;
last = -1;
@@ -230,7 +233,11 @@ gtk_css_image_linear_parse (GtkCssImage *image,
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
guint i;
- if (!_gtk_css_parser_try (parser, "linear-gradient(", TRUE))
+ if (_gtk_css_parser_try (parser, "repeating-linear-gradient(", TRUE))
+ linear->repeating = TRUE;
+ else if (_gtk_css_parser_try (parser, "linear-gradient(", TRUE))
+ linear->repeating = FALSE;
+ else
{
_gtk_css_parser_error (parser, "Not a linear gradient");
return FALSE;
@@ -356,7 +363,11 @@ gtk_css_image_linear_print (GtkCssImage *image,
/* XXX: Do these need to be prinatable? */
g_return_if_fail (!linear->is_computed);
- g_string_append (string, "linear-gradient(");
+ if (linear->repeating)
+ g_string_append (string, "repeating-linear-gradient(");
+ else
+ g_string_append (string, "linear-gradient(");
+
if (linear->angle.unit == GTK_CSS_NUMBER)
{
guint side = linear->angle.value;
@@ -421,6 +432,7 @@ gtk_css_image_linear_compute (GtkCssImage *image,
copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
copy->is_computed = TRUE;
+ copy->repeating = linear->repeating;
_gtk_css_number_compute (©->angle, &linear->angle, context);
diff --git a/gtk/gtkcssimagelinearprivate.h b/gtk/gtkcssimagelinearprivate.h
index 67191b1..f664c5b 100644
--- a/gtk/gtkcssimagelinearprivate.h
+++ b/gtk/gtkcssimagelinearprivate.h
@@ -51,6 +51,7 @@ struct _GtkCssImageLinear
GtkCssNumber angle; /* warning: We use GTK_CSS_NUMBER as an enum for the corners */
GArray *stops;
guint is_computed :1;
+ guint repeating :1;
};
struct _GtkCssImageLinearClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]