forked from osmocom/wireshark
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
This commit is contained in:
parent
8f79902cb3
commit
34de3c15d9
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
* Toolkit-dependent implementations of routines to handle colors.
|
||||
*/
|
||||
|
||||
/** Convert color_t to GdkColor.
|
||||
/** Create a color from R, G, and B values, and do whatever toolkit-dependent
|
||||
** work needs to be done.
|
||||
*
|
||||
* @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 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
|
||||
|
|
20
gtk/colors.c
20
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;
|
||||
}
|
||||
|
|
14
gtk/colors.h
14
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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue