diff options
-rw-r--r-- | libgnomecanvas/Makefile.am | 3 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas-rect.c | 772 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas-rect.h | 89 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas-shape-private.h | 46 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas-shape.c | 582 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas-shape.h | 75 |
6 files changed, 669 insertions, 898 deletions
diff --git a/libgnomecanvas/Makefile.am b/libgnomecanvas/Makefile.am index 828de3c500..4032c8599a 100644 --- a/libgnomecanvas/Makefile.am +++ b/libgnomecanvas/Makefile.am @@ -27,7 +27,6 @@ libgnomecanvasinclude_HEADERS = \ gnome-canvas-pixbuf.h \ gnome-canvas-rect.h \ gnome-canvas-rich-text.h \ - gnome-canvas-shape.h \ gnome-canvas-text.h \ gnome-canvas-util.h \ gnome-canvas-widget.h \ @@ -47,8 +46,6 @@ libgnomecanvas_la_SOURCES = \ gnome-canvas-pixbuf.c \ gnome-canvas-rect.c \ gnome-canvas-rich-text.c \ - gnome-canvas-shape-private.h \ - gnome-canvas-shape.c \ gnome-canvas-text.c \ gnome-canvas-util.c \ gnome-canvas-widget.c \ diff --git a/libgnomecanvas/gnome-canvas-rect.c b/libgnomecanvas/gnome-canvas-rect.c index e41abb9b29..66d0258dca 100644 --- a/libgnomecanvas/gnome-canvas-rect.c +++ b/libgnomecanvas/gnome-canvas-rect.c @@ -1,224 +1,724 @@ -/* - * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation - * All rights reserved. +/* Generic bezier rect item for GnomeCanvasWidget. Most code taken + * from gnome-canvas-bpath but made into a rect item. * - * This file is part of the Gnome Library. - * - * The Gnome Library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * The Gnome Library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with the Gnome Library; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -/* - @NOTATION@ - */ -/* Rectangle and ellipse item types for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget. Tk is - * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties. + * GnomeCanvas is basically a port of the Tk toolkit's most excellent + * canvas widget. Tk is copyrighted by the Regents of the University + * of California, Sun Microsystems, and other parties. * + * Copyright (C) 1998,1999 The Free Software Foundation * * Authors: Federico Mena <federico@nuclecu.unam.mx> + * Raph Levien <raph@acm.org> + * Lauris Kaplinski <lauris@ximian.com> + * Miguel de Icaza <miguel@kernel.org> + * Cody Russell <bratsche@gnome.org> * Rusty Conover <rconover@bangtail.net> */ -#include <config.h> +/* These includes are set up for standalone compile. If/when this codebase + is integrated into libgnomeui, the includes will need to change. */ + #include <math.h> -#include "gnome-canvas-rect.h" +#include <string.h> + +#include <gtk/gtk.h> +#include <cairo-gobject.h> +#include "gnome-canvas.h" #include "gnome-canvas-util.h" -#include "gnome-canvas-shape.h" -/* Base class for rectangle and ellipse item types */ +#include "gnome-canvas-rect.h" + +#define GNOME_CANVAS_RECT_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), GNOME_TYPE_CANVAS_RECT, GnomeCanvasRectPrivate)) + +struct _GnomeCanvasRectPrivate { + cairo_path_t *path; /* Our bezier path representation */ + + gdouble x1, y1, x2, y2; + + gdouble scale; /* CTM scaling (for pen) */ + + guint fill_set : 1; /* Is fill color set? */ + guint outline_set : 1; /* Is outline color set? */ -#define noVERBOSE + gdouble line_width; /* Width of outline, in user coords */ + + guint32 fill_rgba; /* Fill color, RGBA */ + guint32 outline_rgba; /* Outline color, RGBA */ + + cairo_line_cap_t cap; /* Cap style for line */ + cairo_line_join_t join; /* Join style for line */ + cairo_fill_rule_t wind; /* Winding rule */ + gdouble miterlimit; /* Miter limit */ + + guint n_dash; /* Number of elements in dashing pattern */ + gdouble *dash; /* Dashing pattern */ + gdouble dash_offset; /* Dashing offset */ +}; enum { PROP_0, PROP_X1, PROP_Y1, PROP_X2, - PROP_Y2 + PROP_Y2, + PROP_FILL_COLOR, + PROP_FILL_COLOR_GDK, + PROP_FILL_COLOR_RGBA, + PROP_OUTLINE_COLOR, + PROP_OUTLINE_COLOR_GDK, + PROP_OUTLINE_COLOR_RGBA, + PROP_LINE_WIDTH, + PROP_CAP_STYLE, + PROP_JOIN_STYLE, + PROP_WIND, + PROP_MITERLIMIT, + PROP_DASH }; -static void gnome_canvas_rect_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void gnome_canvas_rect_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void gnome_canvas_rect_update (GnomeCanvasItem *item, const cairo_matrix_t *matrix, gint flags); +static void gnome_canvas_rect_bounds (GnomeCanvasItem *item, + gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2); -G_DEFINE_TYPE(GnomeCanvasRect, gnome_canvas_rect, GNOME_TYPE_CANVAS_SHAPE) +G_DEFINE_TYPE (GnomeCanvasRect, gnome_canvas_rect, GNOME_TYPE_CANVAS_ITEM) -static void -gnome_canvas_rect_class_init (GnomeCanvasRectClass *class) +static guint32 +get_rgba_from_color (GdkColor *color) { - GObjectClass *gobject_class; - GnomeCanvasItemClass *item_class; - - gobject_class = (GObjectClass *) class; - - gobject_class->set_property = gnome_canvas_rect_set_property; - gobject_class->get_property = gnome_canvas_rect_get_property; - - g_object_class_install_property - (gobject_class, - PROP_X1, - g_param_spec_double ("x1", NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property - (gobject_class, - PROP_Y1, - g_param_spec_double ("y1", NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property - (gobject_class, - PROP_X2, - g_param_spec_double ("x2", NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property - (gobject_class, - PROP_Y2, - g_param_spec_double ("y2", NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - - item_class = (GnomeCanvasItemClass *) class; + return ((color->red & 0xff00) << 16) | ((color->green & 0xff00) << 8) | (color->blue & 0xff00) | 0xff; +} - item_class->update = gnome_canvas_rect_update; +static gboolean +gnome_canvas_rect_setup_for_fill (GnomeCanvasRect *rect, + cairo_t *cr) +{ + if (!rect->priv->fill_set) + return FALSE; + + cairo_set_source_rgba ( + cr, + ((rect->priv->fill_rgba >> 24) & 0xff) / 255.0, + ((rect->priv->fill_rgba >> 16) & 0xff) / 255.0, + ((rect->priv->fill_rgba >> 8) & 0xff) / 255.0, + ( rect->priv->fill_rgba & 0xff) / 255.0); + cairo_set_fill_rule (cr, rect->priv->wind); + + return TRUE; } -static void -gnome_canvas_rect_init (GnomeCanvasRect *rect) +static gboolean +gnome_canvas_rect_setup_for_stroke (GnomeCanvasRect *rect, + cairo_t *cr) { - rect->x1 = 0.0; - rect->y1 = 0.0; - rect->x2 = 0.0; - rect->y2 = 0.0; - rect->path_dirty = 0; + if (!rect->priv->outline_set) + return FALSE; + + cairo_set_source_rgba ( + cr, + ((rect->priv->outline_rgba >> 24) & 0xff) / 255.0, + ((rect->priv->outline_rgba >> 16) & 0xff) / 255.0, + ((rect->priv->outline_rgba >> 8) & 0xff) / 255.0, + ( rect->priv->outline_rgba & 0xff) / 255.0); + cairo_set_line_width (cr, rect->priv->line_width); + cairo_set_line_cap (cr, rect->priv->cap); + cairo_set_line_join (cr, rect->priv->join); + cairo_set_miter_limit (cr, rect->priv->miterlimit); + cairo_set_dash ( + cr, rect->priv->dash, rect->priv->n_dash, + rect->priv->dash_offset); + + return TRUE; } static void -gnome_canvas_rect_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) +gnome_canvas_rect_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { GnomeCanvasItem *item; GnomeCanvasRect *rect; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNOME_IS_CANVAS_RECT (object)); + GnomeCanvasRectPrivate *priv; + GdkColor color; + GdkColor *colorptr; + const gchar *color_string; item = GNOME_CANVAS_ITEM (object); rect = GNOME_CANVAS_RECT (object); + priv = rect->priv; - switch (param_id) { + switch (property_id) { case PROP_X1: - rect->x1 = g_value_get_double (value); - rect->path_dirty = 1; + priv->x1 = g_value_get_double (value); gnome_canvas_item_request_update (item); break; case PROP_Y1: - rect->y1 = g_value_get_double (value); - rect->path_dirty = 1; + priv->y1 = g_value_get_double (value); gnome_canvas_item_request_update (item); break; case PROP_X2: - rect->x2 = g_value_get_double (value); - rect->path_dirty = 1; + priv->x2 = g_value_get_double (value); gnome_canvas_item_request_update (item); break; case PROP_Y2: - rect->y2 = g_value_get_double (value); - rect->path_dirty = 1; + priv->y2 = g_value_get_double (value); + gnome_canvas_item_request_update (item); + break; + + case PROP_FILL_COLOR: + color_string = g_value_get_string (value); + if (color_string != NULL) { + if (gdk_color_parse (color_string, &color)) { + g_warning ( + "Failed to parse color '%s'", + color_string); + break; + } + priv->fill_set = TRUE; + priv->fill_rgba = get_rgba_from_color (&color); + } else if (priv->fill_set) + priv->fill_set = FALSE; + else + break; + + gnome_canvas_item_request_update (item); + break; + + case PROP_FILL_COLOR_GDK: + colorptr = g_value_get_boxed (value); + if (colorptr != NULL) { + priv->fill_set = TRUE; + priv->fill_rgba = get_rgba_from_color (colorptr); + } else if (priv->fill_set) + priv->fill_set = FALSE; + else + break; + + gnome_canvas_item_request_update (item); + break; + + case PROP_FILL_COLOR_RGBA: + priv->fill_set = TRUE; + priv->fill_rgba = g_value_get_uint (value); + + gnome_canvas_item_request_update (item); + break; + + case PROP_OUTLINE_COLOR: + color_string = g_value_get_string (value); + if (color_string != NULL) { + if (!gdk_color_parse (color_string, &color)) { + g_warning ( + "Failed to parse color '%s'", + color_string); + break; + } + priv->outline_set = TRUE; + priv->outline_rgba = get_rgba_from_color (&color); + } else if (priv->outline_set) + priv->outline_set = FALSE; + else + break; + + gnome_canvas_item_request_update (item); + break; + + case PROP_OUTLINE_COLOR_GDK: + colorptr = g_value_get_boxed (value); + if (colorptr != NULL) { + priv->outline_set = TRUE; + priv->outline_rgba = get_rgba_from_color (colorptr); + } else if (priv->outline_set) + priv->outline_set = FALSE; + else + break; + + gnome_canvas_item_request_update (item); + break; + + case PROP_OUTLINE_COLOR_RGBA: + priv->outline_set = TRUE; + priv->outline_rgba = g_value_get_uint (value); + + gnome_canvas_item_request_update (item); + break; + + case PROP_LINE_WIDTH: + priv->line_width = g_value_get_double (value); + + gnome_canvas_item_request_update (item); + break; + + case PROP_WIND: + priv->wind = g_value_get_enum (value); gnome_canvas_item_request_update (item); break; + case PROP_CAP_STYLE: + priv->cap = g_value_get_enum (value); + gnome_canvas_item_request_update (item); + break; + + case PROP_JOIN_STYLE: + priv->join = g_value_get_enum (value); + gnome_canvas_item_request_update (item); + break; + + case PROP_MITERLIMIT: + priv->miterlimit = g_value_get_double (value); + gnome_canvas_item_request_update (item); + break; + + case PROP_DASH: + /* XXX */ + g_assert_not_reached (); + break; + default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void -gnome_canvas_rect_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) +gnome_canvas_rect_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - GnomeCanvasRect *rect; + GnomeCanvasRect *rect = GNOME_CANVAS_RECT (object); + GnomeCanvasRectPrivate *priv = rect->priv; - g_return_if_fail (object != NULL); - g_return_if_fail (GNOME_IS_CANVAS_RECT (object)); - - rect = GNOME_CANVAS_RECT (object); + switch (property_id) { - switch (param_id) { case PROP_X1: - g_value_set_double (value, rect->x1); + g_value_set_double (value, priv->x1); break; case PROP_Y1: - g_value_set_double (value, rect->y1); + g_value_set_double (value, priv->y1); break; case PROP_X2: - g_value_set_double (value, rect->x2); + g_value_set_double (value, priv->x2); break; case PROP_Y2: - g_value_set_double (value, rect->y2); + g_value_set_double (value, priv->y2); + break; + + case PROP_FILL_COLOR_RGBA: + g_value_set_uint (value, priv->fill_rgba); + break; + + case PROP_OUTLINE_COLOR_RGBA: + g_value_set_uint (value, priv->outline_rgba); + break; + + case PROP_WIND: + g_value_set_uint (value, priv->wind); + break; + + case PROP_CAP_STYLE: + g_value_set_enum (value, priv->cap); + break; + + case PROP_JOIN_STYLE: + g_value_set_enum (value, priv->join); + break; + + case PROP_LINE_WIDTH: + g_value_set_double (value, priv->line_width); + break; + + case PROP_MITERLIMIT: + g_value_set_double (value, priv->miterlimit); + break; + + case PROP_DASH: + /* XXX */ + g_assert_not_reached (); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void -gnome_canvas_rect_update (GnomeCanvasItem *item, const cairo_matrix_t *matrix, gint flags) +gnome_canvas_rect_dispose (GnomeCanvasItem *object) +{ + GnomeCanvasRect *rect; + + g_return_if_fail (GNOME_IS_CANVAS_RECT (object)); + + rect = GNOME_CANVAS_RECT (object); + + if (rect->priv->path != NULL) { + cairo_path_destroy (rect->priv->path); + rect->priv->path = NULL; + } + + g_free (rect->priv->dash); + rect->priv->dash = NULL; + + if (GNOME_CANVAS_ITEM_CLASS (gnome_canvas_rect_parent_class)->dispose) + GNOME_CANVAS_ITEM_CLASS (gnome_canvas_rect_parent_class)->dispose (object); +} + +static void +gnome_canvas_rect_update (GnomeCanvasItem *item, + const cairo_matrix_t *i2c, + gint flags) +{ + GnomeCanvasRect *rect; + double x1, x2, y1, y2; + cairo_matrix_t matrix; + + rect = GNOME_CANVAS_RECT (item); + + GNOME_CANVAS_ITEM_CLASS (gnome_canvas_rect_parent_class)-> + update (item, i2c, flags); + + gnome_canvas_rect_bounds (item, &x1, &y1, &x2, &y2); + gnome_canvas_item_i2w_matrix (item, &matrix); + + gnome_canvas_matrix_transform_rect (&matrix, &x1, &y1, &x2, &y2); + + gnome_canvas_update_bbox ( + item, floor (x1), floor (y1), ceil (x2), ceil (y2)); +} + +static void +gnome_canvas_rect_draw (GnomeCanvasItem *item, + GdkDrawable *drawable, + gint x, + gint y, + gint width, + gint height) { - GnomeCanvasRect *rect = GNOME_CANVAS_RECT (item); + GnomeCanvasRect *rect; + cairo_matrix_t matrix; + cairo_t *cr; - if (rect->path_dirty) { - cairo_t *cr; + rect = GNOME_CANVAS_RECT (item); + cr = gdk_cairo_create (drawable); - cr = gnome_canvas_cairo_create_scratch (); + gnome_canvas_item_i2c_matrix (item, &matrix); + cairo_transform (cr, &matrix); - cairo_rectangle (cr, - rect->x1, rect->y1, - rect->x2 - rect->x1, - rect->y2 - rect->y1); + cairo_rectangle ( + cr, + rect->priv->x1, + rect->priv->y1, + rect->priv->x2 - rect->priv->x1, + rect->priv->y2 - rect->priv->y1); - gnome_canvas_shape_set_path (GNOME_CANVAS_SHAPE (item), - cairo_copy_path (cr)); - - cairo_destroy (cr); + if (gnome_canvas_rect_setup_for_fill (rect, cr)) + cairo_fill_preserve (cr); - rect->path_dirty = 0; + if (gnome_canvas_rect_setup_for_stroke (rect, cr)) + cairo_stroke_preserve (cr); + + cairo_destroy (cr); +} + +static GnomeCanvasItem * +gnome_canvas_rect_point (GnomeCanvasItem *item, + gdouble x, + gdouble y, + gint cx, + gint cy) +{ + GnomeCanvasRect *rect; + cairo_t *cr; + + rect = GNOME_CANVAS_RECT (item); + + cr = gnome_canvas_cairo_create_scratch (); + + cairo_rectangle ( + cr, + rect->priv->x1, + rect->priv->y1, + rect->priv->x2 - rect->priv->x1, + rect->priv->y2 - rect->priv->y1); + + if (gnome_canvas_rect_setup_for_fill (rect, cr) && + cairo_in_fill (cr, x, y)) { + cairo_destroy (cr); + return item; + } + + if (gnome_canvas_rect_setup_for_stroke (rect, cr) && + cairo_in_stroke (cr, x, y)) { + cairo_destroy (cr); + return item; + } + + cairo_destroy (cr); + + return NULL; +} + +static void +gnome_canvas_rect_bounds (GnomeCanvasItem *item, + gdouble *x1, + gdouble *y1, + gdouble *x2, + gdouble *y2) +{ + GnomeCanvasRect *rect; + cairo_t *cr; + + rect = GNOME_CANVAS_RECT (item); + + cr = gnome_canvas_cairo_create_scratch (); + + cairo_rectangle ( + cr, + rect->priv->x1, + rect->priv->y1, + rect->priv->x2 - rect->priv->x1, + rect->priv->y2 - rect->priv->y1); + + if (gnome_canvas_rect_setup_for_stroke (rect, cr)) + cairo_stroke_extents (cr, x1, y1, x2, y2); + else if (gnome_canvas_rect_setup_for_fill (rect, cr)) + cairo_fill_extents (cr, x1, y1, x2, y2); + else { + *x1 = *x2 = *y1 = *y2 = 0; } - if (GNOME_CANVAS_ITEM_CLASS (gnome_canvas_rect_parent_class)->update) - GNOME_CANVAS_ITEM_CLASS (gnome_canvas_rect_parent_class)->update (item, matrix, flags); + cairo_destroy (cr); } + +static void +gnome_canvas_rect_class_init (GnomeCanvasRectClass *class) +{ + GObjectClass *object_class; + GnomeCanvasItemClass *item_class; + + g_type_class_add_private (class, sizeof (GnomeCanvasRectPrivate)); + + object_class = G_OBJECT_CLASS (class); + object_class->set_property = gnome_canvas_rect_set_property; + object_class->get_property = gnome_canvas_rect_get_property; + + item_class = GNOME_CANVAS_ITEM_CLASS (class); + item_class->dispose = gnome_canvas_rect_dispose; + item_class->update = gnome_canvas_rect_update; + item_class->draw = gnome_canvas_rect_draw; + item_class->point = gnome_canvas_rect_point; + item_class->bounds = gnome_canvas_rect_bounds; + + g_object_class_install_property ( + object_class, + PROP_X1, + g_param_spec_double ( + "x1", + NULL, + NULL, + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_Y1, + g_param_spec_double ( + "y1", + NULL, + NULL, + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_X2, + g_param_spec_double ( + "x2", + NULL, + NULL, + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_Y2, + g_param_spec_double ( + "y2", + NULL, + NULL, + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_FILL_COLOR, + g_param_spec_string ( + "fill_color", + NULL, + NULL, + NULL, + G_PARAM_WRITABLE)); + + g_object_class_install_property ( + object_class, + PROP_FILL_COLOR_GDK, + g_param_spec_boxed ( + "fill_color_gdk", + NULL, + NULL, + GDK_TYPE_COLOR, + G_PARAM_WRITABLE)); + + g_object_class_install_property ( + object_class, + PROP_FILL_COLOR_RGBA, + g_param_spec_uint ( + "fill_rgba", + NULL, + NULL, + 0, + G_MAXUINT, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_OUTLINE_COLOR, + g_param_spec_string ( + "outline_color", + NULL, + NULL, + NULL, + G_PARAM_WRITABLE)); + + g_object_class_install_property ( + object_class, + PROP_OUTLINE_COLOR_GDK, + g_param_spec_boxed ( + "outline_color_gdk", + NULL, + NULL, + GDK_TYPE_COLOR, + G_PARAM_WRITABLE)); + + g_object_class_install_property ( + object_class, + PROP_OUTLINE_COLOR_RGBA, + g_param_spec_uint ( + "outline_rgba", + NULL, + NULL, + 0, + G_MAXUINT, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_LINE_WIDTH, + g_param_spec_double ( + "line_width", + NULL, + NULL, + 0.0, + G_MAXDOUBLE, + 1.0, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_CAP_STYLE, + g_param_spec_enum ( + "cap_style", + NULL, + NULL, + CAIRO_GOBJECT_TYPE_LINE_CAP, + CAIRO_LINE_CAP_BUTT, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_JOIN_STYLE, + g_param_spec_enum ( + "join_style", + NULL, + NULL, + CAIRO_GOBJECT_TYPE_LINE_JOIN, + CAIRO_LINE_JOIN_MITER, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_WIND, + g_param_spec_enum ( + "wind", + NULL, + NULL, + CAIRO_GOBJECT_TYPE_FILL_RULE, + CAIRO_FILL_RULE_EVEN_ODD, + G_PARAM_READWRITE)); + + g_object_class_install_property ( + object_class, + PROP_MITERLIMIT, + g_param_spec_double ( + "miterlimit", + NULL, + NULL, + 0.0, + G_MAXDOUBLE, + 10.43, + G_PARAM_READWRITE)); + +#if 0 + /* XXX: Find a good way to pass dash properties in a property */ + g_object_class_install_property ( + object_class, + PROP_DASH, + g_param_spec_pointer ( + "dash", + NULL, + NULL, + G_PARAM_READWRITE)); +#endif +} + +static void +gnome_canvas_rect_init (GnomeCanvasRect *rect) +{ + rect->priv = GNOME_CANVAS_RECT_GET_PRIVATE (rect); + + rect->priv->scale = 1.0; + + rect->priv->fill_set = FALSE; + rect->priv->outline_set = FALSE; + + rect->priv->line_width = 1.0; + + rect->priv->fill_rgba = 0x0000003f; + rect->priv->outline_rgba = 0x0000007f; + + rect->priv->cap = CAIRO_LINE_CAP_BUTT; + rect->priv->join = CAIRO_LINE_JOIN_MITER; + rect->priv->wind = CAIRO_FILL_RULE_EVEN_ODD; + rect->priv->miterlimit = 10.43; /* X11 default */ + + rect->priv->n_dash = 0; + rect->priv->dash = NULL; +} + diff --git a/libgnomecanvas/gnome-canvas-rect.h b/libgnomecanvas/gnome-canvas-rect.h index fd9946583f..683b7523fa 100644 --- a/libgnomecanvas/gnome-canvas-rect.h +++ b/libgnomecanvas/gnome-canvas-rect.h @@ -1,64 +1,45 @@ -/* - * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation - * All rights reserved. - * - * This file is part of the Gnome Library. - * - * The Gnome Library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * The Gnome Library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with the Gnome Library; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -/* - @NOTATION@ - */ -/* Rectangle and ellipse item types for GnomeCanvas widget +/* Generic bezier shape item for GnomeCanvas * * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget. Tk is * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties. * + * Copyright (C) 1998,1999 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Authors: Federico Mena <federico@nuclecu.unam.mx> + * Raph Levien <raph@acm.org> + * Lauris Kaplinski <lauris@ximian.com> + * Rusty Conover <rconover@bangtail.net> */ -#ifndef GNOME_CANVAS_RECT_ELLIPSE_H -#define GNOME_CANVAS_RECT_ELLIPSE_H +#ifndef GNOME_CANVAS_RECT_H +#define GNOME_CANVAS_RECT_H #include <libgnomecanvas/gnome-canvas.h> -#include <libgnomecanvas/gnome-canvas-shape.h> - G_BEGIN_DECLS -/* Rectangle item. These are defined by their top-left and bottom-right corners. - * Rectangles have the following arguments: +/* Rect item for the canvas. + * + * The following object arguments are available: * - * name type read/write description + * name type read/write description * ------------------------------------------------------------------------------------------ - * x1 gdouble RW Leftmost coordinate of rectangle or ellipse - * y1 gdouble RW Topmost coordinate of rectangle or ellipse - * x2 gdouble RW Rightmost coordinate of rectangle or ellipse - * y2 gdouble RW Bottommost coordinate of rectangle or ellipse - * fill_color string W X color specification for fill color, - * or NULL pointer for no color (transparent) - * fill_color_gdk GdkColor* RW Allocated GdkColor for fill - * outline_color string W X color specification for outline color, - * or NULL pointer for no color (transparent) - * outline_color_gdk GdkColor* RW Allocated GdkColor for outline - * width_pixels uint RW Width of the outline in pixels. The outline will - * not be scaled when the canvas zoom factor is changed. - * width_units gdouble RW Width of the outline in canvas units. The outline - * will be scaled when the canvas zoom factor is changed. + * fill_color string W X color specification for fill color, + * or NULL pointer for no color (transparent). + * fill_color_gdk GdkColor* RW Allocated GdkColor for fill. + * outline_color string W X color specification for outline color, + * or NULL pointer for no color (transparent). + * outline_color_gdk GdkColor* RW Allocated GdkColor for outline. + * width_pixels uint RW Width of the outline in pixels. The outline will + * not be scaled when the canvas zoom factor is changed. + * width_units gdouble RW Width of the outline in canvas units. The outline + * will be scaled when the canvas zoom factor is changed. + * cap_style cairo_line_cap_t RW Cap ("endpoint") style for the bpath. + * join_style cairo_line_join_t RW Join ("vertex") style for the bpath. + * wind cairo_fill_rule_t RW Winding rule for the bpath. + * dash XXX: disabled RW Dashing pattern + * miterlimit gdouble RW Minimum angle between segments, where miter join + * rule is applied. */ #define GNOME_TYPE_CANVAS_RECT (gnome_canvas_rect_get_type ()) @@ -66,26 +47,22 @@ G_BEGIN_DECLS #define GNOME_CANVAS_RECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_RECT, GnomeCanvasRectClass)) #define GNOME_IS_CANVAS_RECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS_RECT)) #define GNOME_IS_CANVAS_RECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_RECT)) -#define GNOME_CANVAS_RECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNOME_TYPE_CANVAS_RECT, GnomeCanvasRectClass)) typedef struct _GnomeCanvasRect GnomeCanvasRect; typedef struct _GnomeCanvasRectClass GnomeCanvasRectClass; +typedef struct _GnomeCanvasRectPrivate GnomeCanvasRectPrivate; struct _GnomeCanvasRect { - GnomeCanvasShape parent; - - gdouble x1, y1, x2, y2; /* Corners of item */ - - guint path_dirty : 1; + GnomeCanvasItem item; + GnomeCanvasRectPrivate *priv; }; struct _GnomeCanvasRectClass { - GnomeCanvasShapeClass parent_class; + GnomeCanvasItemClass parent_class; }; -/* Standard Gtk function */ GType gnome_canvas_rect_get_type (void) G_GNUC_CONST; G_END_DECLS -#endif +#endif /* GNOME_CANVAS_RECT_H */ diff --git a/libgnomecanvas/gnome-canvas-shape-private.h b/libgnomecanvas/gnome-canvas-shape-private.h deleted file mode 100644 index 4be04f6ec5..0000000000 --- a/libgnomecanvas/gnome-canvas-shape-private.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef GNOME_CANVAS_SHAPE_PRIVATE_H -#define GNOME_CANVAS_SHAPE_PRIVATE_H - -/* Bpath item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget. Tk is - * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998,1999 The Free Software Foundation - * - * Authors: Federico Mena <federico@nuclecu.unam.mx> - * Raph Levien <raph@acm.org> - * Lauris Kaplinski <lauris@ariman.ee> - */ - -#include <gdk/gdk.h> -#include <libgnomecanvas/gnome-canvas.h> - -G_BEGIN_DECLS - -struct _GnomeCanvasShapePriv { - cairo_path_t *path; /* Our bezier path representation */ - - gdouble scale; /* CTM scaling (for pen) */ - - guint fill_set : 1; /* Is fill color set? */ - guint outline_set : 1; /* Is outline color set? */ - - gdouble line_width; /* Width of outline, in user coords */ - - guint32 fill_rgba; /* Fill color, RGBA */ - guint32 outline_rgba; /* Outline color, RGBA */ - - cairo_line_cap_t cap; /* Cap style for line */ - cairo_line_join_t join; /* Join style for line */ - cairo_fill_rule_t wind; /* Winding rule */ - gdouble miterlimit; /* Miter limit */ - - guint n_dash; /* Number of elements in dashing pattern */ - double *dash; /* Dashing pattern */ - double dash_offset; /* Dashing offset */ -}; - -G_END_DECLS - -#endif diff --git a/libgnomecanvas/gnome-canvas-shape.c b/libgnomecanvas/gnome-canvas-shape.c deleted file mode 100644 index 8d5072facd..0000000000 --- a/libgnomecanvas/gnome-canvas-shape.c +++ /dev/null @@ -1,582 +0,0 @@ -/* Generic bezier shape item for GnomeCanvasWidget. Most code taken - * from gnome-canvas-bpath but made into a shape item. - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998,1999 The Free Software Foundation - * - * Authors: Federico Mena <federico@nuclecu.unam.mx> - * Raph Levien <raph@acm.org> - * Lauris Kaplinski <lauris@ximian.com> - * Miguel de Icaza <miguel@kernel.org> - * Cody Russell <bratsche@gnome.org> - * Rusty Conover <rconover@bangtail.net> - */ - -/* These includes are set up for standalone compile. If/when this codebase - is integrated into libgnomeui, the includes will need to change. */ - -#include <math.h> -#include <string.h> - -#include <gtk/gtk.h> -#include <cairo-gobject.h> -#include "gnome-canvas.h" -#include "gnome-canvas-util.h" - -#include "gnome-canvas-shape.h" -#include "gnome-canvas-shape-private.h" - -enum { - PROP_0, - PROP_FILL_COLOR, - PROP_FILL_COLOR_GDK, - PROP_FILL_COLOR_RGBA, - PROP_OUTLINE_COLOR, - PROP_OUTLINE_COLOR_GDK, - PROP_OUTLINE_COLOR_RGBA, - PROP_LINE_WIDTH, - PROP_CAP_STYLE, - PROP_JOIN_STYLE, - PROP_WIND, - PROP_MITERLIMIT, - PROP_DASH -}; - -static void gnome_canvas_shape_dispose (GnomeCanvasItem *object); -static void gnome_canvas_shape_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void gnome_canvas_shape_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void gnome_canvas_shape_update (GnomeCanvasItem *item, const cairo_matrix_t *i2c, gint flags); -static void gnome_canvas_shape_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - gint x, gint y, gint width, gint height); -static GnomeCanvasItem *gnome_canvas_shape_point (GnomeCanvasItem *item, gdouble x, gdouble y, - gint cx, gint cy); -static void gnome_canvas_shape_bounds (GnomeCanvasItem *item, - gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2); - -G_DEFINE_TYPE (GnomeCanvasShape, gnome_canvas_shape, GNOME_TYPE_CANVAS_ITEM) - -static void -gnome_canvas_shape_class_init (GnomeCanvasShapeClass *class) -{ - GObjectClass *gobject_class; - GnomeCanvasItemClass *item_class; - - gobject_class = (GObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gobject_class->set_property = gnome_canvas_shape_set_property; - gobject_class->get_property = gnome_canvas_shape_get_property; - - g_object_class_install_property (gobject_class, - PROP_FILL_COLOR, - g_param_spec_string ("fill_color", NULL, NULL, - NULL, - (G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_FILL_COLOR_GDK, - g_param_spec_boxed ("fill_color_gdk", NULL, NULL, - GDK_TYPE_COLOR, - G_PARAM_WRITABLE)); - g_object_class_install_property (gobject_class, - PROP_FILL_COLOR_RGBA, - g_param_spec_uint ("fill_rgba", NULL, NULL, - 0, G_MAXUINT, 0, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_OUTLINE_COLOR, - g_param_spec_string ("outline_color", NULL, NULL, - NULL, - (G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_OUTLINE_COLOR_GDK, - g_param_spec_boxed ("outline_color_gdk", NULL, NULL, - GDK_TYPE_COLOR, - G_PARAM_WRITABLE)); - g_object_class_install_property (gobject_class, - PROP_OUTLINE_COLOR_RGBA, - g_param_spec_uint ("outline_rgba", NULL, NULL, - 0, G_MAXUINT, 0, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_LINE_WIDTH, - g_param_spec_double ("line_width", NULL, NULL, - 0.0, G_MAXDOUBLE, 1.0, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_CAP_STYLE, - g_param_spec_enum ("cap_style", NULL, NULL, - CAIRO_GOBJECT_TYPE_LINE_CAP, - CAIRO_LINE_CAP_BUTT, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_JOIN_STYLE, - g_param_spec_enum ("join_style", NULL, NULL, - CAIRO_GOBJECT_TYPE_LINE_JOIN, - CAIRO_LINE_JOIN_MITER, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_WIND, - g_param_spec_enum ("wind", NULL, NULL, - CAIRO_GOBJECT_TYPE_FILL_RULE, - CAIRO_FILL_RULE_EVEN_ODD, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_MITERLIMIT, - g_param_spec_double ("miterlimit", NULL, NULL, - 0.0, G_MAXDOUBLE, 10.43, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); -#if 0 - /* XXX: Find a good way to pass dash properties in a property */ - g_object_class_install_property (gobject_class, - PROP_DASH, - g_param_spec_pointer ("dash", NULL, NULL, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); -#endif - - item_class->dispose = gnome_canvas_shape_dispose; - item_class->update = gnome_canvas_shape_update; - item_class->draw = gnome_canvas_shape_draw; - item_class->point = gnome_canvas_shape_point; - item_class->bounds = gnome_canvas_shape_bounds; - - g_type_class_add_private (class, sizeof (GnomeCanvasShapePriv)); -} - -static void -gnome_canvas_shape_init (GnomeCanvasShape *shape) -{ - shape->priv = G_TYPE_INSTANCE_GET_PRIVATE (shape, - GNOME_TYPE_CANVAS_SHAPE, - GnomeCanvasShapePriv); - - shape->priv->path = NULL; - - shape->priv->scale = 1.0; - - shape->priv->fill_set = FALSE; - shape->priv->outline_set = FALSE; - - shape->priv->line_width = 1.0; - - shape->priv->fill_rgba = 0x0000003f; - shape->priv->outline_rgba = 0x0000007f; - - shape->priv->cap = CAIRO_LINE_CAP_BUTT; - shape->priv->join = CAIRO_LINE_JOIN_MITER; - shape->priv->wind = CAIRO_FILL_RULE_EVEN_ODD; - shape->priv->miterlimit = 10.43; /* X11 default */ - - shape->priv->n_dash = 0; - shape->priv->dash = NULL; -} - -static void -gnome_canvas_shape_dispose (GnomeCanvasItem *object) -{ - GnomeCanvasShape *shape; - - g_return_if_fail (GNOME_IS_CANVAS_SHAPE (object)); - - shape = GNOME_CANVAS_SHAPE (object); - - if (shape->priv->path != NULL) { - cairo_path_destroy (shape->priv->path); - shape->priv->path = NULL; - } - - g_free (shape->priv->dash); - shape->priv->dash = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (gnome_canvas_shape_parent_class)->dispose) - GNOME_CANVAS_ITEM_CLASS (gnome_canvas_shape_parent_class)->dispose (object); -} - -/** - * gnome_canvas_shape_set_path: - * @shape: a GnomeCanvasShape - * @path: a cairo path from a cairo_copy_path() call - * - * This function sets the the path used by the GnomeCanvasShape. - * Notice that it does not request updates, as it is meant to be used - * from item implementations, from inside update queue. - */ -void -gnome_canvas_shape_set_path (GnomeCanvasShape *shape, cairo_path_t *path) -{ - GnomeCanvasShapePriv *priv; - - g_return_if_fail (shape != NULL); - g_return_if_fail (GNOME_IS_CANVAS_SHAPE (shape)); - - priv = shape->priv; - - if (priv->path) { - cairo_path_destroy (priv->path); - priv->path = NULL; - } - - priv->path = path; -} - -static guint32 -get_rgba_from_color (GdkColor * color) -{ - return ((color->red & 0xff00) << 16) | ((color->green & 0xff00) << 8) | (color->blue & 0xff00) | 0xff; -} - -static void -gnome_canvas_shape_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - GnomeCanvasItem *item; - GnomeCanvasShape *shape; - GnomeCanvasShapePriv *priv; - GdkColor color; - GdkColor *colorptr; - const gchar *color_string; - - item = GNOME_CANVAS_ITEM (object); - shape = GNOME_CANVAS_SHAPE (object); - priv = shape->priv; - - switch (param_id) { - case PROP_FILL_COLOR: - color_string = g_value_get_string (value); - if (color_string != NULL) { - if (gdk_color_parse (color_string, &color)) { - g_warning ( - "Failed to parse color '%s'", - color_string); - break; - } - priv->fill_set = TRUE; - priv->fill_rgba = get_rgba_from_color (&color); - } else if (priv->fill_set) - priv->fill_set = FALSE; - else - break; - - gnome_canvas_item_request_update (item); - break; - - case PROP_FILL_COLOR_GDK: - colorptr = g_value_get_boxed (value); - if (colorptr != NULL) { - priv->fill_set = TRUE; - priv->fill_rgba = get_rgba_from_color (colorptr); - } else if (priv->fill_set) - priv->fill_set = FALSE; - else - break; - - gnome_canvas_item_request_update (item); - break; - - case PROP_FILL_COLOR_RGBA: - priv->fill_set = TRUE; - priv->fill_rgba = g_value_get_uint (value); - - gnome_canvas_item_request_update (item); - break; - - case PROP_OUTLINE_COLOR: - color_string = g_value_get_string (value); - if (color_string != NULL) { - if (!gdk_color_parse (color_string, &color)) { - g_warning ( - "Failed to parse color '%s'", - color_string); - break; - } - priv->outline_set = TRUE; - priv->outline_rgba = get_rgba_from_color (&color); - } else if (priv->outline_set) - priv->outline_set = FALSE; - else - break; - - gnome_canvas_item_request_update (item); - break; - - case PROP_OUTLINE_COLOR_GDK: - colorptr = g_value_get_boxed (value); - if (colorptr != NULL) { - priv->outline_set = TRUE; - priv->outline_rgba = get_rgba_from_color (colorptr); - } else if (priv->outline_set) - priv->outline_set = FALSE; - else - break; - - gnome_canvas_item_request_update (item); - break; - - case PROP_OUTLINE_COLOR_RGBA: - priv->outline_set = TRUE; - priv->outline_rgba = g_value_get_uint (value); - - gnome_canvas_item_request_update (item); - break; - - case PROP_LINE_WIDTH: - priv->line_width = g_value_get_double (value); - - gnome_canvas_item_request_update (item); - break; - - case PROP_WIND: - priv->wind = g_value_get_enum (value); - gnome_canvas_item_request_update (item); - break; - - case PROP_CAP_STYLE: - priv->cap = g_value_get_enum (value); - gnome_canvas_item_request_update (item); - break; - - case PROP_JOIN_STYLE: - priv->join = g_value_get_enum (value); - gnome_canvas_item_request_update (item); - break; - - case PROP_MITERLIMIT: - priv->miterlimit = g_value_get_double (value); - gnome_canvas_item_request_update (item); - break; - - case PROP_DASH: - /* XXX */ - g_assert_not_reached (); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -/** - * gnome_canvas_shape_get_path: - * @shape: a GnomeCanvasShape - * - * This function returns the #cairo_path_t that the shape currently - * uses. If there is not a #GnomeCanvasPathDef set for the shape - * it returns NULL. - * - * Returns: a #cairo_path_t or NULL if none is set for the shape. - */ -const cairo_path_t * -gnome_canvas_shape_get_path (GnomeCanvasShape *shape) -{ - g_return_val_if_fail (shape != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CANVAS_SHAPE (shape), NULL); - - return shape->priv->path; -} - -static void -gnome_canvas_shape_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - GnomeCanvasShape *shape = GNOME_CANVAS_SHAPE (object); - GnomeCanvasShapePriv *priv = shape->priv; - - switch (param_id) { - - case PROP_FILL_COLOR_RGBA: - g_value_set_uint (value, priv->fill_rgba); - break; - - case PROP_OUTLINE_COLOR_RGBA: - g_value_set_uint (value, priv->outline_rgba); - break; - - case PROP_WIND: - g_value_set_uint (value, priv->wind); - break; - - case PROP_CAP_STYLE: - g_value_set_enum (value, priv->cap); - break; - - case PROP_JOIN_STYLE: - g_value_set_enum (value, priv->join); - break; - - case PROP_LINE_WIDTH: - g_value_set_double (value, priv->line_width); - break; - - case PROP_MITERLIMIT: - g_value_set_double (value, priv->miterlimit); - break; - - case PROP_DASH: - /* XXX */ - g_assert_not_reached (); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static gboolean -gnome_canvas_shape_setup_for_fill (GnomeCanvasShape *shape, cairo_t *cr) -{ - GnomeCanvasShapePriv *priv = shape->priv; - - if (!priv->fill_set) - return FALSE; - - cairo_set_source_rgba (cr, - ((priv->fill_rgba >> 24) & 0xff) / 255.0, - ((priv->fill_rgba >> 16) & 0xff) / 255.0, - ((priv->fill_rgba >> 8) & 0xff) / 255.0, - ( priv->fill_rgba & 0xff) / 255.0); - cairo_set_fill_rule (cr, priv->wind); - - return TRUE; -} - -static gboolean -gnome_canvas_shape_setup_for_stroke (GnomeCanvasShape *shape, cairo_t *cr) -{ - GnomeCanvasShapePriv *priv = shape->priv; - - if (!priv->outline_set) - return FALSE; - - cairo_set_source_rgba (cr, - ((priv->outline_rgba >> 24) & 0xff) / 255.0, - ((priv->outline_rgba >> 16) & 0xff) / 255.0, - ((priv->outline_rgba >> 8) & 0xff) / 255.0, - ( priv->outline_rgba & 0xff) / 255.0); - cairo_set_line_width (cr, priv->line_width); - cairo_set_line_cap (cr, priv->cap); - cairo_set_line_join (cr, priv->join); - cairo_set_miter_limit (cr, priv->miterlimit); - cairo_set_dash (cr, priv->dash, priv->n_dash, priv->dash_offset); - - return TRUE; -} - -static void -gnome_canvas_shape_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - gint x, - gint y, - gint width, - gint height) -{ - GnomeCanvasShape * shape; - cairo_matrix_t matrix; - cairo_t *cr; - - shape = GNOME_CANVAS_SHAPE (item); - cr = gdk_cairo_create (drawable); - gnome_canvas_item_i2c_matrix (item, &matrix); - cairo_transform (cr, &matrix); - cairo_append_path (cr, shape->priv->path); - - if (gnome_canvas_shape_setup_for_fill (shape, cr)) - cairo_fill_preserve (cr); - - if (gnome_canvas_shape_setup_for_stroke (shape, cr)) - cairo_stroke_preserve (cr); - - cairo_destroy (cr); -} - -static void -gnome_canvas_shape_bounds (GnomeCanvasItem *item, gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2) -{ - GnomeCanvasShape * shape; - GnomeCanvasShapePriv * priv; - cairo_t *cr; - - shape = GNOME_CANVAS_SHAPE (item); - priv = shape->priv; - - cr = gnome_canvas_cairo_create_scratch (); - cairo_append_path (cr, shape->priv->path); - - if (gnome_canvas_shape_setup_for_stroke (shape, cr)) - cairo_stroke_extents (cr, x1, y1, x2, y2); - else if (gnome_canvas_shape_setup_for_fill (shape, cr)) - cairo_fill_extents (cr, x1, y1, x2, y2); - else { - *x1 = *x2 = *y1 = *y2 = 0; - } - - cairo_destroy (cr); -} - -static void -gnome_canvas_shape_update (GnomeCanvasItem *item, const cairo_matrix_t *i2c, gint flags) -{ - GnomeCanvasShape * shape; - GnomeCanvasShapePriv * priv; - double x1, x2, y1, y2; - cairo_matrix_t matrix; - - shape = GNOME_CANVAS_SHAPE (item); - - priv = shape->priv; - - /* Common part */ - if (GNOME_CANVAS_ITEM_CLASS (gnome_canvas_shape_parent_class)->update) - GNOME_CANVAS_ITEM_CLASS (gnome_canvas_shape_parent_class)->update (item, i2c, flags); - - gnome_canvas_shape_bounds (item, &x1, &y1, &x2, &y2); - gnome_canvas_item_i2w_matrix (item, &matrix); - - gnome_canvas_matrix_transform_rect (&matrix, &x1, &y1, &x2, &y2); - gnome_canvas_update_bbox (GNOME_CANVAS_ITEM (shape), - floor (x1), floor (y1), - ceil (x2), ceil (y2)); -} - -static GnomeCanvasItem * -gnome_canvas_shape_point (GnomeCanvasItem *item, gdouble x, gdouble y, - gint cx, gint cy) -{ - GnomeCanvasShape * shape; - cairo_t *cr; - - shape = GNOME_CANVAS_SHAPE (item); - - cr = gnome_canvas_cairo_create_scratch (); - cairo_append_path (cr, shape->priv->path); - - if (gnome_canvas_shape_setup_for_fill (shape, cr) && - cairo_in_fill (cr, x, y)) { - cairo_destroy (cr); - return item; - } - - if (gnome_canvas_shape_setup_for_stroke (shape, cr) && - cairo_in_stroke (cr, x, y)) { - cairo_destroy (cr); - return item; - } - - cairo_destroy (cr); - - return NULL; -} diff --git a/libgnomecanvas/gnome-canvas-shape.h b/libgnomecanvas/gnome-canvas-shape.h deleted file mode 100644 index c27c606868..0000000000 --- a/libgnomecanvas/gnome-canvas-shape.h +++ /dev/null @@ -1,75 +0,0 @@ -/* Generic bezier shape item for GnomeCanvas - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget. Tk is - * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998,1999 The Free Software Foundation - * - * Authors: Federico Mena <federico@nuclecu.unam.mx> - * Raph Levien <raph@acm.org> - * Lauris Kaplinski <lauris@ximian.com> - * Rusty Conover <rconover@bangtail.net> - */ - -#ifndef GNOME_CANVAS_SHAPE_H -#define GNOME_CANVAS_SHAPE_H - -#include <libgnomecanvas/gnome-canvas.h> - -G_BEGIN_DECLS - -/* Shape item for the canvas. - * - * The following object arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * fill_color string W X color specification for fill color, - * or NULL pointer for no color (transparent). - * fill_color_gdk GdkColor* RW Allocated GdkColor for fill. - * outline_color string W X color specification for outline color, - * or NULL pointer for no color (transparent). - * outline_color_gdk GdkColor* RW Allocated GdkColor for outline. - * width_pixels uint RW Width of the outline in pixels. The outline will - * not be scaled when the canvas zoom factor is changed. - * width_units gdouble RW Width of the outline in canvas units. The outline - * will be scaled when the canvas zoom factor is changed. - * cap_style cairo_line_cap_t RW Cap ("endpoint") style for the bpath. - * join_style cairo_line_join_t RW Join ("vertex") style for the bpath. - * wind cairo_fill_rule_t RW Winding rule for the bpath. - * dash XXX: disabled RW Dashing pattern - * miterlimit gdouble RW Minimum angle between segments, where miter join - * rule is applied. - */ - -#define GNOME_TYPE_CANVAS_SHAPE (gnome_canvas_shape_get_type ()) -#define GNOME_CANVAS_SHAPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNOME_TYPE_CANVAS_SHAPE, GnomeCanvasShape)) -#define GNOME_CANVAS_SHAPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNOME_TYPE_CANVAS_SHAPE, GnomeCanvasShapeClass)) -#define GNOME_IS_CANVAS_SHAPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNOME_TYPE_CANVAS_SHAPE)) -#define GNOME_IS_CANVAS_SHAPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_CANVAS_SHAPE)) - -typedef struct _GnomeCanvasShape GnomeCanvasShape; -typedef struct _GnomeCanvasShapePriv GnomeCanvasShapePriv; -typedef struct _GnomeCanvasShapeClass GnomeCanvasShapeClass; - -struct _GnomeCanvasShape { - GnomeCanvasItem item; - - GnomeCanvasShapePriv *priv; /* Private data */ -}; - -struct _GnomeCanvasShapeClass { - GnomeCanvasItemClass parent_class; -}; - -/* WARNING! These are not usable from modifying shapes from user programs */ -/* These are meant, to set master shape from subclass ::update method */ -void gnome_canvas_shape_set_path (GnomeCanvasShape *shape, cairo_path_t *path); -const cairo_path_t *gnome_canvas_shape_get_path (GnomeCanvasShape *shape); - -/* Standard Gtk function */ -GType gnome_canvas_shape_get_type (void) G_GNUC_CONST; - -G_END_DECLS - -#endif |