2 * $Id: rb_image.c 354 2006-02-10 18:14:08Z tilman $
4 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
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.
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.
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
25 #include "rb_evas_main.h"
27 #include "rb_evas_object.h"
31 * Evas::Image.new(evas) => img
33 * Creates an Evas::Image object.
35 static VALUE c_init (VALUE self, VALUE evas)
37 CHECK_CLASS (evas, cEvas);
38 GET_OBJ (evas, RbEvas, e);
39 GET_OBJ (self, RbEvasObject, img);
41 img->real = evas_object_image_add (e->real);
43 rb_call_super (1, &evas);
50 * img.get_file => array
52 * Returns an array containing the filename and the key of <i>img</i>.
54 * img.set_file("foo", "bar") #=> nil
55 * img.get_file #=> ["foo", "bar"]
57 static VALUE c_get_file (VALUE self)
59 char *file = NULL, *key = NULL;
61 GET_OBJ (self, RbEvasObject, e);
63 evas_object_image_file_get (e->real, &file, &key);
65 return rb_ary_new3 (2, file ? rb_str_new2 (file) : Qnil,
66 key ? rb_str_new2 (key) : Qnil);
71 * img.set_file(file [, key]) => nil
73 * Sets the filename and optionally the key of <i>img</i>.
75 * img.set_file("foo.png") #=> nil
76 * img.set_file("foo.edb", "/bar/baz") #=> nil
78 static VALUE c_set_file (int argc, VALUE *argv, VALUE self)
83 GET_OBJ (self, RbEvasObject, e);
85 rb_scan_args (argc, argv, "11", &file, &key);
87 Check_Type (file, T_STRING);
90 Check_Type (key, T_STRING);
91 k = StringValuePtr (key);
94 evas_object_image_file_set (e->real, StringValuePtr (file), k);
101 * img.has_alpha? => true or false
103 * Returns true if <i>img</i> has an alpha channel, else returns false.
105 static VALUE c_has_alpha_get (VALUE self)
107 GET_OBJ (self, RbEvasObject, e);
109 return evas_object_image_alpha_get (e->real) ? Qtrue : Qfalse;
114 * img.has_alpha(true or false)
116 * Sets whether <i>img</i> has an alpha channel.
118 static VALUE c_has_alpha_set (VALUE self, VALUE val)
120 GET_OBJ (self, RbEvasObject, e);
124 evas_object_image_alpha_set (e->real, val == Qtrue);
131 * img.get_size => array
133 * Returns an array containing the size of <i>img</i>.
135 * img.set_size(100, 200) #=> nil
136 * img.get_size #=> [100, 200]
138 static VALUE c_get_size (VALUE self)
142 GET_OBJ (self, RbEvasObject, e);
144 evas_object_image_size_get (e->real, &w, &h);
146 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
151 * img.set_size(x, y) => nil
153 * Returns an array containing the size of <i>img</i>.
155 * img.set_size(100, 200) #=> nil
156 * img.get_size #=> [100, 200]
158 static VALUE c_set_size (VALUE self, VALUE w, VALUE h)
160 GET_OBJ (self, RbEvasObject, e);
162 Check_Type (w, T_FIXNUM);
163 Check_Type (h, T_FIXNUM);
165 evas_object_image_size_set (e->real, FIX2INT (w), FIX2INT (h));
172 * img.get_fill => array
174 * Returns an array containing the dimensions of the rectangle
175 * on <i>img</i> that the image will be drawn to.
177 * img.set_fill(1, 2, 3, 4) #=> nil
178 * img.get_fill #=> [1, 2, 3, 4]
180 static VALUE c_get_fill (VALUE self)
182 Evas_Coord x = 0, y = 0, w = 0, h = 0;
184 GET_OBJ (self, RbEvasObject, e);
186 evas_object_image_fill_get (e->real, &x, &y, &w, &h);
188 return rb_ary_new3 (4, INT2FIX ((int) x), INT2FIX ((int) y),
189 INT2FIX ((int) w), INT2FIX ((int) h));
194 * img.set_fill(x, y, w, h) => nil
196 * Sets the dimensions of the rectangle on <i>img</i> that
197 * the image will be drawn to.
199 * img.set_fill(1, 2, 3, 4) #=> nil
201 static VALUE c_set_fill (VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
203 GET_OBJ (self, RbEvasObject, e);
205 Check_Type (x, T_FIXNUM);
206 Check_Type (y, T_FIXNUM);
207 Check_Type (w, T_FIXNUM);
208 Check_Type (h, T_FIXNUM);
210 evas_object_image_fill_set (e->real, FIX2INT (x), FIX2INT (y),
211 FIX2INT (w), FIX2INT (h));
216 static VALUE c_get_border (VALUE self)
218 int x = 0, y = 0, w = 0, h = 0;
220 GET_OBJ (self, RbEvasObject, e);
222 evas_object_image_border_get (e->real, &x, &y, &w, &h);
224 return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
225 INT2FIX (w), INT2FIX (h));
228 static VALUE c_set_border (VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
230 GET_OBJ (self, RbEvasObject, e);
232 Check_Type (x, T_FIXNUM);
233 Check_Type (y, T_FIXNUM);
234 Check_Type (w, T_FIXNUM);
235 Check_Type (h, T_FIXNUM);
237 evas_object_image_border_set (e->real, FIX2INT (x), FIX2INT (y),
238 FIX2INT (w), FIX2INT (h));
247 * Reloads <i>img</i>.
249 static VALUE c_reload (VALUE self)
251 GET_OBJ (self, RbEvasObject, e);
253 evas_object_image_reload (e->real);
258 void Init_Image (void)
260 VALUE c = rb_define_class_under (mEvas, "Image", cEvasObject);
262 rb_define_method (c, "initialize", c_init, 1);
263 rb_define_method (c, "get_file", c_get_file, -1);
264 rb_define_method (c, "set_file", c_set_file, -1);
265 rb_define_method (c, "has_alpha?", c_has_alpha_get, 0);
266 rb_define_method (c, "has_alpha=", c_has_alpha_set, 1);
267 rb_define_method (c, "get_size", c_get_size, 0);
268 rb_define_method (c, "set_size", c_set_size, 2);
269 rb_define_method (c, "get_fill", c_get_fill, 0);
270 rb_define_method (c, "set_fill", c_set_fill, 4);
271 rb_define_method (c, "get_border", c_get_border, 0);
272 rb_define_method (c, "set_border", c_set_border, 4);
273 rb_define_method (c, "reload", c_reload, 0);