2 * Toolkit-dependent implementations of routines to handle colors.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
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.
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.
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.
32 #include "ui/gtk/color_utils.h"
34 static GdkColormap* sys_cmap;
35 static GdkColormap* our_cmap = NULL;
37 GdkColor WHITE = { 0, 65535, 65535, 65535 };
38 /*GdkColor LTGREY = { 0, 57343, 57343, 57343 };*/
39 GdkColor BLACK = { 0, 0, 0, 0 };
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.
47 initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue)
53 gdk_color.green = green;
54 gdk_color.blue = blue;
56 if (!get_color(&gdk_color))
59 gdkcolor_to_color_t(color, &gdk_color);
63 /* Initialize the colors */
68 gboolean got_white, got_black;
70 sys_cmap = gdk_colormap_get_system();
72 /* Allocate "constant" colors. */
73 got_white = get_color(&WHITE);
74 got_black = get_color(&BLACK);
78 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
79 "Could not allocate colors black or white.");
81 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
82 "Could not allocate color white.");
85 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
86 "Could not allocate color black.");
92 /* allocate a color from the color map */
94 get_color(GdkColor *new_color)
99 if (!gdk_colormap_alloc_color (sys_cmap, new_color, FALSE,
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");
109 return (gdk_colormap_alloc_color(our_cmap, new_color, FALSE, TRUE));
114 color_t_to_gdkcolor(GdkColor *target, const color_t *source)
116 target->pixel = source->pixel;
117 target->red = source->red;
118 target->green = source->green;
119 target->blue = source->blue;
123 color_t_to_gdkRGBAcolor(GdkRGBA *target, const color_t *source)
126 target->red = source->red / 65535.0;
127 target->green = source->green / 65535.0;
128 target->blue = source->blue / 65535.0;
131 gdkcolor_to_color_t(color_t *target, const GdkColor *source)
133 target->pixel = source->pixel;
134 target->red = source->red;
135 target->green = source->green;
136 target->blue = source->blue;
140 gdkRGBAcolor_to_color_t(color_t *target, const GdkRGBA *source)
143 target->red = (guint16)(source->red*65535);
144 target->green = (guint16)(source->green*65535);
145 target->blue = (guint16)(source->blue*65535);
150 GdkColor_to_GdkRGBA(GdkRGBA *target, const GdkColor *source)
153 target->red = (double)source->red / 65535.0;
154 target->green = (double)source->green / 65535.0;
155 target->blue = (double)source->blue / 65535.0;
159 gdkRGBAcolor_to_GdkColor(GdkColor *target, const GdkRGBA *source)
162 target->red = (guint16)(source->red*65535);
163 target->green = (guint16)(source->green*65535);
164 target->blue = (guint16)(source->blue*65535);