diff options
Diffstat (limited to 'gtk/color_utils.c')
-rw-r--r-- | gtk/color_utils.c | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/gtk/color_utils.c b/gtk/color_utils.c index cee6d8a955..abe531d4d6 100644 --- a/gtk/color_utils.c +++ b/gtk/color_utils.c @@ -25,12 +25,25 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include <string.h> + #include <gtk/gtk.h> #include "../color.h" +#include "../simple_dialog.h" + +#include "gtk/color_utils.h" +#include "gtk/gtkglobals.h" + + +static GdkColormap* sys_cmap; +static GdkColormap* our_cmap = NULL; + +GdkColor WHITE = { 0, 65535, 65535, 65535 }; +GdkColor LTGREY = { 0, 57343, 57343, 57343 }; +GdkColor BLACK = { 0, 0, 0, 0 }; -#include "gtk/colors.h" /* * Initialize a color with R, G, and B values, including any toolkit-dependent @@ -50,3 +63,68 @@ initialize_color(color_t *color, guint16 red, guint16 green, guint16 blue) gdkcolor_to_color_t(color, &gdk_color); return TRUE; } + +/* Initialize the colors */ +void +colors_init(void) +{ + gboolean got_white, got_black; + + sys_cmap = gdk_colormap_get_system(); + + /* Allocate "constant" colors. */ + got_white = get_color(&WHITE); + got_black = get_color(&BLACK); + + /* Got milk? */ + if (!got_white) { + if (!got_black) + simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, + "Could not allocate colors black or white."); + else + simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, + "Could not allocate color white."); + } else { + if (!got_black) + simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, + "Could not allocate color black."); + } +} + +/* allocate a color from the color map */ +gboolean +get_color(GdkColor *new_color) +{ + GdkVisual *pv; + + if (!our_cmap) { + if (!gdk_colormap_alloc_color (sys_cmap, new_color, FALSE, + TRUE)) { + pv = gdk_visual_get_best(); + if (!(our_cmap = gdk_colormap_new(pv, TRUE))) { + simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK, + "Could not create new colormap"); + } + } else + return (TRUE); + } + return (gdk_colormap_alloc_color(our_cmap, new_color, FALSE, TRUE)); +} + +void +color_t_to_gdkcolor(GdkColor *target, color_t *source) +{ + target->pixel = source->pixel; + target->red = source->red; + target->green = source->green; + target->blue = source->blue; +} + +void +gdkcolor_to_color_t(color_t *target, GdkColor *source) +{ + target->pixel = source->pixel; + target->red = source->red; + target->green = source->green; + target->blue = source->blue; +} |