Removed RCS-style IDs.
[ruby-evas.git] / src / rb_evas.c
1 /*
2  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <ruby.h>
20
21 #include <Evas.h>
22
23 #define __RB_EVAS_C
24 #include "rb_evas_main.h"
25 #include "rb_evas.h"
26 #include "rb_evas_object.h"
27
28 VALUE cEvas;
29
30 static void c_mark (RbEvas *e)
31 {
32         rb_gc_mark (e->parent);
33 }
34
35 static VALUE c_alloc (VALUE klass)
36 {
37         RbEvas *evas = NULL;
38
39         return Data_Make_Struct (cEvas, RbEvas, c_mark, free, evas);
40 }
41
42 VALUE TO_EVAS (VALUE parent, Evas *e)
43 {
44         VALUE self;
45
46         if (NIL_P (parent) || !e)
47                 return Qnil;
48
49         self = rb_class_new_instance (0, NULL, cEvas);
50
51         GET_OBJ (self, RbEvas, evas);
52
53         evas->real = e;
54         evas->parent = parent;
55
56         return self;
57 }
58
59 /* :nodoc: */
60 static VALUE c_inspect (VALUE self)
61 {
62         INSPECT (self, RbEvas);
63 }
64
65 /*
66  * call-seq:
67  *  e.render => nil
68  *
69  * Forces a re-render of the Evas.
70  */
71 static VALUE c_render (VALUE self)
72 {
73         GET_OBJ (self, RbEvas, e);
74
75         evas_render (e->real);
76
77         return Qnil;
78 }
79
80 static VALUE c_font_path_clear (VALUE self)
81 {
82         GET_OBJ (self, RbEvas, e);
83
84         evas_font_path_clear (e->real);
85
86         return Qnil;
87 }
88
89 /*
90  * call-seq:
91  *  e.font_path_append(path) => nil
92  *
93  * Appends a path to the font path for <i>e</i>.
94  */
95 static VALUE c_font_path_append (VALUE self, VALUE path)
96 {
97         GET_OBJ (self, RbEvas, e);
98
99         evas_font_path_append (e->real, StringValuePtr (path));
100
101         return Qnil;
102 }
103
104 /*
105  * call-seq:
106  *  e.font_path_prepend(path) => nil
107  *
108  * Prepends a path to the font path for <i>e</i>.
109  */
110 static VALUE c_font_path_prepend (VALUE self, VALUE path)
111 {
112         GET_OBJ (self, RbEvas, e);
113
114         evas_font_path_prepend (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         if (!(o = evas_object_name_find (e->real, StringValuePtr (name))))
296                 return Qnil;
297
298         return TO_EVAS_OBJECT (o);
299 }
300
301 static VALUE c_output_size_get (VALUE self)
302 {
303         int w = 0, h = 0;
304
305         GET_OBJ (self, RbEvas, e);
306
307         evas_output_size_get (e->real, &w, &h);
308
309         return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
310 }
311
312 static VALUE c_output_viewport_get (VALUE self)
313 {
314         int x = 0, y = 0, w = 0, h = 0;
315
316         GET_OBJ (self, RbEvas, e);
317
318         evas_output_viewport_get (e->real,
319                                   (Evas_Coord *) &x, (Evas_Coord *) &y,
320                                   (Evas_Coord *) &w, (Evas_Coord *) &h);
321
322         return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y), INT2FIX (w),
323                             INT2FIX (h));
324 }
325
326 void Init_Evas (void)
327 {
328         cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject);
329
330         rb_define_alloc_func (cEvas, c_alloc);
331
332         /* not publically instantiable yet */
333         rb_define_private_method (rb_singleton_class (cEvas),
334                                   "new", NULL, 0);
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);
356 }