]> git.sur5r.net Git - glabels/blob - src/color.h
Imported Upstream version 2.2.8
[glabels] / 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_FILL_MERGE_DEFAULT    GL_COLOR_A(255,255,255,128)
49 #define GL_COLOR_MERGE_DEFAULT         GL_COLOR_A(0,0,0,128)
50 #define GL_COLOR_SHADOW_DEFAULT        GL_COLOR(0,0,0)
51 #define GL_COLOR_SHADOW_MERGE_DEFAULT  GL_COLOR_A(0,0,0,255)
52
53
54 /*
55  * Extract components as floating point (0.0 .. 1.0)
56  */
57 #define GL_COLOR_F_RED(x)   ( (((x)>>24) & 0xff) / 255.0 )
58 #define GL_COLOR_F_GREEN(x) ( (((x)>>16) & 0xff) / 255.0 )
59 #define GL_COLOR_F_BLUE(x)  ( (((x)>>8)  & 0xff) / 255.0 )
60 #define GL_COLOR_F_ALPHA(x) ( ( (x)      & 0xff) / 255.0 )
61
62 /*
63  * Extract arguments for cairo_set_source_rgb()
64  */
65 #define GL_COLOR_RGB_ARGS(x)  \
66         GL_COLOR_F_RED(x),    \
67         GL_COLOR_F_GREEN(x),  \
68         GL_COLOR_F_BLUE(x)
69
70 /*
71  * Extract arguments for cairo_set_source_rgba()
72  */
73 #define GL_COLOR_RGBA_ARGS(x) \
74         GL_COLOR_F_RED(x),    \
75         GL_COLOR_F_GREEN(x),  \
76         GL_COLOR_F_BLUE(x),   \
77         GL_COLOR_F_ALPHA(x)
78
79                 
80
81
82 guint     gl_color_set_opacity            (guint            color,
83                                            gdouble          opacity);
84
85 guint     gl_color_shadow                 (guint            base_color,
86                                            gdouble          opacity,
87                                            guint            object_color);
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__ */