2 * $Id: rb_evas_object.c 281 2005-03-14 20:51:40Z 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 VALUE TO_EVAS_OBJECT (Evas_Object *o)
40 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
41 rb_raise (rb_eException, "EvasObject Ruby object key missing");
48 /* called by the child classes */
49 void c_evas_object_mark (RbEvasObject *e)
51 rb_gc_mark (e->parent);
52 rb_gc_mark (e->callbacks);
55 void c_evas_object_free (RbEvasObject *e, bool free_mem)
58 evas_object_del (e->real);
65 static VALUE c_init (VALUE self, VALUE parent)
67 GET_OBJ (self, RbEvasObject, e);
69 evas_object_data_set (e->real, RUBY_EVAS_OBJECT_KEY, (void *) self);
72 e->callbacks = rb_hash_new ();
78 static VALUE c_inspect (VALUE self)
80 INSPECT (self, RbEvasObject);
89 static VALUE c_delete (VALUE self)
91 GET_OBJ (self, RbEvasObject, e);
93 evas_object_del (e->real);
101 * e.resize(width, height) => nil
103 * Resizes <i>e</i> to width x height.
105 * e.resize(100, 200) #=> nil
107 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
109 GET_OBJ (self, RbEvasObject, e);
111 Check_Type (w, T_FIXNUM);
112 Check_Type (h, T_FIXNUM);
114 evas_object_resize (e->real, (Evas_Coord) FIX2INT (w),
115 (Evas_Coord) FIX2INT (h));
122 * e.move(x, y) => nil
124 * Moves <i>e</i> to the coordinates specified in
125 * <i>x</i> and <i>y</i>.
127 * e.move(100, 200) #=> nil
129 static VALUE c_move (VALUE self, VALUE x, VALUE y)
131 GET_OBJ (self, RbEvasObject, e);
133 Check_Type (x, T_FIXNUM);
134 Check_Type (y, T_FIXNUM);
136 evas_object_move (e->real, (Evas_Coord) FIX2INT (x),
137 (Evas_Coord) FIX2INT (y));
144 * e.geometry => array
146 * Returns an array containing the geometry of <i>e</i>.
148 * e.move(150, 300) #=> nil
149 * e.resize(200, 200) #=> nil
150 * e.geometry #=> [150, 300, 200, 200]
152 static VALUE c_geometry_get (VALUE self)
154 int x = 0, y = 0, w = 0, h = 0;
156 GET_OBJ (self, RbEvasObject, e);
158 evas_object_geometry_get (e->real,
159 (Evas_Coord *) &x, (Evas_Coord *) &y,
160 (Evas_Coord *) &w, (Evas_Coord *) &h);
162 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
172 static VALUE c_show (VALUE self)
174 GET_OBJ (self, RbEvasObject, e);
176 evas_object_show (e->real);
187 static VALUE c_hide (VALUE self)
189 GET_OBJ (self, RbEvasObject, e);
191 evas_object_hide (e->real);
198 * e.visible? => true or false
200 * Returns true if <i>e</i> is visible, else returns false.
202 static VALUE c_visible_get (VALUE self)
204 GET_OBJ (self, RbEvasObject, e);
206 return evas_object_visible_get (e->real) ? Qtrue : Qfalse;
213 * Returns the <code>Evas::Evas</code> for <i>e</i>.
215 static VALUE c_evas_get (VALUE self)
217 GET_OBJ (self, RbEvasObject, e);
226 * Returns the name of <i>e</i>.
228 static VALUE c_name_get (VALUE self)
232 GET_OBJ (self, RbEvasObject, e);
234 if (!(name = evas_object_name_get (e->real)))
237 return rb_str_new2 (name);
244 * Sets the name of <i>e</i>.
246 static VALUE c_name_set (VALUE self, VALUE val)
248 GET_OBJ (self, RbEvasObject, e);
250 Check_Type (val, T_STRING);
252 evas_object_name_set (e->real, StringValuePtr (val));
261 * Returns the layer <i>e</i> is in.
263 static VALUE c_layer_get (VALUE self)
265 GET_OBJ (self, RbEvasObject, e);
267 return INT2FIX (evas_object_layer_get (e->real));
274 * Sets the layer <i>e</i> is in.
276 static VALUE c_layer_set (VALUE self, VALUE val)
278 GET_OBJ (self, RbEvasObject, e);
280 Check_Type (val, T_FIXNUM);
282 evas_object_layer_set (e->real, NUM2INT (val));
289 * e.get_color => array
291 * Returns the color of <i>e</i>.
293 * e.set_color(128, 128, 128, 0) #=> nil
294 * e.get_color #=> [128, 128, 128, 0]
296 static VALUE c_get_color (VALUE self)
298 int r = 0, g = 0, b = 0, a = 0;
300 GET_OBJ (self, RbEvasObject, e);
302 evas_object_color_get (e->real, &r, &g, &b, &a);
304 return rb_ary_new3 (4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
310 * e.set_color(r, g, b, a) => nil
312 * Sets the color of <i>e</i>.
314 * e.set_color(128, 128, 128, 0) #=> nil
316 static VALUE c_set_color (VALUE self, VALUE r, VALUE g, VALUE b,
319 GET_OBJ (self, RbEvasObject, e);
321 Check_Type (r, T_FIXNUM);
322 Check_Type (g, T_FIXNUM);
323 Check_Type (b, T_FIXNUM);
324 Check_Type (a, T_FIXNUM);
326 evas_object_color_set (e->real, FIX2INT (r), FIX2INT (g),
327 FIX2INT (b), FIX2INT (a));
334 * e.pass_events? => true or false
336 * Returns true if <i>e</i> passes events on to EvasObjects that are
337 * below itself, else returns false.
339 static VALUE c_pass_events_get (VALUE self)
341 GET_OBJ (self, RbEvasObject, e);
343 return evas_object_pass_events_get (e->real) ? Qtrue : Qfalse;
348 * e.pass_events(true or false)
350 * Sets whether <i>e</i> passes events on to EvasObjects that are
353 static VALUE c_pass_events_set (VALUE self, VALUE val)
355 GET_OBJ (self, RbEvasObject, e);
359 evas_object_pass_events_set (e->real, val == Qtrue);
366 * e.repeat_events? => true or false
368 * Returns true if <i>e</i> repeats events to EvasObjects that are
369 * below itself, else returns false.
371 static VALUE c_repeat_events_get (VALUE self)
373 GET_OBJ (self, RbEvasObject, e);
375 return evas_object_repeat_events_get (e->real) ? Qtrue : Qfalse;
380 * e.repeat_events(true or false)
382 * Sets whether <i>e</i> repeats events to EvasObjects that are
385 static VALUE c_repeat_events_set (VALUE self, VALUE val)
387 GET_OBJ (self, RbEvasObject, e);
391 evas_object_repeat_events_set (e->real, val == Qtrue);
402 static VALUE c_raise (VALUE self)
404 GET_OBJ (self, RbEvasObject, e);
406 evas_object_raise (e->real);
417 static VALUE c_lower (VALUE self)
419 GET_OBJ (self, RbEvasObject, e);
421 evas_object_lower (e->real);
428 * e.stack_above(evasobject) => nil
430 * Positions <i>e</i> above <i>evasobject</i>.
432 static VALUE c_stack_above (VALUE self, VALUE target)
434 GET_OBJ (self, RbEvasObject, e);
436 CHECK_CLASS (target, cEvasObject);
437 GET_OBJ (target, RbEvasObject, t);
439 evas_object_stack_above (e->real, t->real);
446 * e.stack_below(evasobject) => nil
448 * Positions <i>e</i> below <i>evasobject</i>.
450 static VALUE c_stack_below (VALUE self, VALUE target)
452 GET_OBJ (self, RbEvasObject, e);
454 CHECK_CLASS (target, cEvasObject);
455 GET_OBJ (target, RbEvasObject, t);
457 evas_object_stack_below (e->real, t->real);
464 * e.above => evasobject
466 * Returns the <code>Evas::EvasObject</code> that's positioned above
469 static VALUE c_above_get (VALUE self)
471 GET_OBJ (self, RbEvasObject, e);
473 return TO_EVAS_OBJECT (evas_object_above_get (e->real));
478 * e.below => evasobject
480 * Returns the <code>Evas::EvasObject</code> that's positioned below
483 static VALUE c_below_get (VALUE self)
485 GET_OBJ (self, RbEvasObject, e);
487 return TO_EVAS_OBJECT (evas_object_below_get (e->real));
490 void Init_EvasObject (void)
492 cEvasObject = rb_define_class_under (mEvas, "EvasObject",
495 rb_define_private_method (rb_singleton_class (cEvasObject),
497 rb_define_method (cEvasObject, "initialize", c_init, 1);
498 rb_define_method (cEvasObject, "inspect", c_inspect, 0);
499 rb_define_method (cEvasObject, "delete", c_delete, 0);
500 rb_define_method (cEvasObject, "resize", c_resize, 2);
501 rb_define_method (cEvasObject, "move", c_move, 2);
502 rb_define_method (cEvasObject, "geometry", c_geometry_get, 0);
503 rb_define_method (cEvasObject, "show", c_show, 0);
504 rb_define_method (cEvasObject, "hide", c_hide, 0);
505 rb_define_method (cEvasObject, "visible?", c_visible_get, 0);
506 rb_define_method (cEvasObject, "evas", c_evas_get, 0);
507 rb_define_method (cEvasObject, "name", c_name_get, 0);
508 rb_define_method (cEvasObject, "name=", c_name_set, 1);
509 rb_define_method (cEvasObject, "layer", c_layer_get, 0);
510 rb_define_method (cEvasObject, "layer=", c_layer_set, 1);
511 rb_define_method (cEvasObject, "get_color", c_get_color, 0);
512 rb_define_method (cEvasObject, "set_color", c_set_color, 4);
513 rb_define_method (cEvasObject, "pass_events?",
514 c_pass_events_get, 0);
515 rb_define_method (cEvasObject, "pass_events=",
516 c_pass_events_set, 1);
517 rb_define_method (cEvasObject, "repeat_events?",
518 c_repeat_events_get, 0);
519 rb_define_method (cEvasObject, "repeat_events=",
520 c_repeat_events_set, 1);
521 rb_define_method (cEvasObject, "raise", c_raise, 0);
522 rb_define_method (cEvasObject, "lower", c_lower, 0);
523 rb_define_method (cEvasObject, "stack_above", c_stack_above, 1);
524 rb_define_method (cEvasObject, "stack_below", c_stack_below, 1);
525 rb_define_method (cEvasObject, "above", c_above_get, 0);
526 rb_define_method (cEvasObject, "below", c_below_get, 0);