2 * $Id: rb_evas_object.c 38 2004-07-25 11:27:25Z 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
25 #include "rb_evas_main.h"
27 #include "rb_evas_object.h"
31 /* called by the child classes */
32 void c_evas_object_free (Evas_Object **e)
37 rb_hash_aset (parents, INT2NUM ((long) e), Qnil);
42 void c_evas_object_mark (Evas_Object **e)
46 parent = rb_hash_aref (parents, INT2NUM ((long) (e)));
51 static VALUE c_init (VALUE self, VALUE parent)
53 GET_OBJ (self, Evas_Object *, e);
55 evas_object_data_set (*e, RUBY_EVAS_OBJECT_KEY, (void *) self);
57 rb_hash_aset (parents, INT2NUM ((long) e), parent);
62 static VALUE c_inspect (VALUE self)
64 INSPECT (self, Evas_Object *);
67 static VALUE c_delete (VALUE self)
69 GET_OBJ (self, Evas_Object *, e);
77 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
79 GET_OBJ (self, Evas_Object *, e);
81 Check_Type (w, T_FIXNUM);
82 Check_Type (h, T_FIXNUM);
84 evas_object_resize (*e, (Evas_Coord) FIX2INT (w),
85 (Evas_Coord) FIX2INT (h));
90 static VALUE c_move (VALUE self, VALUE x, VALUE y)
92 GET_OBJ (self, Evas_Object *, e);
94 Check_Type (x, T_FIXNUM);
95 Check_Type (y, T_FIXNUM);
97 evas_object_move (*e, (Evas_Coord) FIX2INT (x),
98 (Evas_Coord) FIX2INT (y));
103 static VALUE c_geometry_get (VALUE self)
105 int x = 0, y = 0, w = 0, h = 0;
107 GET_OBJ (self, Evas_Object *, e);
109 evas_object_geometry_get (*e, (Evas_Coord *) &x, (Evas_Coord *) &y,
110 (Evas_Coord *) & w, (Evas_Coord *) &h);
112 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
116 static VALUE c_show (VALUE self)
118 GET_OBJ (self, Evas_Object *, e);
120 evas_object_show (*e);
125 static VALUE c_hide (VALUE self)
127 GET_OBJ (self, Evas_Object *, e);
129 evas_object_hide (*e);
134 static VALUE c_visible_get (VALUE self)
136 GET_OBJ (self, Evas_Object *, e);
138 return evas_object_visible_get (*e) ? Qtrue : Qfalse;
141 static VALUE c_evas_get (VALUE self)
143 GET_OBJ (self, Evas_Object *, e);
145 return rb_hash_aref (parents, INT2NUM ((long) (e)));
148 static VALUE c_name_get (VALUE self)
152 GET_OBJ (self, Evas_Object *, e);
154 if (!(name = evas_object_name_get (*e)))
157 return rb_str_new2 (name);
160 static VALUE c_name_set (VALUE self, VALUE val)
162 GET_OBJ (self, Evas_Object *, e);
164 Check_Type (val, T_STRING);
166 evas_object_name_set (*e, StringValuePtr (val));
171 static VALUE c_layer_get (VALUE self)
173 GET_OBJ (self, Evas_Object *, e);
175 return INT2FIX (evas_object_layer_get (*e));
178 static VALUE c_layer_set (VALUE self, VALUE val)
180 GET_OBJ (self, Evas_Object *, e);
182 Check_Type (val, T_FIXNUM);
184 evas_object_layer_set (*e, NUM2INT (val));
189 static VALUE c_get_color (VALUE self)
191 int r = 0, g = 0, b = 0, a = 0;
193 GET_OBJ (self, Evas_Object *, e);
195 evas_object_color_get (*e, &r, &g, &b, &a);
197 return rb_ary_new3 (4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
201 static VALUE c_set_color (VALUE self, VALUE r, VALUE g, VALUE b,
204 GET_OBJ (self, Evas_Object *, e);
206 Check_Type (r, T_FIXNUM);
207 Check_Type (g, T_FIXNUM);
208 Check_Type (b, T_FIXNUM);
209 Check_Type (a, T_FIXNUM);
211 evas_object_color_set (*e, FIX2INT (r), FIX2INT (g), FIX2INT (b),
217 static VALUE c_pass_events_get (VALUE self)
219 GET_OBJ (self, Evas_Object *, e);
221 return evas_object_pass_events_get (*e) ? Qtrue : Qfalse;
224 static VALUE c_pass_events_set (VALUE self, VALUE val)
226 GET_OBJ (self, Evas_Object *, e);
230 evas_object_pass_events_set (*e, val == Qtrue ? 1 : 0);
235 static VALUE c_raise (VALUE self)
237 GET_OBJ (self, Evas_Object *, e);
239 evas_object_raise (*e);
244 static VALUE c_lower (VALUE self)
246 GET_OBJ (self, Evas_Object *, e);
248 evas_object_lower (*e);
253 static VALUE c_stack_above (VALUE self, VALUE target)
255 GET_OBJ (self, Evas_Object *, e);
257 if (!rb_obj_is_kind_of (target, cEvasObject)) {
258 rb_raise (rb_eTypeError,
259 "wrong argument type %s (expected EvasObject)",
260 rb_obj_classname (target));
264 GET_OBJ (target, Evas_Object *, target2);
266 evas_object_stack_above (*e, *target2);
271 static VALUE c_stack_below (VALUE self, VALUE target)
273 GET_OBJ (self, Evas_Object *, e);
275 if (!rb_obj_is_kind_of (target, cEvasObject)) {
276 rb_raise (rb_eTypeError,
277 "wrong argument type %s (expected EvasObject)",
278 rb_obj_classname (target));
282 GET_OBJ (target, Evas_Object *, target2);
284 evas_object_stack_below (*e, *target2);
289 static VALUE c_above_get (VALUE self)
294 GET_OBJ (self, Evas_Object *, e);
296 if (!(evas_object_above_get (*e)))
299 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
300 rb_raise (rb_eException, "EvasObject Ruby object key missing");
307 static VALUE c_below_get (VALUE self)
312 GET_OBJ (self, Evas_Object *, e);
314 if (!(evas_object_below_get (*e)))
317 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
318 rb_raise (rb_eException, "EvasObject Ruby object key missing");
325 void Init_EvasObject (void)
327 cEvasObject = rb_define_class_under (mEvas, "EvasObject",
330 rb_define_private_method (rb_singleton_class (cEvasObject),
332 rb_define_method (cEvasObject, "initialize", c_init, 1);
333 rb_define_method (cEvasObject, "inspect", c_inspect, 0);
334 rb_define_method (cEvasObject, "delete", c_delete, 0);
335 rb_define_method (cEvasObject, "resize", c_resize, 2);
336 rb_define_method (cEvasObject, "move", c_move, 2);
337 rb_define_method (cEvasObject, "geometry", c_geometry_get, 0);
338 rb_define_method (cEvasObject, "show", c_show, 0);
339 rb_define_method (cEvasObject, "hide", c_hide, 0);
340 rb_define_method (cEvasObject, "visible?", c_visible_get, 0);
341 rb_define_method (cEvasObject, "evas", c_evas_get, 0);
342 rb_define_method (cEvasObject, "name", c_name_get, 0);
343 rb_define_method (cEvasObject, "name=", c_name_set, 1);
344 rb_define_method (cEvasObject, "layer", c_layer_get, 0);
345 rb_define_method (cEvasObject, "layer=", c_layer_set, 1);
346 rb_define_method (cEvasObject, "get_color", c_get_color, 0);
347 rb_define_method (cEvasObject, "set_color", c_set_color, 4);
348 rb_define_method (cEvasObject, "pass_events?", c_pass_events_get, 0);
349 rb_define_method (cEvasObject, "pass_events=", c_pass_events_set, 1);
350 rb_define_method (cEvasObject, "raise", c_raise, 0);
351 rb_define_method (cEvasObject, "lower", c_lower, 0);
352 rb_define_method (cEvasObject, "stack_above", c_stack_above, 1);
353 rb_define_method (cEvasObject, "stack_below", c_stack_below, 1);
354 rb_define_method (cEvasObject, "above", c_above_get, 0);
355 rb_define_method (cEvasObject, "below", c_below_get, 0);
357 parents = rb_hash_new ();
358 rb_global_variable (&parents);