diff options
author | Anders Broman <anders.broman@ericsson.com> | 2013-01-04 17:07:26 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2013-01-04 17:07:26 +0000 |
commit | d9d58c34f298a0c3340bfb01976ffe0c7a49c317 (patch) | |
tree | b16578a07fdd3acaff62dd0204d2f9f97b885c53 /ui | |
parent | 886ac9a613b48746c2a9f389de96a92a4b3ffcb6 (diff) |
Add a wrapper for gdk_cairo_set_source_rgba() in GTK2 and use it in io_stat.c
svn path=/trunk/; revision=46932
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gtk/color_utils.c | 27 | ||||
-rw-r--r-- | ui/gtk/color_utils.h | 10 | ||||
-rw-r--r-- | ui/gtk/gui_utils.c | 18 | ||||
-rw-r--r-- | ui/gtk/gui_utils.h | 8 | ||||
-rw-r--r-- | ui/gtk/io_stat.c | 17 |
5 files changed, 61 insertions, 19 deletions
diff --git a/ui/gtk/color_utils.c b/ui/gtk/color_utils.c index dcc8813b8d..d90b41c525 100644 --- a/ui/gtk/color_utils.c +++ b/ui/gtk/color_utils.c @@ -32,6 +32,7 @@ #include "ui/simple_dialog.h" +#include "ui/gtk/gui_utils.h" #include "ui/gtk/color_utils.h" #include "ui/gtk/gtkglobals.h" #if 0 @@ -113,6 +114,7 @@ get_color(GdkColor *new_color) return (gdk_colormap_alloc_color(our_cmap, new_color, FALSE, TRUE)); } #endif + void color_t_to_gdkcolor(GdkColor *target, const color_t *source) { @@ -121,7 +123,7 @@ color_t_to_gdkcolor(GdkColor *target, const color_t *source) target->green = source->green; target->blue = source->blue; } -#if GTK_CHECK_VERSION(3,0,0) + void color_t_to_gdkRGBAcolor(GdkRGBA *target, const color_t *source) { @@ -130,7 +132,6 @@ color_t_to_gdkRGBAcolor(GdkRGBA *target, const color_t *source) target->green = source->green / 65535.0; target->blue = source->blue / 65535.0; } -#endif void gdkcolor_to_color_t(color_t *target, const GdkColor *source) { @@ -139,7 +140,7 @@ gdkcolor_to_color_t(color_t *target, const GdkColor *source) target->green = source->green; target->blue = source->blue; } -#if GTK_CHECK_VERSION(3,0,0) + void gdkRGBAcolor_to_color_t(color_t *target, const GdkRGBA *source) { @@ -148,5 +149,23 @@ gdkRGBAcolor_to_color_t(color_t *target, const GdkRGBA *source) target->green = (guint16)(source->green*65535); target->blue = (guint16)(source->blue*65535); } -#endif + + +void +GdkColor_to_GdkRGBA(GdkRGBA *target, const GdkColor *source) +{ + target->alpha = 1; + target->red = (double)source->red / 65535.0; + target->green = (double)source->green / 65535.0; + target->blue = (double)source->blue / 65535.0; +} + +void +gdkRGBAcolor_to_GdkColor(GdkColor *target, const GdkRGBA *source) +{ + target->pixel = 0; + target->red = (guint16)(source->red*65535); + target->green = (guint16)(source->green*65535); + target->blue = (guint16)(source->blue*65535); +} diff --git a/ui/gtk/color_utils.h b/ui/gtk/color_utils.h index 91ca97eac4..6f29625160 100644 --- a/ui/gtk/color_utils.h +++ b/ui/gtk/color_utils.h @@ -25,6 +25,8 @@ #ifndef __COLORS_H__ #define __COLORS_H__ +#include "ui/gtk/gui_utils.h" + /** @file * Definitions for color structures and routines */ @@ -49,22 +51,22 @@ void colors_init(void); #if 0 gboolean get_color(GdkColor *new_color); #endif + /** 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, const color_t *source); -#if GTK_CHECK_VERSION(3,0,0) void color_t_to_gdkRGBAcolor(GdkRGBA *target, const color_t *source); -#endif /** 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, const GdkColor *source); -#if GTK_CHECK_VERSION(3,0,0) void gdkRGBAcolor_to_color_t(color_t *target, const GdkRGBA *source); -#endif + +void GdkColor_to_GdkRGBA(GdkRGBA *target, const GdkColor *source); +void gdkRGBAcolor_to_GdkColor(GdkColor *target, const GdkRGBA *source); #endif /* __COLORS_H__ */ diff --git a/ui/gtk/gui_utils.c b/ui/gtk/gui_utils.c index b03126757e..1c6aa8f74d 100644 --- a/ui/gtk/gui_utils.c +++ b/ui/gtk/gui_utils.c @@ -50,6 +50,7 @@ #include "ui/gtk/gtkglobals.h" #include "ui/gtk/gui_utils.h" #include "ui/gtk/font_utils.h" +#include "ui/gtk/color_utils.h" #include "ui/gtk/old-gtk-compat.h" @@ -2040,7 +2041,6 @@ gtk_separator_new(GtkOrientation orientation) */ #if !GTK_CHECK_VERSION(3,0,0) - #else /* GTK3 */ void @@ -2093,4 +2093,20 @@ ws_gtk_grid_set_homogeneous(GtkGrid *grid, gboolean homogeneous) gtk_grid_set_column_homogeneous(grid, homogeneous); } +/* + * Wrapp gdk_cairo_set_source_color() with the GTK 3 equivalent + * to be used in GTK2 + */ +#if !GTK_CHECK_VERSION(3,0,0) +void +gdk_cairo_set_source_rgba(cairo_t *cr, const GdkRGBA *rgba) +{ + GdkColor color; + + gdkRGBAcolor_to_GdkColor(&color, rgba); + + gdk_cairo_set_source_color(cr, &color); + +} +#endif /* !GTK_CHECK_VERSION(3,0,0) */ #endif /* GTK_CHECK_VERSION(3,0,0) */ diff --git a/ui/gtk/gui_utils.h b/ui/gtk/gui_utils.h index a17b78a4eb..8c14f49dfd 100644 --- a/ui/gtk/gui_utils.h +++ b/ui/gtk/gui_utils.h @@ -530,10 +530,18 @@ GdkPixbuf *gdk_pixbuf_get_from_surface (cairo_surface_t *surface, GtkWidget * ws_gtk_box_new(GtkOrientation orientation, gint spacing, gboolean homogeneous); #if !GTK_CHECK_VERSION(3,0,0) +typedef struct { + gdouble red; + gdouble green; + gdouble blue; + gdouble alpha; +} GdkRGBA; + GtkWidget * gtk_button_box_new(GtkOrientation orientation); GtkWidget * gtk_scrollbar_new(GtkOrientation orientation, GtkAdjustment *adjustment); GtkWidget * gtk_paned_new(GtkOrientation orientation); GtkWidget * gtk_separator_new (GtkOrientation orientation); +void gdk_cairo_set_source_rgba(cairo_t *cr, const GdkRGBA *rgba); #endif /* GTK_CHECK_VERSION(3,0,0) */ diff --git a/ui/gtk/io_stat.c b/ui/gtk/io_stat.c index f6f499444a..6cf64abada 100644 --- a/ui/gtk/io_stat.c +++ b/ui/gtk/io_stat.c @@ -54,6 +54,7 @@ #include "ui/main_statusbar.h" #include "ui/gtk/old-gtk-compat.h" +#include "ui/gtk/gui_utils.h" #define MAX_GRAPHS 5 @@ -152,9 +153,7 @@ typedef struct _io_stat_graph_t { int hf_index; GtkWidget *calc_field; GdkColor color; -#if GTK_CHECK_VERSION(3,0,0) GdkRGBA rgba_color; -#endif construct_args_t *args; GtkWidget *filter_bt; @@ -1165,7 +1164,7 @@ static void if( (prev_y_pos!=0) || (y_pos!=0) ){ cairo_move_to(cr, prev_x_pos+0.5, prev_y_pos+0.5); cairo_line_to(cr, x_pos+0.5, y_pos+0.5); - gdk_cairo_set_source_color (cr, &io->graphs[i].color); + gdk_cairo_set_source_rgba (cr, &io->graphs[i].rgba_color); cairo_stroke(cr); } break; @@ -1173,7 +1172,7 @@ static void if(val){ cairo_move_to(cr, x_pos+0.5, draw_height-1+top_y_border+0.5); cairo_line_to(cr, x_pos+0.5, y_pos+0.5); - gdk_cairo_set_source_color (cr, &io->graphs[i].color); + gdk_cairo_set_source_rgba (cr, &io->graphs[i].rgba_color); cairo_stroke(cr); } break; @@ -1184,7 +1183,7 @@ static void y_pos+0.5, io->pixels_per_tick, draw_height-1+top_y_border-y_pos); - gdk_cairo_set_source_color (cr, &io->graphs[i].color); + gdk_cairo_set_source_rgba (cr, &io->graphs[i].rgba_color); cairo_fill (cr); } break; @@ -1196,7 +1195,7 @@ static void (gdouble)io->pixels_per_tick/2, 0, 2 * G_PI); - gdk_cairo_set_source_color (cr, &io->graphs[i].color); + gdk_cairo_set_source_rgba (cr, &io->graphs[i].rgba_color); cairo_fill (cr); } break; @@ -1333,7 +1332,7 @@ iostat_init(const char *opt_arg _U_, void* userdata _U_) {0, 0x0000, 0x0000, 0xffff}, /* Blue */ {0, 0xffff, 0x5000, 0xffff} /* Light brilliant magenta */ }; -#if GTK_CHECK_VERSION(3,0,0) + static GdkRGBA rgba_col[MAX_GRAPHS] = { {0.0, 0.0, 0.0, 1.0}, /* Black */ {1.0, 0.0, 0.1, 1.0}, /* Red */ @@ -1341,7 +1340,7 @@ iostat_init(const char *opt_arg _U_, void* userdata _U_) {0.0, 0.0, 1.0, 1.0}, /* Blue */ {1.0, 0.314, 1.0, 1.0} /* Light brilliant magenta */ }; -#endif + GString *error_string; io=g_new(io_stat_t,1); @@ -1375,12 +1374,10 @@ iostat_init(const char *opt_arg _U_, void* userdata _U_) io->graphs[i].color.red=col[i].red; io->graphs[i].color.green=col[i].green; io->graphs[i].color.blue=col[i].blue; -#if GTK_CHECK_VERSION(3,0,0) io->graphs[i].rgba_color.red=rgba_col[i].red; io->graphs[i].rgba_color.green=rgba_col[i].green; io->graphs[i].rgba_color.blue=rgba_col[i].blue; io->graphs[i].rgba_color.alpha=rgba_col[i].alpha; -#endif io->graphs[i].display=0; io->graphs[i].display_button=NULL; io->graphs[i].filter_field=NULL; |