Fixed the build with the latest Ecore snapshot.
[ruby-ecore.git] / src / ecore_evas / rb_buffer.c
1 /*
2  * Copyright (C) 2004-2005 ruby-ecore team (see AUTHORS)
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 <Ecore.h>
22 #include <Ecore_Evas.h>
23
24 #include "../ecore/rb_ecore.h"
25 #include "rb_ecore_evas_main.h"
26 #include "rb_ecore_evas.h"
27
28 static void c_free (RbEcoreEvas *ee)
29 {
30         c_ecore_evas_free (ee, true);
31 }
32
33 static VALUE c_alloc (VALUE klass)
34 {
35         RbEcoreEvas *ee = NULL;
36
37         ecore_init ();
38         ecore_evas_init ();
39
40         return Data_Make_Struct (klass, RbEcoreEvas,
41                                  c_ecore_evas_mark, c_free, ee);
42 }
43
44 /*
45  * call-seq:
46  *  Ecore::Evas::Buffer.new([w, h]) => buffer
47  *
48  * Creates an Ecore::Evas::Buffer object.
49  */
50 static VALUE c_init (int argc, VALUE *argv, VALUE self)
51 {
52         VALUE w, h;
53         int iw = 0, ih = 0;
54
55         GET_OBJ (self, RbEcoreEvas, ee);
56
57         rb_scan_args (argc, argv, "02", &w, &h);
58
59         if (!NIL_P (w)) {
60                 Check_Type (w, T_FIXNUM);
61                 iw = FIX2INT (w);
62         }
63
64         if (!NIL_P (h)) {
65                 Check_Type (h, T_FIXNUM);
66                 ih = FIX2INT (h);
67         }
68
69         ee->real = ecore_evas_buffer_new (iw, ih);
70
71         rb_call_super (argc, argv);
72
73         return self;
74 }
75
76 static VALUE c_pixels_get (VALUE self)
77 {
78         const int *p;
79         int w = 0, h = 0;
80
81         GET_OBJ (self, RbEcoreEvas, ee);
82
83         p = ecore_evas_buffer_pixels_get (ee->real);
84         if (!p)
85                 return rb_str_new2 (""); /* FIXME raise an error instead? */
86
87         ecore_evas_geometry_get (ee->real, NULL, NULL, &w, &h);
88
89         return rb_str_new ((char *) p, h * w * 4);
90 }
91
92 void Init_Buffer (void)
93 {
94         VALUE c = rb_define_class_under (mEvas, "Buffer", cEcoreEvas);
95
96         rb_define_alloc_func (c, c_alloc);
97         rb_define_method (c, "initialize", c_init, -1);
98         rb_define_method (c, "pixels", c_pixels_get, 0);
99 }