Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / ui / gtk / color_utils.c
blobd90b41c525a31d5e998a449ed2afaa35cf9c81b6
1 /* color_utils.c
2 * Toolkit-dependent implementations of routines to handle colors.
4 * $Id$
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "config.h"
27 #include <string.h>
29 #include <gtk/gtk.h>
31 #include "../color.h"
33 #include "ui/simple_dialog.h"
35 #include "ui/gtk/gui_utils.h"
36 #include "ui/gtk/color_utils.h"
37 #include "ui/gtk/gtkglobals.h"
38 #if 0
39 static GdkColormap* sys_cmap;
40 static GdkColormap* our_cmap = NULL;
41 #endif
42 GdkColor WHITE = { 0, 65535, 65535, 65535 };
43 /*GdkColor LTGREY = { 0, 57343, 57343, 57343 };*/
44 GdkColor BLACK = { 0, 0, 0, 0 };
47 * Initialize a color with R, G, and B values, including any toolkit-dependent
48 * work that needs to be done.
49 * Returns TRUE if it succeeds, FALSE if it fails.
51 gboolean
52 initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue)
54 GdkColor gdk_color;
56 gdk_color.pixel = 0;
57 gdk_color.red = red;
58 gdk_color.green = green;
59 gdk_color.blue = blue;
60 #if 0
61 if (!get_color(&gdk_color))
62 return FALSE;
63 #endif
64 gdkcolor_to_color_t(color, &gdk_color);
65 return TRUE;
68 /* Initialize the colors */
69 void
70 colors_init(void)
72 #if 0
73 gboolean got_white, got_black;
75 sys_cmap = gdk_colormap_get_system();
77 /* Allocate "constant" colors. */
78 got_white = get_color(&WHITE);
79 got_black = get_color(&BLACK);
80 /* Got milk? */
81 if (!got_white) {
82 if (!got_black)
83 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
84 "Could not allocate colors black or white.");
85 else
86 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
87 "Could not allocate color white.");
88 } else {
89 if (!got_black)
90 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
91 "Could not allocate color black.");
93 #endif
96 #if 0
97 /* allocate a color from the color map */
98 gboolean
99 get_color(GdkColor *new_color)
101 GdkVisual *pv;
103 if (!our_cmap) {
104 if (!gdk_colormap_alloc_color (sys_cmap, new_color, FALSE,
105 TRUE)) {
106 pv = gdk_visual_get_best();
107 if (!(our_cmap = gdk_colormap_new(pv, TRUE))) {
108 simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
109 "Could not create new colormap");
111 } else
112 return (TRUE);
114 return (gdk_colormap_alloc_color(our_cmap, new_color, FALSE, TRUE));
116 #endif
118 void
119 color_t_to_gdkcolor(GdkColor *target, const color_t *source)
121 target->pixel = source->pixel;
122 target->red = source->red;
123 target->green = source->green;
124 target->blue = source->blue;
127 void
128 color_t_to_gdkRGBAcolor(GdkRGBA *target, const color_t *source)
130 target->alpha = 1;
131 target->red = source->red / 65535.0;
132 target->green = source->green / 65535.0;
133 target->blue = source->blue / 65535.0;
135 void
136 gdkcolor_to_color_t(color_t *target, const GdkColor *source)
138 target->pixel = source->pixel;
139 target->red = source->red;
140 target->green = source->green;
141 target->blue = source->blue;
144 void
145 gdkRGBAcolor_to_color_t(color_t *target, const GdkRGBA *source)
147 target->pixel = 0;
148 target->red = (guint16)(source->red*65535);
149 target->green = (guint16)(source->green*65535);
150 target->blue = (guint16)(source->blue*65535);
154 void
155 GdkColor_to_GdkRGBA(GdkRGBA *target, const GdkColor *source)
157 target->alpha = 1;
158 target->red = (double)source->red / 65535.0;
159 target->green = (double)source->green / 65535.0;
160 target->blue = (double)source->blue / 65535.0;
163 void
164 gdkRGBAcolor_to_GdkColor(GdkColor *target, const GdkRGBA *source)
166 target->pixel = 0;
167 target->red = (guint16)(source->red*65535);
168 target->green = (guint16)(source->green*65535);
169 target->blue = (guint16)(source->blue*65535);