2 * $Id: rb_evas.c 382 2006-05-25 09:20:31Z 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 evas_font_path_append (e->real, StringValuePtr (path));
108 * e.font_path_prepend(path) => nil
110 * Prepends a path to the font path for <i>e</i>.
112 static VALUE c_font_path_prepend (VALUE self, VALUE path)
114 GET_OBJ (self, RbEvas, e);
116 evas_font_path_append (e->real, StringValuePtr (path));
123 * e.font_path => array
125 * Returns the font path for <i>e</i>.
127 static VALUE c_font_path_get (VALUE self)
130 const Evas_List *list, *l;
132 GET_OBJ (self, RbEvas, e);
134 if (!(list = evas_font_path_list (e->real)))
135 return rb_ary_new ();
137 ary = rb_ary_new2 (evas_list_count ((Evas_List *) list));
139 for (l = list; l; l = l->next)
140 rb_ary_push (ary, rb_str_new2 (l->data));
146 * e.font_cache => fixnum
148 * Returns the size of the font cache for <i>e</i>.
150 static VALUE c_font_cache_get (VALUE self)
152 GET_OBJ (self, RbEvas, e);
154 return INT2FIX (evas_font_cache_get (e->real));
159 * e.font_cache(fixnum)
161 * Sets the size of the font cache for <i>e</i>.
163 static VALUE c_font_cache_set (VALUE self, VALUE val)
165 GET_OBJ (self, RbEvas, e);
167 Check_Type (val, T_FIXNUM);
169 evas_font_cache_set (e->real, FIX2INT (val));
176 * e.font_cache_reload => nil
178 * Flushes the font cache for <i>e</i>.
180 static VALUE c_font_cache_flush (VALUE self)
182 GET_OBJ (self, RbEvas, e);
184 evas_font_cache_flush (e->real);
191 * e.image_cache => fixnum
193 * Returns the size of the image cache for <i>e</i>.
195 static VALUE c_image_cache_get (VALUE self)
197 GET_OBJ (self, RbEvas, e);
199 return INT2FIX (evas_image_cache_get (e->real));
204 * e.image_cache(fixnum)
206 * Sets the size of the image cache for <i>e</i>.
208 static VALUE c_image_cache_set (VALUE self, VALUE val)
210 GET_OBJ (self, RbEvas, e);
212 Check_Type (val, T_FIXNUM);
214 evas_image_cache_set (e->real, FIX2INT (val));
221 * e.image_cache_reload => nil
223 * Flushes the image cache for <i>e</i>.
225 static VALUE c_image_cache_reload (VALUE self)
227 GET_OBJ (self, RbEvas, e);
229 evas_image_cache_reload (e->real);
236 * e.image_cache_flush => nil
238 * Flushes the image cache for <i>e</i>.
240 static VALUE c_image_cache_flush (VALUE self)
242 GET_OBJ (self, RbEvas, e);
244 evas_image_cache_flush (e->real);
251 * e.top => evasobject
253 * Returns the <code>Evas::EvasObject</code> at the top of <i>e</i>.
255 static VALUE c_top_get (VALUE self)
259 GET_OBJ (self, RbEvas, e);
261 if (!(o = evas_object_top_get (e->real)))
264 return TO_EVAS_OBJECT (o);
269 * e.bottom => evasobject
271 * Returns the <code>Evas::EvasObject</code> at the bottom of <i>e</i>.
273 static VALUE c_bottom_get (VALUE self)
277 GET_OBJ (self, RbEvas, e);
279 if (!(o = evas_object_bottom_get (e->real)))
282 return TO_EVAS_OBJECT (o);
287 * e.find_object(name) => evasobject
289 * Returns the <code>Evas::EvasObject</code> with the name <i>name</i>.
291 static VALUE c_find_object (VALUE self, VALUE name)
295 GET_OBJ (self, RbEvas, e);
297 if (!(o = evas_object_name_find (e->real, StringValuePtr (name))))
300 return TO_EVAS_OBJECT (o);
303 static VALUE c_output_size_get (VALUE self)
307 GET_OBJ (self, RbEvas, e);
309 evas_output_size_get (e->real, &w, &h);
311 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
314 static VALUE c_output_viewport_get (VALUE self)
316 int x = 0, y = 0, w = 0, h = 0;
318 GET_OBJ (self, RbEvas, e);
320 evas_output_viewport_get (e->real,
321 (Evas_Coord *) &x, (Evas_Coord *) &y,
322 (Evas_Coord *) &w, (Evas_Coord *) &h);
324 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
328 void Init_Evas (void)
330 cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject);
332 rb_define_alloc_func (cEvas, c_alloc);
334 /* not publically instantiable yet */
335 rb_define_private_method (rb_singleton_class (cEvas),
337 rb_define_method (cEvas, "inspect", c_inspect, 0);
338 rb_define_method (cEvas, "render", c_render, 0);
339 rb_define_method (cEvas, "font_path_clear", c_font_path_clear, 0);
340 rb_define_method (cEvas, "font_path_append", c_font_path_append, 1);
341 rb_define_method (cEvas, "font_path_prepend", c_font_path_prepend, 1);
342 rb_define_method (cEvas, "font_path", c_font_path_get, 0);
343 rb_define_method (cEvas, "font_cache", c_font_cache_get, 0);
344 rb_define_method (cEvas, "font_cache=", c_font_cache_set, 1);
345 rb_define_method (cEvas, "font_cache_flush",
346 c_font_cache_flush, 0);
347 rb_define_method (cEvas, "image_cache", c_image_cache_get, 0);
348 rb_define_method (cEvas, "image_cache=", c_image_cache_set, 1);
349 rb_define_method (cEvas, "image_cache_reload",
350 c_image_cache_reload, 0);
351 rb_define_method (cEvas, "image_cache_flush",
352 c_image_cache_flush, 0);
353 rb_define_method (cEvas, "top", c_top_get, 0);
354 rb_define_method (cEvas, "bottom", c_bottom_get, 0);
355 rb_define_method (cEvas, "find_object", c_find_object, 1);
356 rb_define_method (cEvas, "output_size", c_output_size_get, 0);
357 rb_define_method (cEvas, "output_viewport", c_output_viewport_get, 0);