[gtk+/composite-templates] cssimage: Add a hack to get antialiased circles
- From: Juan Pablo Ugarte <jpu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/composite-templates] cssimage: Add a hack to get antialiased circles
- Date: Sat, 6 Oct 2012 17:01:00 +0000 (UTC)
commit 76f597f29e70c7ba6c04f07e0a97026241a48c17
Author: Benjamin Otte <otte redhat com>
Date: Tue Sep 18 13:26:20 2012 +0200
cssimage: Add a hack to get antialiased circles
We like to draw circles in themes, and as radial gradients are the only
okayish way to do that, at least make them antialiased.
gtk/gtkcssimagegradient.c | 51 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssimagegradient.c b/gtk/gtkcssimagegradient.c
index adaee94..d8db2e2 100644
--- a/gtk/gtkcssimagegradient.c
+++ b/gtk/gtkcssimagegradient.c
@@ -46,6 +46,54 @@ gtk_css_image_gradient_compute (GtkCssImage *image,
return GTK_CSS_IMAGE (copy);
}
+static gboolean
+gtk_css_image_gradient_draw_circle (GtkCssImageGradient *image,
+ cairo_t *cr,
+ double width,
+ double height)
+{
+ cairo_pattern_t *pattern = image->pattern;
+ double x0, y0, x1, y1, r0, r1;
+ GdkRGBA color0, color1;
+ double offset0, offset1;
+ int n_stops;
+
+ if (cairo_pattern_get_type (pattern) != CAIRO_PATTERN_TYPE_RADIAL)
+ return FALSE;
+ if (cairo_pattern_get_extend (pattern) != CAIRO_EXTEND_PAD)
+ return FALSE;
+
+ cairo_pattern_get_radial_circles (pattern, &x0, &y0, &r0, &x1, &y1, &r1);
+
+ if (x0 != x1 ||
+ y0 != y1 ||
+ r0 != 0.0)
+ return FALSE;
+
+ cairo_pattern_get_color_stop_count (pattern, &n_stops);
+ if (n_stops != 2)
+ return FALSE;
+
+ cairo_pattern_get_color_stop_rgba (pattern, 0, &offset0, &color0.red, &color0.green, &color0.blue, &color0.alpha);
+ cairo_pattern_get_color_stop_rgba (pattern, 1, &offset1, &color1.red, &color1.green, &color1.blue, &color1.alpha);
+ if (offset0 != offset1)
+ return FALSE;
+
+ cairo_scale (cr, width, height);
+
+ cairo_rectangle (cr, 0, 0, 1, 1);
+ cairo_clip (cr);
+
+ gdk_cairo_set_source_rgba (cr, &color1);
+ cairo_paint (cr);
+
+ gdk_cairo_set_source_rgba (cr, &color0);
+ cairo_arc (cr, x1, y1, r1 * offset1, 0, 2 * G_PI);
+ cairo_fill (cr);
+
+ return TRUE;
+}
+
static void
gtk_css_image_gradient_draw (GtkCssImage *image,
cairo_t *cr,
@@ -60,6 +108,9 @@ gtk_css_image_gradient_draw (GtkCssImage *image,
return;
}
+ if (gtk_css_image_gradient_draw_circle (gradient, cr, width, height))
+ return;
+
cairo_scale (cr, width, height);
cairo_rectangle (cr, 0, 0, 1, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]