2 * $Id: rb_part.c 113 2004-10-10 10:00:07Z 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_edje_main.h"
30 static inline char *GET_NAME (VALUE o)
36 id = rb_intern ("@name");
38 name = rb_ivar_get (o, id);
40 return StringValuePtr (name);
43 static inline VALUE GET_EDJE (VALUE o)
48 id = rb_intern ("@edje");
50 return rb_ivar_get (o, id);
53 VALUE TO_PART (VALUE edje, VALUE name)
57 CHECK_CLASS (edje, cEdje);
58 Check_Type (name, T_STRING);
60 self = rb_obj_alloc (cPart);
62 rb_iv_set (self, "@edje", edje);
63 rb_iv_set (self, "@name", rb_str_dup (name));
65 rb_obj_call_init (self, 0, NULL);
72 * part.geometry => array
74 * Returns an array containing the geometry of <i>part</i>.
76 static VALUE c_geometry_get (VALUE self)
78 int x = 0, y = 0, w = 0, h = 0;
80 GET_OBJ (GET_EDJE (self), RbEdje, e);
82 edje_object_part_geometry_get (e->real.real, GET_NAME (self),
88 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
89 INT2FIX (y), INT2FIX (h));
94 * part.swallow(evasobject) => nil
96 * Swallows an <code>Evas::EvasObject</code> into <i>part</i>.
98 static VALUE c_swallow (VALUE self, VALUE target)
100 GET_OBJ (GET_EDJE (self), RbEdje, e);
102 CHECK_CLASS (target, cEvasObject);
103 GET_OBJ (target, RbEvasObject, t);
105 edje_object_part_swallow (e->real.real, GET_NAME (self), t->real);
106 rb_iv_set (self, "swallowed_obj", target);
113 * part.unswallow => nil
115 * Unswallows the <code>Evas::EvasObject</code> swallowed by
118 static VALUE c_unswallow (VALUE self)
122 GET_OBJ (GET_EDJE (self), RbEdje, e);
124 o = edje_object_part_swallow_get (e->real.real, GET_NAME (self));
126 rb_raise (rb_eException, "Part didn't swallow an EvasObject");
130 edje_object_part_unswallow (e->real.real, o);
131 rb_iv_set (self, "swallowed_obj", Qnil);
138 * part.swallowed_object => evasobject or nil
140 * Returns the <code>Evas::EvasObject</code> swallowed by
141 * <i>part</i> or nil if <i>part</i> didn't swallow an
142 * <code>Evas::EvasObject</code>.
144 static VALUE c_swallowed_object_get (VALUE self)
148 GET_OBJ (GET_EDJE (self), RbEdje, e);
150 o = edje_object_part_swallow_get (e->real.real, GET_NAME (self));
154 return TO_EVAS_OBJECT (o);
159 * part.text => string
161 * Returns the text of <i>part</i>.
163 static VALUE c_text_get (VALUE self)
167 GET_OBJ (GET_EDJE (self), RbEdje, e);
169 s = edje_object_part_text_get (e->real.real, GET_NAME (self));
171 return s ? rb_str_new2 (s) : Qnil;
178 * Sets the text of <i>part</i>.
180 static VALUE c_text_set (VALUE self, VALUE text)
182 GET_OBJ (GET_EDJE (self), RbEdje, e);
184 Check_Type (text, T_STRING);
186 edje_object_part_text_set (e->real.real, GET_NAME (self),
187 StringValuePtr (text));
194 * part.get_drag_value => array
196 * Returns the drag value of <i>part</i>.
198 * part.set_drag_value(1.5, 2.5) #=> nil
199 * part.get_drag_value #=> [1.5, 2.5]
201 static VALUE c_get_drag_value (VALUE self)
203 double dx = 0, dy = 0;
205 GET_OBJ (GET_EDJE (self), RbEdje, e);
207 edje_object_part_drag_value_get (e->real.real, GET_NAME (self), &dx, &dy);
209 return rb_ary_new3 (2, rb_float_new (dx), rb_float_new (dy));
214 * part.set_drag_value(dx, dy) => nil
216 * Sets the drag value of <i>part</i>.
218 * part.set_drag_value(1.5, 2.5) #=> nil
220 static VALUE c_set_drag_value (VALUE self, VALUE dx, VALUE dy)
222 GET_OBJ (GET_EDJE (self), RbEdje, e);
225 Check_Type (dx, T_FLOAT);
228 Check_Type (dy, T_FLOAT);
230 edje_object_part_drag_value_set (e->real.real, GET_NAME (self),
231 NUM2DBL (dx), NUM2DBL (dy));
236 void Init_Part (void)
238 cPart = rb_define_class_under (mEdje, "Part", rb_cObject);
240 rb_define_attr (cPart, "edje", 1, 0);
241 rb_define_attr (cPart, "name", 1, 0);
243 /* not publically instantiable yet */
244 rb_define_private_method (rb_singleton_class (cPart),
246 rb_define_method (cPart, "geometry", c_geometry_get, 0);
247 rb_define_method (cPart, "swallow", c_swallow, 1);
248 rb_define_method (cPart, "unswallow", c_unswallow, 1);
249 rb_define_method (cPart, "swallowed_object",
250 c_swallowed_object_get, 0);
251 rb_define_method (cPart, "text", c_text_get, 0);
252 rb_define_method (cPart, "text=", c_text_set, 1);
253 rb_define_method (cPart, "get_drag_value", c_get_drag_value, 0);
254 rb_define_method (cPart, "set_drag_value", c_set_drag_value, 2);