Remove unneeded includes from ui folder
[metze/wireshark/wip.git] / ui / gtk / color_utils.c
1 /* color_utils.c
2  * Toolkit-dependent implementations of routines to handle colors.
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <string.h>
26
27 #include <gtk/gtk.h>
28
29 #include "../color.h"
30
31
32 #include "ui/gtk/color_utils.h"
33 #if 0
34 static GdkColormap*     sys_cmap;
35 static GdkColormap*     our_cmap = NULL;
36 #endif
37 GdkColor        WHITE = { 0, 65535, 65535, 65535 };
38 /*GdkColor      LTGREY = { 0, 57343, 57343, 57343 };*/
39 GdkColor        BLACK = { 0, 0, 0, 0 };
40
41 /*
42  * Initialize a color with R, G, and B values, including any toolkit-dependent
43  * work that needs to be done.
44  * Returns TRUE if it succeeds, FALSE if it fails.
45  */
46 gboolean
47 initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue)
48 {
49         GdkColor gdk_color;
50
51         gdk_color.pixel = 0;
52         gdk_color.red = red;
53         gdk_color.green = green;
54         gdk_color.blue = blue;
55 #if 0
56         if (!get_color(&gdk_color))
57                 return FALSE;
58 #endif
59         gdkcolor_to_color_t(color, &gdk_color);
60         return TRUE;
61 }
62
63 /* Initialize the colors */
64 void
65 colors_init(void)
66 {
67 #if 0
68         gboolean got_white, got_black;
69
70         sys_cmap = gdk_colormap_get_system();
71
72         /* Allocate "constant" colors. */
73         got_white = get_color(&WHITE);
74         got_black = get_color(&BLACK);
75         /* Got milk? */
76         if (!got_white) {
77                 if (!got_black)
78                         simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
79                                 "Could not allocate colors black or white.");
80                 else
81                         simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
82                                 "Could not allocate color white.");
83         } else {
84                 if (!got_black)
85                         simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
86                                 "Could not allocate color black.");
87         }
88 #endif
89
90 }
91 #if 0
92 /* allocate a color from the color map */
93 gboolean
94 get_color(GdkColor *new_color)
95 {
96         GdkVisual *pv;
97
98         if (!our_cmap) {
99                 if (!gdk_colormap_alloc_color (sys_cmap, new_color, FALSE,
100                         TRUE)) {
101                         pv = gdk_visual_get_best();
102                         if (!(our_cmap = gdk_colormap_new(pv, TRUE))) {
103                                 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
104                                         "Could not create new colormap");
105                         }
106                 } else
107                         return (TRUE);
108         }
109         return (gdk_colormap_alloc_color(our_cmap, new_color, FALSE, TRUE));
110 }
111 #endif
112
113 void
114 color_t_to_gdkcolor(GdkColor *target, const color_t *source)
115 {
116         target->pixel = source->pixel;
117         target->red   = source->red;
118         target->green = source->green;
119         target->blue  = source->blue;
120 }
121
122 void
123 color_t_to_gdkRGBAcolor(GdkRGBA *target, const color_t *source)
124 {
125         target->alpha = 1;
126         target->red   = source->red / 65535.0;
127         target->green = source->green / 65535.0;
128         target->blue  = source->blue / 65535.0;
129 }
130 void
131 gdkcolor_to_color_t(color_t *target, const GdkColor *source)
132 {
133         target->pixel = source->pixel;
134         target->red   = source->red;
135         target->green = source->green;
136         target->blue  = source->blue;
137 }
138
139 void
140 gdkRGBAcolor_to_color_t(color_t *target, const GdkRGBA *source)
141 {
142         target->pixel = 0;
143         target->red   = (guint16)(source->red*65535);
144         target->green = (guint16)(source->green*65535);
145         target->blue  = (guint16)(source->blue*65535);
146 }
147
148
149 void
150 GdkColor_to_GdkRGBA(GdkRGBA *target, const GdkColor *source)
151 {
152         target->alpha = 1;
153         target->red   = (double)source->red / 65535.0;
154         target->green = (double)source->green / 65535.0;
155         target->blue  = (double)source->blue / 65535.0;
156 }
157
158 void
159 gdkRGBAcolor_to_GdkColor(GdkColor *target, const GdkRGBA *source)
160 {
161         target->pixel = 0;
162         target->red   = (guint16)(source->red*65535);
163         target->green = (guint16)(source->green*65535);
164         target->blue  = (guint16)(source->blue*65535);
165 }
166