]> git.sur5r.net Git - glabels/blob - glabels2/src/color.h
ac774dc403f10036fe50a5e3d6309efe2ca46a65
[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
50 #define GL_COLOR_TEXT_DEFAULT          GL_COLOR_BLACK
51 #define GL_COLOR_BC_DEFAULT            GL_COLOR_BLACK
52 #define GL_COLOR_NO_LINE               GL_COLOR_NONE
53 #define GL_COLOR_NO_FILL               GL_COLOR_NONE
54 #define GL_COLOR_FILL_MERGE_DEFAULT    GL_COLOR_A(255,255,255,128)
55 #define GL_COLOR_MERGE_DEFAULT         GL_COLOR_A(0,0,0,128)
56 #define GL_COLOR_SHADOW_DEFAULT        GL_COLOR(0,0,0)
57 #define GL_COLOR_SHADOW_MERGE_DEFAULT  GL_COLOR_A(0,0,0,255)
58
59
60 /*
61  * Extract components as floating point (0.0 .. 1.0)
62  */
63 #define GL_COLOR_F_RED(x)   ( (((x)>>24) & 0xff) / 255.0 )
64 #define GL_COLOR_F_GREEN(x) ( (((x)>>16) & 0xff) / 255.0 )
65 #define GL_COLOR_F_BLUE(x)  ( (((x)>>8)  & 0xff) / 255.0 )
66 #define GL_COLOR_F_ALPHA(x) ( ( (x)      & 0xff) / 255.0 )
67
68 /*
69  * Extract arguments for cairo_set_source_rgb()
70  */
71 #define GL_COLOR_RGB_ARGS(x)  \
72         GL_COLOR_F_RED(x),    \
73         GL_COLOR_F_GREEN(x),  \
74         GL_COLOR_F_BLUE(x)
75
76 /*
77  * Extract arguments for cairo_set_source_rgba()
78  */
79 #define GL_COLOR_RGBA_ARGS(x) \
80         GL_COLOR_F_RED(x),    \
81         GL_COLOR_F_GREEN(x),  \
82         GL_COLOR_F_BLUE(x),   \
83         GL_COLOR_F_ALPHA(x)
84
85                 
86
87
88 guint     gl_color_set_opacity            (guint            color,
89                                            gdouble          opacity);
90
91 guint     gl_color_shadow                 (guint            base_color,
92                                            gdouble          opacity,
93                                            guint            object_color);
94
95 /*
96  * Routines to convert to/from GdkColor.
97  */
98 GdkColor *gl_color_to_gdk_color           (guint            color);
99
100 guint     gl_color_from_gdk_color         (GdkColor        *gdk_color);
101
102
103
104 /*
105  * Color nodes
106  */
107 typedef struct {
108         gboolean field_flag;
109         guint color;
110         gchar *key;
111 } glColorNode;
112
113 glColorNode *gl_color_node_new_default    (void);
114
115 glColorNode *gl_color_node_dup            (glColorNode     *color_node);
116 gboolean     gl_color_node_equal          (glColorNode     *color_node1,
117                                            glColorNode     *color_node2);
118 guint        gl_color_node_expand         (glColorNode     *color_node,
119                                            glMergeRecord   *record);
120 void         gl_color_node_free           (glColorNode    **color_node);
121
122
123 G_END_DECLS
124
125 #endif /* __COLOR_H__ */