+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
* color.c: various small utilities for dealing with canvas colors
*
- * Copyright (C) 2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2002-2007 Jim Evins <evins@snaught.com>.
*
* 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
/*****************************************************************************/
guint
gl_color_set_opacity (guint color,
- gdouble opacity)
+ gdouble opacity)
{
- guint new_color;
+ guint new_color;
- new_color = (color & 0xFFFFFF00) | (((guint)(255.0*opacity)) & 0xFF);
+ new_color = (color & 0xFFFFFF00) | (((guint)(255.0*opacity)) & 0xFF);
- return new_color;
+ return new_color;
}
/*****************************************************************************/
GdkColor *
gl_color_to_gdk_color (guint color)
{
- GdkColor *gdk_color;
+ GdkColor *gdk_color;
- gdk_color = g_new0 (GdkColor, 1);
+ gdk_color = g_new0 (GdkColor, 1);
- gdk_color->red = GL_COLOR_F_RED (color) * 65535;
- gdk_color->green = GL_COLOR_F_GREEN (color) * 65535;
- gdk_color->blue = GL_COLOR_F_BLUE (color) * 65535;
+ gdk_color->red = GL_COLOR_F_RED (color) * 65535;
+ gdk_color->green = GL_COLOR_F_GREEN (color) * 65535;
+ gdk_color->blue = GL_COLOR_F_BLUE (color) * 65535;
- return gdk_color;
+ return gdk_color;
}
/*****************************************************************************/
guint
gl_color_from_gdk_color (GdkColor *gdk_color)
{
- guint color;
+ guint color;
- color = GL_COLOR ((gdk_color->red >>8),
- (gdk_color->green >>8),
- (gdk_color->blue >>8));
+ color = GL_COLOR ((gdk_color->red >>8),
+ (gdk_color->green >>8),
+ (gdk_color->blue >>8));
- return color;
+ return color;
}
/*****************************************************************************/
/*****************************************************************************/
guint
gl_color_shadow (guint base_color,
- gdouble opacity,
- guint object_color)
+ gdouble opacity,
+ guint object_color)
{
- guint color;
+ guint color;
- color = gl_color_set_opacity (base_color,
- opacity * GL_COLOR_F_ALPHA (object_color));
+ color = gl_color_set_opacity (base_color,
+ opacity * GL_COLOR_F_ALPHA (object_color));
- return color;
+ return color;
}
/****************************************************************************/
glColorNode *
gl_color_node_new_default ()
{
- glColorNode* color_node;
-
- color_node = g_new0(glColorNode,1);
-
- color_node->field_flag = FALSE;
- color_node->color = GL_COLOR_NONE;
- color_node->key = NULL;
-
- return color_node;
+ glColorNode* color_node;
+
+ color_node = g_new0(glColorNode,1);
+
+ color_node->field_flag = FALSE;
+ color_node->color = GL_COLOR_NONE;
+ color_node->key = NULL;
+
+ return color_node;
}
/****************************************************************************/
glColorNode *
gl_color_node_dup (glColorNode *src)
{
- glColorNode *dst;
+ glColorNode *dst;
- if ( src == NULL ) return NULL;
+ if ( src == NULL ) return NULL;
- dst = g_new0 (glColorNode, 1);
+ dst = g_new0 (glColorNode, 1);
- dst->field_flag = src->field_flag;
- if (src->key != NULL)
- {
- dst->key = g_strdup (src->key);
- }
- else
- {
- dst->key = NULL;
- }
- dst->color = src->color;
+ dst->field_flag = src->field_flag;
+ if (src->key != NULL)
+ {
+ dst->key = g_strdup (src->key);
+ }
+ else
+ {
+ dst->key = NULL;
+ }
+ dst->color = src->color;
- return dst;
+ return dst;
}
/****************************************************************************/
/****************************************************************************/
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 ) {
- return ( color_node2 == NULL );
- } else {
- if ( color_node2 == NULL ) {
- return FALSE;
- }
- }
-
- /* Bail if field flags differ. */
- 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 ){
- return FALSE;
- }
-
- /* Then take care of the case of either or both key fields being NULL. */
- if ( color_node1->key == NULL ) {
- return ( color_node2->key == NULL );
- } else {
- if ( color_node2->key == NULL ) {
- return FALSE;
- }
- }
-
- /* Field flags are identical, so now compare the keys. */
- return (strcmp (color_node1->key, color_node2->key) == 0);
+ /* First take care of the case of either or both being NULL. */
+ if ( color_node1 == NULL ) {
+ return ( color_node2 == NULL );
+ } else {
+ if ( color_node2 == NULL ) {
+ return FALSE;
+ }
+ }
+
+ /* Bail if field flags differ. */
+ 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 ){
+ return FALSE;
+ }
+
+ /* Then take care of the case of either or both key fields being NULL. */
+ if ( color_node1->key == NULL ) {
+ return ( color_node2->key == NULL );
+ } else {
+ if ( color_node2->key == NULL ) {
+ return FALSE;
+ }
+ }
+
+ /* Field flags are identical, so now compare the keys. */
+ return (strcmp (color_node1->key, color_node2->key) == 0);
}
/****************************************************************************/
/****************************************************************************/
guint
gl_color_node_expand (glColorNode *color_node,
- glMergeRecord *record)
+ glMergeRecord *record)
{
- gchar* text;
- GdkColor *gdk_color;
- guint color;
-
- if (color_node->field_flag) {
- if (record == NULL) {
- return GL_COLOR_NONE;
- } else {
- text = gl_merge_eval_key (record, color_node->key);
- if (text != NULL) {
- gdk_color = g_new0 (GdkColor, 1);
- if (gdk_color_parse (text, gdk_color))
- {
- color = gl_color_from_gdk_color (gdk_color);
- g_free (gdk_color);
- return color;
- }
- else
- {
- g_free (gdk_color);
- return GL_COLOR_NONE;
- }
- } else {
- return GL_COLOR_NONE;
- }
- }
- } else {
- return color_node->color;
- }
+ gchar* text;
+ GdkColor *gdk_color;
+ guint color;
+
+ if (color_node->field_flag) {
+ if (record == NULL) {
+ return GL_COLOR_NONE;
+ } else {
+ text = gl_merge_eval_key (record, color_node->key);
+ if (text != NULL) {
+ gdk_color = g_new0 (GdkColor, 1);
+ if (gdk_color_parse (text, gdk_color))
+ {
+ color = gl_color_from_gdk_color (gdk_color);
+ g_free (gdk_color);
+ return color;
+ }
+ else
+ {
+ g_free (gdk_color);
+ return GL_COLOR_NONE;
+ }
+ } else {
+ return GL_COLOR_NONE;
+ }
+ }
+ } else {
+ return color_node->color;
+ }
}
/****************************************************************************/
void
gl_color_node_free (glColorNode **color_node)
{
- if ( *color_node == NULL ) return;
+ if ( *color_node == NULL ) return;
- g_free ((*color_node)->key);
- (*color_node)->key = NULL;
- g_free (*color_node);
- *color_node = NULL;
+ g_free ((*color_node)->key);
+ (*color_node)->key = NULL;
+ g_free (*color_node);
+ *color_node = NULL;
}
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
* color.h: various small utilities for dealing with canvas colors
*
- * Copyright (C) 2002 Jim Evins <evins@snaught.com>.
+ * Copyright (C) 2002-2007 Jim Evins <evins@snaught.com>.
*
* 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
#ifndef __COLOR_H__
#define __COLOR_H__
-#include <libgnomecanvas/gnome-canvas.h>
#include "merge.h"
+#include <gdk/gdkcolor.h>
G_BEGIN_DECLS
typedef struct {
- gboolean field_flag;
- guint color;
- gchar *key;
+ gboolean field_flag;
+ guint color;
+ gchar *key;
} glColorNode;
-#define GL_COLOR(r,g,b) GNOME_CANVAS_COLOR(r,g,b)
-#define GL_COLOR_A(r,g,b,a) GNOME_CANVAS_COLOR_A(r,g,b,a)
+
+#define GL_COLOR(r,g,b) ( (((unsigned int) (r) & 0xff) << 24) \
+ | (((unsigned int) (g) & 0xff) << 16) \
+ | (((unsigned int) (b) & 0xff) << 8) \
+ | 0xff )
+
+#define GL_COLOR_A(r,g,b,a) ( (((unsigned int) (r) & 0xff) << 24) \
+ | (((unsigned int) (g) & 0xff) << 16) \
+ | (((unsigned int) (b) & 0xff) << 8) \
+ | ( (unsigned int) (a) & 0xff ) )
+
#define GL_COLOR_NONE GL_COLOR_A(0,0,0,0)
#define GL_COLOR_FILL_MERGE_DEFAULT GL_COLOR_A(255,255,255,128)
#define GL_COLOR_SHADOW_DEFAULT GL_COLOR(0,0,0)
#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_F_BLUE(x) ( (((x)>>8) & 0xff) / 255.0 )
#define GL_COLOR_F_ALPHA(x) ( ( (x) & 0xff) / 255.0 )
-guint gl_color_set_opacity (guint color, gdouble opacity);
-GdkColor *gl_color_to_gdk_color (guint color);
-guint gl_color_from_gdk_color (GdkColor *gdk_color);
+guint gl_color_set_opacity (guint color,
+ gdouble opacity);
+
+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);
-guint gl_color_shadow (guint base_color,
- gdouble opacity,
- guint object_color);
glColorNode *gl_color_node_new_default ();
glColorNode *gl_color_node_dup (glColorNode *color_node);
gboolean gl_color_node_equal (glColorNode *color_node1,
- glColorNode *color_node2);
+ glColorNode *color_node2);
guint gl_color_node_expand (glColorNode *color_node,
- glMergeRecord *record);
+ glMergeRecord *record);
void gl_color_node_free (glColorNode **color_node);