forked from AuroraMiddleware/gtk
color chooser: Port checkered pattern drawing from cairo
This commit is contained in:
parent
c6961f1b61
commit
6f1cade817
@ -23,6 +23,8 @@
|
||||
#include "gtkintl.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtksnapshot.h"
|
||||
#include "gdk/gdkrgbaprivate.h"
|
||||
|
||||
/**
|
||||
* SECTION:gtkcolorchooser
|
||||
@ -222,23 +224,18 @@ gtk_color_chooser_add_palette (GtkColorChooser *chooser,
|
||||
GTK_COLOR_CHOOSER_GET_IFACE (chooser)->add_palette (chooser, orientation, colors_per_line, n_colors, colors);
|
||||
}
|
||||
|
||||
cairo_pattern_t *
|
||||
_gtk_color_chooser_get_checkered_pattern (void)
|
||||
void
|
||||
_gtk_color_chooser_snapshot_checkered_pattern (GtkSnapshot *snapshot,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
/* 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;
|
||||
const GdkRGBA color1 = GDK_RGBA("A8A8A8");
|
||||
const GdkRGBA color2 = GDK_RGBA("545445");
|
||||
|
||||
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;
|
||||
gtk_snapshot_push_repeat (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height), NULL);
|
||||
gtk_snapshot_append_color (snapshot, &color1, &GRAPHENE_RECT_INIT (0, 0, 10, 10));
|
||||
gtk_snapshot_append_color (snapshot, &color2, &GRAPHENE_RECT_INIT (10, 0, 10, 10));
|
||||
gtk_snapshot_append_color (snapshot, &color2, &GRAPHENE_RECT_INIT (0, 10, 10, 10));
|
||||
gtk_snapshot_append_color (snapshot, &color1, &GRAPHENE_RECT_INIT (10, 10, 10, 10));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
|
@ -25,7 +25,10 @@ G_BEGIN_DECLS
|
||||
void _gtk_color_chooser_color_activated (GtkColorChooser *chooser,
|
||||
const GdkRGBA *color);
|
||||
|
||||
cairo_pattern_t * _gtk_color_chooser_get_checkered_pattern (void);
|
||||
void _gtk_color_chooser_snapshot_checkered_pattern (GtkSnapshot *snapshot,
|
||||
int width,
|
||||
int height);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -120,17 +120,12 @@ gtk_color_scale_snapshot_trough (GtkColorScale *scale,
|
||||
}
|
||||
else if (priv->type == GTK_COLOR_SCALE_ALPHA)
|
||||
{
|
||||
cairo_t *cr;
|
||||
graphene_point_t start, end;
|
||||
|
||||
cr = gtk_snapshot_append_cairo (snapshot,
|
||||
&GRAPHENE_RECT_INIT(0, 0, width, height));
|
||||
const GdkRGBA *color;
|
||||
|
||||
if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL &&
|
||||
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
||||
{
|
||||
cairo_translate (cr, width, 0);
|
||||
cairo_scale (cr, -1, 1);
|
||||
graphene_point_init (&start, width, 0);
|
||||
graphene_point_init (&end, 0, 0);
|
||||
}
|
||||
@ -140,21 +135,7 @@ gtk_color_scale_snapshot_trough (GtkColorScale *scale,
|
||||
graphene_point_init (&end, width, 0);
|
||||
}
|
||||
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_matrix_t matrix;
|
||||
GdkRGBA *color;
|
||||
|
||||
cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
|
||||
cairo_paint (cr);
|
||||
cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
|
||||
|
||||
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);
|
||||
cairo_pattern_destroy (pattern);
|
||||
|
||||
cairo_destroy (cr);
|
||||
_gtk_color_chooser_snapshot_checkered_pattern (snapshot, width, height);
|
||||
|
||||
color = &priv->color;
|
||||
|
||||
|
@ -85,40 +85,18 @@ swatch_snapshot (GtkWidget *widget,
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
const int width = gtk_widget_get_width (widget);
|
||||
const int height = gtk_widget_get_height (widget);
|
||||
|
||||
if (priv->has_color)
|
||||
{
|
||||
cairo_pattern_t *pattern;
|
||||
cairo_matrix_t matrix;
|
||||
|
||||
if (priv->use_alpha && !gdk_rgba_is_opaque (&priv->color))
|
||||
{
|
||||
cairo_t *cr;
|
||||
|
||||
cr = gtk_snapshot_append_cairo (snapshot,
|
||||
&GRAPHENE_RECT_INIT (
|
||||
0, 0,
|
||||
gtk_widget_get_width (widget),
|
||||
gtk_widget_get_height (widget)));
|
||||
cairo_set_source_rgb (cr, 0.33, 0.33, 0.33);
|
||||
cairo_paint (cr);
|
||||
|
||||
pattern = _gtk_color_chooser_get_checkered_pattern ();
|
||||
cairo_matrix_init_scale (&matrix, 0.125, 0.125);
|
||||
cairo_pattern_set_matrix (pattern, &matrix);
|
||||
|
||||
cairo_set_source_rgb (cr, 0.66, 0.66, 0.66);
|
||||
cairo_mask (cr, pattern);
|
||||
cairo_pattern_destroy (pattern);
|
||||
|
||||
cairo_destroy (cr);
|
||||
_gtk_color_chooser_snapshot_checkered_pattern (snapshot, width, height);
|
||||
|
||||
gtk_snapshot_append_color (snapshot,
|
||||
&priv->color,
|
||||
&GRAPHENE_RECT_INIT (
|
||||
0, 0,
|
||||
gtk_widget_get_width (widget),
|
||||
gtk_widget_get_height (widget)));
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -128,10 +106,7 @@ swatch_snapshot (GtkWidget *widget,
|
||||
|
||||
gtk_snapshot_append_color (snapshot,
|
||||
&color,
|
||||
&GRAPHENE_RECT_INIT (
|
||||
0, 0,
|
||||
gtk_widget_get_width (widget),
|
||||
gtk_widget_get_height (widget)));
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user