goocanvas 0.90.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +87 -0
- data/README +37 -0
- data/Rakefile +14 -0
- data/ext/goocanvas/Makefile +162 -0
- data/ext/goocanvas/depend +5 -0
- data/ext/goocanvas/extconf.rb +66 -0
- data/ext/goocanvas/goocanvas.def +2 -0
- data/ext/goocanvas/goocanvas.so +0 -0
- data/ext/goocanvas/rbgoo_canvasversion.h +25 -0
- data/ext/goocanvas/rbgoocairo.c +74 -0
- data/ext/goocanvas/rbgoocairo.o +0 -0
- data/ext/goocanvas/rbgoocanvas.c +236 -0
- data/ext/goocanvas/rbgoocanvas.h +66 -0
- data/ext/goocanvas/rbgoocanvas.o +0 -0
- data/ext/goocanvas/rbgoocanvasellipse.c +50 -0
- data/ext/goocanvas/rbgoocanvasellipse.o +0 -0
- data/ext/goocanvas/rbgoocanvasgroup.c +41 -0
- data/ext/goocanvas/rbgoocanvasgroup.o +0 -0
- data/ext/goocanvas/rbgoocanvasimage.c +45 -0
- data/ext/goocanvas/rbgoocanvasimage.o +0 -0
- data/ext/goocanvas/rbgoocanvasitem.c +358 -0
- data/ext/goocanvas/rbgoocanvasitem.o +0 -0
- data/ext/goocanvas/rbgoocanvaspolyline.c +102 -0
- data/ext/goocanvas/rbgoocanvaspolyline.o +0 -0
- data/ext/goocanvas/rbgoocanvasrect.c +47 -0
- data/ext/goocanvas/rbgoocanvasrect.o +0 -0
- data/ext/goocanvas/rbgoocanvasstyle.c +61 -0
- data/ext/goocanvas/rbgoocanvasstyle.o +0 -0
- data/ext/goocanvas/rbgoocanvastable.c +41 -0
- data/ext/goocanvas/rbgoocanvastable.o +0 -0
- data/ext/goocanvas/rbgoocanvastext.c +58 -0
- data/ext/goocanvas/rbgoocanvastext.o +0 -0
- data/ext/goocanvas/rbgoocanvaswidget.c +48 -0
- data/ext/goocanvas/rbgoocanvaswidget.o +0 -0
- data/ext/goocanvas/rbgooutils.c +44 -0
- data/ext/goocanvas/rbgooutils.o +0 -0
- data/ext/goocanvas/ruby-goocanvas.pc +3 -0
- data/extconf.rb +49 -0
- data/lib/goocanvas.rb +145 -0
- data/sample/demo-arrowhead.rb +315 -0
- data/sample/demo-fifteen.rb +218 -0
- data/sample/demo-primitives.rb +720 -0
- data/sample/demo.rb +84 -0
- data/sample/flower.png +0 -0
- data/sample/scalability-demo.rb +130 -0
- data/sample/simple-demo.rb +35 -0
- data/sample/table-demo.rb +137 -0
- data/sample/toroid.png +0 -0
- data/sample/units-demo.rb +80 -0
- data/sample/widgets-demo.rb +197 -0
- metadata +133 -0
Binary file
|
@@ -0,0 +1,358 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/* $Id: rbgoocanvasitem.c 3288 2008-09-13 10:07:44Z ktou $ */
|
3
|
+
/* GooCanvasItem
|
4
|
+
* Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "rbgoocanvas.h"
|
22
|
+
|
23
|
+
#define SELF(self) RVAL2GCI(self)
|
24
|
+
|
25
|
+
static VALUE
|
26
|
+
rb_goo_canvas_item_rotate(VALUE self, VALUE degrees, VALUE cx, VALUE cy)
|
27
|
+
{
|
28
|
+
goo_canvas_item_rotate(SELF(self), NUM2DBL(degrees),
|
29
|
+
NUM2DBL(cx), NUM2DBL(cy));
|
30
|
+
return self;
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE
|
34
|
+
rb_goo_canvas_item_translate(VALUE self, VALUE tx, VALUE ty)
|
35
|
+
{
|
36
|
+
goo_canvas_item_translate(SELF(self), NUM2DBL(tx), NUM2DBL(ty));
|
37
|
+
return self;
|
38
|
+
}
|
39
|
+
|
40
|
+
static VALUE
|
41
|
+
rb_goo_canvas_item_lower(VALUE self, VALUE below)
|
42
|
+
{
|
43
|
+
goo_canvas_item_lower(SELF(self), SELF(below));
|
44
|
+
return self;
|
45
|
+
}
|
46
|
+
|
47
|
+
static VALUE
|
48
|
+
rb_goo_canvas_item_raise(VALUE self, VALUE above)
|
49
|
+
{
|
50
|
+
goo_canvas_item_raise(SELF(self), SELF(above));
|
51
|
+
return self;
|
52
|
+
}
|
53
|
+
|
54
|
+
static VALUE
|
55
|
+
rb_goo_canvas_item_scale(VALUE self, VALUE sx, VALUE sy)
|
56
|
+
{
|
57
|
+
goo_canvas_item_scale(SELF(self), NUM2DBL(sx), NUM2DBL(sy));
|
58
|
+
return self;
|
59
|
+
}
|
60
|
+
|
61
|
+
static VALUE
|
62
|
+
rb_goo_canvas_bounds_x1(VALUE self)
|
63
|
+
{
|
64
|
+
GooCanvasBounds bounds;
|
65
|
+
goo_canvas_item_get_bounds(SELF(self), &bounds);
|
66
|
+
return rb_float_new(bounds.x1);
|
67
|
+
}
|
68
|
+
|
69
|
+
static VALUE
|
70
|
+
rb_goo_canvas_bounds_x2(VALUE self)
|
71
|
+
{
|
72
|
+
GooCanvasBounds bounds;
|
73
|
+
goo_canvas_item_get_bounds(SELF(self), &bounds);
|
74
|
+
return rb_float_new(bounds.x2);
|
75
|
+
}
|
76
|
+
|
77
|
+
static VALUE
|
78
|
+
rb_goo_canvas_bounds_y1(VALUE self)
|
79
|
+
{
|
80
|
+
GooCanvasBounds bounds;
|
81
|
+
goo_canvas_item_get_bounds(SELF(self), &bounds);
|
82
|
+
return rb_float_new(bounds.y1);
|
83
|
+
}
|
84
|
+
|
85
|
+
static VALUE
|
86
|
+
rb_goo_canvas_bounds_y2(VALUE self)
|
87
|
+
{
|
88
|
+
GooCanvasBounds bounds;
|
89
|
+
goo_canvas_item_get_bounds(SELF(self), &bounds);
|
90
|
+
return rb_float_new(bounds.y2);
|
91
|
+
}
|
92
|
+
|
93
|
+
static VALUE
|
94
|
+
rb_goo_canvas_item_skew_x(VALUE self, VALUE degrees, VALUE cx, VALUE cy)
|
95
|
+
{
|
96
|
+
goo_canvas_item_skew_x(SELF(self), NUM2DBL(degrees),
|
97
|
+
NUM2DBL(cx), NUM2DBL(cy));
|
98
|
+
return self;
|
99
|
+
}
|
100
|
+
|
101
|
+
static VALUE
|
102
|
+
rb_goo_canvas_item_skew_y(VALUE self, VALUE degrees, VALUE cx, VALUE cy)
|
103
|
+
{
|
104
|
+
goo_canvas_item_skew_y(SELF(self), NUM2DBL(degrees),
|
105
|
+
NUM2DBL(cx), NUM2DBL(cy));
|
106
|
+
return self;
|
107
|
+
}
|
108
|
+
|
109
|
+
static VALUE
|
110
|
+
rb_goo_canvas_item_set_simple_transform(VALUE self, VALUE x, VALUE y,
|
111
|
+
VALUE scale, VALUE rotation)
|
112
|
+
{
|
113
|
+
goo_canvas_item_set_simple_transform(SELF(self), NUM2DBL(x), NUM2DBL(y),
|
114
|
+
NUM2DBL(scale), NUM2DBL(rotation));
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
|
118
|
+
static VALUE
|
119
|
+
rb_goo_canvas_item_animate(VALUE self, VALUE x, VALUE y, VALUE scale,
|
120
|
+
VALUE degrees, VALUE absolute, VALUE duration,
|
121
|
+
VALUE step_time, VALUE type)
|
122
|
+
{
|
123
|
+
goo_canvas_item_animate(SELF(self),
|
124
|
+
NUM2DBL(x),
|
125
|
+
NUM2DBL(y),
|
126
|
+
NUM2DBL(scale),
|
127
|
+
NUM2DBL(degrees),
|
128
|
+
RTEST(absolute),
|
129
|
+
NUM2INT(duration),
|
130
|
+
NUM2INT(step_time),
|
131
|
+
rbgobj_get_enum(type, GOO_TYPE_CANVAS_ANIMATE_TYPE));
|
132
|
+
return self;
|
133
|
+
}
|
134
|
+
|
135
|
+
static VALUE
|
136
|
+
rb_goo_canvas_item_stop_animation(VALUE self)
|
137
|
+
{
|
138
|
+
goo_canvas_item_stop_animation(SELF(self));
|
139
|
+
return self;
|
140
|
+
}
|
141
|
+
|
142
|
+
static VALUE
|
143
|
+
rb_goo_canvas_item_set_style(VALUE self, VALUE style)
|
144
|
+
{
|
145
|
+
goo_canvas_item_set_style(SELF(self), RVAL2GCS(style));
|
146
|
+
return self;
|
147
|
+
}
|
148
|
+
|
149
|
+
static VALUE
|
150
|
+
rb_goo_canvas_item_set_child_property(VALUE self, VALUE child,
|
151
|
+
VALUE prop_name, VALUE val)
|
152
|
+
{
|
153
|
+
GParamSpec* pspec;
|
154
|
+
const char* name;
|
155
|
+
|
156
|
+
if (SYMBOL_P(prop_name)) {
|
157
|
+
name = rb_id2name(SYM2ID(prop_name));
|
158
|
+
} else {
|
159
|
+
StringValue(prop_name);
|
160
|
+
name = StringValuePtr(prop_name);
|
161
|
+
}
|
162
|
+
pspec = goo_canvas_item_class_find_child_property(G_OBJECT_GET_CLASS(RVAL2GOBJ(self)), name);
|
163
|
+
|
164
|
+
if (!pspec)
|
165
|
+
rb_raise(rb_eRuntimeError, "No such child property: %s", name);
|
166
|
+
|
167
|
+
#define _SET_PROP_FOR_TYPE(gtype, ctype, val) \
|
168
|
+
case gtype: \
|
169
|
+
goo_canvas_item_set_child_properties(SELF(self), SELF(child), name, (ctype)(val), NULL); \
|
170
|
+
break;
|
171
|
+
|
172
|
+
switch (G_TYPE_FUNDAMENTAL(G_PARAM_SPEC_VALUE_TYPE(pspec))) {
|
173
|
+
_SET_PROP_FOR_TYPE(G_TYPE_CHAR, gchar, NUM2INT(val));
|
174
|
+
_SET_PROP_FOR_TYPE(G_TYPE_UCHAR, guchar, NUM2INT(val));
|
175
|
+
_SET_PROP_FOR_TYPE(G_TYPE_BOOLEAN, gboolean, RTEST(val));
|
176
|
+
_SET_PROP_FOR_TYPE(G_TYPE_INT, gint, NUM2INT(val));
|
177
|
+
_SET_PROP_FOR_TYPE(G_TYPE_UINT, guint, NUM2UINT(val));
|
178
|
+
_SET_PROP_FOR_TYPE(G_TYPE_LONG, glong, NUM2LONG(val));
|
179
|
+
_SET_PROP_FOR_TYPE(G_TYPE_ULONG, gulong, NUM2ULONG(val));
|
180
|
+
_SET_PROP_FOR_TYPE(G_TYPE_INT64, gint64, rbglib_num_to_int64(val));
|
181
|
+
_SET_PROP_FOR_TYPE(G_TYPE_UINT64, guint64, rbglib_num_to_uint64(val));
|
182
|
+
_SET_PROP_FOR_TYPE(G_TYPE_ENUM, gint, rbgobj_get_enum(val, G_PARAM_SPEC_VALUE_TYPE(pspec)));
|
183
|
+
_SET_PROP_FOR_TYPE(G_TYPE_FLAGS, guint, rbgobj_get_flags(val, G_PARAM_SPEC_VALUE_TYPE(pspec)));
|
184
|
+
_SET_PROP_FOR_TYPE(G_TYPE_FLOAT, gfloat, NUM2DBL(val));
|
185
|
+
_SET_PROP_FOR_TYPE(G_TYPE_DOUBLE, gdouble, NUM2DBL(val));
|
186
|
+
case G_TYPE_STRING:
|
187
|
+
{
|
188
|
+
if (SYMBOL_P(val))
|
189
|
+
val = rb_funcall(val, rb_intern("to_s"), 0);
|
190
|
+
goo_canvas_item_set_child_properties(SELF(self), SELF(child), name, StringValuePtr(val), NULL);
|
191
|
+
break;
|
192
|
+
}
|
193
|
+
|
194
|
+
default:
|
195
|
+
g_warning("rb_goo_canvas_item_set_child_property: unsupported type: %s\n", g_type_name(G_PARAM_SPEC_VALUE_TYPE(pspec)));
|
196
|
+
return Qnil;
|
197
|
+
}
|
198
|
+
|
199
|
+
#undef _SET_PROP_FOR_TYPE
|
200
|
+
|
201
|
+
G_CHILD_ADD(child, val);
|
202
|
+
|
203
|
+
return self;
|
204
|
+
}
|
205
|
+
|
206
|
+
static VALUE
|
207
|
+
rb_goo_canvas_item_get_canvas(VALUE self, VALUE tx, VALUE ty)
|
208
|
+
{
|
209
|
+
return GOBJ2RVAL(goo_canvas_item_get_canvas(SELF(self)));
|
210
|
+
}
|
211
|
+
|
212
|
+
static VALUE
|
213
|
+
rb_goo_canvas_item_remove_child(VALUE self, VALUE child)
|
214
|
+
{
|
215
|
+
gint child_num;
|
216
|
+
|
217
|
+
child_num = goo_canvas_item_find_child(SELF(self), SELF(child));
|
218
|
+
goo_canvas_item_remove_child(SELF(self), child_num);
|
219
|
+
G_CHILD_REMOVE(self, child);
|
220
|
+
|
221
|
+
return self;
|
222
|
+
}
|
223
|
+
|
224
|
+
void
|
225
|
+
Init_goocanvasitem(void)
|
226
|
+
{
|
227
|
+
VALUE GooCanvasItem;
|
228
|
+
|
229
|
+
GooCanvasItem = G_DEF_CLASS(GOO_TYPE_CANVAS_ITEM, "CanvasItem", mGoo);
|
230
|
+
|
231
|
+
rb_define_method(GooCanvasItem, "rotate", rb_goo_canvas_item_rotate, 3);
|
232
|
+
rb_define_method(GooCanvasItem, "translate", rb_goo_canvas_item_translate, 2);
|
233
|
+
rb_define_method(GooCanvasItem, "lower", rb_goo_canvas_item_lower, 1);
|
234
|
+
rb_define_method(GooCanvasItem, "raise", rb_goo_canvas_item_raise, 1);
|
235
|
+
rb_define_method(GooCanvasItem, "scale", rb_goo_canvas_item_scale, 2);
|
236
|
+
rb_define_method(GooCanvasItem, "skew_x", rb_goo_canvas_item_skew_x, 3);
|
237
|
+
rb_define_method(GooCanvasItem, "skew_y", rb_goo_canvas_item_skew_y, 3);
|
238
|
+
rb_define_method(GooCanvasItem, "set_simple_transform", rb_goo_canvas_item_set_simple_transform, 4);
|
239
|
+
rb_define_method(GooCanvasItem, "animate", rb_goo_canvas_item_animate, 8);
|
240
|
+
rb_define_method(GooCanvasItem, "stop_animation", rb_goo_canvas_item_stop_animation, 0);
|
241
|
+
|
242
|
+
rb_define_method(GooCanvasItem, "set_style", rb_goo_canvas_item_set_style, 1);
|
243
|
+
|
244
|
+
rb_define_method(GooCanvasItem, "set_child_property", rb_goo_canvas_item_set_child_property, 3);
|
245
|
+
|
246
|
+
rb_define_method(GooCanvasItem, "canvas", rb_goo_canvas_item_get_canvas, 0);
|
247
|
+
|
248
|
+
rb_define_method(GooCanvasItem, "remove_child", rb_goo_canvas_item_remove_child, 1);
|
249
|
+
|
250
|
+
rb_define_method(GooCanvasItem, "x1", rb_goo_canvas_bounds_x1, 0);
|
251
|
+
rb_define_method(GooCanvasItem, "x2", rb_goo_canvas_bounds_x2, 0);
|
252
|
+
rb_define_method(GooCanvasItem, "y1", rb_goo_canvas_bounds_y1, 0);
|
253
|
+
rb_define_method(GooCanvasItem, "y2", rb_goo_canvas_bounds_y2, 0);
|
254
|
+
|
255
|
+
/* Enums */
|
256
|
+
G_DEF_CLASS(GOO_TYPE_CANVAS_ITEM_VISIBILITY, "Visibility", GooCanvasItem);
|
257
|
+
G_DEF_CONSTANTS(GooCanvasItem, GOO_TYPE_CANVAS_ITEM_VISIBILITY, "GOO_CANVAS_ITEM_");
|
258
|
+
G_DEF_CLASS(GOO_TYPE_CANVAS_ANIMATE_TYPE, "AnimateType", GooCanvasItem);
|
259
|
+
G_DEF_CONSTANTS(GooCanvasItem, GOO_TYPE_CANVAS_ANIMATE_TYPE, "GOO_CANVAS_");
|
260
|
+
|
261
|
+
|
262
|
+
G_DEF_CLASS(GOO_TYPE_CANVAS_POINTER_EVENTS, "PointerEvents",GooCanvasItem);
|
263
|
+
G_DEF_CONSTANTS(GooCanvasItem, GOO_TYPE_CANVAS_POINTER_EVENTS,"GOO_CANVAS_");
|
264
|
+
|
265
|
+
#if 0
|
266
|
+
gint goo_canvas_item_get_n_children (GooCanvasItem *item);
|
267
|
+
GooCanvasItem* goo_canvas_item_get_child (GooCanvasItem *item,
|
268
|
+
gint child_num);
|
269
|
+
gint goo_canvas_item_find_child (GooCanvasItem *item,
|
270
|
+
GooCanvasItem *child);
|
271
|
+
void goo_canvas_item_add_child (GooCanvasItem *item,
|
272
|
+
GooCanvasItem *child,
|
273
|
+
gint position);
|
274
|
+
void goo_canvas_item_move_child (GooCanvasItem *item,
|
275
|
+
gint old_position,
|
276
|
+
gint new_position);
|
277
|
+
void goo_canvas_item_remove_child (GooCanvasItem *item,
|
278
|
+
gint child_num);
|
279
|
+
|
280
|
+
void goo_canvas_item_get_child_properties (GooCanvasItem *item,
|
281
|
+
GooCanvasItem *child,
|
282
|
+
...) G_GNUC_NULL_TERMINATED;
|
283
|
+
void goo_canvas_item_set_child_properties (GooCanvasItem *item,
|
284
|
+
GooCanvasItem *child,
|
285
|
+
...) G_GNUC_NULL_TERMINATED;
|
286
|
+
void goo_canvas_item_get_child_properties_valist (GooCanvasItem *item,
|
287
|
+
GooCanvasItem *child,
|
288
|
+
va_list var_args);
|
289
|
+
void goo_canvas_item_set_child_properties_valist (GooCanvasItem *item,
|
290
|
+
GooCanvasItem *child,
|
291
|
+
va_list var_args);
|
292
|
+
|
293
|
+
gboolean goo_canvas_item_get_transform_for_child (GooCanvasItem *item,
|
294
|
+
GooCanvasItem *child,
|
295
|
+
cairo_matrix_t *transform);
|
296
|
+
|
297
|
+
|
298
|
+
/*
|
299
|
+
* Item functions - these are safe to call on all items.
|
300
|
+
*/
|
301
|
+
GooCanvas* goo_canvas_item_get_canvas (GooCanvasItem *item);
|
302
|
+
void goo_canvas_item_set_canvas (GooCanvasItem *item,
|
303
|
+
GooCanvas *canvas);
|
304
|
+
GooCanvasItem* goo_canvas_item_get_parent (GooCanvasItem *item);
|
305
|
+
void goo_canvas_item_set_parent (GooCanvasItem *item,
|
306
|
+
GooCanvasItem *parent);
|
307
|
+
gboolean goo_canvas_item_is_container (GooCanvasItem *item);
|
308
|
+
|
309
|
+
cairo_matrix_t* goo_canvas_item_get_transform (GooCanvasItem *item);
|
310
|
+
void goo_canvas_item_set_transform (GooCanvasItem *item,
|
311
|
+
cairo_matrix_t *matrix);
|
312
|
+
void goo_canvas_item_set_simple_transform (GooCanvasItem *item,
|
313
|
+
gdouble x,
|
314
|
+
gdouble y,
|
315
|
+
gdouble scale,
|
316
|
+
gdouble rotation);
|
317
|
+
|
318
|
+
GooCanvasStyle* goo_canvas_item_get_style (GooCanvasItem *item);
|
319
|
+
|
320
|
+
|
321
|
+
void goo_canvas_item_get_bounds (GooCanvasItem *item,
|
322
|
+
GooCanvasBounds *bounds);
|
323
|
+
GooCanvasItem* goo_canvas_item_get_item_at (GooCanvasItem *item,
|
324
|
+
gdouble x,
|
325
|
+
gdouble y,
|
326
|
+
cairo_t *cr,
|
327
|
+
gboolean is_pointer_event,
|
328
|
+
gboolean parent_is_visible);
|
329
|
+
gboolean goo_canvas_item_is_visible (GooCanvasItem *item);
|
330
|
+
|
331
|
+
GooCanvasItemModel* goo_canvas_item_get_model (GooCanvasItem *item);
|
332
|
+
void goo_canvas_item_set_model (GooCanvasItem *item,
|
333
|
+
GooCanvasItemModel *model);
|
334
|
+
|
335
|
+
void goo_canvas_item_request_update (GooCanvasItem *item);
|
336
|
+
void goo_canvas_item_ensure_updated (GooCanvasItem *item);
|
337
|
+
void goo_canvas_item_update (GooCanvasItem *item,
|
338
|
+
gboolean entire_tree,
|
339
|
+
cairo_t *cr,
|
340
|
+
GooCanvasBounds *bounds);
|
341
|
+
void goo_canvas_item_paint (GooCanvasItem *item,
|
342
|
+
cairo_t *cr,
|
343
|
+
GooCanvasBounds *bounds,
|
344
|
+
gdouble scale);
|
345
|
+
|
346
|
+
gboolean goo_canvas_item_get_requested_area (GooCanvasItem *item,
|
347
|
+
cairo_t *cr,
|
348
|
+
GooCanvasBounds *requested_area);
|
349
|
+
void goo_canvas_item_allocate_area (GooCanvasItem *item,
|
350
|
+
cairo_t *cr,
|
351
|
+
GooCanvasBounds *requested_area,
|
352
|
+
GooCanvasBounds *allocated_area,
|
353
|
+
gdouble x_offset,
|
354
|
+
gdouble y_offset);
|
355
|
+
#endif
|
356
|
+
|
357
|
+
G_DEF_SETTERS(GooCanvasItem);
|
358
|
+
}
|
Binary file
|
@@ -0,0 +1,102 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/* $Id: rbgoocanvaspolyline.c 3426 2008-11-01 14:20:52Z ktou $ */
|
3
|
+
/* GooCanvasPolyline and GooCanvasPoints
|
4
|
+
* Copyright (C) 2007 Vincent Isambart <vincent.isambart@gmail.com>
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include "rbgoocanvas.h"
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
rb_goo_canvas_polyline_new(VALUE self, VALUE parent, VALUE close_path)
|
25
|
+
{
|
26
|
+
GooCanvasItem *item;
|
27
|
+
item = goo_canvas_polyline_new(RVAL2GCI(parent), RTEST(close_path), 0, NULL);
|
28
|
+
RB_GOO_CANVAS_ITEM_INITIALIZE(self, item);
|
29
|
+
G_CHILD_ADD(parent, self);
|
30
|
+
return Qnil;
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE
|
34
|
+
rb_goo_canvas_points_new(VALUE self, VALUE num_points)
|
35
|
+
{
|
36
|
+
G_INITIALIZE(self, goo_canvas_points_new(NUM2INT(num_points)));
|
37
|
+
return Qnil;
|
38
|
+
}
|
39
|
+
|
40
|
+
static VALUE
|
41
|
+
rb_goo_canvas_points_get(VALUE self, VALUE point)
|
42
|
+
{
|
43
|
+
int i;
|
44
|
+
GooCanvasPoints *points;
|
45
|
+
|
46
|
+
i = NUM2INT(point);
|
47
|
+
points = RVAL2GCPOINTS(self);
|
48
|
+
if ((i < 0) || (i >= points->num_points))
|
49
|
+
rb_raise(rb_eArgError, "invalid point number %d", i);
|
50
|
+
return rb_ary_new3(2,
|
51
|
+
rb_float_new(points->coords[i * 2]),
|
52
|
+
rb_float_new(points->coords[i * 2 + 1]));
|
53
|
+
}
|
54
|
+
|
55
|
+
static VALUE
|
56
|
+
rb_goo_canvas_points_set(VALUE self, VALUE point, VALUE new_coords)
|
57
|
+
{
|
58
|
+
int i;
|
59
|
+
GooCanvasPoints *points;
|
60
|
+
|
61
|
+
i = NUM2INT(point);
|
62
|
+
points = RVAL2GCPOINTS(self);
|
63
|
+
if ((i < 0) || (i >= points->num_points))
|
64
|
+
rb_raise(rb_eArgError, "invalid point number %d", i);
|
65
|
+
if (TYPE(new_coords) != T_ARRAY)
|
66
|
+
rb_raise(rb_eArgError, "rb_goo_canvas_points_set should be given an array as new value");
|
67
|
+
if (RARRAY_LEN(new_coords) != 2)
|
68
|
+
rb_raise(rb_eArgError, "rb_goo_canvas_points_set should be given an array of length 2 as new value");
|
69
|
+
points->coords[i*2] = NUM2DBL(RARRAY_PTR(new_coords)[0]);
|
70
|
+
points->coords[i*2+1] = NUM2DBL(RARRAY_PTR(new_coords)[1]);
|
71
|
+
return self;
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE
|
75
|
+
rb_goo_canvas_points_get_num_points(VALUE self)
|
76
|
+
{
|
77
|
+
GooCanvasPoints *points;
|
78
|
+
|
79
|
+
points = RVAL2GCPOINTS(self);
|
80
|
+
return INT2NUM(points->num_points);
|
81
|
+
}
|
82
|
+
|
83
|
+
void
|
84
|
+
Init_goocanvaspolyline(void)
|
85
|
+
{
|
86
|
+
VALUE GooCanvasPolyline;
|
87
|
+
VALUE GooCanvasPoints;
|
88
|
+
|
89
|
+
GooCanvasPolyline = G_DEF_CLASS(GOO_TYPE_CANVAS_POLYLINE,
|
90
|
+
"CanvasPolyline", mGoo);
|
91
|
+
|
92
|
+
rb_define_method(GooCanvasPolyline, "initialize",
|
93
|
+
rb_goo_canvas_polyline_new, 2);
|
94
|
+
|
95
|
+
GooCanvasPoints = G_DEF_CLASS(GOO_TYPE_CANVAS_POINTS, "CanvasPoints", mGoo);
|
96
|
+
|
97
|
+
rb_define_method(GooCanvasPoints, "initialize", rb_goo_canvas_points_new, 1);
|
98
|
+
rb_define_method(GooCanvasPoints, "[]", rb_goo_canvas_points_get, 1);
|
99
|
+
rb_define_method(GooCanvasPoints, "[]=", rb_goo_canvas_points_set, 2);
|
100
|
+
rb_define_method(GooCanvasPoints, "num_points",
|
101
|
+
rb_goo_canvas_points_get_num_points, 0);
|
102
|
+
}
|