Compilation: clean up dialog including.
[gnumeric.git] / src / pattern.c
blobd6cbe0f52552de407b6b40e482b9521b01768fb8
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * pattern.c : Support and specifications for patterns.
5 * Author:
6 * Jody Goldberg <jody@gnome.org>
8 * (C) 1999-2003 Jody Goldberg
9 */
10 #include <gnumeric-config.h>
11 #include "gnumeric.h"
12 #include "pattern.h"
14 #include "style-color.h"
16 #include <goffice/utils/go-pattern.h>
18 static const GOPatternType patterns[] = {
19 GO_PATTERN_SOLID, /* dummy filler */
20 GO_PATTERN_SOLID,
21 GO_PATTERN_GREY75,
22 GO_PATTERN_GREY50,
23 GO_PATTERN_GREY25,
24 GO_PATTERN_GREY125,
25 GO_PATTERN_GREY625,
26 GO_PATTERN_HORIZ,
27 GO_PATTERN_VERT,
28 GO_PATTERN_DIAG,
29 GO_PATTERN_REV_DIAG,
30 GO_PATTERN_DIAG_CROSS,
31 GO_PATTERN_THICK_DIAG_CROSS,
32 GO_PATTERN_THIN_HORIZ,
33 GO_PATTERN_THIN_VERT,
34 GO_PATTERN_THIN_REV_DIAG,
35 GO_PATTERN_THIN_DIAG,
36 GO_PATTERN_THIN_HORIZ_CROSS,
37 GO_PATTERN_THIN_DIAG_CROSS,
38 GO_PATTERN_SMALL_CIRCLES,
39 GO_PATTERN_SEMI_CIRCLES,
40 GO_PATTERN_THATCH,
41 GO_PATTERN_LARGE_CIRCLES,
42 GO_PATTERN_BRICKS,
43 GO_PATTERN_FOREGROUND_SOLID
46 /**
47 * gnm_pattern_background_set:
48 * @mstyle:
49 * @cr:
50 * @is_selected:
51 * @ctxt:
53 * Returns: %TRUE if there is a background to paint.
55 * Set up a cairo context to paint the background of a cell.
58 gboolean
59 gnm_pattern_background_set (GnmStyle const *mstyle, cairo_t *cr,
60 gboolean const is_selected, GtkStyleContext *ctxt)
62 int pattern;
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) {
72 GOPattern gopat;
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;
77 if (is_selected) {
78 GOColor light;
79 GdkRGBA rgba;
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);
87 if (crpat)
88 cairo_set_source (cr, crpat);
89 cairo_pattern_destroy (crpat);
90 return TRUE;
91 } else if (is_selected) {
92 GdkRGBA rgba;
93 GOColor color;
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));
101 return FALSE;