From 6c00fe9f6e32f702f5887d6145f8b88e2e09de3d Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Tue, 1 May 2007 03:29:27 +0000 Subject: [PATCH] 2007-04-30 Jim Evins * src/color.h: * src/color.c: (gl_color_shadow), (gl_color_node_new_default), (gl_color_node_equal), (gl_color_node_expand): * src/label-barcode.c: (draw_object): * src/label-box.c: (draw_object), (draw_shadow): * src/label-ellipse.c: (draw_object), (draw_shadow): * src/label-line.c: (draw_object), (draw_shadow): * src/label-text.c: (draw_object), (draw_shadow): * src/wdgt-mini-preview.c: (draw_shadow), (draw_labels): * src/wdgt-rotate-label.c: (drawingarea_update): Some cleanup to color related code. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@656 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- glabels2/ChangeLog | 14 +++++ glabels2/src/color.c | 93 +++++++++++++++++++------------- glabels2/src/color.h | 58 ++++++++++++++------ glabels2/src/label-barcode.c | 6 +-- glabels2/src/label-box.c | 24 ++------- glabels2/src/label-ellipse.c | 24 ++------- glabels2/src/label-line.c | 12 +---- glabels2/src/label-text.c | 14 +---- glabels2/src/wdgt-mini-preview.c | 10 +--- glabels2/src/wdgt-rotate-label.c | 15 ++---- 10 files changed, 130 insertions(+), 140 deletions(-) diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 4b91d90a..997bc085 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,17 @@ +2007-04-30 Jim Evins + + * src/color.h: + * src/color.c: (gl_color_shadow), (gl_color_node_new_default), + (gl_color_node_equal), (gl_color_node_expand): + * src/label-barcode.c: (draw_object): + * src/label-box.c: (draw_object), (draw_shadow): + * src/label-ellipse.c: (draw_object), (draw_shadow): + * src/label-line.c: (draw_object), (draw_shadow): + * src/label-text.c: (draw_object), (draw_shadow): + * src/wdgt-mini-preview.c: (draw_shadow), (draw_labels): + * src/wdgt-rotate-label.c: (drawingarea_update): + Some cleanup to color related code. + 2007-04-30 Jim Evins * src/label.h: diff --git a/glabels2/src/color.c b/glabels2/src/color.c index 65445559..e8c039dc 100644 --- a/glabels2/src/color.c +++ b/glabels2/src/color.c @@ -42,7 +42,23 @@ gl_color_set_opacity (guint color, } /*****************************************************************************/ -/* Convert canvas color into a GdkColor */ +/* Resolve actual shadow color by adjusting opacity. */ +/*****************************************************************************/ +guint +gl_color_shadow (guint base_color, + gdouble opacity, + guint object_color) +{ + guint color; + + color = gl_color_set_opacity (base_color, + opacity * GL_COLOR_F_ALPHA (object_color)); + + return color; +} + +/*****************************************************************************/ +/* Convert gLabels color into a GdkColor */ /*****************************************************************************/ GdkColor * gl_color_to_gdk_color (guint color) @@ -59,7 +75,7 @@ gl_color_to_gdk_color (guint color) } /*****************************************************************************/ -/* Convert GdkColor into a canvas color */ +/* Convert GdkColor into a gLabels color */ /*****************************************************************************/ guint gl_color_from_gdk_color (GdkColor *gdk_color) @@ -73,27 +89,11 @@ gl_color_from_gdk_color (GdkColor *gdk_color) return color; } -/*****************************************************************************/ -/* Resolve actual shadow color by adjusting opacity. */ -/*****************************************************************************/ -guint -gl_color_shadow (guint base_color, - gdouble opacity, - guint object_color) -{ - guint color; - - color = gl_color_set_opacity (base_color, - opacity * GL_COLOR_F_ALPHA (object_color)); - - return color; -} - /****************************************************************************/ /* Create a single color node with default color. */ /****************************************************************************/ glColorNode * -gl_color_node_new_default () +gl_color_node_new_default (void) { glColorNode* color_node; @@ -137,32 +137,42 @@ gl_color_node_dup (glColorNode *src) /****************************************************************************/ gboolean gl_color_node_equal (glColorNode *color_node1, - glColorNode *color_node2) + glColorNode *color_node2) { /* First take care of the case of either or both being NULL. */ - if ( color_node1 == NULL ) { + if ( color_node1 == NULL ) + { return ( color_node2 == NULL ); - } else { - if ( color_node2 == NULL ) { + } + else + { + if ( color_node2 == NULL ) + { return FALSE; } } /* Bail if field flags differ. */ - if ( color_node1->field_flag != color_node2->field_flag ) { + if ( color_node1->field_flag != color_node2->field_flag ) + { return FALSE; } /* Now take care of the case of either or both color fields being different. */ - if ( color_node1->color != color_node2->color ){ + if ( color_node1->color != color_node2->color ) + { return FALSE; } /* Then take care of the case of either or both key fields being NULL. */ - if ( color_node1->key == NULL ) { + if ( color_node1->key == NULL ) + { return ( color_node2->key == NULL ); - } else { - if ( color_node2->key == NULL ) { + } + else + { + if ( color_node2->key == NULL ) + { return FALSE; } } @@ -176,18 +186,23 @@ gl_color_node_equal (glColorNode *color_node1, /****************************************************************************/ guint gl_color_node_expand (glColorNode *color_node, - glMergeRecord *record) + glMergeRecord *record) { - gchar* text; + gchar *text; GdkColor *gdk_color; - guint color; + guint color; - if (color_node->field_flag) { - if (record == NULL) { + if (color_node->field_flag) + { + if (record == NULL) + { return GL_COLOR_NONE; - } else { + } + else + { text = gl_merge_eval_key (record, color_node->key); - if (text != NULL) { + if (text != NULL) + { gdk_color = g_new0 (GdkColor, 1); if (gdk_color_parse (text, gdk_color)) { @@ -200,11 +215,15 @@ gl_color_node_expand (glColorNode *color_node, g_free (gdk_color); return GL_COLOR_NONE; } - } else { + } + else + { return GL_COLOR_NONE; } } - } else { + } + else + { return color_node->color; } } diff --git a/glabels2/src/color.h b/glabels2/src/color.h index 1faaa66a..c4403ad5 100644 --- a/glabels2/src/color.h +++ b/glabels2/src/color.h @@ -30,13 +30,9 @@ G_BEGIN_DECLS -typedef struct { - gboolean field_flag; - guint color; - gchar *key; -} glColorNode; - - +/* + * gLabels stores colors as a 32-bit unsigned integer in RGBA format (MSByte = Red) + */ #define GL_COLOR(r,g,b) ( (((unsigned int) (r) & 0xff) << 24) \ | (((unsigned int) (g) & 0xff) << 16) \ | (((unsigned int) (b) & 0xff) << 8) \ @@ -55,30 +51,60 @@ typedef struct { #define GL_COLOR_SHADOW_MERGE_DEFAULT GL_COLOR_A(0,0,0,255) -#define GL_COLOR_I_RED(x) (((x)>>24) & 0xff) -#define GL_COLOR_I_GREEN(x) (((x)>>16) & 0xff) -#define GL_COLOR_I_BLUE(x) (((x)>>8) & 0xff) -#define GL_COLOR_I_ALPHA(x) ( (x) & 0xff) - +/* + * Extract components as floating point (0.0 .. 1.0) + */ #define GL_COLOR_F_RED(x) ( (((x)>>24) & 0xff) / 255.0 ) #define GL_COLOR_F_GREEN(x) ( (((x)>>16) & 0xff) / 255.0 ) #define GL_COLOR_F_BLUE(x) ( (((x)>>8) & 0xff) / 255.0 ) #define GL_COLOR_F_ALPHA(x) ( ( (x) & 0xff) / 255.0 ) +/* + * Extract arguments for cairo_set_source_rgb() + */ +#define GL_COLOR_RGB_ARGS(x) \ + GL_COLOR_F_RED(x), \ + GL_COLOR_F_GREEN(x), \ + GL_COLOR_F_BLUE(x) + +/* + * Extract arguments for cairo_set_source_rgba() + */ +#define GL_COLOR_RGBA_ARGS(x) \ + GL_COLOR_F_RED(x), \ + GL_COLOR_F_GREEN(x), \ + GL_COLOR_F_BLUE(x), \ + GL_COLOR_F_ALPHA(x) + + + guint gl_color_set_opacity (guint color, gdouble opacity); +guint gl_color_shadow (guint base_color, + gdouble opacity, + guint object_color); + +/* + * Routines to convert to/from GdkColor. + */ GdkColor *gl_color_to_gdk_color (guint color); guint gl_color_from_gdk_color (GdkColor *gdk_color); -guint gl_color_shadow (guint base_color, - gdouble opacity, - guint object_color); -glColorNode *gl_color_node_new_default (); +/* + * Color nodes + */ +typedef struct { + gboolean field_flag; + guint color; + gchar *key; +} glColorNode; + +glColorNode *gl_color_node_new_default (void); glColorNode *gl_color_node_dup (glColorNode *color_node); gboolean gl_color_node_equal (glColorNode *color_node1, diff --git a/glabels2/src/label-barcode.c b/glabels2/src/label-barcode.c index 7cf6feaa..9f93d011 100644 --- a/glabels2/src/label-barcode.c +++ b/glabels2/src/label-barcode.c @@ -398,11 +398,7 @@ draw_object (glLabelObject *object, gbc = gl_barcode_new (id, text_flag, checksum_flag, w, h, text); - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (color), - GL_COLOR_F_GREEN (color), - GL_COLOR_F_BLUE (color), - GL_COLOR_F_ALPHA (color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (color)); if (gbc == NULL) { diff --git a/glabels2/src/label-box.c b/glabels2/src/label-box.c index 06084c3b..a42ad75b 100644 --- a/glabels2/src/label-box.c +++ b/glabels2/src/label-box.c @@ -315,19 +315,11 @@ draw_object (glLabelObject *object, cairo_rectangle (cr, 0.0, 0.0, w, h); /* Paint fill color */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (fill_color), - GL_COLOR_F_GREEN (fill_color), - GL_COLOR_F_BLUE (fill_color), - GL_COLOR_F_ALPHA (fill_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (fill_color)); cairo_fill_preserve (cr); /* Draw outline */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (line_color), - GL_COLOR_F_GREEN (line_color), - GL_COLOR_F_BLUE (line_color), - GL_COLOR_F_ALPHA (line_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (line_color)); cairo_set_line_width (cr, line_width); cairo_stroke (cr); @@ -392,19 +384,11 @@ draw_shadow (glLabelObject *object, /* Draw fill shadow */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (shadow_fill_color), - GL_COLOR_F_GREEN (shadow_fill_color), - GL_COLOR_F_BLUE (shadow_fill_color), - GL_COLOR_F_ALPHA (shadow_fill_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_fill_color)); cairo_fill_preserve (cr); /* Draw outline shadow */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (shadow_line_color), - GL_COLOR_F_GREEN (shadow_line_color), - GL_COLOR_F_BLUE (shadow_line_color), - GL_COLOR_F_ALPHA (shadow_line_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_line_color)); cairo_set_line_width (cr, line_width); cairo_stroke (cr); diff --git a/glabels2/src/label-ellipse.c b/glabels2/src/label-ellipse.c index 9b955edc..efc8dd88 100644 --- a/glabels2/src/label-ellipse.c +++ b/glabels2/src/label-ellipse.c @@ -320,19 +320,11 @@ draw_object (glLabelObject *object, gl_cairo_ellipse_path (cr, w/2, h/2); /* Paint fill color */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (fill_color), - GL_COLOR_F_GREEN (fill_color), - GL_COLOR_F_BLUE (fill_color), - GL_COLOR_F_ALPHA (fill_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (fill_color)); cairo_fill_preserve (cr); /* Draw outline */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (line_color), - GL_COLOR_F_GREEN (line_color), - GL_COLOR_F_BLUE (line_color), - GL_COLOR_F_ALPHA (line_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (line_color)); cairo_set_line_width (cr, line_width); cairo_stroke (cr); @@ -397,19 +389,11 @@ draw_shadow (glLabelObject *object, /* Draw fill shadow */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (shadow_fill_color), - GL_COLOR_F_GREEN (shadow_fill_color), - GL_COLOR_F_BLUE (shadow_fill_color), - GL_COLOR_F_ALPHA (shadow_fill_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_fill_color)); cairo_fill_preserve (cr); /* Draw outline shadow */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (shadow_line_color), - GL_COLOR_F_GREEN (shadow_line_color), - GL_COLOR_F_BLUE (shadow_line_color), - GL_COLOR_F_ALPHA (shadow_line_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_line_color)); cairo_set_line_width (cr, line_width); cairo_stroke (cr); diff --git a/glabels2/src/label-line.c b/glabels2/src/label-line.c index 4543b3b0..b3eae407 100644 --- a/glabels2/src/label-line.c +++ b/glabels2/src/label-line.c @@ -259,11 +259,7 @@ draw_object (glLabelObject *object, /* Draw line */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (line_color), - GL_COLOR_F_GREEN (line_color), - GL_COLOR_F_BLUE (line_color), - GL_COLOR_F_ALPHA (line_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (line_color)); cairo_set_line_width (cr, line_width); cairo_stroke (cr); @@ -314,11 +310,7 @@ draw_shadow (glLabelObject *object, /* Draw outline shadow */ - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (shadow_line_color), - GL_COLOR_F_GREEN (shadow_line_color), - GL_COLOR_F_BLUE (shadow_line_color), - GL_COLOR_F_ALPHA (shadow_line_color)); + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_line_color)); cairo_set_line_width (cr, line_width); cairo_stroke (cr); diff --git a/glabels2/src/label-text.c b/glabels2/src/label-text.c index 5902da6f..b9b0da26 100644 --- a/glabels2/src/label-text.c +++ b/glabels2/src/label-text.c @@ -881,12 +881,7 @@ draw_object (glLabelObject *object, pango_layout_set_alignment (layout, alignment); - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (color), - GL_COLOR_F_GREEN (color), - GL_COLOR_F_BLUE (color), - GL_COLOR_F_ALPHA (color)); - + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (color)); cairo_move_to (cr, GL_LABEL_TEXT_MARGIN/scale_x, 0); pango_cairo_show_layout (cr, layout); @@ -1026,12 +1021,7 @@ draw_shadow (glLabelObject *object, pango_layout_set_wrap (layout, PANGO_WRAP_CHAR); pango_layout_set_alignment (layout, alignment); - cairo_set_source_rgba (cr, - GL_COLOR_F_RED (shadow_color), - GL_COLOR_F_GREEN (shadow_color), - GL_COLOR_F_BLUE (shadow_color), - GL_COLOR_F_ALPHA (shadow_color)); - + cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (shadow_color)); cairo_move_to (cr, GL_LABEL_TEXT_MARGIN/scale_x, 0); pango_cairo_show_layout (cr, layout); diff --git a/glabels2/src/wdgt-mini-preview.c b/glabels2/src/wdgt-mini-preview.c index abd1c501..bb12059e 100644 --- a/glabels2/src/wdgt-mini-preview.c +++ b/glabels2/src/wdgt-mini-preview.c @@ -627,10 +627,7 @@ draw_shadow (glWdgtMiniPreview *preview, style = gtk_widget_get_style (GTK_WIDGET(preview)); shadow_color = gl_color_from_gdk_color (&style->bg[GTK_STATE_ACTIVE]); - cairo_set_source_rgb (cr, - GL_COLOR_F_RED (shadow_color), - GL_COLOR_F_GREEN (shadow_color), - GL_COLOR_F_BLUE (shadow_color)); + cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (shadow_color)); cairo_fill (cr); @@ -702,10 +699,7 @@ draw_labels (glWdgtMiniPreview *preview, if ( ((i+1) >= preview->priv->highlight_first) && ((i+1) <= preview->priv->highlight_last) ) { - cairo_set_source_rgb (cr, - GL_COLOR_F_RED (highlight_color), - GL_COLOR_F_GREEN (highlight_color), - GL_COLOR_F_BLUE (highlight_color)); + cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (highlight_color)); } else { diff --git a/glabels2/src/wdgt-rotate-label.c b/glabels2/src/wdgt-rotate-label.c index a4226006..b3a4e8ad 100644 --- a/glabels2/src/wdgt-rotate-label.c +++ b/glabels2/src/wdgt-rotate-label.c @@ -292,10 +292,7 @@ drawingarea_update (GtkDrawingArea *drawing_area, cairo_translate (cr, SHADOW_X_OFFSET/scale, SHADOW_Y_OFFSET/scale); gl_cairo_label_path (cr, template, rotate_flag, FALSE); - cairo_set_source_rgb (cr, - GL_COLOR_F_RED(shadow_color), - GL_COLOR_F_GREEN(shadow_color), - GL_COLOR_F_BLUE(shadow_color)); + cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (shadow_color)); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_fill (cr); cairo_restore (cr); @@ -305,18 +302,12 @@ drawingarea_update (GtkDrawingArea *drawing_area, */ gl_cairo_label_path (cr, template, rotate_flag, FALSE); - cairo_set_source_rgb (cr, - GL_COLOR_F_RED(fill_color), - GL_COLOR_F_GREEN(fill_color), - GL_COLOR_F_BLUE(fill_color)); + cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (fill_color)); cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_fill_preserve (cr); cairo_set_line_width (cr, LINE_WIDTH_PIXELS/scale); - cairo_set_source_rgb (cr, - GL_COLOR_F_RED(line_color), - GL_COLOR_F_GREEN(line_color), - GL_COLOR_F_BLUE(line_color)); + cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (line_color)); cairo_stroke (cr); -- 2.39.5