1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * pattern.c : Support and specifications for patterns.
6 * Jody Goldberg <jody@gnome.org>
8 * (C) 1999-2003 Jody Goldberg
10 #include <gnumeric-config.h>
14 #include "style-color.h"
16 #include <goffice/utils/go-pattern.h>
18 static const GOPatternType patterns
[] = {
19 GO_PATTERN_SOLID
, /* dummy filler */
30 GO_PATTERN_DIAG_CROSS
,
31 GO_PATTERN_THICK_DIAG_CROSS
,
32 GO_PATTERN_THIN_HORIZ
,
34 GO_PATTERN_THIN_REV_DIAG
,
36 GO_PATTERN_THIN_HORIZ_CROSS
,
37 GO_PATTERN_THIN_DIAG_CROSS
,
38 GO_PATTERN_SMALL_CIRCLES
,
39 GO_PATTERN_SEMI_CIRCLES
,
41 GO_PATTERN_LARGE_CIRCLES
,
43 GO_PATTERN_FOREGROUND_SOLID
47 * gnm_pattern_background_set:
53 * Returns: %TRUE if there is a background to paint.
55 * Set up a cairo context to paint the background of a cell.
59 gnm_pattern_background_set (GnmStyle
const *mstyle
, cairo_t
*cr
,
60 gboolean
const is_selected
, GtkStyleContext
*ctxt
)
64 g_return_val_if_fail (!is_selected
|| ctxt
!= NULL
, FALSE
);
67 * Draw the background if the PATTERN is non 0
68 * Draw a stipple too if the pattern is > 1
70 pattern
= gnm_style_get_pattern (mstyle
);
71 if (pattern
> 0 && pattern
< GNM_PATTERNS_MAX
) {
73 cairo_pattern_t
*crpat
;
74 gopat
.pattern
= patterns
[pattern
];
75 gopat
.fore
= gnm_style_get_pattern_color (mstyle
)->go_color
;
76 gopat
.back
= gnm_style_get_back_color (mstyle
)->go_color
;
80 gtk_style_context_get_background_color
81 (ctxt
, GTK_STATE_FLAG_SELECTED
, &rgba
);
82 light
= GO_COLOR_FROM_GDK_RGBA (rgba
);
83 gopat
.fore
= GO_COLOR_INTERPOLATE (light
, gopat
.fore
, .5);
84 gopat
.back
= GO_COLOR_INTERPOLATE (light
, gopat
.back
, .5);
86 crpat
= go_pattern_create_cairo_pattern (&gopat
, cr
);
88 cairo_set_source (cr
, crpat
);
89 cairo_pattern_destroy (crpat
);
91 } else if (is_selected
) {
95 gtk_style_context_get_background_color (ctxt
, GTK_STATE_FLAG_SELECTED
, &rgba
);
96 color
= GO_COLOR_FROM_GDK_RGBA (rgba
);
97 /* Make a lighter version. */
98 color
= GO_COLOR_INTERPOLATE (GO_COLOR_WHITE
, color
, .5);
99 cairo_set_source_rgba (cr
, GO_COLOR_TO_CAIRO (color
));