2 * $Id: rb_evas_object.c 20 2004-06-22 20:46:56Z 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"
29 #define GET_OBJ(obj, type, o, desc) \
32 Data_Get_Struct ((obj), type *, (o)); \
35 rb_raise (rb_eException, desc " destroyed already"); \
39 #define CHECK_BOOL(val) \
40 if (TYPE ((val)) != T_TRUE && TYPE ((val)) != T_FALSE) { \
41 rb_raise (rb_eTypeError, \
42 "wrong argument type %s (expected true or false)", \
43 rb_obj_classname ((val))); \
49 /* called by the child classes */
50 void c_evas_object_free (Evas_Object **e)
58 void c_evas_object_mark (Evas_Object **e)
62 parent = rb_hash_aref (parents, INT2NUM ((long) (e)));
67 static VALUE c_init (VALUE self, VALUE parent)
69 GET_OBJ (self, Evas_Object, e, "EvasObject");
71 evas_object_data_set (*e, RUBY_EVAS_OBJECT_KEY, (void *) self);
73 rb_hash_aset (parents, INT2NUM ((long) e), parent);
78 static VALUE c_inspect (VALUE self)
82 GET_OBJ (self, Evas_Object, e, "EvasObject");
84 snprintf (buf, sizeof (buf), "#<EvasObject:%p ptr=%p>",
87 return rb_str_new2 (buf);
90 static VALUE c_delete (VALUE self)
92 GET_OBJ (self, Evas_Object, e, "EvasObject");
102 static VALUE c_resize (VALUE self, VALUE w, VALUE h)
104 GET_OBJ (self, Evas_Object, e, "EvasObject");
106 Check_Type (w, T_FIXNUM);
107 Check_Type (h, T_FIXNUM);
109 evas_object_resize (*e, (Evas_Coord) FIX2INT (w),
110 (Evas_Coord) FIX2INT (h));
115 static VALUE c_move (VALUE self, VALUE x, VALUE y)
117 GET_OBJ (self, Evas_Object, e, "EvasObject");
119 Check_Type (x, T_FIXNUM);
120 Check_Type (y, T_FIXNUM);
122 evas_object_move (*e, (Evas_Coord) FIX2INT (x),
123 (Evas_Coord) FIX2INT (y));
128 static VALUE c_geometry_get (VALUE self)
130 int x = 0, y = 0, w = 0, h = 0;
132 GET_OBJ (self, Evas_Object, e, "EvasObject");
134 evas_object_geometry_get (*e, (Evas_Coord *) &x, (Evas_Coord *) &y,
135 (Evas_Coord *) & w, (Evas_Coord *) &h);
137 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
141 static VALUE c_show (VALUE self)
143 GET_OBJ (self, Evas_Object, e, "EvasObject");
145 evas_object_show (*e);
150 static VALUE c_hide (VALUE self)
152 GET_OBJ (self, Evas_Object, e, "EvasObject");
154 evas_object_hide (*e);
159 static VALUE c_visible_get (VALUE self)
161 GET_OBJ (self, Evas_Object, e, "EvasObject");
163 return evas_object_visible_get (*e) ? Qtrue : Qfalse;
166 static VALUE c_evas_get (VALUE self)
168 GET_OBJ (self, Evas_Object, e, "EvasObject");
170 return rb_hash_aref (parents, INT2NUM ((long) (e)));
173 static VALUE c_name_get (VALUE self)
177 GET_OBJ (self, Evas_Object, e, "EvasObject");
179 if (!(name = evas_object_name_get (*e)))
182 return rb_str_new2 (name);
185 static VALUE c_name_set (VALUE self, VALUE val)
187 GET_OBJ (self, Evas_Object, e, "EvasObject");
189 Check_Type (val, T_STRING);
191 evas_object_name_set (*e, StringValuePtr (val));
196 static VALUE c_layer_get (VALUE self)
198 GET_OBJ (self, Evas_Object, e, "EvasObject");
200 return INT2FIX (evas_object_layer_get (*e));
203 static VALUE c_layer_set (VALUE self, VALUE val)
205 GET_OBJ (self, Evas_Object, e, "EvasObject");
207 Check_Type (val, T_FIXNUM);
209 evas_object_layer_set (*e, NUM2INT (val));
214 static VALUE c_get_color (VALUE self)
216 int r = 0, g = 0, b = 0, a = 0;
218 GET_OBJ (self, Evas_Object, e, "EvasObject");
220 evas_object_color_get (*e, &r, &g, &b, &a);
222 return rb_ary_new3 (4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
226 static VALUE c_set_color (VALUE self, VALUE r, VALUE g, VALUE b,
229 GET_OBJ (self, Evas_Object, e, "EvasObject");
231 Check_Type (r, T_FIXNUM);
232 Check_Type (g, T_FIXNUM);
233 Check_Type (b, T_FIXNUM);
234 Check_Type (a, T_FIXNUM);
236 evas_object_color_set (*e, FIX2INT (r), FIX2INT (g), FIX2INT (b),
242 static VALUE c_pass_events_get (VALUE self)
244 GET_OBJ (self, Evas_Object, e, "EvasObject");
246 return evas_object_pass_events_get (*e) ? Qtrue : Qfalse;
249 static VALUE c_pass_events_set (VALUE self, VALUE val)
251 GET_OBJ (self, Evas_Object, e, "EvasObject");
255 evas_object_pass_events_set (*e, val == Qtrue ? 1 : 0);
260 static VALUE c_raise (VALUE self)
262 GET_OBJ (self, Evas_Object, e, "EvasObject");
264 evas_object_raise (*e);
269 static VALUE c_lower (VALUE self)
271 GET_OBJ (self, Evas_Object, e, "EvasObject");
273 evas_object_lower (*e);
278 static VALUE c_stack_above (VALUE self, VALUE target)
280 GET_OBJ (self, Evas_Object, e, "EvasObject");
282 if (!rb_obj_is_kind_of (target, cEvasObject)) {
283 rb_raise (rb_eTypeError,
284 "wrong argument type %s (expected EvasObject)",
285 rb_obj_classname (target));
289 GET_OBJ (target, Evas_Object, target2, "EvasObject");
291 evas_object_stack_above (*e, *target2);
296 static VALUE c_stack_below (VALUE self, VALUE target)
298 GET_OBJ (self, Evas_Object, e, "EvasObject");
300 if (!rb_obj_is_kind_of (target, cEvasObject)) {
301 rb_raise (rb_eTypeError,
302 "wrong argument type %s (expected EvasObject)",
303 rb_obj_classname (target));
307 GET_OBJ (target, Evas_Object, target2, "EvasObject");
309 evas_object_stack_below (*e, *target2);
314 static VALUE c_above_get (VALUE self)
319 GET_OBJ (self, Evas_Object, e, "EvasObject");
321 if (!(evas_object_above_get (*e)))
324 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
325 rb_raise (rb_eException, "EvasObject Ruby object key missing");
332 static VALUE c_below_get (VALUE self)
337 GET_OBJ (self, Evas_Object, e, "EvasObject");
339 if (!(evas_object_below_get (*e)))
342 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
343 rb_raise (rb_eException, "EvasObject Ruby object key missing");
350 void Init_EvasObject (void)
352 cEvasObject = rb_define_class_under (mEvas, "EvasObject",
355 rb_define_private_method (rb_singleton_class (cEvasObject),
357 rb_define_method (cEvasObject, "initialize", c_init, 1);
358 rb_define_method (cEvasObject, "inspect", c_inspect, 0);
359 rb_define_method (cEvasObject, "delete", c_delete, 0);
360 rb_define_method (cEvasObject, "resize", c_resize, 2);
361 rb_define_method (cEvasObject, "move", c_move, 2);
362 rb_define_method (cEvasObject, "geometry", c_geometry_get, 0);
363 rb_define_method (cEvasObject, "show", c_show, 0);
364 rb_define_method (cEvasObject, "hide", c_hide, 0);
365 rb_define_method (cEvasObject, "visible?", c_visible_get, 0);
366 rb_define_method (cEvasObject, "evas", c_evas_get, 0);
367 rb_define_method (cEvasObject, "name", c_name_get, 0);
368 rb_define_method (cEvasObject, "name=", c_name_set, 1);
369 rb_define_method (cEvasObject, "layer", c_layer_get, 0);
370 rb_define_method (cEvasObject, "layer=", c_layer_set, 1);
371 rb_define_method (cEvasObject, "get_color", c_get_color, 0);
372 rb_define_method (cEvasObject, "set_color", c_set_color, 4);
373 rb_define_method (cEvasObject, "pass_events?", c_pass_events_get, 0);
374 rb_define_method (cEvasObject, "pass_events=", c_pass_events_set, 1);
375 rb_define_method (cEvasObject, "raise", c_raise, 0);
376 rb_define_method (cEvasObject, "lower", c_lower, 0);
377 rb_define_method (cEvasObject, "stack_above", c_stack_above, 1);
378 rb_define_method (cEvasObject, "stack_below", c_stack_below, 1);
379 rb_define_method (cEvasObject, "above", c_above_get, 0);
380 rb_define_method (cEvasObject, "below", c_below_get, 0);
382 parents = rb_hash_new ();
383 rb_global_variable (&parents);