]> git.sur5r.net Git - glabels/blob - src/mygal/e-colors.c
Imported Upstream version 2.2.8
[glabels] / src / mygal / e-colors.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * e-colors.c - General color allocation utilities
4  * Copyright 2000, 2001, Ximian, Inc.
5  *
6  * Authors:
7  *  Miguel de Icaza (miguel@kernel.org)
8  *
9  * Modified for gLabels by:
10  *   Jim Evins <evins@snaught.com>
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public
14  * License, version 2, as published by the Free Software Foundation.
15  *
16  * This library is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  * 02111-1307, USA.
25  */
26
27 /* We keep our own color context, as the color allocation might take
28  * place before things are realized.
29  */
30
31 #include <config.h>
32 #include <gtk/gtkwidget.h>
33 #include "e-colors.h"
34
35 GdkColor e_white, e_dark_gray, e_black;
36
37 gulong
38 e_color_alloc (gushort red, gushort green, gushort blue)
39 {
40         e_color_init ();
41
42         red >>= 8;
43         green >>= 8;
44         blue >>= 8;
45         return gdk_rgb_xpixel_from_rgb (
46                 ((red & 0xff) << 16) | ((green & 0xff) << 8) |
47                 (blue & 0xff));
48 }
49
50 void
51 e_color_alloc_gdk (GtkWidget *widget, GdkColor *c)
52 {
53         GdkColormap *map;
54
55         e_color_init ();
56
57         if (widget)
58                 map = gtk_widget_get_colormap (widget);
59         else /* FIXME: multi depth broken ? */
60                 map = gtk_widget_get_default_colormap ();
61
62         gdk_rgb_find_color (map, c);
63 }
64
65 void
66 e_color_alloc_name (GtkWidget *widget, const char *name, GdkColor *c)
67 {
68         GdkColormap *map;
69
70         e_color_init ();
71
72         gdk_color_parse (name, c);
73
74         if (widget)
75                 map = gtk_widget_get_colormap (widget);
76         else /* FIXME: multi depth broken ? */
77                 map = gtk_widget_get_default_colormap ();
78
79         gdk_rgb_find_color (map, c);
80 }
81
82 void
83 e_color_init (void)
84 {
85         static gboolean e_color_inited = FALSE;
86
87         /* It's surprisingly easy to end up calling this twice.  Survive.  */
88         if (e_color_inited)
89                 return;
90
91         e_color_inited = TRUE;
92
93         /* Allocate the default colors */
94         e_white.red   = 65535;
95         e_white.green = 65535;
96         e_white.blue  = 65535;
97         e_color_alloc_gdk (NULL, &e_white);
98
99         e_black.red   = 0;
100         e_black.green = 0;
101         e_black.blue  = 0;
102         e_color_alloc_gdk (NULL, &e_black);
103
104         e_color_alloc_name (NULL, "gray20",  &e_dark_gray);
105 }
106