2
* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
5
* This file is part of the Gnome Library.
7
* The Gnome Library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public License as
9
* published by the Free Software Foundation; either version 2 of the
10
* License, or (at your option) any later version.
12
* The Gnome Library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with the Gnome Library; see the file COPYING.LIB. If not,
19
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
25
/* Polygon item type for GnomeCanvas widget
27
* GnomeCanvas is basically a port of the Tk toolkit's most excellent canvas widget. Tk is
28
* copyrighted by the Regents of the University of California, Sun Microsystems, and other parties.
30
* Author: Federico Mena <federico@nuclecu.unam.mx>
31
* Rusty Conover <rconover@bangtail.net>
37
#include "libart_lgpl/art_vpath.h"
38
#include "libart_lgpl/art_svp.h"
39
#include "libart_lgpl/art_svp_vpath.h"
40
#include "libart_lgpl/art_svp_vpath_stroke.h"
41
#include "libgnomecanvas.h"
43
#include "gnome-canvas-shape.h"
46
#define NUM_STATIC_POINTS 256 /* Number of static points to use to avoid allocating arrays */
55
static void gnome_canvas_polygon_class_init (GnomeCanvasPolygonClass *class);
56
static void gnome_canvas_polygon_init (GnomeCanvasPolygon *poly);
57
static void gnome_canvas_polygon_destroy (GtkObject *object);
58
static void gnome_canvas_polygon_set_property (GObject *object,
62
static void gnome_canvas_polygon_get_property (GObject *object,
67
static void gnome_canvas_polygon_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags);
69
static GnomeCanvasItemClass *parent_class;
72
gnome_canvas_polygon_get_type (void)
74
static GType polygon_type;
77
static const GTypeInfo object_info = {
78
sizeof (GnomeCanvasPolygonClass),
80
(GBaseFinalizeFunc) NULL,
81
(GClassInitFunc) gnome_canvas_polygon_class_init,
82
(GClassFinalizeFunc) NULL,
83
NULL, /* class_data */
84
sizeof (GnomeCanvasPolygon),
86
(GInstanceInitFunc) gnome_canvas_polygon_init,
87
NULL /* value_table */
90
polygon_type = g_type_register_static (GNOME_TYPE_CANVAS_SHAPE, "GnomeCanvasPolygon",
98
gnome_canvas_polygon_class_init (GnomeCanvasPolygonClass *class)
100
GObjectClass *gobject_class;
101
GtkObjectClass *object_class;
102
GnomeCanvasItemClass *item_class;
104
gobject_class = (GObjectClass *) class;
105
object_class = (GtkObjectClass *) class;
106
item_class = (GnomeCanvasItemClass *) class;
108
parent_class = g_type_class_peek_parent (class);
110
gobject_class->set_property = gnome_canvas_polygon_set_property;
111
gobject_class->get_property = gnome_canvas_polygon_get_property;
113
g_object_class_install_property
116
g_param_spec_boxed ("points", NULL, NULL,
117
GNOME_TYPE_CANVAS_POINTS,
118
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
120
object_class->destroy = gnome_canvas_polygon_destroy;
122
item_class->update = gnome_canvas_polygon_update;
126
gnome_canvas_polygon_init (GnomeCanvasPolygon *poly)
128
poly->path_def = NULL;
132
gnome_canvas_polygon_destroy (GtkObject *object)
134
GnomeCanvasPolygon *poly;
136
g_return_if_fail (object != NULL);
137
g_return_if_fail (GNOME_IS_CANVAS_POLYGON (object));
139
poly = GNOME_CANVAS_POLYGON (object);
141
/* remember, destroy can be run multiple times! */
144
gnome_canvas_path_def_unref(poly->path_def);
146
poly->path_def = NULL;
149
if (GTK_OBJECT_CLASS (parent_class)->destroy)
150
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
154
set_points (GnomeCanvasPolygon *poly, GnomeCanvasPoints *points)
160
gnome_canvas_path_def_unref(poly->path_def);
163
poly->path_def = gnome_canvas_path_def_new();
164
gnome_canvas_shape_set_path_def (GNOME_CANVAS_SHAPE (poly), poly->path_def);
169
/* Optomize the path def to the number of points */
170
poly->path_def = gnome_canvas_path_def_new_sized(points->num_points+1);
173
/* No need for explicit duplicate, as closepaths does it for us (Lauris) */
174
/* See if we need to duplicate the first point */
175
duplicate = ((points->coords[0] != points->coords[2 * points->num_points - 2])
176
|| (points->coords[1] != points->coords[2 * points->num_points - 1]));
180
gnome_canvas_path_def_moveto (poly->path_def, points->coords[0], points->coords[1]);
182
for (i = 1; i < points->num_points; i++) {
183
gnome_canvas_path_def_lineto(poly->path_def, points->coords[i * 2], points->coords[(i * 2) + 1]);
186
gnome_canvas_path_def_closepath (poly->path_def);
188
gnome_canvas_shape_set_path_def (GNOME_CANVAS_SHAPE (poly), poly->path_def);
193
gnome_canvas_polygon_set_property (GObject *object,
198
GnomeCanvasItem *item;
199
GnomeCanvasPolygon *poly;
200
GnomeCanvasPoints *points;
202
g_return_if_fail (object != NULL);
203
g_return_if_fail (GNOME_IS_CANVAS_POLYGON (object));
205
item = GNOME_CANVAS_ITEM (object);
206
poly = GNOME_CANVAS_POLYGON (object);
210
points = g_value_get_boxed (value);
212
set_points (poly, points);
214
gnome_canvas_item_request_update (item);
217
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
224
gnome_canvas_polygon_get_property (GObject *object,
229
g_return_if_fail (object != NULL);
230
g_return_if_fail (GNOME_IS_CANVAS_POLYGON (object));
236
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
243
gnome_canvas_polygon_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
245
/* Since the path has already been defined just pass the update up. */
247
if (parent_class->update)
248
(* parent_class->update) (item, affine, clip_path, flags);