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
23 #include "rb_evas_main.h"
25 #include "rb_evas_object.h"
29 * Evas::Image.new(evas) => img
31 * Creates an Evas::Image object.
33 static VALUE c_init (VALUE self, VALUE evas)
35 CHECK_CLASS (evas, cEvas);
36 GET_OBJ (evas, RbEvas, e);
37 GET_OBJ (self, RbEvasObject, img);
39 img->real = evas_object_image_add (e->real);
41 rb_call_super (1, &evas);
48 * img.get_file => array
50 * Returns an array containing the filename and the key of <i>img</i>.
52 * img.set_file("foo", "bar") #=> nil
53 * img.get_file #=> ["foo", "bar"]
55 static VALUE c_get_file (VALUE self)
57 char *file = NULL, *key = NULL;
59 GET_OBJ (self, RbEvasObject, e);
61 evas_object_image_file_get (e->real, &file, &key);
63 return rb_ary_new3 (2, file ? rb_str_new2 (file) : Qnil,
64 key ? rb_str_new2 (key) : Qnil);
69 * img.set_file(file [, key]) => nil
71 * Sets the filename and optionally the key of <i>img</i>.
73 * img.set_file("foo.png") #=> nil
74 * img.set_file("foo.edb", "/bar/baz") #=> nil
76 static VALUE c_set_file (int argc, VALUE *argv, VALUE self)
81 GET_OBJ (self, RbEvasObject, e);
83 rb_scan_args (argc, argv, "11", &file, &key);
86 k = StringValuePtr (key);
88 evas_object_image_file_set (e->real, StringValuePtr (file), k);
95 * img.has_alpha? => true or false
97 * Returns true if <i>img</i> has an alpha channel, else returns false.
99 static VALUE c_has_alpha_get (VALUE self)
101 GET_OBJ (self, RbEvasObject, e);
103 return evas_object_image_alpha_get (e->real) ? Qtrue : Qfalse;
108 * img.has_alpha(true or false)
110 * Sets whether <i>img</i> has an alpha channel.
112 static VALUE c_has_alpha_set (VALUE self, VALUE val)
114 GET_OBJ (self, RbEvasObject, e);
118 evas_object_image_alpha_set (e->real, val == Qtrue);
125 * img.get_size => array
127 * Returns an array containing the size of <i>img</i>.
129 * img.set_size(100, 200) #=> nil
130 * img.get_size #=> [100, 200]
132 static VALUE c_get_size (VALUE self)
136 GET_OBJ (self, RbEvasObject, e);
138 evas_object_image_size_get (e->real, &w, &h);
140 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
145 * img.set_size(x, y) => nil
147 * Returns an array containing the size of <i>img</i>.
149 * img.set_size(100, 200) #=> nil
150 * img.get_size #=> [100, 200]
152 static VALUE c_set_size (VALUE self, VALUE w, VALUE h)
154 GET_OBJ (self, RbEvasObject, e);
156 Check_Type (w, T_FIXNUM);
157 Check_Type (h, T_FIXNUM);
159 evas_object_image_size_set (e->real, FIX2INT (w), FIX2INT (h));
166 * img.get_fill => array
168 * Returns an array containing the dimensions of the rectangle
169 * on <i>img</i> that the image will be drawn to.
171 * img.set_fill(1, 2, 3, 4) #=> nil
172 * img.get_fill #=> [1, 2, 3, 4]
174 static VALUE c_get_fill (VALUE self)
176 Evas_Coord x = 0, y = 0, w = 0, h = 0;
178 GET_OBJ (self, RbEvasObject, e);
180 evas_object_image_fill_get (e->real, &x, &y, &w, &h);
182 return rb_ary_new3 (4, INT2FIX ((int) x), INT2FIX ((int) y),
183 INT2FIX ((int) w), INT2FIX ((int) h));
188 * img.set_fill(x, y, w, h) => nil
190 * Sets the dimensions of the rectangle on <i>img</i> that
191 * the image will be drawn to.
193 * img.set_fill(1, 2, 3, 4) #=> nil
195 static VALUE c_set_fill (VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
197 GET_OBJ (self, RbEvasObject, e);
199 Check_Type (x, T_FIXNUM);
200 Check_Type (y, T_FIXNUM);
201 Check_Type (w, T_FIXNUM);
202 Check_Type (h, T_FIXNUM);
204 evas_object_image_fill_set (e->real, FIX2INT (x), FIX2INT (y),
205 FIX2INT (w), FIX2INT (h));
210 static VALUE c_get_border (VALUE self)
212 int x = 0, y = 0, w = 0, h = 0;
214 GET_OBJ (self, RbEvasObject, e);
216 evas_object_image_border_get (e->real, &x, &y, &w, &h);
218 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
219 INT2FIX (w), INT2FIX (h));
222 static VALUE c_set_border (VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
224 GET_OBJ (self, RbEvasObject, e);
226 Check_Type (x, T_FIXNUM);
227 Check_Type (y, T_FIXNUM);
228 Check_Type (w, T_FIXNUM);
229 Check_Type (h, T_FIXNUM);
231 evas_object_image_border_set (e->real, FIX2INT (x), FIX2INT (y),
232 FIX2INT (w), FIX2INT (h));
241 * Reloads <i>img</i>.
243 static VALUE c_reload (VALUE self)
245 GET_OBJ (self, RbEvasObject, e);
247 evas_object_image_reload (e->real);
252 static VALUE c_data_get (int argc, VALUE *argv, VALUE self)
254 VALUE read_write = Qfalse;
258 GET_OBJ (self, RbEvasObject, e);
260 rb_scan_args (argc, argv, "01", &read_write);
262 if (NIL_P (read_write))
265 data = evas_object_image_data_get (e->real, read_write == Qtrue);
266 evas_object_image_size_get (e->real, &w, &h);
268 return rb_str_new (data, h * w * 4);
271 static VALUE c_data_set (VALUE self, VALUE data)
273 GET_OBJ (self, RbEvasObject, e);
275 evas_object_image_data_set (e->real, StringValuePtr (data));
280 static VALUE c_data_update_add (VALUE self, VALUE x, VALUE y,
283 GET_OBJ (self, RbEvasObject, e);
285 evas_object_image_data_update_add (e->real,
286 FIX2INT (x), FIX2INT (y),
287 FIX2INT (w), FIX2INT (h));
292 void Init_Image (void)
294 VALUE c = rb_define_class_under (mEvas, "Image", cEvasObject);
296 rb_define_method (c, "initialize", c_init, 1);
297 rb_define_method (c, "get_file", c_get_file, -1);
298 rb_define_method (c, "set_file", c_set_file, -1);
299 rb_define_method (c, "has_alpha?", c_has_alpha_get, 0);
300 rb_define_method (c, "has_alpha=", c_has_alpha_set, 1);
301 rb_define_method (c, "get_size", c_get_size, 0);
302 rb_define_method (c, "set_size", c_set_size, 2);
303 rb_define_method (c, "get_fill", c_get_fill, 0);
304 rb_define_method (c, "set_fill", c_set_fill, 4);
305 rb_define_method (c, "get_border", c_get_border, 0);
306 rb_define_method (c, "set_border", c_set_border, 4);
307 rb_define_method (c, "reload", c_reload, 0);
308 rb_define_method (c, "data", c_data_get, -1);
309 rb_define_method (c, "data=", c_data_set, 1);
310 rb_define_method (c, "data_update_add", c_data_update_add, 4);