2 * $Id: rb_evas_object.c 369 2006-02-15 18:09:44Z 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);
69 static void c_free (RbEvasObject *e)
71 c_evas_object_free (e, true);
74 static VALUE c_alloc (VALUE klass)
78 return Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
83 static VALUE c_init (VALUE self, VALUE parent)
85 GET_OBJ (self, RbEvasObject, e);
87 evas_object_data_set (e->real, RUBY_EVAS_OBJECT_KEY, (void *) self);
96 static VALUE c_inspect (VALUE self)
98 INSPECT (self, RbEvasObject);
101 static VALUE c_type_get (VALUE self)
105 GET_OBJ (self, RbEvasObject, e);
107 s = evas_object_type_get (e->real);
109 return s ? rb_str_new2 (s) : Qnil;
118 static VALUE c_delete (VALUE self)
120 GET_OBJ (self, RbEvasObject, e);
122 evas_object_del (e->real);
130 * e.resize(width, height) => nil
132 * Resizes <i>e</i> to width x height.
134 * e.resize(100, 200) #=> nil
136 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
138 GET_OBJ (self, RbEvasObject, e);
140 Check_Type (w, T_FIXNUM);
141 Check_Type (h, T_FIXNUM);
143 evas_object_resize (e->real, (Evas_Coord) FIX2INT (w),
144 (Evas_Coord) FIX2INT (h));
151 * e.move(x, y) => nil
153 * Moves <i>e</i> to the coordinates specified in
154 * <i>x</i> and <i>y</i>.
156 * e.move(100, 200) #=> nil
158 static VALUE c_move (VALUE self, VALUE x, VALUE y)
160 GET_OBJ (self, RbEvasObject, e);
162 Check_Type (x, T_FIXNUM);
163 Check_Type (y, T_FIXNUM);
165 evas_object_move (e->real, (Evas_Coord) FIX2INT (x),
166 (Evas_Coord) FIX2INT (y));
173 * e.geometry => array
175 * Returns an array containing the geometry of <i>e</i>.
177 * e.move(150, 300) #=> nil
178 * e.resize(200, 200) #=> nil
179 * e.geometry #=> [150, 300, 200, 200]
181 static VALUE c_geometry_get (VALUE self)
183 int x = 0, y = 0, w = 0, h = 0;
185 GET_OBJ (self, RbEvasObject, e);
187 evas_object_geometry_get (e->real,
188 (Evas_Coord *) &x, (Evas_Coord *) &y,
189 (Evas_Coord *) &w, (Evas_Coord *) &h);
191 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
201 static VALUE c_show (VALUE self)
203 GET_OBJ (self, RbEvasObject, e);
205 evas_object_show (e->real);
216 static VALUE c_hide (VALUE self)
218 GET_OBJ (self, RbEvasObject, e);
220 evas_object_hide (e->real);
227 * e.visible? => true or false
229 * Returns true if <i>e</i> is visible, else returns false.
231 static VALUE c_visible_get (VALUE self)
233 GET_OBJ (self, RbEvasObject, e);
235 return evas_object_visible_get (e->real) ? Qtrue : Qfalse;
240 * e.focused? => true or false
242 * Returns true if <i>e</i> is focused, else returns false.
244 static VALUE c_focused_get (VALUE self)
246 GET_OBJ (self, RbEvasObject, e);
248 return evas_object_focus_get (e->real) ? Qtrue : Qfalse;
253 * e.focused(true or false)
255 * (Un)focuses <i>e</i>.
257 static VALUE c_focused_set (VALUE self, VALUE val)
259 GET_OBJ (self, RbEvasObject, e);
263 evas_object_focus_set (e->real, val == Qtrue);
272 * Returns the <code>Evas::Evas</code> for <i>e</i>.
274 static VALUE c_evas_get (VALUE self)
276 GET_OBJ (self, RbEvasObject, e);
285 * Returns the name of <i>e</i>.
287 static VALUE c_name_get (VALUE self)
291 GET_OBJ (self, RbEvasObject, e);
293 if (!(name = evas_object_name_get (e->real)))
296 return rb_str_new2 (name);
303 * Sets the name of <i>e</i>.
305 static VALUE c_name_set (VALUE self, VALUE val)
307 GET_OBJ (self, RbEvasObject, e);
309 Check_Type (val, T_STRING);
311 evas_object_name_set (e->real, StringValuePtr (val));
320 * Returns the layer <i>e</i> is in.
322 static VALUE c_layer_get (VALUE self)
324 GET_OBJ (self, RbEvasObject, e);
326 return INT2FIX (evas_object_layer_get (e->real));
333 * Sets the layer <i>e</i> is in.
335 static VALUE c_layer_set (VALUE self, VALUE val)
337 GET_OBJ (self, RbEvasObject, e);
339 Check_Type (val, T_FIXNUM);
341 evas_object_layer_set (e->real, NUM2INT (val));
348 * e.get_color => array
350 * Returns the color of <i>e</i>.
352 * e.set_color(128, 128, 128, 0) #=> nil
353 * e.get_color #=> [128, 128, 128, 0]
355 static VALUE c_get_color (VALUE self)
357 int r = 0, g = 0, b = 0, a = 0;
359 GET_OBJ (self, RbEvasObject, e);
361 evas_object_color_get (e->real, &r, &g, &b, &a);
363 return rb_ary_new3 (4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
369 * e.set_color(r, g, b, a) => nil
371 * Sets the color of <i>e</i>.
373 * e.set_color(128, 128, 128, 0) #=> nil
375 static VALUE c_set_color (VALUE self, VALUE r, VALUE g, VALUE b,
378 GET_OBJ (self, RbEvasObject, e);
380 Check_Type (r, T_FIXNUM);
381 Check_Type (g, T_FIXNUM);
382 Check_Type (b, T_FIXNUM);
383 Check_Type (a, T_FIXNUM);
385 evas_object_color_set (e->real, FIX2INT (r), FIX2INT (g),
386 FIX2INT (b), FIX2INT (a));
391 static VALUE c_get_clip (VALUE self)
393 GET_OBJ (self, RbEvasObject, e);
395 return TO_EVAS_OBJECT (evas_object_clip_get (e->real));
398 static VALUE c_set_clip (VALUE self, VALUE clip)
400 GET_OBJ (self, RbEvasObject, e);
401 GET_OBJ (clip, RbEvasObject, e2);
403 evas_object_clip_set (e->real, e2->real);
410 * e.pass_events? => true or false
412 * Returns true if <i>e</i> passes events on to EvasObjects that are
413 * below itself, else returns false.
415 static VALUE c_pass_events_get (VALUE self)
417 GET_OBJ (self, RbEvasObject, e);
419 return evas_object_pass_events_get (e->real) ? Qtrue : Qfalse;
424 * e.pass_events(true or false)
426 * Sets whether <i>e</i> passes events on to EvasObjects that are
429 static VALUE c_pass_events_set (VALUE self, VALUE val)
431 GET_OBJ (self, RbEvasObject, e);
435 evas_object_pass_events_set (e->real, val == Qtrue);
442 * e.repeat_events? => true or false
444 * Returns true if <i>e</i> repeats events to EvasObjects that are
445 * below itself, else returns false.
447 static VALUE c_repeat_events_get (VALUE self)
449 GET_OBJ (self, RbEvasObject, e);
451 return evas_object_repeat_events_get (e->real) ? Qtrue : Qfalse;
456 * e.repeat_events(true or false)
458 * Sets whether <i>e</i> repeats events to EvasObjects that are
461 static VALUE c_repeat_events_set (VALUE self, VALUE val)
463 GET_OBJ (self, RbEvasObject, e);
467 evas_object_repeat_events_set (e->real, val == Qtrue);
472 static VALUE c_anti_alias_get (VALUE self)
474 GET_OBJ (self, RbEvasObject, e);
476 return evas_object_anti_alias_get (e->real) ? Qtrue : Qfalse;
479 static VALUE c_anti_alias_set (VALUE self, VALUE val)
481 GET_OBJ (self, RbEvasObject, e);
485 evas_object_anti_alias_set (e->real, val == Qtrue);
496 static VALUE c_raise (VALUE self)
498 GET_OBJ (self, RbEvasObject, e);
500 evas_object_raise (e->real);
511 static VALUE c_lower (VALUE self)
513 GET_OBJ (self, RbEvasObject, e);
515 evas_object_lower (e->real);
522 * e.stack_above(evasobject) => nil
524 * Positions <i>e</i> above <i>evasobject</i>.
526 static VALUE c_stack_above (VALUE self, VALUE target)
528 GET_OBJ (self, RbEvasObject, e);
530 CHECK_CLASS (target, cEvasObject);
531 GET_OBJ (target, RbEvasObject, t);
533 evas_object_stack_above (e->real, t->real);
540 * e.stack_below(evasobject) => nil
542 * Positions <i>e</i> below <i>evasobject</i>.
544 static VALUE c_stack_below (VALUE self, VALUE target)
546 GET_OBJ (self, RbEvasObject, e);
548 CHECK_CLASS (target, cEvasObject);
549 GET_OBJ (target, RbEvasObject, t);
551 evas_object_stack_below (e->real, t->real);
558 * e.above => evasobject
560 * Returns the <code>Evas::EvasObject</code> that's positioned above
563 static VALUE c_above_get (VALUE self)
565 GET_OBJ (self, RbEvasObject, e);
567 return TO_EVAS_OBJECT (evas_object_above_get (e->real));
572 * e.below => evasobject
574 * Returns the <code>Evas::EvasObject</code> that's positioned below
577 static VALUE c_below_get (VALUE self)
579 GET_OBJ (self, RbEvasObject, e);
581 return TO_EVAS_OBJECT (evas_object_below_get (e->real));
584 static VALUE c_userdata_get (VALUE self)
586 GET_OBJ (self, RbEvasObject, e);
588 if (NIL_P (e->userdata))
589 e->userdata = rb_hash_new ();
594 void Init_EvasObject (void)
596 cEvasObject = rb_define_class_under (mEvas, "EvasObject",
599 rb_define_alloc_func (cEvasObject, c_alloc);
600 rb_define_method (cEvasObject, "initialize", c_init, 1);
601 rb_define_method (cEvasObject, "inspect", c_inspect, 0);
602 rb_define_method (cEvasObject, "type", c_type_get, 0);
603 rb_define_method (cEvasObject, "delete", c_delete, 0);
604 rb_define_method (cEvasObject, "resize", c_resize, 2);
605 rb_define_method (cEvasObject, "move", c_move, 2);
606 rb_define_method (cEvasObject, "geometry", c_geometry_get, 0);
607 rb_define_method (cEvasObject, "show", c_show, 0);
608 rb_define_method (cEvasObject, "hide", c_hide, 0);
609 rb_define_method (cEvasObject, "visible?", c_visible_get, 0);
610 rb_define_method (cEvasObject, "focused?", c_focused_get, 0);
611 rb_define_method (cEvasObject, "focused=", c_focused_set, 1);
612 rb_define_method (cEvasObject, "evas", c_evas_get, 0);
613 rb_define_method (cEvasObject, "name", c_name_get, 0);
614 rb_define_method (cEvasObject, "name=", c_name_set, 1);
615 rb_define_method (cEvasObject, "layer", c_layer_get, 0);
616 rb_define_method (cEvasObject, "layer=", c_layer_set, 1);
617 rb_define_method (cEvasObject, "get_color", c_get_color, 0);
618 rb_define_method (cEvasObject, "set_color", c_set_color, 4);
619 rb_define_method (cEvasObject, "clip", c_get_clip, 0);
620 rb_define_method (cEvasObject, "clip=", c_set_clip, 1);
621 rb_define_method (cEvasObject, "pass_events?",
622 c_pass_events_get, 0);
623 rb_define_method (cEvasObject, "pass_events=",
624 c_pass_events_set, 1);
625 rb_define_method (cEvasObject, "repeat_events?",
626 c_repeat_events_get, 0);
627 rb_define_method (cEvasObject, "repeat_events=",
628 c_repeat_events_set, 1);
629 rb_define_method (cEvasObject, "anti_alias?", c_anti_alias_get, 0);
630 rb_define_method (cEvasObject, "anti_alias=", c_anti_alias_set, 1);
631 rb_define_method (cEvasObject, "raise", c_raise, 0);
632 rb_define_method (cEvasObject, "lower", c_lower, 0);
633 rb_define_method (cEvasObject, "stack_above", c_stack_above, 1);
634 rb_define_method (cEvasObject, "stack_below", c_stack_below, 1);
635 rb_define_method (cEvasObject, "above", c_above_get, 0);
636 rb_define_method (cEvasObject, "below", c_below_get, 0);
637 rb_define_method (cEvasObject, "userdata", c_userdata_get, 0);