]> git.sur5r.net Git - glabels/blob - src/color.h
Imported Upstream version 3.4.0
[glabels] / src / color.h
1 /*
2  *  color.h
3  *  Copyright (C) 2002-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
7  *  gLabels is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  gLabels is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef __COLOR_H__
22 #define __COLOR_H__
23
24 #include "merge.h"
25 #include <gdk/gdk.h>
26
27 G_BEGIN_DECLS
28
29 /*
30  * gLabels stores colors as a 32-bit unsigned integer in RGBA format (MSByte = Red)
31  */
32 #define GL_COLOR(r,g,b)     (  (((unsigned int) (r) & 0xff) << 24) \
33                              | (((unsigned int) (g) & 0xff) << 16) \
34                              | (((unsigned int) (b) & 0xff) << 8)  \
35                              | 0xff )
36
37 #define GL_COLOR_A(r,g,b,a) (  (((unsigned int) (r) & 0xff) << 24) \
38                              | (((unsigned int) (g) & 0xff) << 16) \
39                              | (((unsigned int) (b) & 0xff) << 8)  \
40                              | ( (unsigned int) (a) & 0xff ) )
41
42
43 #define GL_COLOR_NONE                  GL_COLOR_A(0,0,0,0)
44 #define GL_COLOR_BLACK                 GL_COLOR_A(0,0,0,255)
45 #define GL_COLOR_WHITE                 GL_COLOR_A(255,255,255,255)
46
47 #define GL_COLOR_TEXT_DEFAULT          GL_COLOR_BLACK
48 #define GL_COLOR_BC_DEFAULT            GL_COLOR_BLACK
49 #define GL_COLOR_NO_LINE               GL_COLOR_NONE
50 #define GL_COLOR_NO_FILL               GL_COLOR_NONE
51 #define GL_COLOR_FILL_MERGE_DEFAULT    GL_COLOR_A(255,255,255,128)
52 #define GL_COLOR_MERGE_DEFAULT         GL_COLOR_A(0,0,0,128)
53 #define GL_COLOR_SHADOW_DEFAULT        GL_COLOR(0,0,0)
54 #define GL_COLOR_SHADOW_MERGE_DEFAULT  GL_COLOR_A(0,0,0,255)
55
56
57 /*
58  * Extract components as floating point (0.0 .. 1.0)
59  */
60 #define GL_COLOR_F_RED(x)   ( (((x)>>24) & 0xff) / 255.0 )
61 #define GL_COLOR_F_GREEN(x) ( (((x)>>16) & 0xff) / 255.0 )
62 #define GL_COLOR_F_BLUE(x)  ( (((x)>>8)  & 0xff) / 255.0 )
63 #define GL_COLOR_F_ALPHA(x) ( ( (x)      & 0xff) / 255.0 )
64
65 /*
66  * Extract arguments for cairo_set_source_rgb()
67  */
68 #define GL_COLOR_RGB_ARGS(x)  \
69         GL_COLOR_F_RED(x),    \
70         GL_COLOR_F_GREEN(x),  \
71         GL_COLOR_F_BLUE(x)
72
73 /*
74  * Extract arguments for cairo_set_source_rgba()
75  */
76 #define GL_COLOR_RGBA_ARGS(x) \
77         GL_COLOR_F_RED(x),    \
78         GL_COLOR_F_GREEN(x),  \
79         GL_COLOR_F_BLUE(x),   \
80         GL_COLOR_F_ALPHA(x)
81
82                 
83
84
85 guint     gl_color_set_opacity            (guint            color,
86                                            gdouble          opacity);
87
88
89 /*
90  * Routines to convert to/from GdkColor.
91  */
92 GdkColor *gl_color_to_gdk_color           (guint            color);
93
94 guint     gl_color_from_gdk_color         (GdkColor        *gdk_color);
95
96
97
98 /*
99  * Color nodes
100  */
101 typedef struct {
102         gboolean field_flag;
103         guint color;
104         gchar *key;
105 } glColorNode;
106
107 glColorNode *gl_color_node_new_default    (void);
108
109 glColorNode *gl_color_node_dup            (glColorNode     *color_node);
110 gboolean     gl_color_node_equal          (glColorNode     *color_node1,
111                                            glColorNode     *color_node2);
112 guint        gl_color_node_expand         (glColorNode     *color_node,
113                                            glMergeRecord   *record);
114 void         gl_color_node_free           (glColorNode    **color_node);
115
116
117 G_END_DECLS
118
119 #endif /* __COLOR_H__ */
120
121
122
123 /*
124  * Local Variables:       -- emacs
125  * mode: C                -- emacs
126  * c-basic-offset: 8      -- emacs
127  * tab-width: 8           -- emacs
128  * indent-tabs-mode: nil  -- emacs
129  * End:                   -- emacs
130  */