From 8d1565df94fab35fe5f0b855ef392c57f816aa11 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 31 Jan 2012 00:58:07 -0500 Subject: [PATCH] Show alpha in the palette as well --- gtk/gtkcolorswatch.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c index 4211f60a97..682fecd70c 100644 --- a/gtk/gtkcolorswatch.c +++ b/gtk/gtkcolorswatch.c @@ -88,6 +88,27 @@ swatch_finalize (GObject *object) #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) +static cairo_pattern_t * +get_checkered_pattern (void) +{ + /* need to respect pixman's stride being a multiple of 4 */ + static unsigned char data[8] = { 0xFF, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0x00, 0x00 }; + static cairo_surface_t *checkered = NULL; + cairo_pattern_t *pattern; + + if (checkered == NULL) + checkered = cairo_image_surface_create_for_data (data, + CAIRO_FORMAT_A8, + 2, 2, 4); + + pattern = cairo_pattern_create_for_surface (checkered); + cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT); + cairo_pattern_set_filter (pattern, CAIRO_FILTER_NEAREST); + + return pattern; +} + static gboolean swatch_draw (GtkWidget *widget, cairo_t *cr) @@ -118,6 +139,21 @@ swatch_draw (GtkWidget *widget, if (swatch->priv->has_color) { + cairo_pattern_t *pattern; + cairo_matrix_t matrix; + + cairo_set_source_rgb (cr, 0.33, 0.33, 0.33); + cairo_fill_preserve (cr); + + cairo_set_source_rgb (cr, 0.66, 0.66, 0.66); + + pattern = get_checkered_pattern (); + cairo_matrix_init_scale (&matrix, 0.125, 0.125); + cairo_pattern_set_matrix (pattern, &matrix); + cairo_clip_preserve (cr); + cairo_mask (cr, pattern); + cairo_pattern_destroy (pattern); + gdk_cairo_set_source_rgba (cr, &swatch->priv->color); cairo_fill_preserve (cr); }