diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-07-24 00:35:13 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-07-24 00:35:13 +0000 |
commit | 34de3c15d994d65a99b65d0dd55b0e2208685b3b (patch) | |
tree | 40889b5cba6f301462f8498de380ddf094003047 /gtk | |
parent | 8f79902cb339f422956fedac39037884ca6c8729 (diff) |
Have "gtk/color_utils.c" contain routines with toolkit-independent APIs,
but toolkit-dependent implementations, for manipulating colors, and have
"gtk/color_utils.h" declare them (the header file should eventually be
moved to the top-level directory). Move the routines to convert between
GdkColor and color_t out of there into "colors.c", and move their
declarations into "colors.h", as their APIs are toolkit-dependent.
Have the first such routine be a "create_color()" routine, which takes
RGB values and initializes a "color_t", including doing any
toolkit-dependent work necessary for that; use that in the
"gtk/color_filters.c" code (the goal is to remove as many of the toolkit
dependencies as possible from that code, and move it to the top-level
directory).
svn path=/trunk/; revision=11497
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/color_dlg.c | 1 | ||||
-rw-r--r-- | gtk/color_filters.c | 13 | ||||
-rw-r--r-- | gtk/color_utils.c | 39 | ||||
-rw-r--r-- | gtk/color_utils.h | 24 | ||||
-rw-r--r-- | gtk/colors.c | 20 | ||||
-rw-r--r-- | gtk/colors.h | 14 | ||||
-rw-r--r-- | gtk/follow_dlg.c | 2 | ||||
-rw-r--r-- | gtk/main.c | 1 | ||||
-rw-r--r-- | gtk/packet_list.c | 2 | ||||
-rw-r--r-- | gtk/stream_prefs.c | 2 |
10 files changed, 69 insertions, 49 deletions
diff --git a/gtk/color_dlg.c b/gtk/color_dlg.c index 6d5118e210..1a45a943df 100644 --- a/gtk/color_dlg.c +++ b/gtk/color_dlg.c @@ -36,7 +36,6 @@ #include "colors.h" #include "color_filters.h" #include "color_dlg.h" -#include "color_utils.h" #include "file.h" #include <epan/dfilter/dfilter.h> #include "simple_dialog.h" diff --git a/gtk/color_filters.c b/gtk/color_filters.c index e3b64af3dc..f36852ac0c 100644 --- a/gtk/color_filters.c +++ b/gtk/color_filters.c @@ -242,7 +242,6 @@ read_filters_file(FILE *f, gpointer arg) /* we got a complete color filter */ - GdkColor gdk_fg_color, gdk_bg_color; color_t bg_color, fg_color; color_filter_t *colorf; dfilter_t *temp_dfilter; @@ -255,10 +254,7 @@ read_filters_file(FILE *f, gpointer arg) continue; } - gdk_fg_color.red = fg_r; - gdk_fg_color.green = fg_g; - gdk_fg_color.blue = fg_b; - if (!get_color(&gdk_fg_color)) { + if (!create_color(&fg_color, fg_r, fg_g, fg_b)) { /* oops */ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not allocate foreground color " @@ -267,11 +263,7 @@ read_filters_file(FILE *f, gpointer arg) skip_end_of_line = TRUE; continue; } - gdkcolor_to_color_t(&fg_color, &gdk_fg_color); - gdk_bg_color.red = bg_r; - gdk_bg_color.green = bg_g; - gdk_bg_color.blue = bg_b; - if (!get_color(&gdk_bg_color)) { + if (!create_color(&bg_color, bg_r, bg_g, bg_b)) { /* oops */ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not allocate background color " @@ -280,7 +272,6 @@ read_filters_file(FILE *f, gpointer arg) skip_end_of_line = TRUE; continue; } - gdkcolor_to_color_t(&bg_color, &gdk_bg_color); colorf = new_color_filter(name, filter_exp, &bg_color, &fg_color); diff --git a/gtk/color_utils.c b/gtk/color_utils.c index 6fca4eadfa..ae72adfa91 100644 --- a/gtk/color_utils.c +++ b/gtk/color_utils.c @@ -1,14 +1,12 @@ /* color_utils.c - * Utilities for converting between "toolkit-independent" and GDK - * notions of color + * Toolkit-dependent implementations of routines to handle colors. * * $Id$ * * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> + * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 Gerald Combs * - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 @@ -30,22 +28,25 @@ #include <gtk/gtk.h> -#include "color.h" /* to declare "color_t" */ +#include "color.h" -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; -} +#include "color_utils.h" -void -gdkcolor_to_color_t(color_t *target, GdkColor *source) +/* + * Create a color from R, G, and B values, and do whatever toolkit-dependent + * work needs to be done. + * Returns TRUE if it succeeds, FALSE if it fails. + */ +gboolean +create_color(color_t *color, guint16 red, guint16 green, guint16 blue) { - target->pixel = source->pixel; - target->red = source->red; - target->green = source->green; - target->blue = source->blue; + GdkColor gdk_color; + + gdk_color.red = red; + gdk_color.green = green; + gdk_color.blue = blue; + if (!get_color(&gdk_color)) + return FALSE; + gdkcolor_to_color_t(color, &gdk_color); + return TRUE; } diff --git a/gtk/color_utils.h b/gtk/color_utils.h index 36f27ce2f9..28ebbf689a 100644 --- a/gtk/color_utils.h +++ b/gtk/color_utils.h @@ -5,10 +5,9 @@ * $Id$ * * Ethereal - Network traffic analyzer - * By Gerald Combs <gerald@zing.org> + * By Gerald Combs <gerald@ethereal.com> * Copyright 1998 Gerald Combs * - * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 @@ -28,22 +27,19 @@ #define __COLOR_UTILS_H__ /** @file - * Utilities for converting between "toolkit-independent" - * and GDK notions of color. - */ - -/** Convert color_t to GdkColor. - * - * @param target the GdkColor to be filled - * @param source the source color_t + * Toolkit-dependent implementations of routines to handle colors. */ -void color_t_to_gdkcolor(GdkColor *target, color_t *source); -/** Convert GdkColor to color_t. +/** Create a color from R, G, and B values, and do whatever toolkit-dependent + ** work needs to be done. * - * @param target the source color_t + * @param color the color_t to be filled + * @param red the red value for the color + * @param green the green value for the color + * @param blue the blue value for the color * @param source the GdkColor to be filled + * @return TRUE if it succeeds, FALSE if it fails */ -void gdkcolor_to_color_t(color_t *target, GdkColor *source); +gboolean create_color(color_t *color, guint16 red, guint16 green, guint16 blue); #endif diff --git a/gtk/colors.c b/gtk/colors.c index 3d9ad7f1ce..b0b1766347 100644 --- a/gtk/colors.c +++ b/gtk/colors.c @@ -29,6 +29,8 @@ #include <string.h> +#include "color.h" /* to declare "color_t" */ + #include "colors.h" #include "simple_dialog.h" #include "gtkglobals.h" @@ -85,3 +87,21 @@ get_color(GdkColor *new_color) } 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; +} diff --git a/gtk/colors.h b/gtk/colors.h index 4ff136d8c2..8f4c1100c6 100644 --- a/gtk/colors.h +++ b/gtk/colors.h @@ -44,4 +44,18 @@ void colors_init(void); */ gboolean get_color(GdkColor *new_color); +/** Convert color_t to GdkColor. + * + * @param target the GdkColor to be filled + * @param source the source color_t + */ +void color_t_to_gdkcolor(GdkColor *target, color_t *source); + +/** Convert GdkColor to color_t. + * + * @param target the source color_t + * @param source the GdkColor to be filled + */ +void gdkcolor_to_color_t(color_t *target, GdkColor *source); + #endif diff --git a/gtk/follow_dlg.c b/gtk/follow_dlg.c index 1ef0a8df93..1fb308edcf 100644 --- a/gtk/follow_dlg.c +++ b/gtk/follow_dlg.c @@ -43,7 +43,7 @@ #include "isprint.h" #include "color.h" -#include "color_utils.h" +#include "colors.h" #include "file.h" #include "follow_dlg.h" #include "follow.h" diff --git a/gtk/main.c b/gtk/main.c index e46737fddb..2e0ebd0634 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -90,7 +90,6 @@ #include "layout_prefs.h" #include "color.h" #include "color_filters.h" -#include "color_utils.h" #include "print.h" #include "simple_dialog.h" #include "register.h" diff --git a/gtk/packet_list.c b/gtk/packet_list.c index abf61293d4..ff996a3652 100644 --- a/gtk/packet_list.c +++ b/gtk/packet_list.c @@ -37,7 +37,7 @@ #include "ui_util.h" #include "main.h" #include "menu.h" -#include "color_utils.h" +#include "colors.h" #include "column.h" #include "epan/column_info.h" #include "compat_macros.h" diff --git a/gtk/stream_prefs.c b/gtk/stream_prefs.c index bac2ebfac1..ebf80dfd0e 100644 --- a/gtk/stream_prefs.c +++ b/gtk/stream_prefs.c @@ -29,7 +29,7 @@ #include <gtk/gtk.h> #include "color.h" -#include "color_utils.h" +#include "colors.h" #include "globals.h" #include "stream_prefs.h" #include "keys.h" |