+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:
}
/*****************************************************************************/
-/* 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)
}
/*****************************************************************************/
-/* Convert GdkColor into a canvas color */
+/* Convert GdkColor into a gLabels color */
/*****************************************************************************/
guint
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;
/****************************************************************************/
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;
}
}
/****************************************************************************/
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))
{
g_free (gdk_color);
return GL_COLOR_NONE;
}
- } else {
+ }
+ else
+ {
return GL_COLOR_NONE;
}
}
- } else {
+ }
+ else
+ {
return color_node->color;
}
}
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) \
#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,
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) {
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);
/* 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);
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);
/* 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);
/* 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);
/* 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);
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);
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);
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);
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
{
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);
*/
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);