mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 14:30:15 +00:00
colorchooser: factor out a private method to get the checkboard pattern
And use it in the color widgets.
This commit is contained in:
parent
453aecd346
commit
19da38b811
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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__ */
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user