2 * $Id: rb_evas_object.c 350 2006-02-08 21:13:34Z 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);
88 static VALUE c_type_get (VALUE self)
92 GET_OBJ (self, RbEvasObject, e);
94 s = evas_object_type_get (e->real);
96 return s ? rb_str_new2 (s) : Qnil;
105 static VALUE c_delete (VALUE self)
107 GET_OBJ (self, RbEvasObject, e);
109 evas_object_del (e->real);
117 * e.resize(width, height) => nil
119 * Resizes <i>e</i> to width x height.
121 * e.resize(100, 200) #=> nil
123 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
125 GET_OBJ (self, RbEvasObject, e);
127 Check_Type (w, T_FIXNUM);
128 Check_Type (h, T_FIXNUM);
130 evas_object_resize (e->real, (Evas_Coord) FIX2INT (w),
131 (Evas_Coord) FIX2INT (h));
138 * e.move(x, y) => nil
140 * Moves <i>e</i> to the coordinates specified in
141 * <i>x</i> and <i>y</i>.
143 * e.move(100, 200) #=> nil
145 static VALUE c_move (VALUE self, VALUE x, VALUE y)
147 GET_OBJ (self, RbEvasObject, e);
149 Check_Type (x, T_FIXNUM);
150 Check_Type (y, T_FIXNUM);
152 evas_object_move (e->real, (Evas_Coord) FIX2INT (x),
153 (Evas_Coord) FIX2INT (y));
160 * e.geometry => array
162 * Returns an array containing the geometry of <i>e</i>.
164 * e.move(150, 300) #=> nil
165 * e.resize(200, 200) #=> nil
166 * e.geometry #=> [150, 300, 200, 200]
168 static VALUE c_geometry_get (VALUE self)
170 int x = 0, y = 0, w = 0, h = 0;
172 GET_OBJ (self, RbEvasObject, e);
174 evas_object_geometry_get (e->real,
175 (Evas_Coord *) &x, (Evas_Coord *) &y,
176 (Evas_Coord *) &w, (Evas_Coord *) &h);
178 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
188 static VALUE c_show (VALUE self)
190 GET_OBJ (self, RbEvasObject, e);
192 evas_object_show (e->real);
203 static VALUE c_hide (VALUE self)
205 GET_OBJ (self, RbEvasObject, e);
207 evas_object_hide (e->real);
214 * e.visible? => true or false
216 * Returns true if <i>e</i> is visible, else returns false.
218 static VALUE c_visible_get (VALUE self)
220 GET_OBJ (self, RbEvasObject, e);
222 return evas_object_visible_get (e->real) ? Qtrue : Qfalse;
227 * e.focused? => true or false
229 * Returns true if <i>e</i> is focused, else returns false.
231 static VALUE c_focused_get (VALUE self)
233 GET_OBJ (self, RbEvasObject, e);
235 return evas_object_focus_get (e->real) ? Qtrue : Qfalse;
240 * e.focused(true or false)
242 * (Un)focuses <i>e</i>.
244 static VALUE c_focused_set (VALUE self, VALUE val)
246 GET_OBJ (self, RbEvasObject, e);
250 evas_object_focus_set (e->real, val == Qtrue);
259 * Returns the <code>Evas::Evas</code> for <i>e</i>.
261 static VALUE c_evas_get (VALUE self)
263 GET_OBJ (self, RbEvasObject, e);
272 * Returns the name of <i>e</i>.
274 static VALUE c_name_get (VALUE self)
278 GET_OBJ (self, RbEvasObject, e);
280 if (!(name = evas_object_name_get (e->real)))
283 return rb_str_new2 (name);
290 * Sets the name of <i>e</i>.
292 static VALUE c_name_set (VALUE self, VALUE val)
294 GET_OBJ (self, RbEvasObject, e);
296 Check_Type (val, T_STRING);
298 evas_object_name_set (e->real, StringValuePtr (val));
307 * Returns the layer <i>e</i> is in.
309 static VALUE c_layer_get (VALUE self)
311 GET_OBJ (self, RbEvasObject, e);
313 return INT2FIX (evas_object_layer_get (e->real));
320 * Sets the layer <i>e</i> is in.
322 static VALUE c_layer_set (VALUE self, VALUE val)
324 GET_OBJ (self, RbEvasObject, e);
326 Check_Type (val, T_FIXNUM);
328 evas_object_layer_set (e->real, NUM2INT (val));
335 * e.get_color => array
337 * Returns the color of <i>e</i>.
339 * e.set_color(128, 128, 128, 0) #=> nil
340 * e.get_color #=> [128, 128, 128, 0]
342 static VALUE c_get_color (VALUE self)
344 int r = 0, g = 0, b = 0, a = 0;
346 GET_OBJ (self, RbEvasObject, e);
348 evas_object_color_get (e->real, &r, &g, &b, &a);
350 return rb_ary_new3 (4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
356 * e.set_color(r, g, b, a) => nil
358 * Sets the color of <i>e</i>.
360 * e.set_color(128, 128, 128, 0) #=> nil
362 static VALUE c_set_color (VALUE self, VALUE r, VALUE g, VALUE b,
365 GET_OBJ (self, RbEvasObject, e);
367 Check_Type (r, T_FIXNUM);
368 Check_Type (g, T_FIXNUM);
369 Check_Type (b, T_FIXNUM);
370 Check_Type (a, T_FIXNUM);
372 evas_object_color_set (e->real, FIX2INT (r), FIX2INT (g),
373 FIX2INT (b), FIX2INT (a));
378 static VALUE c_get_clip (VALUE self)
380 GET_OBJ (self, RbEvasObject, e);
382 return TO_EVAS_OBJECT (evas_object_clip_get (e->real));
385 static VALUE c_set_clip (VALUE self, VALUE clip)
387 GET_OBJ (self, RbEvasObject, e);
388 GET_OBJ (clip, RbEvasObject, e2);
390 evas_object_clip_set (e->real, e2->real);
397 * e.pass_events? => true or false
399 * Returns true if <i>e</i> passes events on to EvasObjects that are
400 * below itself, else returns false.
402 static VALUE c_pass_events_get (VALUE self)
404 GET_OBJ (self, RbEvasObject, e);
406 return evas_object_pass_events_get (e->real) ? Qtrue : Qfalse;
411 * e.pass_events(true or false)
413 * Sets whether <i>e</i> passes events on to EvasObjects that are
416 static VALUE c_pass_events_set (VALUE self, VALUE val)
418 GET_OBJ (self, RbEvasObject, e);
422 evas_object_pass_events_set (e->real, val == Qtrue);
429 * e.repeat_events? => true or false
431 * Returns true if <i>e</i> repeats events to EvasObjects that are
432 * below itself, else returns false.
434 static VALUE c_repeat_events_get (VALUE self)
436 GET_OBJ (self, RbEvasObject, e);
438 return evas_object_repeat_events_get (e->real) ? Qtrue : Qfalse;
443 * e.repeat_events(true or false)
445 * Sets whether <i>e</i> repeats events to EvasObjects that are
448 static VALUE c_repeat_events_set (VALUE self, VALUE val)
450 GET_OBJ (self, RbEvasObject, e);
454 evas_object_repeat_events_set (e->real, val == Qtrue);
465 static VALUE c_raise (VALUE self)
467 GET_OBJ (self, RbEvasObject, e);
469 evas_object_raise (e->real);
480 static VALUE c_lower (VALUE self)
482 GET_OBJ (self, RbEvasObject, e);
484 evas_object_lower (e->real);
491 * e.stack_above(evasobject) => nil
493 * Positions <i>e</i> above <i>evasobject</i>.
495 static VALUE c_stack_above (VALUE self, VALUE target)
497 GET_OBJ (self, RbEvasObject, e);
499 CHECK_CLASS (target, cEvasObject);
500 GET_OBJ (target, RbEvasObject, t);
502 evas_object_stack_above (e->real, t->real);
509 * e.stack_below(evasobject) => nil
511 * Positions <i>e</i> below <i>evasobject</i>.
513 static VALUE c_stack_below (VALUE self, VALUE target)
515 GET_OBJ (self, RbEvasObject, e);
517 CHECK_CLASS (target, cEvasObject);
518 GET_OBJ (target, RbEvasObject, t);
520 evas_object_stack_below (e->real, t->real);
527 * e.above => evasobject
529 * Returns the <code>Evas::EvasObject</code> that's positioned above
532 static VALUE c_above_get (VALUE self)
534 GET_OBJ (self, RbEvasObject, e);
536 return TO_EVAS_OBJECT (evas_object_above_get (e->real));
541 * e.below => evasobject
543 * Returns the <code>Evas::EvasObject</code> that's positioned below
546 static VALUE c_below_get (VALUE self)
548 GET_OBJ (self, RbEvasObject, e);
550 return TO_EVAS_OBJECT (evas_object_below_get (e->real));
553 static VALUE c_userdata_get (VALUE self)
555 GET_OBJ (self, RbEvasObject, e);
557 if (NIL_P (e->userdata))
558 e->userdata = rb_hash_new ();
563 void Init_EvasObject (void)
565 cEvasObject = rb_define_class_under (mEvas, "EvasObject",
568 rb_define_private_method (rb_singleton_class (cEvasObject),
570 rb_define_method (cEvasObject, "initialize", c_init, 1);
571 rb_define_method (cEvasObject, "inspect", c_inspect, 0);
572 rb_define_method (cEvasObject, "type", c_type_get, 0);
573 rb_define_method (cEvasObject, "delete", c_delete, 0);
574 rb_define_method (cEvasObject, "resize", c_resize, 2);
575 rb_define_method (cEvasObject, "move", c_move, 2);
576 rb_define_method (cEvasObject, "geometry", c_geometry_get, 0);
577 rb_define_method (cEvasObject, "show", c_show, 0);
578 rb_define_method (cEvasObject, "hide", c_hide, 0);
579 rb_define_method (cEvasObject, "visible?", c_visible_get, 0);
580 rb_define_method (cEvasObject, "focused?", c_focused_get, 0);
581 rb_define_method (cEvasObject, "focused=", c_focused_set, 1);
582 rb_define_method (cEvasObject, "evas", c_evas_get, 0);
583 rb_define_method (cEvasObject, "name", c_name_get, 0);
584 rb_define_method (cEvasObject, "name=", c_name_set, 1);
585 rb_define_method (cEvasObject, "layer", c_layer_get, 0);
586 rb_define_method (cEvasObject, "layer=", c_layer_set, 1);
587 rb_define_method (cEvasObject, "get_color", c_get_color, 0);
588 rb_define_method (cEvasObject, "set_color", c_set_color, 4);
589 rb_define_method (cEvasObject, "clip", c_get_clip, 0);
590 rb_define_method (cEvasObject, "clip=", c_set_clip, 1);
591 rb_define_method (cEvasObject, "pass_events?",
592 c_pass_events_get, 0);
593 rb_define_method (cEvasObject, "pass_events=",
594 c_pass_events_set, 1);
595 rb_define_method (cEvasObject, "repeat_events?",
596 c_repeat_events_get, 0);
597 rb_define_method (cEvasObject, "repeat_events=",
598 c_repeat_events_set, 1);
599 rb_define_method (cEvasObject, "raise", c_raise, 0);
600 rb_define_method (cEvasObject, "lower", c_lower, 0);
601 rb_define_method (cEvasObject, "stack_above", c_stack_above, 1);
602 rb_define_method (cEvasObject, "stack_below", c_stack_below, 1);
603 rb_define_method (cEvasObject, "above", c_above_get, 0);
604 rb_define_method (cEvasObject, "below", c_below_get, 0);
605 rb_define_method (cEvasObject, "userdata", c_userdata_get, 0);