2 * $Id: rb_evas.c 354 2006-02-10 18:14:08Z 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
26 #include "rb_evas_main.h"
28 #include "rb_evas_object.h"
32 static void c_mark (RbEvas *e)
34 rb_gc_mark (e->parent);
37 static VALUE c_alloc (VALUE klass)
41 return Data_Make_Struct (cEvas, RbEvas, c_mark, free, evas);
44 VALUE TO_EVAS (VALUE parent, Evas *e)
48 if (NIL_P (parent) || !e)
51 self = rb_class_new_instance (0, NULL, cEvas);
53 GET_OBJ (self, RbEvas, evas);
56 evas->parent = parent;
62 static VALUE c_inspect (VALUE self)
64 INSPECT (self, RbEvas);
71 * Forces a re-render of the Evas.
73 static VALUE c_render (VALUE self)
75 GET_OBJ (self, RbEvas, e);
77 evas_render (e->real);
82 static VALUE c_font_path_clear (VALUE self)
84 GET_OBJ (self, RbEvas, e);
86 evas_font_path_clear (e->real);
93 * e.font_path_append(path) => nil
95 * Appends a path to the font path for <i>e</i>.
97 static VALUE c_font_path_append (VALUE self, VALUE path)
99 GET_OBJ (self, RbEvas, e);
101 Check_Type (path, T_STRING);
103 evas_font_path_append (e->real, StringValuePtr (path));
110 * e.font_path_prepend(path) => nil
112 * Prepends a path to the font path for <i>e</i>.
114 static VALUE c_font_path_prepend (VALUE self, VALUE path)
116 GET_OBJ (self, RbEvas, e);
118 Check_Type (path, T_STRING);
120 evas_font_path_append (e->real, StringValuePtr (path));
127 * e.font_path => array
129 * Returns the font path for <i>e</i>.
131 static VALUE c_font_path_get (VALUE self)
134 const Evas_List *list, *l;
136 GET_OBJ (self, RbEvas, e);
138 if (!(list = evas_font_path_list (e->real)))
139 return rb_ary_new ();
141 ary = rb_ary_new2 (evas_list_count ((Evas_List *) list));
143 for (l = list; l; l = l->next)
144 rb_ary_push (ary, rb_str_new2 (l->data));
150 * e.font_cache => fixnum
152 * Returns the size of the font cache for <i>e</i>.
154 static VALUE c_font_cache_get (VALUE self)
156 GET_OBJ (self, RbEvas, e);
158 return INT2FIX (evas_font_cache_get (e->real));
163 * e.font_cache(fixnum)
165 * Sets the size of the font cache for <i>e</i>.
167 static VALUE c_font_cache_set (VALUE self, VALUE val)
169 GET_OBJ (self, RbEvas, e);
171 Check_Type (val, T_FIXNUM);
173 evas_font_cache_set (e->real, FIX2INT (val));
180 * e.font_cache_reload => nil
182 * Flushes the font cache for <i>e</i>.
184 static VALUE c_font_cache_flush (VALUE self)
186 GET_OBJ (self, RbEvas, e);
188 evas_font_cache_flush (e->real);
195 * e.image_cache => fixnum
197 * Returns the size of the image cache for <i>e</i>.
199 static VALUE c_image_cache_get (VALUE self)
201 GET_OBJ (self, RbEvas, e);
203 return INT2FIX (evas_image_cache_get (e->real));
208 * e.image_cache(fixnum)
210 * Sets the size of the image cache for <i>e</i>.
212 static VALUE c_image_cache_set (VALUE self, VALUE val)
214 GET_OBJ (self, RbEvas, e);
216 Check_Type (val, T_FIXNUM);
218 evas_image_cache_set (e->real, FIX2INT (val));
225 * e.image_cache_reload => nil
227 * Flushes the image cache for <i>e</i>.
229 static VALUE c_image_cache_reload (VALUE self)
231 GET_OBJ (self, RbEvas, e);
233 evas_image_cache_reload (e->real);
240 * e.image_cache_flush => nil
242 * Flushes the image cache for <i>e</i>.
244 static VALUE c_image_cache_flush (VALUE self)
246 GET_OBJ (self, RbEvas, e);
248 evas_image_cache_flush (e->real);
255 * e.top => evasobject
257 * Returns the <code>Evas::EvasObject</code> at the top of <i>e</i>.
259 static VALUE c_top_get (VALUE self)
263 GET_OBJ (self, RbEvas, e);
265 if (!(o = evas_object_top_get (e->real)))
268 return TO_EVAS_OBJECT (o);
273 * e.bottom => evasobject
275 * Returns the <code>Evas::EvasObject</code> at the bottom of <i>e</i>.
277 static VALUE c_bottom_get (VALUE self)
281 GET_OBJ (self, RbEvas, e);
283 if (!(o = evas_object_bottom_get (e->real)))
286 return TO_EVAS_OBJECT (o);
291 * e.find_object(name) => evasobject
293 * Returns the <code>Evas::EvasObject</code> with the name <i>name</i>.
295 static VALUE c_find_object (VALUE self, VALUE name)
299 GET_OBJ (self, RbEvas, e);
301 Check_Type (name, T_STRING);
303 if (!(o = evas_object_name_find (e->real, StringValuePtr (name))))
306 return TO_EVAS_OBJECT (o);
309 static VALUE c_output_size_get (VALUE self)
313 GET_OBJ (self, RbEvas, e);
315 evas_output_size_get (e->real, &w, &h);
317 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
320 static VALUE c_output_viewport_get (VALUE self)
322 int x = 0, y = 0, w = 0, h = 0;
324 GET_OBJ (self, RbEvas, e);
326 evas_output_viewport_get (e->real,
327 (Evas_Coord *) &x, (Evas_Coord *) &y,
328 (Evas_Coord *) &w, (Evas_Coord *) &h);
330 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
334 void Init_Evas (void)
336 cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject);
338 rb_define_alloc_func (cEvas, c_alloc);
340 /* not publically instantiable yet */
341 rb_define_private_method (rb_singleton_class (cEvas),
343 rb_define_method (cEvas, "inspect", c_inspect, 0);
344 rb_define_method (cEvas, "render", c_render, 0);
345 rb_define_method (cEvas, "font_path_clear", c_font_path_clear, 0);
346 rb_define_method (cEvas, "font_path_append", c_font_path_append, 1);
347 rb_define_method (cEvas, "font_path_prepend", c_font_path_prepend, 1);
348 rb_define_method (cEvas, "font_path", c_font_path_get, 0);
349 rb_define_method (cEvas, "font_cache", c_font_cache_get, 0);
350 rb_define_method (cEvas, "font_cache=", c_font_cache_set, 1);
351 rb_define_method (cEvas, "font_cache_flush",
352 c_font_cache_flush, 0);
353 rb_define_method (cEvas, "image_cache", c_image_cache_get, 0);
354 rb_define_method (cEvas, "image_cache=", c_image_cache_set, 1);
355 rb_define_method (cEvas, "image_cache_reload",
356 c_image_cache_reload, 0);
357 rb_define_method (cEvas, "image_cache_flush",
358 c_image_cache_flush, 0);
359 rb_define_method (cEvas, "top", c_top_get, 0);
360 rb_define_method (cEvas, "bottom", c_bottom_get, 0);
361 rb_define_method (cEvas, "find_object", c_find_object, 1);
362 rb_define_method (cEvas, "output_size", c_output_size_get, 0);
363 rb_define_method (cEvas, "output_viewport", c_output_viewport_get, 0);