[gtk+/wip/colorchooser-v2: 83/84] colorchooser: factor out a private method to get the checkboard pattern
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/colorchooser-v2: 83/84] colorchooser: factor out a private method to get the checkboard pattern
- Date: Tue, 14 Feb 2012 19:11:48 +0000 (UTC)
commit 843ea99b7110af333478e128a0547ac64d45971d
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Feb 14 12:16:56 2012 -0500
colorchooser: factor out a private method to get the checkboard pattern
And use it in the color widgets.
gtk/gtkcolorbutton.c | 28 +++-------------------------
gtk/gtkcolorchooser.c | 21 +++++++++++++++++++++
gtk/gtkcolorchooserprivate.h | 2 ++
gtk/gtkcolorscale.c | 24 ++----------------------
gtk/gtkcolorswatch.c | 24 ++----------------------
5 files changed, 30 insertions(+), 69 deletions(-)
---
diff --git a/gtk/gtkcolorbutton.c b/gtk/gtkcolorbutton.c
index c046cc1..d9aeabc 100644
--- a/gtk/gtkcolorbutton.c
+++ b/gtk/gtkcolorbutton.c
@@ -36,6 +36,7 @@
#include "gtkbutton.h"
#include "gtkmain.h"
#include "gtkcolorchooser.h"
+#include "gtkcolorchooserprivate.h"
#include "gtkcolorchooserdialog.h"
#include "gtkdnd.h"
#include "gtkdrawingarea.h"
@@ -271,29 +272,6 @@ gtk_color_button_has_alpha (GtkColorButton *button)
return button->priv->use_alpha && button->priv->rgba.alpha < 1;
}
-static cairo_pattern_t *
-gtk_color_button_get_checkered (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;
-}
-
/* Handle exposure events for the color picker's drawing area */
static gint
gtk_color_button_draw_cb (GtkWidget *widget,
@@ -311,7 +289,7 @@ gtk_color_button_draw_cb (GtkWidget *widget,
cairo_set_source_rgb (cr, CHECK_LIGHT, CHECK_LIGHT, CHECK_LIGHT);
cairo_scale (cr, CHECK_SIZE, CHECK_SIZE);
- checkered = gtk_color_button_get_checkered ();
+ checkered = _gtk_color_chooser_get_checkered_pattern ();
cairo_mask (cr, checkered);
cairo_pattern_destroy (checkered);
@@ -336,7 +314,7 @@ gtk_color_button_draw_cb (GtkWidget *widget,
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_INSENSITIVE, &color);
gdk_cairo_set_source_rgba (cr, &color);
- checkered = gtk_color_button_get_checkered ();
+ checkered = _gtk_color_chooser_get_checkered_pattern ();
cairo_mask (cr, checkered);
cairo_pattern_destroy (checkered);
}
diff --git a/gtk/gtkcolorchooser.c b/gtk/gtkcolorchooser.c
index 075331b..a54127b 100644
--- a/gtk/gtkcolorchooser.c
+++ b/gtk/gtkcolorchooser.c
@@ -235,3 +235,24 @@ gtk_color_chooser_add_palette (GtkColorChooser *chooser,
if (GTK_COLOR_CHOOSER_GET_IFACE (chooser)->add_palette)
GTK_COLOR_CHOOSER_GET_IFACE (chooser)->add_palette (chooser, horizontal, colors_per_line, n_colors, colors);
}
+
+cairo_pattern_t *
+_gtk_color_chooser_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;
+}
diff --git a/gtk/gtkcolorchooserprivate.h b/gtk/gtkcolorchooserprivate.h
index 0a9f4f5..4109901 100644
--- a/gtk/gtkcolorchooserprivate.h
+++ b/gtk/gtkcolorchooserprivate.h
@@ -27,6 +27,8 @@ G_BEGIN_DECLS
void _gtk_color_chooser_color_activated (GtkColorChooser *chooser,
const GdkRGBA *color);
+cairo_pattern_t * _gtk_color_chooser_get_checkered_pattern (void);
+
G_END_DECLS
#endif /* ! __GTK_COLOR_CHOOSER_PRIVATE_H__ */
diff --git a/gtk/gtkcolorscale.c b/gtk/gtkcolorscale.c
index 7070281..7cfa5a0 100644
--- a/gtk/gtkcolorscale.c
+++ b/gtk/gtkcolorscale.c
@@ -21,6 +21,7 @@
#include "gtkcolorscaleprivate.h"
+#include "gtkcolorchooserprivate.h"
#include "gtkcolorutils.h"
#include "gtkorientable.h"
#include "gtkstylecontext.h"
@@ -44,27 +45,6 @@ enum
G_DEFINE_TYPE (GtkColorScale, gtk_color_scale, GTK_TYPE_SCALE)
-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 void
create_surface (GtkColorScale *scale)
{
@@ -152,7 +132,7 @@ create_surface (GtkColorScale *scale)
cairo_paint (cr);
cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
- pattern = get_checkered_pattern ();
+ pattern = _gtk_color_chooser_get_checkered_pattern ();
cairo_matrix_init_scale (&matrix, 0.125, 0.125);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_mask (cr, pattern);
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index 10ec66e..8e9c385 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -21,6 +21,7 @@
#include "gtkcolorswatchprivate.h"
+#include "gtkcolorchooserprivate.h"
#include "gtkroundedboxprivate.h"
#include "gtkthemingbackgroundprivate.h"
#include "gtkdnd.h"
@@ -78,27 +79,6 @@ gtk_color_swatch_init (GtkColorSwatch *swatch)
#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)
@@ -141,7 +121,7 @@ swatch_draw (GtkWidget *widget,
cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
cairo_fill_preserve (cr);
- pattern = get_checkered_pattern ();
+ pattern = _gtk_color_chooser_get_checkered_pattern ();
cairo_matrix_init_scale (&matrix, 0.125, 0.125);
cairo_pattern_set_matrix (pattern, &matrix);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]