2 * $Id: rb_evas_object.c 304 2005-03-22 17:51:51Z 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);
53 if (!NIL_P (e->callbacks))
54 rb_gc_mark (e->callbacks);
56 if (!NIL_P (e->userdata))
57 rb_gc_mark (e->userdata);
60 void c_evas_object_free (RbEvasObject *e, bool free_mem)
63 evas_object_del (e->real);
70 static VALUE c_init (VALUE self, VALUE parent)
72 GET_OBJ (self, RbEvasObject, e);
74 evas_object_data_set (e->real, RUBY_EVAS_OBJECT_KEY, (void *) self);
83 static VALUE c_inspect (VALUE self)
85 INSPECT (self, RbEvasObject);
94 static VALUE c_delete (VALUE self)
96 GET_OBJ (self, RbEvasObject, e);
98 evas_object_del (e->real);
106 * e.resize(width, height) => nil
108 * Resizes <i>e</i> to width x height.
110 * e.resize(100, 200) #=> nil
112 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
114 GET_OBJ (self, RbEvasObject, e);
116 Check_Type (w, T_FIXNUM);
117 Check_Type (h, T_FIXNUM);
119 evas_object_resize (e->real, (Evas_Coord) FIX2INT (w),
120 (Evas_Coord) FIX2INT (h));
127 * e.move(x, y) => nil
129 * Moves <i>e</i> to the coordinates specified in
130 * <i>x</i> and <i>y</i>.
132 * e.move(100, 200) #=> nil
134 static VALUE c_move (VALUE self, VALUE x, VALUE y)
136 GET_OBJ (self, RbEvasObject, e);
138 Check_Type (x, T_FIXNUM);
139 Check_Type (y, T_FIXNUM);
141 evas_object_move (e->real, (Evas_Coord) FIX2INT (x),
142 (Evas_Coord) FIX2INT (y));
149 * e.geometry => array
151 * Returns an array containing the geometry of <i>e</i>.
153 * e.move(150, 300) #=> nil
154 * e.resize(200, 200) #=> nil
155 * e.geometry #=> [150, 300, 200, 200]
157 static VALUE c_geometry_get (VALUE self)
159 int x = 0, y = 0, w = 0, h = 0;
161 GET_OBJ (self, RbEvasObject, e);
163 evas_object_geometry_get (e->real,
164 (Evas_Coord *) &x, (Evas_Coord *) &y,
165 (Evas_Coord *) &w, (Evas_Coord *) &h);
167 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
177 static VALUE c_show (VALUE self)
179 GET_OBJ (self, RbEvasObject, e);
181 evas_object_show (e->real);
192 static VALUE c_hide (VALUE self)
194 GET_OBJ (self, RbEvasObject, e);
196 evas_object_hide (e->real);
203 * e.visible? => true or false
205 * Returns true if <i>e</i> is visible, else returns false.
207 static VALUE c_visible_get (VALUE self)
209 GET_OBJ (self, RbEvasObject, e);
211 return evas_object_visible_get (e->real) ? Qtrue : Qfalse;
218 * Returns the <code>Evas::Evas</code> for <i>e</i>.
220 static VALUE c_evas_get (VALUE self)
222 GET_OBJ (self, RbEvasObject, e);
231 * Returns the name of <i>e</i>.
233 static VALUE c_name_get (VALUE self)
237 GET_OBJ (self, RbEvasObject, e);
239 if (!(name = evas_object_name_get (e->real)))
242 return rb_str_new2 (name);
249 * Sets the name of <i>e</i>.
251 static VALUE c_name_set (VALUE self, VALUE val)
253 GET_OBJ (self, RbEvasObject, e);
255 Check_Type (val, T_STRING);
257 evas_object_name_set (e->real, StringValuePtr (val));
266 * Returns the layer <i>e</i> is in.
268 static VALUE c_layer_get (VALUE self)
270 GET_OBJ (self, RbEvasObject, e);
272 return INT2FIX (evas_object_layer_get (e->real));
279 * Sets the layer <i>e</i> is in.
281 static VALUE c_layer_set (VALUE self, VALUE val)
283 GET_OBJ (self, RbEvasObject, e);
285 Check_Type (val, T_FIXNUM);
287 evas_object_layer_set (e->real, NUM2INT (val));
294 * e.get_color => array
296 * Returns the color of <i>e</i>.
298 * e.set_color(128, 128, 128, 0) #=> nil
299 * e.get_color #=> [128, 128, 128, 0]
301 static VALUE c_get_color (VALUE self)
303 int r = 0, g = 0, b = 0, a = 0;
305 GET_OBJ (self, RbEvasObject, e);
307 evas_object_color_get (e->real, &r, &g, &b, &a);
309 return rb_ary_new3 (4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
315 * e.set_color(r, g, b, a) => nil
317 * Sets the color of <i>e</i>.
319 * e.set_color(128, 128, 128, 0) #=> nil
321 static VALUE c_set_color (VALUE self, VALUE r, VALUE g, VALUE b,
324 GET_OBJ (self, RbEvasObject, e);
326 Check_Type (r, T_FIXNUM);
327 Check_Type (g, T_FIXNUM);
328 Check_Type (b, T_FIXNUM);
329 Check_Type (a, T_FIXNUM);
331 evas_object_color_set (e->real, FIX2INT (r), FIX2INT (g),
332 FIX2INT (b), FIX2INT (a));
339 * e.pass_events? => true or false
341 * Returns true if <i>e</i> passes events on to EvasObjects that are
342 * below itself, else returns false.
344 static VALUE c_pass_events_get (VALUE self)
346 GET_OBJ (self, RbEvasObject, e);
348 return evas_object_pass_events_get (e->real) ? Qtrue : Qfalse;
353 * e.pass_events(true or false)
355 * Sets whether <i>e</i> passes events on to EvasObjects that are
358 static VALUE c_pass_events_set (VALUE self, VALUE val)
360 GET_OBJ (self, RbEvasObject, e);
364 evas_object_pass_events_set (e->real, val == Qtrue);
371 * e.repeat_events? => true or false
373 * Returns true if <i>e</i> repeats events to EvasObjects that are
374 * below itself, else returns false.
376 static VALUE c_repeat_events_get (VALUE self)
378 GET_OBJ (self, RbEvasObject, e);
380 return evas_object_repeat_events_get (e->real) ? Qtrue : Qfalse;
385 * e.repeat_events(true or false)
387 * Sets whether <i>e</i> repeats events to EvasObjects that are
390 static VALUE c_repeat_events_set (VALUE self, VALUE val)
392 GET_OBJ (self, RbEvasObject, e);
396 evas_object_repeat_events_set (e->real, val == Qtrue);
407 static VALUE c_raise (VALUE self)
409 GET_OBJ (self, RbEvasObject, e);
411 evas_object_raise (e->real);
422 static VALUE c_lower (VALUE self)
424 GET_OBJ (self, RbEvasObject, e);
426 evas_object_lower (e->real);
433 * e.stack_above(evasobject) => nil
435 * Positions <i>e</i> above <i>evasobject</i>.
437 static VALUE c_stack_above (VALUE self, VALUE target)
439 GET_OBJ (self, RbEvasObject, e);
441 CHECK_CLASS (target, cEvasObject);
442 GET_OBJ (target, RbEvasObject, t);
444 evas_object_stack_above (e->real, t->real);
451 * e.stack_below(evasobject) => nil
453 * Positions <i>e</i> below <i>evasobject</i>.
455 static VALUE c_stack_below (VALUE self, VALUE target)
457 GET_OBJ (self, RbEvasObject, e);
459 CHECK_CLASS (target, cEvasObject);
460 GET_OBJ (target, RbEvasObject, t);
462 evas_object_stack_below (e->real, t->real);
469 * e.above => evasobject
471 * Returns the <code>Evas::EvasObject</code> that's positioned above
474 static VALUE c_above_get (VALUE self)
476 GET_OBJ (self, RbEvasObject, e);
478 return TO_EVAS_OBJECT (evas_object_above_get (e->real));
483 * e.below => evasobject
485 * Returns the <code>Evas::EvasObject</code> that's positioned below
488 static VALUE c_below_get (VALUE self)
490 GET_OBJ (self, RbEvasObject, e);
492 return TO_EVAS_OBJECT (evas_object_below_get (e->real));
495 static VALUE c_userdata_get (VALUE self)
497 GET_OBJ (self, RbEvasObject, e);
499 if (NIL_P (e->userdata))
500 e->userdata = rb_hash_new ();
505 void Init_EvasObject (void)
507 cEvasObject = rb_define_class_under (mEvas, "EvasObject",
510 rb_define_private_method (rb_singleton_class (cEvasObject),
512 rb_define_method (cEvasObject, "initialize", c_init, 1);
513 rb_define_method (cEvasObject, "inspect", c_inspect, 0);
514 rb_define_method (cEvasObject, "delete", c_delete, 0);
515 rb_define_method (cEvasObject, "resize", c_resize, 2);
516 rb_define_method (cEvasObject, "move", c_move, 2);
517 rb_define_method (cEvasObject, "geometry", c_geometry_get, 0);
518 rb_define_method (cEvasObject, "show", c_show, 0);
519 rb_define_method (cEvasObject, "hide", c_hide, 0);
520 rb_define_method (cEvasObject, "visible?", c_visible_get, 0);
521 rb_define_method (cEvasObject, "evas", c_evas_get, 0);
522 rb_define_method (cEvasObject, "name", c_name_get, 0);
523 rb_define_method (cEvasObject, "name=", c_name_set, 1);
524 rb_define_method (cEvasObject, "layer", c_layer_get, 0);
525 rb_define_method (cEvasObject, "layer=", c_layer_set, 1);
526 rb_define_method (cEvasObject, "get_color", c_get_color, 0);
527 rb_define_method (cEvasObject, "set_color", c_set_color, 4);
528 rb_define_method (cEvasObject, "pass_events?",
529 c_pass_events_get, 0);
530 rb_define_method (cEvasObject, "pass_events=",
531 c_pass_events_set, 1);
532 rb_define_method (cEvasObject, "repeat_events?",
533 c_repeat_events_get, 0);
534 rb_define_method (cEvasObject, "repeat_events=",
535 c_repeat_events_set, 1);
536 rb_define_method (cEvasObject, "raise", c_raise, 0);
537 rb_define_method (cEvasObject, "lower", c_lower, 0);
538 rb_define_method (cEvasObject, "stack_above", c_stack_above, 1);
539 rb_define_method (cEvasObject, "stack_below", c_stack_below, 1);
540 rb_define_method (cEvasObject, "above", c_above_get, 0);
541 rb_define_method (cEvasObject, "below", c_below_get, 0);
542 rb_define_method (cEvasObject, "userdata", c_userdata_get, 0);