2 * $Id: rb_evas.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"); \
41 static void c_mark (Evas **e)
45 parent = rb_hash_aref (parents, INT2NUM ((long) (e)));
50 VALUE TO_EVAS (VALUE parent, Evas *e)
55 if (parent == Qnil || !e)
58 self = Data_Make_Struct (cEvas, Evas *,
62 rb_hash_aset (parents, INT2NUM ((long) my_e), parent);
64 rb_obj_call_init (self, 0, NULL);
69 static VALUE c_font_path_clear (VALUE self)
71 GET_OBJ (self, Evas, e, "Evas");
73 evas_font_path_clear (*e);
78 static VALUE c_font_path_append (VALUE self, VALUE path)
80 GET_OBJ (self, Evas, e, "Evas");
82 Check_Type (path, T_STRING);
84 evas_font_path_append (*e, StringValuePtr (path));
89 static VALUE c_font_path_prepend (VALUE self, VALUE path)
91 GET_OBJ (self, Evas, e, "Evas");
93 Check_Type (path, T_STRING);
95 evas_font_path_append (*e, StringValuePtr (path));
100 static VALUE c_font_path_get (VALUE self)
103 const Evas_List *list, *l;
105 GET_OBJ (self, Evas, e, "Evas");
107 if (!(list = evas_font_path_list (*e)))
108 return rb_ary_new ();
110 ary = rb_ary_new2 (evas_list_count ((Evas_List *) list));
112 for (l = list; l; l = l->next)
113 rb_ary_push (ary, rb_str_new2 (l->data));
118 static VALUE c_font_cache_get (VALUE self)
120 GET_OBJ (self, Evas, e, "Evas");
122 return INT2FIX (evas_font_cache_get (*e));
125 static VALUE c_font_cache_set (VALUE self, VALUE val)
127 GET_OBJ (self, Evas, e, "Evas");
129 Check_Type (val, T_FIXNUM);
131 evas_font_cache_set (*e, FIX2INT (val));
136 static VALUE c_font_cache_flush (VALUE self)
138 GET_OBJ (self, Evas, e, "Evas");
140 evas_font_cache_flush (*e);
145 static VALUE c_image_cache_get (VALUE self)
147 GET_OBJ (self, Evas, e, "Evas");
149 return INT2FIX (evas_image_cache_get (*e));
152 static VALUE c_image_cache_set (VALUE self, VALUE val)
154 GET_OBJ (self, Evas, e, "Evas");
156 Check_Type (val, T_FIXNUM);
158 evas_image_cache_set (*e, FIX2INT (val));
163 static VALUE c_image_cache_reload (VALUE self)
165 GET_OBJ (self, Evas, e, "Evas");
167 evas_image_cache_reload (*e);
172 static VALUE c_image_cache_flush (VALUE self)
174 GET_OBJ (self, Evas, e, "Evas");
176 evas_image_cache_flush (*e);
181 static VALUE c_top_get (VALUE self)
186 GET_OBJ (self, Evas, e, "Evas");
188 if (!(o = evas_object_top_get (*e)))
191 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
192 rb_raise (rb_eException, "EvasObject Ruby object key missing");
199 static VALUE c_bottom_get (VALUE self)
204 GET_OBJ (self, Evas, e, "Evas");
206 if (!(o = evas_object_bottom_get (*e)))
209 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
210 rb_raise (rb_eException, "EvasObject Ruby object key missing");
217 static VALUE c_find_object (VALUE self, VALUE name)
222 GET_OBJ (self, Evas, e, "Evas");
224 Check_Type (name, T_STRING);
226 if (!(o = evas_object_name_find (*e, StringValuePtr (name))))
229 if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
230 rb_raise (rb_eException, "EvasObject Ruby object key missing");
237 void Init_Evas (void)
239 cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject);
241 /* not publically instantiable yet */
242 rb_define_private_method (rb_singleton_class (cEvas),
244 rb_define_method (cEvas, "font_path_clear", c_font_path_clear, 0);
245 rb_define_method (cEvas, "font_path_append", c_font_path_append, 1);
246 rb_define_method (cEvas, "font_path_prepend", c_font_path_prepend, 1);
247 rb_define_method (cEvas, "font_path", c_font_path_get, 0);
248 rb_define_method (cEvas, "font_cache", c_font_cache_get, 0);
249 rb_define_method (cEvas, "font_cache=", c_font_cache_set, 1);
250 rb_define_method (cEvas, "font_cache_flush",
251 c_font_cache_flush, 0);
252 rb_define_method (cEvas, "image_cache", c_image_cache_get, 0);
253 rb_define_method (cEvas, "image_cache=", c_image_cache_set, 1);
254 rb_define_method (cEvas, "image_cache_reload",
255 c_image_cache_reload, 0);
256 rb_define_method (cEvas, "image_cache_flush",
257 c_image_cache_flush, 0);
258 rb_define_method (cEvas, "top", c_top_get, 0);
259 rb_define_method (cEvas, "bottom", c_bottom_get, 0);
260 rb_define_method (cEvas, "find_object", c_find_object, 1);
262 parents = rb_hash_new ();
263 rb_global_variable (&parents);