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
23 #include "rb_edje_main.h"
28 static inline char *GET_NAME (VALUE o)
34 id = rb_intern ("@name");
36 name = rb_ivar_get (o, id);
38 return StringValuePtr (name);
41 static inline VALUE GET_EDJE (VALUE o)
46 id = rb_intern ("@edje");
48 return rb_ivar_get (o, id);
51 VALUE TO_PART (VALUE edje, VALUE name)
55 CHECK_CLASS (edje, cEdje);
56 Check_Type (name, T_STRING);
58 self = rb_obj_alloc (cPart);
60 rb_iv_set (self, "@edje", edje);
61 rb_iv_set (self, "@name", rb_str_dup (name));
63 rb_obj_call_init (self, 0, NULL);
70 * part.geometry => array
72 * Returns an array containing the geometry of <i>part</i>.
74 static VALUE c_geometry_get (VALUE self)
76 int x = 0, y = 0, w = 0, h = 0;
78 GET_OBJ (GET_EDJE (self), RbEdje, e);
80 edje_object_part_geometry_get (e->real.real, GET_NAME (self),
86 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
87 INT2FIX (w), INT2FIX (h));
92 * part.swallow(evasobject) => nil
94 * Swallows an <code>Evas::EvasObject</code> into <i>part</i>.
96 static VALUE c_swallow (VALUE self, VALUE target)
98 GET_OBJ (GET_EDJE (self), RbEdje, e);
100 CHECK_CLASS (target, cEvasObject);
101 GET_OBJ (target, RbEvasObject, t);
103 edje_object_part_swallow (e->real.real, GET_NAME (self), t->real);
104 rb_iv_set (self, "swallowed_obj", target);
111 * part.unswallow => nil
113 * Unswallows the <code>Evas::EvasObject</code> swallowed by
116 static VALUE c_unswallow (VALUE self)
120 GET_OBJ (GET_EDJE (self), RbEdje, e);
122 o = edje_object_part_swallow_get (e->real.real, GET_NAME (self));
124 rb_raise (rb_eException, "Part didn't swallow an EvasObject");
128 edje_object_part_unswallow (e->real.real, o);
129 rb_iv_set (self, "swallowed_obj", Qnil);
136 * part.swallowed_object => evasobject or nil
138 * Returns the <code>Evas::EvasObject</code> swallowed by
139 * <i>part</i> or nil if <i>part</i> didn't swallow an
140 * <code>Evas::EvasObject</code>.
142 static VALUE c_swallowed_object_get (VALUE self)
146 GET_OBJ (GET_EDJE (self), RbEdje, e);
148 o = edje_object_part_swallow_get (e->real.real, GET_NAME (self));
152 return TO_EVAS_OBJECT (o);
157 * part.text => string
159 * Returns the text of <i>part</i>.
161 static VALUE c_text_get (VALUE self)
165 GET_OBJ (GET_EDJE (self), RbEdje, e);
167 s = edje_object_part_text_get (e->real.real, GET_NAME (self));
169 return s ? rb_str_new2 (s) : Qnil;
176 * Sets the text of <i>part</i>.
178 static VALUE c_text_set (VALUE self, VALUE text)
180 GET_OBJ (GET_EDJE (self), RbEdje, e);
182 Check_Type (text, T_STRING);
184 edje_object_part_text_set (e->real.real, GET_NAME (self),
185 StringValuePtr (text));
192 * part.get_drag_value => array
194 * Returns the drag value of <i>part</i>.
196 * part.set_drag_value(1.5, 2.5) #=> nil
197 * part.get_drag_value #=> [1.5, 2.5]
199 static VALUE c_get_drag_value (VALUE self)
201 double dx = 0, dy = 0;
203 GET_OBJ (GET_EDJE (self), RbEdje, e);
205 edje_object_part_drag_value_get (e->real.real, GET_NAME (self), &dx, &dy);
207 return rb_ary_new3 (2, rb_float_new (dx), rb_float_new (dy));
212 * part.set_drag_value(dx, dy) => nil
214 * Sets the drag value of <i>part</i>.
216 * part.set_drag_value(1.5, 2.5) #=> nil
218 static VALUE c_set_drag_value (VALUE self, VALUE dx, VALUE dy)
220 GET_OBJ (GET_EDJE (self), RbEdje, e);
223 Check_Type (dx, T_FLOAT);
226 Check_Type (dy, T_FLOAT);
228 edje_object_part_drag_value_set (e->real.real, GET_NAME (self),
229 NUM2DBL (dx), NUM2DBL (dy));
234 static VALUE c_state_get (VALUE self)
239 GET_OBJ (GET_EDJE (self), RbEdje, e);
241 name = edje_object_part_state_get (e->real.real,
242 GET_NAME (self), &val);
244 return rb_ary_new3 (2, rb_str_new2 (name), rb_float_new (val));
247 void Init_Part (void)
249 cPart = rb_define_class_under (mEdje, "Part", rb_cObject);
251 rb_define_attr (cPart, "edje", 1, 0);
252 rb_define_attr (cPart, "name", 1, 0);
254 /* not publically instantiable yet */
255 rb_define_private_method (rb_singleton_class (cPart),
257 rb_define_method (cPart, "geometry", c_geometry_get, 0);
258 rb_define_method (cPart, "swallow", c_swallow, 1);
259 rb_define_method (cPart, "unswallow", c_unswallow, 1);
260 rb_define_method (cPart, "swallowed_object",
261 c_swallowed_object_get, 0);
262 rb_define_method (cPart, "text", c_text_get, 0);
263 rb_define_method (cPart, "text=", c_text_set, 1);
264 rb_define_method (cPart, "get_drag_value", c_get_drag_value, 0);
265 rb_define_method (cPart, "set_drag_value", c_set_drag_value, 2);
266 rb_define_method (cPart, "state", c_state_get, 0);