]> Pileus Git - ~andy/gtk/commitdiff
Show alpha in the palette as well
authorMatthias Clasen <mclasen@redhat.com>
Tue, 31 Jan 2012 05:58:07 +0000 (00:58 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 14 Feb 2012 21:36:51 +0000 (16:36 -0500)
gtk/gtkcolorswatch.c

index 4211f60a97d6071a98c0f11975788bc2cc450f34..682fecd70cf9e35f6e0e7123756ec4d63dc46322 100644 (file)
@@ -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);
     }