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