2 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #define __RB_EVAS_OBJECT_C
25 #include "rb_evas_main.h"
27 #include "rb_evas_object.h"
31 VALUE TO_EVAS_OBJECT (Evas_Object *o)
38 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
39 rb_raise (rb_eException, "EvasObject Ruby object key missing");
46 /* called by the child classes */
47 void c_evas_object_mark (RbEvasObject *e)
49 rb_gc_mark (e->parent);
51 if (!NIL_P (e->callbacks))
52 rb_gc_mark (e->callbacks);
54 if (!NIL_P (e->userdata))
55 rb_gc_mark (e->userdata);
58 void c_evas_object_free (RbEvasObject *e, bool free_mem)
61 evas_object_del (e->real);
67 static void c_free (RbEvasObject *e)
69 c_evas_object_free (e, true);
72 static VALUE c_alloc (VALUE klass)
76 return Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
81 static VALUE c_init (VALUE self, VALUE parent)
83 GET_OBJ (self, RbEvasObject, e);
85 evas_object_data_set (e->real, RUBY_EVAS_OBJECT_KEY, (void *) self);
94 static VALUE c_inspect (VALUE self)
96 INSPECT (self, RbEvasObject);
99 static VALUE c_type_get (VALUE self)
103 GET_OBJ (self, RbEvasObject, e);
105 s = evas_object_type_get (e->real);
107 return s ? rb_str_new2 (s) : Qnil;
116 static VALUE c_delete (VALUE self)
118 GET_OBJ (self, RbEvasObject, e);
120 evas_object_del (e->real);
128 * e.resize(width, height) => nil
130 * Resizes <i>e</i> to width x height.
132 * e.resize(100, 200) #=> nil
134 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
136 GET_OBJ (self, RbEvasObject, e);
138 Check_Type (w, T_FIXNUM);
139 Check_Type (h, T_FIXNUM);
141 evas_object_resize (e->real, (Evas_Coord) FIX2INT (w),
142 (Evas_Coord) FIX2INT (h));
149 * e.move(x, y) => nil
151 * Moves <i>e</i> to the coordinates specified in
152 * <i>x</i> and <i>y</i>.
154 * e.move(100, 200) #=> nil
156 static VALUE c_move (VALUE self, VALUE x, VALUE y)
158 GET_OBJ (self, RbEvasObject, e);
160 Check_Type (x, T_FIXNUM);
161 Check_Type (y, T_FIXNUM);
163 evas_object_move (e->real, (Evas_Coord) FIX2INT (x),
164 (Evas_Coord) FIX2INT (y));
171 * e.geometry => array
173 * Returns an array containing the geometry of <i>e</i>.
175 * e.move(150, 300) #=> nil
176 * e.resize(200, 200) #=> nil
177 * e.geometry #=> [150, 300, 200, 200]
179 static VALUE c_geometry_get (VALUE self)
181 int x = 0, y = 0, w = 0, h = 0;
183 GET_OBJ (self, RbEvasObject, e);
185 evas_object_geometry_get (e->real,
186 (Evas_Coord *) &x, (Evas_Coord *) &y,
187 (Evas_Coord *) &w, (Evas_Coord *) &h);
189 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
199 static VALUE c_show (VALUE self)
201 GET_OBJ (self, RbEvasObject, e);
203 evas_object_show (e->real);
214 static VALUE c_hide (VALUE self)
216 GET_OBJ (self, RbEvasObject, e);
218 evas_object_hide (e->real);
225 * e.visible? => true or false
227 * Returns true if <i>e</i> is visible, else returns false.
229 static VALUE c_visible_get (VALUE self)
231 GET_OBJ (self, RbEvasObject, e);
233 return evas_object_visible_get (e->real) ? Qtrue : Qfalse;
238 * e.focused? => true or false
240 * Returns true if <i>e</i> is focused, else returns false.
242 static VALUE c_focused_get (VALUE self)
244 GET_OBJ (self, RbEvasObject, e);
246 return evas_object_focus_get (e->real) ? Qtrue : Qfalse;
251 * e.focused(true or false)
253 * (Un)focuses <i>e</i>.
255 static VALUE c_focused_set (VALUE self, VALUE val)
257 GET_OBJ (self, RbEvasObject, e);
261 evas_object_focus_set (e->real, val == Qtrue);
270 * Returns the <code>Evas::Evas</code> for <i>e</i>.
272 static VALUE c_evas_get (VALUE self)
274 GET_OBJ (self, RbEvasObject, e);
283 * Returns the name of <i>e</i>.
285 static VALUE c_name_get (VALUE self)
289 GET_OBJ (self, RbEvasObject, e);
291 if (!(name = evas_object_name_get (e->real)))
294 return rb_str_new2 (name);
301 * Sets the name of <i>e</i>.
303 static VALUE c_name_set (VALUE self, VALUE val)
305 GET_OBJ (self, RbEvasObject, e);
307 evas_object_name_set (e->real, StringValuePtr (val));
316 * Returns the layer <i>e</i> is in.
318 static VALUE c_layer_get (VALUE self)
320 GET_OBJ (self, RbEvasObject, e);
322 return INT2FIX (evas_object_layer_get (e->real));
329 * Sets the layer <i>e</i> is in.
331 static VALUE c_layer_set (VALUE self, VALUE val)
333 GET_OBJ (self, RbEvasObject, e);
335 Check_Type (val, T_FIXNUM);
337 evas_object_layer_set (e->real, NUM2INT (val));
344 * e.get_color => array
346 * Returns the color of <i>e</i>.
348 * e.set_color(128, 128, 128, 0) #=> nil
349 * e.get_color #=> [128, 128, 128, 0]
351 static VALUE c_get_color (VALUE self)
353 int r = 0, g = 0, b = 0, a = 0;
355 GET_OBJ (self, RbEvasObject, e);
357 evas_object_color_get (e->real, &r, &g, &b, &a);
359 return rb_ary_new3 (4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
365 * e.set_color(r, g, b, a) => nil
367 * Sets the color of <i>e</i>.
369 * e.set_color(128, 128, 128, 0) #=> nil
371 static VALUE c_set_color (VALUE self, VALUE r, VALUE g, VALUE b,
374 GET_OBJ (self, RbEvasObject, e);
376 Check_Type (r, T_FIXNUM);
377 Check_Type (g, T_FIXNUM);
378 Check_Type (b, T_FIXNUM);
379 Check_Type (a, T_FIXNUM);
381 evas_object_color_set (e->real, FIX2INT (r), FIX2INT (g),
382 FIX2INT (b), FIX2INT (a));
387 static VALUE c_get_clip (VALUE self)
389 GET_OBJ (self, RbEvasObject, e);
391 return TO_EVAS_OBJECT (evas_object_clip_get (e->real));
394 static VALUE c_set_clip (VALUE self, VALUE clip)
396 GET_OBJ (self, RbEvasObject, e);
397 GET_OBJ (clip, RbEvasObject, e2);
399 evas_object_clip_set (e->real, e2->real);
406 * e.pass_events? => true or false
408 * Returns true if <i>e</i> passes events on to EvasObjects that are
409 * below itself, else returns false.
411 static VALUE c_pass_events_get (VALUE self)
413 GET_OBJ (self, RbEvasObject, e);
415 return evas_object_pass_events_get (e->real) ? Qtrue : Qfalse;
420 * e.pass_events(true or false)
422 * Sets whether <i>e</i> passes events on to EvasObjects that are
425 static VALUE c_pass_events_set (VALUE self, VALUE val)
427 GET_OBJ (self, RbEvasObject, e);
431 evas_object_pass_events_set (e->real, val == Qtrue);
438 * e.repeat_events? => true or false
440 * Returns true if <i>e</i> repeats events to EvasObjects that are
441 * below itself, else returns false.
443 static VALUE c_repeat_events_get (VALUE self)
445 GET_OBJ (self, RbEvasObject, e);
447 return evas_object_repeat_events_get (e->real) ? Qtrue : Qfalse;
452 * e.repeat_events(true or false)
454 * Sets whether <i>e</i> repeats events to EvasObjects that are
457 static VALUE c_repeat_events_set (VALUE self, VALUE val)
459 GET_OBJ (self, RbEvasObject, e);
463 evas_object_repeat_events_set (e->real, val == Qtrue);
468 static VALUE c_anti_alias_get (VALUE self)
470 GET_OBJ (self, RbEvasObject, e);
472 return evas_object_anti_alias_get (e->real) ? Qtrue : Qfalse;
475 static VALUE c_anti_alias_set (VALUE self, VALUE val)
477 GET_OBJ (self, RbEvasObject, e);
481 evas_object_anti_alias_set (e->real, val == Qtrue);
492 static VALUE c_raise (VALUE self)
494 GET_OBJ (self, RbEvasObject, e);
496 evas_object_raise (e->real);
507 static VALUE c_lower (VALUE self)
509 GET_OBJ (self, RbEvasObject, e);
511 evas_object_lower (e->real);
518 * e.stack_above(evasobject) => nil
520 * Positions <i>e</i> above <i>evasobject</i>.
522 static VALUE c_stack_above (VALUE self, VALUE target)
524 GET_OBJ (self, RbEvasObject, e);
526 CHECK_CLASS (target, cEvasObject);
527 GET_OBJ (target, RbEvasObject, t);
529 evas_object_stack_above (e->real, t->real);
536 * e.stack_below(evasobject) => nil
538 * Positions <i>e</i> below <i>evasobject</i>.
540 static VALUE c_stack_below (VALUE self, VALUE target)
542 GET_OBJ (self, RbEvasObject, e);
544 CHECK_CLASS (target, cEvasObject);
545 GET_OBJ (target, RbEvasObject, t);
547 evas_object_stack_below (e->real, t->real);
554 * e.above => evasobject
556 * Returns the <code>Evas::EvasObject</code> that's positioned above
559 static VALUE c_above_get (VALUE self)
561 GET_OBJ (self, RbEvasObject, e);
563 return TO_EVAS_OBJECT (evas_object_above_get (e->real));
568 * e.below => evasobject
570 * Returns the <code>Evas::EvasObject</code> that's positioned below
573 static VALUE c_below_get (VALUE self)
575 GET_OBJ (self, RbEvasObject, e);
577 return TO_EVAS_OBJECT (evas_object_below_get (e->real));
580 static VALUE c_userdata_get (VALUE self)
582 GET_OBJ (self, RbEvasObject, e);
584 if (NIL_P (e->userdata))
585 e->userdata = rb_hash_new ();
590 void Init_EvasObject (void)
592 cEvasObject = rb_define_class_under (mEvas, "EvasObject",
595 rb_define_alloc_func (cEvasObject, c_alloc);
596 rb_define_method (cEvasObject, "initialize", c_init, 1);
597 rb_define_method (cEvasObject, "inspect", c_inspect, 0);
598 rb_define_method (cEvasObject, "type", c_type_get, 0);
599 rb_define_method (cEvasObject, "delete", c_delete, 0);
600 rb_define_method (cEvasObject, "resize", c_resize, 2);
601 rb_define_method (cEvasObject, "move", c_move, 2);
602 rb_define_method (cEvasObject, "geometry", c_geometry_get, 0);
603 rb_define_method (cEvasObject, "show", c_show, 0);
604 rb_define_method (cEvasObject, "hide", c_hide, 0);
605 rb_define_method (cEvasObject, "visible?", c_visible_get, 0);
606 rb_define_method (cEvasObject, "focused?", c_focused_get, 0);
607 rb_define_method (cEvasObject, "focused=", c_focused_set, 1);
608 rb_define_method (cEvasObject, "evas", c_evas_get, 0);
609 rb_define_method (cEvasObject, "name", c_name_get, 0);
610 rb_define_method (cEvasObject, "name=", c_name_set, 1);
611 rb_define_method (cEvasObject, "layer", c_layer_get, 0);
612 rb_define_method (cEvasObject, "layer=", c_layer_set, 1);
613 rb_define_method (cEvasObject, "get_color", c_get_color, 0);
614 rb_define_method (cEvasObject, "set_color", c_set_color, 4);
615 rb_define_method (cEvasObject, "clip", c_get_clip, 0);
616 rb_define_method (cEvasObject, "clip=", c_set_clip, 1);
617 rb_define_method (cEvasObject, "pass_events?",
618 c_pass_events_get, 0);
619 rb_define_method (cEvasObject, "pass_events=",
620 c_pass_events_set, 1);
621 rb_define_method (cEvasObject, "repeat_events?",
622 c_repeat_events_get, 0);
623 rb_define_method (cEvasObject, "repeat_events=",
624 c_repeat_events_set, 1);
625 rb_define_method (cEvasObject, "anti_alias?", c_anti_alias_get, 0);
626 rb_define_method (cEvasObject, "anti_alias=", c_anti_alias_set, 1);
627 rb_define_method (cEvasObject, "raise", c_raise, 0);
628 rb_define_method (cEvasObject, "lower", c_lower, 0);
629 rb_define_method (cEvasObject, "stack_above", c_stack_above, 1);
630 rb_define_method (cEvasObject, "stack_below", c_stack_below, 1);
631 rb_define_method (cEvasObject, "above", c_above_get, 0);
632 rb_define_method (cEvasObject, "below", c_below_get, 0);
633 rb_define_method (cEvasObject, "userdata", c_userdata_get, 0);