]> git.sur5r.net Git - glabels/commitdiff
Moved color utilities to separate module (color.[ch])
authorJim Evins <evins@snaught.com>
Wed, 4 Sep 2002 02:07:09 +0000 (02:07 +0000)
committerJim Evins <evins@snaught.com>
Wed, 4 Sep 2002 02:07:09 +0000 (02:07 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@88 f5e0f49d-192f-0410-a22d-a8d8700d0965

12 files changed:
glabels2/po/POTFILES.in
glabels2/src/Makefile.am
glabels2/src/color.c [new file with mode: 0644]
glabels2/src/color.h [new file with mode: 0644]
glabels2/src/print-dialog.c
glabels2/src/print.c
glabels2/src/view.c
glabels2/src/wdgt-bc-props.c
glabels2/src/wdgt-fill.c
glabels2/src/wdgt-line.c
glabels2/src/wdgt-mini-preview.c
glabels2/src/wdgt-text-props.c

index 49097e70da73c1db2fe39d19e3f7139585148d3e..b8378228d59dfa1db1ac747078a48ed7dc4bbb21 100644 (file)
@@ -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
index 14bcc38801b7a97d3b4c46817259a44d2ca0e944..24068f4ab0801e98721403c226e2850ae58c834c 100644 (file)
@@ -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 (file)
index 0000000..d8caf6c
--- /dev/null
@@ -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 <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
+ *  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 <config.h>
+
+#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 (file)
index 0000000..d146345
--- /dev/null
@@ -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 <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
+ *  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 <libgnomecanvas/gnome-canvas.h>
+
+#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__ */
index 3943b92bffd021829bb537d66742f6f1dc90e425..c4c6b9e2a15215fff117e6860f01c2c652dfcae6 100644 (file)
 
 #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.                            */
 /*===========================================*/
index fae10c324d2c5c83f6f51f9a6363ecdf60099171..a3a697980106d5ec98264cd0ae99d3311cf11c4f 100644 (file)
 #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 -
index b6b5d5f6817139f0b192badfe5c65e03205deff9..28f6849b38b0880787a9b70a71019a2d8fae14fc 100644 (file)
 #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                           */
index ed4ddbcd21776cce30c568df86e8cbf2561de811..b83fd9a3b0dbceb476d4648b3ded5602cf5d3396 100644 (file)
 
 #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));
 }
index 3a49ca924c929165b39b86b186291695f602f852..6a3515e50423c9f94fddebf5a506c5f997f0ebfe 100644 (file)
 
 #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));
 }
index 71e369a09a31126904a23a7f5c5bd249010f0445..04d36383ef54984d3e3cee5bf5ebd22bb94fad34 100644 (file)
 
 #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));
 }
index d2c0577d329a4099c8e8ee5d974fa19e94a52fa2..caf85f0e39ace7cd6fe938d99efa0214192466ce 100644 (file)
 
 #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                             */
index 50e01d8874fb069af432763b65dd08ef03248a61..1524dcbee87f4b7001477e3fde1e2b95b2b504d9 100644 (file)
 
 #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));