2 * $Id: rb_evas.c 29 2004-07-08 18:47:44Z 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 static void c_mark (Evas **e)
35 parent = rb_hash_aref (parents, INT2NUM ((long) (e)));
40 static void c_free (Evas **e)
42 /* do NOT call evas_free() here, since the Evas is freed
43 * by ecore_evas_free() eventually */
44 rb_hash_aset (parents, INT2NUM ((long) e), Qnil);
49 VALUE TO_EVAS (VALUE parent, Evas *e)
54 if (NIL_P (parent) || !e)
57 self = Data_Make_Struct (cEvas, Evas *,
58 c_mark, c_free, my_e);
61 rb_hash_aset (parents, INT2NUM ((long) my_e), parent);
63 rb_obj_call_init (self, 0, NULL);
68 static VALUE c_inspect (VALUE self)
72 GET_OBJ (self, Evas, e, "Evas");
74 snprintf (buf, sizeof (buf), "#<Evas::Evas:%p ptr=%p>",
77 return rb_str_new2 (buf);
80 static VALUE c_render (VALUE self)
82 GET_OBJ (self, Evas, e, "Evas");
89 static VALUE c_font_path_clear (VALUE self)
91 GET_OBJ (self, Evas, e, "Evas");
93 evas_font_path_clear (*e);
98 static VALUE c_font_path_append (VALUE self, VALUE path)
100 GET_OBJ (self, Evas, e, "Evas");
102 Check_Type (path, T_STRING);
104 evas_font_path_append (*e, StringValuePtr (path));
109 static VALUE c_font_path_prepend (VALUE self, VALUE path)
111 GET_OBJ (self, Evas, e, "Evas");
113 Check_Type (path, T_STRING);
115 evas_font_path_append (*e, StringValuePtr (path));
120 static VALUE c_font_path_get (VALUE self)
123 const Evas_List *list, *l;
125 GET_OBJ (self, Evas, e, "Evas");
127 if (!(list = evas_font_path_list (*e)))
128 return rb_ary_new ();
130 ary = rb_ary_new2 (evas_list_count ((Evas_List *) list));
132 for (l = list; l; l = l->next)
133 rb_ary_push (ary, rb_str_new2 (l->data));
138 static VALUE c_font_cache_get (VALUE self)
140 GET_OBJ (self, Evas, e, "Evas");
142 return INT2FIX (evas_font_cache_get (*e));
145 static VALUE c_font_cache_set (VALUE self, VALUE val)
147 GET_OBJ (self, Evas, e, "Evas");
149 Check_Type (val, T_FIXNUM);
151 evas_font_cache_set (*e, FIX2INT (val));
156 static VALUE c_font_cache_flush (VALUE self)
158 GET_OBJ (self, Evas, e, "Evas");
160 evas_font_cache_flush (*e);
165 static VALUE c_image_cache_get (VALUE self)
167 GET_OBJ (self, Evas, e, "Evas");
169 return INT2FIX (evas_image_cache_get (*e));
172 static VALUE c_image_cache_set (VALUE self, VALUE val)
174 GET_OBJ (self, Evas, e, "Evas");
176 Check_Type (val, T_FIXNUM);
178 evas_image_cache_set (*e, FIX2INT (val));
183 static VALUE c_image_cache_reload (VALUE self)
185 GET_OBJ (self, Evas, e, "Evas");
187 evas_image_cache_reload (*e);
192 static VALUE c_image_cache_flush (VALUE self)
194 GET_OBJ (self, Evas, e, "Evas");
196 evas_image_cache_flush (*e);
201 static VALUE c_top_get (VALUE self)
206 GET_OBJ (self, Evas, e, "Evas");
208 if (!(o = evas_object_top_get (*e)))
211 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
212 rb_raise (rb_eException, "EvasObject Ruby object key missing");
219 static VALUE c_bottom_get (VALUE self)
224 GET_OBJ (self, Evas, e, "Evas");
226 if (!(o = evas_object_bottom_get (*e)))
229 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
230 rb_raise (rb_eException, "EvasObject Ruby object key missing");
237 static VALUE c_find_object (VALUE self, VALUE name)
242 GET_OBJ (self, Evas, e, "Evas");
244 Check_Type (name, T_STRING);
246 if (!(o = evas_object_name_find (*e, StringValuePtr (name))))
249 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
250 rb_raise (rb_eException, "EvasObject Ruby object key missing");
257 void Init_Evas (void)
259 cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject);
261 /* not publically instantiable yet */
262 rb_define_private_method (rb_singleton_class (cEvas),
264 rb_define_method (cEvas, "inspect", c_inspect, 0);
265 rb_define_method (cEvas, "render", c_render, 0);
266 rb_define_method (cEvas, "font_path_clear", c_font_path_clear, 0);
267 rb_define_method (cEvas, "font_path_append", c_font_path_append, 1);
268 rb_define_method (cEvas, "font_path_prepend", c_font_path_prepend, 1);
269 rb_define_method (cEvas, "font_path", c_font_path_get, 0);
270 rb_define_method (cEvas, "font_cache", c_font_cache_get, 0);
271 rb_define_method (cEvas, "font_cache=", c_font_cache_set, 1);
272 rb_define_method (cEvas, "font_cache_flush",
273 c_font_cache_flush, 0);
274 rb_define_method (cEvas, "image_cache", c_image_cache_get, 0);
275 rb_define_method (cEvas, "image_cache=", c_image_cache_set, 1);
276 rb_define_method (cEvas, "image_cache_reload",
277 c_image_cache_reload, 0);
278 rb_define_method (cEvas, "image_cache_flush",
279 c_image_cache_flush, 0);
280 rb_define_method (cEvas, "top", c_top_get, 0);
281 rb_define_method (cEvas, "bottom", c_bottom_get, 0);
282 rb_define_method (cEvas, "find_object", c_find_object, 1);
284 parents = rb_hash_new ();
285 rb_global_variable (&parents);