Introduced TO_EVAS_OBJECT.
[ruby-evas.git] / src / rb_evas.c
1 /*
2  * $Id: rb_evas.c 68 2004-08-16 15:42:19Z tilman $
3  *
4  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <ruby.h>
22
23 #include <Evas.h>
24
25 #define __RB_EVAS_C
26 #include "rb_evas_main.h"
27 #include "rb_evas.h"
28 #include "rb_evas_object.h"
29
30 VALUE cEvas;
31
32 static void c_mark (RbEvas *e)
33 {
34         rb_gc_mark (e->parent);
35 }
36
37 VALUE TO_EVAS (VALUE parent, Evas *e)
38 {
39         VALUE self;
40         RbEvas *evas = NULL;
41
42         if (NIL_P (parent) || !e)
43                 return Qnil;
44
45         self = Data_Make_Struct (cEvas, RbEvas,
46                                  c_mark, free, evas);
47         evas->real = e;
48         evas->parent = parent;
49
50         rb_obj_call_init (self, 0, NULL);
51
52         return self;
53 }
54
55 /* :nodoc: */
56 static VALUE c_inspect (VALUE self)
57 {
58         INSPECT (self, RbEvas);
59 }
60
61 /*
62  * call-seq:
63  *  e.render => nil
64  *
65  * Forces a re-render of the Evas.
66  */
67 static VALUE c_render (VALUE self)
68 {
69         GET_OBJ (self, RbEvas, e);
70
71         evas_render (e->real);
72
73         return Qnil;
74 }
75
76 static VALUE c_font_path_clear (VALUE self)
77 {
78         GET_OBJ (self, RbEvas, e);
79
80         evas_font_path_clear (e->real);
81
82         return Qnil;
83 }
84
85 /*
86  * call-seq:
87  *  e.font_path_append(path) => nil
88  *
89  * Appends a path to the font path for <i>e</i>.
90  */
91 static VALUE c_font_path_append (VALUE self, VALUE path)
92 {
93         GET_OBJ (self, RbEvas, e);
94
95         Check_Type (path, T_STRING);
96
97         evas_font_path_append (e->real, StringValuePtr (path));
98
99         return Qnil;
100 }
101
102 /*
103  * call-seq:
104  *  e.font_path_prepend(path) => nil
105  *
106  * Prepends a path to the font path for <i>e</i>.
107  */
108 static VALUE c_font_path_prepend (VALUE self, VALUE path)
109 {
110         GET_OBJ (self, RbEvas, e);
111
112         Check_Type (path, T_STRING);
113
114         evas_font_path_append (e->real, StringValuePtr (path));
115
116         return Qnil;
117 }
118
119 /*
120  * call-seq:
121  *  e.font_path => array
122  *
123  * Returns the font path for <i>e</i>.
124  */
125 static VALUE c_font_path_get (VALUE self)
126 {
127         VALUE ary;
128         const Evas_List *list, *l;
129
130         GET_OBJ (self, RbEvas, e);
131
132         if (!(list = evas_font_path_list (e->real)))
133                 return rb_ary_new ();
134
135         ary = rb_ary_new2 (evas_list_count ((Evas_List *) list));
136
137         for (l = list; l; l = l->next)
138                 rb_ary_push (ary, rb_str_new2 (l->data));
139
140         return ary;
141 }
142 /*
143  * call-seq:
144  *  e.font_cache => fixnum
145  *
146  * Returns the size of the font cache for <i>e</i>.
147  */
148 static VALUE c_font_cache_get (VALUE self)
149  {
150         GET_OBJ (self, RbEvas, e);
151
152         return INT2FIX (evas_font_cache_get (e->real));
153 }
154
155 /*
156  * call-seq:
157  *  e.font_cache(fixnum)
158  *
159  * Sets the size of the font cache for <i>e</i>.
160  */
161 static VALUE c_font_cache_set (VALUE self, VALUE val)
162 {
163         GET_OBJ (self, RbEvas, e);
164
165         Check_Type (val, T_FIXNUM);
166
167         evas_font_cache_set (e->real, FIX2INT (val));
168
169         return Qnil;
170 }
171
172 /*
173  * call-seq:
174  *  e.font_cache_reload => nil
175  *
176  * Flushes the font cache for <i>e</i>.
177  */
178 static VALUE c_font_cache_flush (VALUE self)
179 {
180         GET_OBJ (self, RbEvas, e);
181
182         evas_font_cache_flush (e->real);
183
184         return Qnil;
185 }
186
187 /*
188  * call-seq:
189  *  e.image_cache => fixnum
190  *
191  * Returns the size of the image cache for <i>e</i>.
192  */
193 static VALUE c_image_cache_get (VALUE self)
194 {
195         GET_OBJ (self, RbEvas, e);
196
197         return INT2FIX (evas_image_cache_get (e->real));
198 }
199
200 /*
201  * call-seq:
202  *  e.image_cache(fixnum)
203  *
204  * Sets the size of the image cache for <i>e</i>.
205  */
206 static VALUE c_image_cache_set (VALUE self, VALUE val)
207 {
208         GET_OBJ (self, RbEvas, e);
209
210         Check_Type (val, T_FIXNUM);
211
212         evas_image_cache_set (e->real, FIX2INT (val));
213
214         return Qnil;
215 }
216
217 /*
218  * call-seq:
219  *  e.image_cache_reload => nil
220  *
221  * Flushes the image cache for <i>e</i>.
222  */
223 static VALUE c_image_cache_reload (VALUE self)
224 {
225         GET_OBJ (self, RbEvas, e);
226
227         evas_image_cache_reload (e->real);
228
229         return Qnil;
230 }
231
232 /*
233  * call-seq:
234  *  e.image_cache_flush => nil
235  *
236  * Flushes the image cache for <i>e</i>.
237  */
238 static VALUE c_image_cache_flush (VALUE self)
239 {
240         GET_OBJ (self, RbEvas, e);
241
242         evas_image_cache_flush (e->real);
243
244         return Qnil;
245 }
246
247 /*
248  * call-seq:
249  *  e.top => evasobject
250  *
251  * Returns the <code>Evas::EvasObject</code> at the top of <i>e</i>.
252  */
253 static VALUE c_top_get (VALUE self)
254 {
255         Evas_Object *o;
256
257         GET_OBJ (self, RbEvas, e);
258
259         if (!(o = evas_object_top_get (e->real)))
260                 return Qnil;
261
262         return TO_EVAS_OBJECT (o);
263 }
264
265 /*
266  * call-seq:
267  *  e.bottom => evasobject
268  *
269  * Returns the <code>Evas::EvasObject</code> at the bottom of <i>e</i>.
270  */
271 static VALUE c_bottom_get (VALUE self)
272 {
273         Evas_Object *o;
274
275         GET_OBJ (self, RbEvas, e);
276
277         if (!(o = evas_object_bottom_get (e->real)))
278                 return Qnil;
279
280         return TO_EVAS_OBJECT (o);
281 }
282
283 /*
284  * call-seq:
285  *  e.find_object(name) => evasobject
286  *
287  * Returns the <code>Evas::EvasObject</code> with the name <i>name</i>.
288  */
289 static VALUE c_find_object (VALUE self, VALUE name)
290 {
291         Evas_Object *o;
292
293         GET_OBJ (self, RbEvas, e);
294
295         Check_Type (name, T_STRING);
296
297         if (!(o = evas_object_name_find (e->real, StringValuePtr (name))))
298                 return Qnil;
299
300         return TO_EVAS_OBJECT (o);
301 }
302
303 void Init_Evas (void)
304 {
305         cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject);
306
307         /* not publically instantiable yet */
308         rb_define_private_method (rb_singleton_class (cEvas),
309                                   "new", NULL, 0);
310         rb_define_method (cEvas, "inspect", c_inspect, 0);
311         rb_define_method (cEvas, "render", c_render, 0);
312         rb_define_method (cEvas, "font_path_clear", c_font_path_clear, 0);
313         rb_define_method (cEvas, "font_path_append", c_font_path_append, 1);
314         rb_define_method (cEvas, "font_path_prepend", c_font_path_prepend, 1);
315         rb_define_method (cEvas, "font_path", c_font_path_get, 0);
316         rb_define_method (cEvas, "font_cache", c_font_cache_get, 0);
317         rb_define_method (cEvas, "font_cache=", c_font_cache_set, 1);
318         rb_define_method (cEvas, "font_cache_flush",
319                           c_font_cache_flush, 0);
320         rb_define_method (cEvas, "image_cache", c_image_cache_get, 0);
321         rb_define_method (cEvas, "image_cache=", c_image_cache_set, 1);
322         rb_define_method (cEvas, "image_cache_reload",
323                           c_image_cache_reload, 0);
324         rb_define_method (cEvas, "image_cache_flush",
325                           c_image_cache_flush, 0);
326         rb_define_method (cEvas, "top", c_top_get, 0);
327         rb_define_method (cEvas, "bottom", c_bottom_get, 0);
328         rb_define_method (cEvas, "find_object", c_find_object, 1);
329 }