2 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "rb_evas_main.h"
26 #include "rb_evas_object.h"
30 static void c_mark (RbEvas *e)
32 rb_gc_mark (e->parent);
35 static VALUE c_alloc (VALUE klass)
39 return Data_Make_Struct (cEvas, RbEvas, c_mark, free, evas);
42 VALUE TO_EVAS (VALUE parent, Evas *e)
46 if (NIL_P (parent) || !e)
49 self = rb_class_new_instance (0, NULL, cEvas);
51 GET_OBJ (self, RbEvas, evas);
54 evas->parent = parent;
60 static VALUE c_inspect (VALUE self)
62 INSPECT (self, RbEvas);
69 * Forces a re-render of the Evas.
71 static VALUE c_render (VALUE self)
73 GET_OBJ (self, RbEvas, e);
75 evas_render (e->real);
80 static VALUE c_font_path_clear (VALUE self)
82 GET_OBJ (self, RbEvas, e);
84 evas_font_path_clear (e->real);
91 * e.font_path_append(path) => nil
93 * Appends a path to the font path for <i>e</i>.
95 static VALUE c_font_path_append (VALUE self, VALUE path)
97 GET_OBJ (self, RbEvas, e);
99 evas_font_path_append (e->real, StringValuePtr (path));
106 * e.font_path_prepend(path) => nil
108 * Prepends a path to the font path for <i>e</i>.
110 static VALUE c_font_path_prepend (VALUE self, VALUE path)
112 GET_OBJ (self, RbEvas, e);
114 evas_font_path_prepend (e->real, StringValuePtr (path));
121 * e.font_path => array
123 * Returns the font path for <i>e</i>.
125 static VALUE c_font_path_get (VALUE self)
128 const Evas_List *list, *l;
130 GET_OBJ (self, RbEvas, e);
132 if (!(list = evas_font_path_list (e->real)))
133 return rb_ary_new ();
135 ary = rb_ary_new2 (evas_list_count ((Evas_List *) list));
137 for (l = list; l; l = l->next)
138 rb_ary_push (ary, rb_str_new2 (l->data));
144 * e.font_cache => fixnum
146 * Returns the size of the font cache for <i>e</i>.
148 static VALUE c_font_cache_get (VALUE self)
150 GET_OBJ (self, RbEvas, e);
152 return INT2FIX (evas_font_cache_get (e->real));
157 * e.font_cache(fixnum)
159 * Sets the size of the font cache for <i>e</i>.
161 static VALUE c_font_cache_set (VALUE self, VALUE val)
163 GET_OBJ (self, RbEvas, e);
165 Check_Type (val, T_FIXNUM);
167 evas_font_cache_set (e->real, FIX2INT (val));
174 * e.font_cache_reload => nil
176 * Flushes the font cache for <i>e</i>.
178 static VALUE c_font_cache_flush (VALUE self)
180 GET_OBJ (self, RbEvas, e);
182 evas_font_cache_flush (e->real);
189 * e.image_cache => fixnum
191 * Returns the size of the image cache for <i>e</i>.
193 static VALUE c_image_cache_get (VALUE self)
195 GET_OBJ (self, RbEvas, e);
197 return INT2FIX (evas_image_cache_get (e->real));
202 * e.image_cache(fixnum)
204 * Sets the size of the image cache for <i>e</i>.
206 static VALUE c_image_cache_set (VALUE self, VALUE val)
208 GET_OBJ (self, RbEvas, e);
210 Check_Type (val, T_FIXNUM);
212 evas_image_cache_set (e->real, FIX2INT (val));
219 * e.image_cache_reload => nil
221 * Flushes the image cache for <i>e</i>.
223 static VALUE c_image_cache_reload (VALUE self)
225 GET_OBJ (self, RbEvas, e);
227 evas_image_cache_reload (e->real);
234 * e.image_cache_flush => nil
236 * Flushes the image cache for <i>e</i>.
238 static VALUE c_image_cache_flush (VALUE self)
240 GET_OBJ (self, RbEvas, e);
242 evas_image_cache_flush (e->real);
249 * e.top => evasobject
251 * Returns the <code>Evas::EvasObject</code> at the top of <i>e</i>.
253 static VALUE c_top_get (VALUE self)
257 GET_OBJ (self, RbEvas, e);
259 if (!(o = evas_object_top_get (e->real)))
262 return TO_EVAS_OBJECT (o);
267 * e.bottom => evasobject
269 * Returns the <code>Evas::EvasObject</code> at the bottom of <i>e</i>.
271 static VALUE c_bottom_get (VALUE self)
275 GET_OBJ (self, RbEvas, e);
277 if (!(o = evas_object_bottom_get (e->real)))
280 return TO_EVAS_OBJECT (o);
285 * e.find_object(name) => evasobject
287 * Returns the <code>Evas::EvasObject</code> with the name <i>name</i>.
289 static VALUE c_find_object (VALUE self, VALUE name)
293 GET_OBJ (self, RbEvas, e);
295 if (!(o = evas_object_name_find (e->real, StringValuePtr (name))))
298 return TO_EVAS_OBJECT (o);
301 static VALUE c_output_size_get (VALUE self)
305 GET_OBJ (self, RbEvas, e);
307 evas_output_size_get (e->real, &w, &h);
309 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
312 static VALUE c_output_viewport_get (VALUE self)
314 int x = 0, y = 0, w = 0, h = 0;
316 GET_OBJ (self, RbEvas, e);
318 evas_output_viewport_get (e->real,
319 (Evas_Coord *) &x, (Evas_Coord *) &y,
320 (Evas_Coord *) &w, (Evas_Coord *) &h);
322 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
326 void Init_Evas (void)
328 cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject);
330 rb_define_alloc_func (cEvas, c_alloc);
332 /* not publically instantiable yet */
333 rb_define_private_method (rb_singleton_class (cEvas),
335 rb_define_method (cEvas, "inspect", c_inspect, 0);
336 rb_define_method (cEvas, "render", c_render, 0);
337 rb_define_method (cEvas, "font_path_clear", c_font_path_clear, 0);
338 rb_define_method (cEvas, "font_path_append", c_font_path_append, 1);
339 rb_define_method (cEvas, "font_path_prepend", c_font_path_prepend, 1);
340 rb_define_method (cEvas, "font_path", c_font_path_get, 0);
341 rb_define_method (cEvas, "font_cache", c_font_cache_get, 0);
342 rb_define_method (cEvas, "font_cache=", c_font_cache_set, 1);
343 rb_define_method (cEvas, "font_cache_flush",
344 c_font_cache_flush, 0);
345 rb_define_method (cEvas, "image_cache", c_image_cache_get, 0);
346 rb_define_method (cEvas, "image_cache=", c_image_cache_set, 1);
347 rb_define_method (cEvas, "image_cache_reload",
348 c_image_cache_reload, 0);
349 rb_define_method (cEvas, "image_cache_flush",
350 c_image_cache_flush, 0);
351 rb_define_method (cEvas, "top", c_top_get, 0);
352 rb_define_method (cEvas, "bottom", c_bottom_get, 0);
353 rb_define_method (cEvas, "find_object", c_find_object, 1);
354 rb_define_method (cEvas, "output_size", c_output_size_get, 0);
355 rb_define_method (cEvas, "output_viewport", c_output_viewport_get, 0);