1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
/*
* 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
*
* 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.
*
*
* Authors: Federico Mena <federico@nuclecu.unam.mx>
* Rusty Conover <rconover@bangtail.net>
*/
#include <config.h>
#include <math.h>
#include "gnome-canvas-rect-ellipse.h"
#include "gnome-canvas-util.h"
#include "gnome-canvas-shape.h"
#include <libart_lgpl/art_vpath.h>
#include <libart_lgpl/art_svp.h>
#include <libart_lgpl/art_svp_vpath.h>
#include <libart_lgpl/art_rgb_svp.h>
/* Base class for rectangle and ellipse item types */
#define noVERBOSE
enum {
PROP_0,
PROP_X1,
PROP_Y1,
PROP_X2,
PROP_Y2
};
static void gnome_canvas_re_class_init (GnomeCanvasREClass *class);
static void gnome_canvas_re_init (GnomeCanvasRE *re);
static void gnome_canvas_re_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static void gnome_canvas_re_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void gnome_canvas_rect_update (GnomeCanvasItem *item, gdouble *affine, ArtSVP *clip_path, gint flags);
static GnomeCanvasItemClass *re_parent_class;
GType
gnome_canvas_re_get_type (void)
{
static GType re_type;
if (!re_type) {
const GTypeInfo object_info = {
sizeof (GnomeCanvasREClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gnome_canvas_re_class_init,
(GClassFinalizeFunc) NULL,
NULL, /* class_data */
sizeof (GnomeCanvasRE),
0, /* n_preallocs */
(GInstanceInitFunc) gnome_canvas_re_init,
NULL /* value_table */
};
re_type = g_type_register_static (GNOME_TYPE_CANVAS_SHAPE, "GnomeCanvasRE",
&object_info, 0);
}
return re_type;
}
static void
gnome_canvas_re_class_init (GnomeCanvasREClass *class)
{
GObjectClass *gobject_class;
gobject_class = (GObjectClass *) class;
re_parent_class = g_type_class_peek_parent (class);
gobject_class->set_property = gnome_canvas_re_set_property;
gobject_class->get_property = gnome_canvas_re_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)));
}
static void
gnome_canvas_re_init (GnomeCanvasRE *re)
{
re->x1 = 0.0;
re->y1 = 0.0;
re->x2 = 0.0;
re->y2 = 0.0;
re->path_dirty = 0;
}
static void
gnome_canvas_re_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
GnomeCanvasItem *item;
GnomeCanvasRE *re;
g_return_if_fail (object != NULL);
g_return_if_fail (GNOME_IS_CANVAS_RE (object));
item = GNOME_CANVAS_ITEM (object);
re = GNOME_CANVAS_RE (object);
switch (param_id) {
case PROP_X1:
re->x1 = g_value_get_double (value);
re->path_dirty = 1;
gnome_canvas_item_request_update (item);
break;
case PROP_Y1:
re->y1 = g_value_get_double (value);
re->path_dirty = 1;
gnome_canvas_item_request_update (item);
break;
case PROP_X2:
re->x2 = g_value_get_double (value);
re->path_dirty = 1;
gnome_canvas_item_request_update (item);
break;
case PROP_Y2:
re->y2 = g_value_get_double (value);
re->path_dirty = 1;
gnome_canvas_item_request_update (item);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
gnome_canvas_re_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
GnomeCanvasRE *re;
g_return_if_fail (object != NULL);
g_return_if_fail (GNOME_IS_CANVAS_RE (object));
re = GNOME_CANVAS_RE (object);
switch (param_id) {
case PROP_X1:
g_value_set_double (value, re->x1);
break;
case PROP_Y1:
g_value_set_double (value, re->y1);
break;
case PROP_X2:
g_value_set_double (value, re->x2);
break;
case PROP_Y2:
g_value_set_double (value, re->y2);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
/* Rectangle item */
static void gnome_canvas_rect_class_init (GnomeCanvasRectClass *class);
GType
gnome_canvas_rect_get_type (void)
{
static GType rect_type;
if (!rect_type) {
const GTypeInfo object_info = {
sizeof (GnomeCanvasRectClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gnome_canvas_rect_class_init,
(GClassFinalizeFunc) NULL,
NULL, /* class_data */
sizeof (GnomeCanvasRect),
0, /* n_preallocs */
(GInstanceInitFunc) NULL,
NULL /* value_table */
};
rect_type = g_type_register_static (GNOME_TYPE_CANVAS_RE, "GnomeCanvasRect",
&object_info, 0);
}
return rect_type;
}
static void
gnome_canvas_rect_class_init (GnomeCanvasRectClass *class)
{
GnomeCanvasItemClass *item_class;
item_class = (GnomeCanvasItemClass *) class;
item_class->update = gnome_canvas_rect_update;
}
static void
gnome_canvas_rect_update (GnomeCanvasItem *item, gdouble affine[6], ArtSVP *clip_path, gint flags)
{ GnomeCanvasRE *re;
GnomeCanvasPathDef *path_def;
re = GNOME_CANVAS_RE (item);
if (re->path_dirty) {
path_def = gnome_canvas_path_def_new ();
gnome_canvas_path_def_moveto (path_def, re->x1, re->y1);
gnome_canvas_path_def_lineto (path_def, re->x2, re->y1);
gnome_canvas_path_def_lineto (path_def, re->x2, re->y2);
gnome_canvas_path_def_lineto (path_def, re->x1, re->y2);
gnome_canvas_path_def_lineto (path_def, re->x1, re->y1);
gnome_canvas_path_def_closepath_current (path_def);
gnome_canvas_shape_set_path_def (GNOME_CANVAS_SHAPE (item), path_def);
gnome_canvas_path_def_unref (path_def);
re->path_dirty = 0;
}
if (re_parent_class->update)
(* re_parent_class->update) (item, affine, clip_path, flags);
}
|