[gtk+/wip/colorchooser-v2: 12/84] Show alpha in the palette as well



commit 3789c262d47b6057433d50dd732176775dac3487
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 31 00:58:07 2012 -0500

    Show alpha in the palette as well

 gtk/gtkcolorswatch.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index 4211f60..682fecd 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);
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]