From: Jim Evins Date: Wed, 4 Sep 2002 02:07:09 +0000 (+0000) Subject: Moved color utilities to separate module (color.[ch]) X-Git-Tag: glabels-2_3_0~796 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=076dbabb5fc635eddd38a863379c5ebe5becd9b5;p=glabels Moved color utilities to separate module (color.[ch]) git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@88 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/po/POTFILES.in b/glabels2/po/POTFILES.in index 49097e70..b8378228 100644 --- a/glabels2/po/POTFILES.in +++ b/glabels2/po/POTFILES.in @@ -122,6 +122,8 @@ src/wdgt-rotate-label.c src/wdgt-rotate-label.h src/util.c src/util.h +src/color.c +src/color.h src/canvas-hacktext.c src/canvas-hacktext.h src/bonobo-mdi-child.c diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index 14bcc388..24068f4a 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -163,6 +163,8 @@ glabels_SOURCES = \ wdgt-rotate-label.h \ util.c \ util.h \ + color.c \ + color.h \ canvas-hacktext.c \ canvas-hacktext.h \ bonobo-mdi-child.c \ diff --git a/glabels2/src/color.c b/glabels2/src/color.c new file mode 100644 index 00000000..d8caf6c4 --- /dev/null +++ b/glabels2/src/color.c @@ -0,0 +1,37 @@ +/* + * (GLABELS) Label and Business Card Creation program for GNOME + * + * color.c: various small utilities for dealing with canvas colors + * + * Copyright (C) 2002 Jim Evins . + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include + +#include "color.h" + +/*****************************************************************************/ +/* Apply given opacity to given color. */ +/*****************************************************************************/ +guint +gl_color_set_opacity (guint color, + gdouble opacity) +{ + guint new_color; + + new_color = (color & 0xFFFFFF00) | ((guint)(255.0*opacity) & 0xFF); +} + diff --git a/glabels2/src/color.h b/glabels2/src/color.h new file mode 100644 index 00000000..d146345d --- /dev/null +++ b/glabels2/src/color.h @@ -0,0 +1,44 @@ +/* + * (GLABELS) Label and Business Card Creation program for GNOME + * + * color.h: various small utilities for dealing with canvas colors + * + * Copyright (C) 2002 Jim Evins . + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __COLOR_H__ +#define __COLOR_H__ + +#include + +#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_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) + +#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 ) + +extern guint gl_color_set_opacity (guint color, gdouble opacity); + + +#endif /* __COLOR_H__ */ diff --git a/glabels2/src/print-dialog.c b/glabels2/src/print-dialog.c index 3943b92b..c4c6b9e2 100644 --- a/glabels2/src/print-dialog.c +++ b/glabels2/src/print-dialog.c @@ -44,11 +44,6 @@ #include "debug.h" -#define RED(x) ( (((x)>>24) & 0xff) / 255.0 ) -#define GREEN(x) ( (((x)>>16) & 0xff) / 255.0 ) -#define BLUE(x) ( (((x)>>8) & 0xff) / 255.0 ) -#define ALPHA(x) ( ( (x) & 0xff) / 255.0 ) - /*===========================================*/ /* Private types. */ /*===========================================*/ diff --git a/glabels2/src/print.c b/glabels2/src/print.c index fae10c32..a3a69798 100644 --- a/glabels2/src/print.c +++ b/glabels2/src/print.c @@ -38,16 +38,12 @@ #include "label-barcode.h" #include "bc.h" #include "template.h" +#include "color.h" #include "debug.h" #define GL_PRINT_DEFAULT_PAPER "US Letter" -#define RED(x) ( (((x)>>24) & 0xff) / 255.0 ) -#define GREEN(x) ( (((x)>>16) & 0xff) / 255.0 ) -#define BLUE(x) ( (((x)>>8) & 0xff) / 255.0 ) -#define ALPHA(x) ( ( (x) & 0xff) / 255.0 ) - /*===========================================*/ /* Private types. */ /*===========================================*/ @@ -541,10 +537,10 @@ draw_text_object (PrintInfo * pi, gnome_print_setfont (pi->pc, font); gnome_print_setrgbcolor (pi->pc, - RED (color), - GREEN (color), - BLUE (color)); - gnome_print_setopacity (pi->pc, ALPHA (color)); + GL_COLOR_F_RED (color), + GL_COLOR_F_GREEN (color), + GL_COLOR_F_BLUE (color)); + gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (color)); text = gl_text_node_lines_expand (lines, record); line = g_strsplit (text, "\n", -1); @@ -619,19 +615,19 @@ draw_box_object (PrintInfo * pi, /* Paint fill color */ create_rectangle_path (pi->pc, x, y, w, h); gnome_print_setrgbcolor (pi->pc, - RED (fill_color), - GREEN (fill_color), - BLUE (fill_color)); - gnome_print_setopacity (pi->pc, ALPHA (fill_color)); + GL_COLOR_F_RED (fill_color), + GL_COLOR_F_GREEN (fill_color), + GL_COLOR_F_BLUE (fill_color)); + gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color)); gnome_print_fill (pi->pc); /* Draw outline */ create_rectangle_path (pi->pc, x, y, w, h); gnome_print_setrgbcolor (pi->pc, - RED (line_color), - GREEN (line_color), - BLUE (line_color)); - gnome_print_setopacity (pi->pc, ALPHA (line_color)); + GL_COLOR_F_RED (line_color), + GL_COLOR_F_GREEN (line_color), + GL_COLOR_F_BLUE (line_color)); + gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color)); gnome_print_setlinewidth (pi->pc, line_width); gnome_print_stroke (pi->pc); @@ -659,10 +655,10 @@ draw_line_object (PrintInfo * pi, gnome_print_moveto (pi->pc, x, y); gnome_print_lineto (pi->pc, x + w, y + h); gnome_print_setrgbcolor (pi->pc, - RED (line_color), - GREEN (line_color), - BLUE (line_color)); - gnome_print_setopacity (pi->pc, ALPHA (line_color)); + GL_COLOR_F_RED (line_color), + GL_COLOR_F_GREEN (line_color), + GL_COLOR_F_BLUE (line_color)); + gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color)); gnome_print_setlinewidth (pi->pc, line_width); gnome_print_stroke (pi->pc); @@ -696,19 +692,19 @@ draw_ellipse_object (PrintInfo * pi, /* Paint fill color */ create_ellipse_path (pi->pc, x0, y0, rx, ry); gnome_print_setrgbcolor (pi->pc, - RED (fill_color), - GREEN (fill_color), - BLUE (fill_color)); - gnome_print_setopacity (pi->pc, ALPHA (fill_color)); + GL_COLOR_F_RED (fill_color), + GL_COLOR_F_GREEN (fill_color), + GL_COLOR_F_BLUE (fill_color)); + gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (fill_color)); gnome_print_fill (pi->pc); /* Draw outline */ create_ellipse_path (pi->pc, x0, y0, rx, ry); gnome_print_setrgbcolor (pi->pc, - RED (line_color), - GREEN (line_color), - BLUE (line_color)); - gnome_print_setopacity (pi->pc, ALPHA (line_color)); + GL_COLOR_F_RED (line_color), + GL_COLOR_F_GREEN (line_color), + GL_COLOR_F_BLUE (line_color)); + gnome_print_setopacity (pi->pc, GL_COLOR_F_ALPHA (line_color)); gnome_print_setlinewidth (pi->pc, line_width); gnome_print_stroke (pi->pc); @@ -800,11 +796,11 @@ draw_barcode_object (PrintInfo * pi, gnome_print_setfont (pi->pc, font); gnome_print_setrgbcolor (pi->pc, - RED (color), - GREEN (color), - BLUE (color)); + GL_COLOR_F_RED (color), + GL_COLOR_F_GREEN (color), + GL_COLOR_F_BLUE (color)); gnome_print_setopacity (pi->pc, - ALPHA (color)); + GL_COLOR_F_ALPHA (color)); y_offset = 12.0 - gnome_font_get_descender (font); gnome_print_moveto (pi->pc, x, y + y_offset); @@ -823,11 +819,11 @@ draw_barcode_object (PrintInfo * pi, gnome_print_lineto (pi->pc, x + line->x, y + line->y + line->length); gnome_print_setrgbcolor (pi->pc, - RED (color), - GREEN (color), - BLUE (color)); + GL_COLOR_F_RED (color), + GL_COLOR_F_GREEN (color), + GL_COLOR_F_BLUE (color)); gnome_print_setopacity (pi->pc, - ALPHA (color)); + GL_COLOR_F_ALPHA (color)); gnome_print_setlinewidth (pi->pc, line->width); gnome_print_stroke (pi->pc); } @@ -842,11 +838,11 @@ draw_barcode_object (PrintInfo * pi, gnome_print_setfont (pi->pc, font); gnome_print_setrgbcolor (pi->pc, - RED (color), - GREEN (color), - BLUE (color)); + GL_COLOR_F_RED (color), + GL_COLOR_F_GREEN (color), + GL_COLOR_F_BLUE (color)); gnome_print_setopacity (pi->pc, - ALPHA (color)); + GL_COLOR_F_ALPHA (color)); y_offset = bchar->y + bchar->fsize - diff --git a/glabels2/src/view.c b/glabels2/src/view.c index b6b5d5f6..28f6849b 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -37,11 +37,12 @@ #include "view-text.h" #include "view-barcode.h" #include "xml-label.h" +#include "color.h" #include "debug.h" -#define SEL_LINE_COLOR GNOME_CANVAS_COLOR_A (0, 0, 255, 128) -#define SEL_FILL_COLOR GNOME_CANVAS_COLOR_A (192, 192, 255, 128) +#define SEL_LINE_COLOR GL_COLOR_A (0, 0, 255, 128) +#define SEL_FILL_COLOR GL_COLOR_A (192, 192, 255, 128) /*===========================================*/ /* Private globals */ diff --git a/glabels2/src/wdgt-bc-props.c b/glabels2/src/wdgt-bc-props.c index ed4ddbcd..b83fd9a3 100644 --- a/glabels2/src/wdgt-bc-props.c +++ b/glabels2/src/wdgt-bc-props.c @@ -24,14 +24,10 @@ #include "wdgt-bc-props.h" #include "marshal.h" +#include "color.h" #include "debug.h" -#define RED(x) ( ((x)>>24) & 0xff ) -#define GREEN(x) ( ((x)>>16) & 0xff ) -#define BLUE(x) ( ((x)>>8) & 0xff ) -#define ALPHA(x) ( (x) & 0xff ) - /*===========================================*/ /* Private types */ /*===========================================*/ @@ -228,7 +224,7 @@ gl_wdgt_bc_props_get_params (glWdgtBCProps * prop, /* ------- Get updated line color ------ */ gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (prop->color_picker), &r, &g, &b, &a); - *color = GNOME_CANVAS_COLOR_A (r, g, b, a); + *color = GL_COLOR_A (r, g, b, a); } @@ -244,7 +240,8 @@ gl_wdgt_bc_props_set_params (glWdgtBCProps * prop, gtk_spin_button_set_value (GTK_SPIN_BUTTON (prop->scale_spin), scale); gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (prop->color_picker), - RED (color), GREEN (color), BLUE (color), - ALPHA (color)); - + GL_COLOR_I_RED (color), + GL_COLOR_I_GREEN (color), + GL_COLOR_I_BLUE (color), + GL_COLOR_I_ALPHA (color)); } diff --git a/glabels2/src/wdgt-fill.c b/glabels2/src/wdgt-fill.c index 3a49ca92..6a3515e5 100644 --- a/glabels2/src/wdgt-fill.c +++ b/glabels2/src/wdgt-fill.c @@ -24,14 +24,10 @@ #include "wdgt-fill.h" #include "marshal.h" +#include "color.h" #include "debug.h" -#define RED(x) ( ((x)>>24) & 0xff ) -#define GREEN(x) ( ((x)>>16) & 0xff ) -#define BLUE(x) ( ((x)>>8) & 0xff ) -#define ALPHA(x) ( (x) & 0xff ) - /*===========================================*/ /* Private types */ /*===========================================*/ @@ -202,7 +198,7 @@ gl_wdgt_fill_get_params (glWdgtFill * fill, gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (fill->color_picker), &r, &g, &b, &a); - *color = GNOME_CANVAS_COLOR_A (r, g, b, a); + *color = GL_COLOR_A (r, g, b, a); } /*====================================================================*/ @@ -213,6 +209,8 @@ gl_wdgt_fill_set_params (glWdgtFill * fill, guint color) { gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (fill->color_picker), - RED (color), GREEN (color), BLUE (color), - ALPHA (color)); + GL_COLOR_I_RED (color), + GL_COLOR_I_GREEN (color), + GL_COLOR_I_BLUE (color), + GL_COLOR_I_ALPHA (color)); } diff --git a/glabels2/src/wdgt-line.c b/glabels2/src/wdgt-line.c index 71e369a0..04d36383 100644 --- a/glabels2/src/wdgt-line.c +++ b/glabels2/src/wdgt-line.c @@ -24,14 +24,10 @@ #include "wdgt-line.h" #include "marshal.h" +#include "color.h" #include "debug.h" -#define RED(x) ( ((x)>>24) & 0xff ) -#define GREEN(x) ( ((x)>>16) & 0xff ) -#define BLUE(x) ( ((x)>>8) & 0xff ) -#define ALPHA(x) ( (x) & 0xff ) - /*===========================================*/ /* Private types */ /*===========================================*/ @@ -228,7 +224,7 @@ gl_wdgt_line_get_params (glWdgtLine * line, gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (line->color_picker), &r, &g, &b, &a); - *color = GNOME_CANVAS_COLOR_A (r, g, b, a); + *color = GL_COLOR_A (r, g, b, a); } /*====================================================================*/ @@ -242,6 +238,8 @@ gl_wdgt_line_set_params (glWdgtLine * line, gtk_spin_button_set_value (GTK_SPIN_BUTTON (line->width_spin), width); gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (line->color_picker), - RED (color), GREEN (color), BLUE (color), - ALPHA (color)); + GL_COLOR_I_RED (color), + GL_COLOR_I_GREEN (color), + GL_COLOR_I_BLUE (color), + GL_COLOR_I_ALPHA (color)); } diff --git a/glabels2/src/wdgt-mini-preview.c b/glabels2/src/wdgt-mini-preview.c index d2c0577d..caf85f0e 100644 --- a/glabels2/src/wdgt-mini-preview.c +++ b/glabels2/src/wdgt-mini-preview.c @@ -26,13 +26,14 @@ #include "wdgt-mini-preview.h" #include "marshal.h" +#include "color.h" #include "debug.h" #define WDGT_MINI_PREVIEW_MAX_PIXELS 175 #define SHADOW_X_OFFSET 3 #define SHADOW_Y_OFFSET 3 -#define SHADOW_COLOR GNOME_CANVAS_COLOR_A (33, 33, 33, 192) +#define SHADOW_COLOR GL_COLOR_A (33, 33, 33, 192) /*===========================================*/ /* Private types */ diff --git a/glabels2/src/wdgt-text-props.c b/glabels2/src/wdgt-text-props.c index 50e01d88..1524dcbe 100644 --- a/glabels2/src/wdgt-text-props.c +++ b/glabels2/src/wdgt-text-props.c @@ -26,14 +26,10 @@ #include "wdgt-text-props.h" #include "marshal.h" +#include "color.h" #include "debug.h" -#define RED(x) ( ((x)>>24) & 0xff ) -#define GREEN(x) ( ((x)>>16) & 0xff ) -#define BLUE(x) ( ((x)>>8) & 0xff ) -#define ALPHA(x) ( (x) & 0xff ) - /*===========================================*/ /* Private types */ /*===========================================*/ @@ -391,7 +387,7 @@ gl_wdgt_text_props_get_params (glWdgtTextProps *text, /* ------ Get updated color ------ */ gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (text->color_picker), &r, &g, &b, &a); - *color = GNOME_CANVAS_COLOR_A (r, g, b, a); + *color = GL_COLOR_A (r, g, b, a); /* ------- Get updated justification ------ */ if (gtk_toggle_button_get_active @@ -435,8 +431,10 @@ gl_wdgt_text_props_set_params (glWdgtTextProps *text, font_italic_flag); gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (text->color_picker), - RED (color), GREEN (color), BLUE (color), - ALPHA (color)); + GL_COLOR_I_RED (color), + GL_COLOR_I_GREEN (color), + GL_COLOR_I_BLUE (color), + GL_COLOR_I_ALPHA (color)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text->left_button), (just == GTK_JUSTIFY_LEFT));