2 * $Id: rb_evas_object.c 58 2004-08-10 14:10:02Z tilman $
4 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
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.
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.
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
26 #define __RB_EVAS_OBJECT_C
27 #include "rb_evas_main.h"
29 #include "rb_evas_object.h"
33 /* called by the child classes */
34 void c_evas_object_mark (RbEvasObject *e)
36 rb_gc_mark (e->parent);
39 void c_evas_object_free (RbEvasObject *e, bool free_mem)
42 evas_object_del (e->real);
49 static VALUE c_init (VALUE self, VALUE parent)
51 GET_OBJ (self, RbEvasObject, e);
53 evas_object_data_set (e->real, RUBY_EVAS_OBJECT_KEY, (void *) self);
61 static VALUE c_inspect (VALUE self)
63 INSPECT (self, RbEvasObject);
72 static VALUE c_delete (VALUE self)
74 GET_OBJ (self, RbEvasObject, e);
76 evas_object_del (e->real);
84 * e.resize(width, height) => nil
86 * Resizes <i>e</i> to width x height.
88 * e.resize(100, 200) #=> nil
90 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
92 GET_OBJ (self, RbEvasObject, e);
94 Check_Type (w, T_FIXNUM);
95 Check_Type (h, T_FIXNUM);
97 evas_object_resize (e->real, (Evas_Coord) FIX2INT (w),
98 (Evas_Coord) FIX2INT (h));
105 * e.move(x, y) => nil
107 * Moves <i>e</i> to the coordinates specified in
108 * <i>x</i> and <i>y</i>.
110 * e.move(100, 200) #=> nil
112 static VALUE c_move (VALUE self, VALUE x, VALUE y)
114 GET_OBJ (self, RbEvasObject, e);
116 Check_Type (x, T_FIXNUM);
117 Check_Type (y, T_FIXNUM);
119 evas_object_move (e->real, (Evas_Coord) FIX2INT (x),
120 (Evas_Coord) FIX2INT (y));
127 * e.geometry => array
129 * Returns an array containing the geometry of <i>e</i>.
131 * e.move(150, 300) #=> nil
132 * e.resize(200, 200) #=> nil
133 * e.geometry #=> [150, 300, 200, 200]
135 static VALUE c_geometry_get (VALUE self)
137 int x = 0, y = 0, w = 0, h = 0;
139 GET_OBJ (self, RbEvasObject, e);
141 evas_object_geometry_get (e->real,
142 (Evas_Coord *) &x, (Evas_Coord *) &y,
143 (Evas_Coord *) &w, (Evas_Coord *) &h);
145 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
155 static VALUE c_show (VALUE self)
157 GET_OBJ (self, RbEvasObject, e);
159 evas_object_show (e->real);
170 static VALUE c_hide (VALUE self)
172 GET_OBJ (self, RbEvasObject, e);
174 evas_object_hide (e->real);
181 * e.visible? => true or false
183 * Returns true if <i>e</i> is visible, else false.
185 static VALUE c_visible_get (VALUE self)
187 GET_OBJ (self, RbEvasObject, e);
189 return evas_object_visible_get (e->real) ? Qtrue : Qfalse;
196 * Returns the <code>Evas::Evas</code> for <i>e</i>.
198 static VALUE c_evas_get (VALUE self)
200 GET_OBJ (self, RbEvasObject, e);
209 * Returns the name of <i>e</i>.
211 static VALUE c_name_get (VALUE self)
215 GET_OBJ (self, RbEvasObject, e);
217 if (!(name = evas_object_name_get (e->real)))
220 return rb_str_new2 (name);
227 * Sets the name of <i>e</i>.
229 static VALUE c_name_set (VALUE self, VALUE val)
231 GET_OBJ (self, RbEvasObject, e);
233 Check_Type (val, T_STRING);
235 evas_object_name_set (e->real, StringValuePtr (val));
244 * Returns the layer <i>e</i> is in.
246 static VALUE c_layer_get (VALUE self)
248 GET_OBJ (self, RbEvasObject, e);
250 return INT2FIX (evas_object_layer_get (e->real));
257 * Sets the layer <i>e</i> is in.
259 static VALUE c_layer_set (VALUE self, VALUE val)
261 GET_OBJ (self, RbEvasObject, e);
263 Check_Type (val, T_FIXNUM);
265 evas_object_layer_set (e->real, NUM2INT (val));
272 * e.get_color => array
274 * Returns the color of <i>e</i>.
276 * e.set_color(128, 128, 128, 0) #=> nil
277 * e.get_color #=> [128, 128, 128, 0]
279 static VALUE c_get_color (VALUE self)
281 int r = 0, g = 0, b = 0, a = 0;
283 GET_OBJ (self, RbEvasObject, e);
285 evas_object_color_get (e->real, &r, &g, &b, &a);
287 return rb_ary_new3 (4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
293 * e.set_color(r, g, b, a) => nil
295 * Sets the color of <i>e</i>.
297 * e.set_color(128, 128, 128, 0) #=> nil
299 static VALUE c_set_color (VALUE self, VALUE r, VALUE g, VALUE b,
302 GET_OBJ (self, RbEvasObject, e);
304 Check_Type (r, T_FIXNUM);
305 Check_Type (g, T_FIXNUM);
306 Check_Type (b, T_FIXNUM);
307 Check_Type (a, T_FIXNUM);
309 evas_object_color_set (e->real, FIX2INT (r), FIX2INT (g),
310 FIX2INT (b), FIX2INT (a));
317 * e.pass_events? => true or false
319 * Returns true if <i>e</i> passes events on to EvasObjects that are
320 * below itself, else false.
322 static VALUE c_pass_events_get (VALUE self)
324 GET_OBJ (self, RbEvasObject, e);
326 return evas_object_pass_events_get (e->real) ? Qtrue : Qfalse;
331 * e.pass_events(true or false)
333 * Sets whether <i>e</i> passes events on to EvasObjects that are
336 static VALUE c_pass_events_set (VALUE self, VALUE val)
338 GET_OBJ (self, RbEvasObject, e);
342 evas_object_pass_events_set (e->real, val == Qtrue);
353 static VALUE c_raise (VALUE self)
355 GET_OBJ (self, RbEvasObject, e);
357 evas_object_raise (e->real);
368 static VALUE c_lower (VALUE self)
370 GET_OBJ (self, RbEvasObject, e);
372 evas_object_lower (e->real);
379 * e.stack_above(evasobject) => nil
381 * Positions <i>e</i> above <i>evasobject</i>.
383 static VALUE c_stack_above (VALUE self, VALUE target)
385 GET_OBJ (self, RbEvasObject, e);
387 CHECK_CLASS (target, cEvasObject);
388 GET_OBJ (target, RbEvasObject, t);
390 evas_object_stack_above (e->real, t->real);
397 * e.stack_below(evasobject) => nil
399 * Positions <i>e</i> below <i>evasobject</i>.
401 static VALUE c_stack_below (VALUE self, VALUE target)
403 GET_OBJ (self, RbEvasObject, e);
405 CHECK_CLASS (target, cEvasObject);
406 GET_OBJ (target, RbEvasObject, t);
408 evas_object_stack_below (e->real, t->real);
415 * e.above => evasobject
417 * Returns the <code>Evas::EvasObject</code> that's positioned above
420 static VALUE c_above_get (VALUE self)
425 GET_OBJ (self, RbEvasObject, e);
427 if (!(o = evas_object_above_get (e->real)))
430 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
431 rb_raise (rb_eException, "EvasObject Ruby object key missing");
440 * e.below => evasobject
442 * Returns the <code>Evas::EvasObject</code> that's positioned below
445 static VALUE c_below_get (VALUE self)
450 GET_OBJ (self, RbEvasObject, e);
452 if (!(o = evas_object_below_get (e->real)))
455 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
456 rb_raise (rb_eException, "EvasObject Ruby object key missing");
463 void Init_EvasObject (void)
465 cEvasObject = rb_define_class_under (mEvas, "EvasObject",
468 rb_define_private_method (rb_singleton_class (cEvasObject),
470 rb_define_method (cEvasObject, "initialize", c_init, 1);
471 rb_define_method (cEvasObject, "inspect", c_inspect, 0);
472 rb_define_method (cEvasObject, "delete", c_delete, 0);
473 rb_define_method (cEvasObject, "resize", c_resize, 2);
474 rb_define_method (cEvasObject, "move", c_move, 2);
475 rb_define_method (cEvasObject, "geometry", c_geometry_get, 0);
476 rb_define_method (cEvasObject, "show", c_show, 0);
477 rb_define_method (cEvasObject, "hide", c_hide, 0);
478 rb_define_method (cEvasObject, "visible?", c_visible_get, 0);
479 rb_define_method (cEvasObject, "evas", c_evas_get, 0);
480 rb_define_method (cEvasObject, "name", c_name_get, 0);
481 rb_define_method (cEvasObject, "name=", c_name_set, 1);
482 rb_define_method (cEvasObject, "layer", c_layer_get, 0);
483 rb_define_method (cEvasObject, "layer=", c_layer_set, 1);
484 rb_define_method (cEvasObject, "get_color", c_get_color, 0);
485 rb_define_method (cEvasObject, "set_color", c_set_color, 4);
486 rb_define_method (cEvasObject, "pass_events?", c_pass_events_get, 0);
487 rb_define_method (cEvasObject, "pass_events=", c_pass_events_set, 1);
488 rb_define_method (cEvasObject, "raise", c_raise, 0);
489 rb_define_method (cEvasObject, "lower", c_lower, 0);
490 rb_define_method (cEvasObject, "stack_above", c_stack_above, 1);
491 rb_define_method (cEvasObject, "stack_below", c_stack_below, 1);
492 rb_define_method (cEvasObject, "above", c_above_get, 0);
493 rb_define_method (cEvasObject, "below", c_below_get, 0);