]> git.sur5r.net Git - glabels/commitdiff
2007-04-30 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Tue, 1 May 2007 03:29:27 +0000 (03:29 +0000)
committerJim Evins <evins@snaught.com>
Tue, 1 May 2007 03:29:27 +0000 (03:29 +0000)
* 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
glabels2/src/color.c
glabels2/src/color.h
glabels2/src/label-barcode.c
glabels2/src/label-box.c
glabels2/src/label-ellipse.c
glabels2/src/label-line.c
glabels2/src/label-text.c
glabels2/src/wdgt-mini-preview.c
glabels2/src/wdgt-rotate-label.c

index 4b91d90ad3cd1b976529629eb6fa442e2c208bcf..997bc0852d3126ede70bb74b796603b6ebcbbe03 100644 (file)
@@ -1,3 +1,17 @@
+2007-04-30  Jim Evins  <evins@snaught.com>
+
+       * 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  <evins@snaught.com>
 
        * src/label.h:
index 65445559368762e4835799f1e804ff4395bf2425..e8c039dc7078c380ef3ebb62151cdab599fd6e63 100644 (file)
@@ -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)
 {
-        gchartext;
+        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;
         }
 }
index 1faaa66ae32ba878a766ca30929699778394e6ea..c4403ad5dc24b73b1437eb530c154e7d11764849 100644 (file)
 
 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,
index 7cf6feaa43404b75be9ca3e31a7731be3f3ef86e..9f93d0114eb09160b63a065531f632eab458ddcb 100644 (file)
@@ -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) {
 
index 06084c3b0f81661c7ec9758537665c1e770e0441..a42ad75b38b2914cce2ab6772b860f0fa00f86fa 100644 (file)
@@ -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);
 
index 9b955edc63d5827e9c89d5f03c1043607353e269..efc8dd88b7e42faba5a581eae7717079cdc0ad89 100644 (file)
@@ -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);
 
index 4543b3b016c8e368d92bdd27bcaf9913622ce75c..b3eae407df7ba7dc72dfe0f51dedc5f79e0f455e 100644 (file)
@@ -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);
 
index 5902da6fab45705d8df5c6d274decda53283b41a..b9b0da26fa714cbe41382b297c23885c4491eca6 100644 (file)
@@ -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);
 
index abd1c5012ec3c99a7cbcb75ebc0525adf1f6909a..bb12059e1d7da2b12683d84ffb17b7d950c47376 100644 (file)
@@ -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
                {
index a4226006982ec71da9f59d24a87426e304fa1565..b3a4e8adea9427bb9643d0e27eab87654b9ff687 100644 (file)
@@ -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);