2 * $Id: rb_image.c 62 2004-08-12 19:35:01Z 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"
29 static void c_free (RbEvasObject *e)
31 c_evas_object_free (e, true);
36 * Evas::Image.new(evas) => img
38 * Creates an Evas::Image object.
40 static VALUE c_new (VALUE klass, VALUE evas)
45 CHECK_CLASS (evas, cEvas);
46 GET_OBJ (evas, RbEvas, e);
48 self = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
50 img->real = evas_object_image_add (e->real);
53 rb_obj_call_init (self, 1, argv);
60 * img.get_file => array
62 * Returns an array containing the filename and the key of <i>img</i>.
64 * img.set_file("foo", "bar") #=> nil
65 * img.get_file #=> ["foo", "bar"]
67 static VALUE c_get_file (VALUE self)
69 char *file = NULL, *key = NULL;
71 GET_OBJ (self, RbEvasObject, e);
73 evas_object_image_file_get (e->real, &file, &key);
75 return rb_ary_new3 (2, file ? rb_str_new2 (file) : Qnil,
76 key ? rb_str_new2 (key) : Qnil);
81 * img.set_file(file [, key]) => nil
83 * Sets the filename and optionally the key of <i>img</i>.
85 * img.set_file("foo.png") #=> nil
86 * img.set_file("foo.edb", "/bar/baz") #=> nil
88 static VALUE c_set_file (int argc, VALUE *argv, VALUE self)
93 GET_OBJ (self, RbEvasObject, e);
95 rb_scan_args (argc, argv, "11", &file, &key);
97 Check_Type (file, T_STRING);
100 Check_Type (key, T_STRING);
101 k = StringValuePtr (key);
104 evas_object_image_file_set (e->real, StringValuePtr (file), k);
111 * img.has_alpha? => true or false
113 * Returns true if <i>img</i> has an alpha channel, else returns false.
115 static VALUE c_has_alpha_get (VALUE self)
117 GET_OBJ (self, RbEvasObject, e);
119 return evas_object_image_alpha_get (e->real) ? Qtrue : Qfalse;
124 * img.has_alpha(true or false)
126 * Sets whether <i>img</i> has an alpha channel.
128 static VALUE c_has_alpha_set (VALUE self, VALUE val)
130 GET_OBJ (self, RbEvasObject, e);
134 evas_object_image_alpha_set (e->real, val == Qtrue);
141 * img.get_size => array
143 * Returns an array containing the size of <i>img</i>.
145 * img.set_size(100, 200) #=> nil
146 * img.get_size #=> [100, 200]
148 static VALUE c_get_size (VALUE self)
152 GET_OBJ (self, RbEvasObject, e);
154 evas_object_image_size_get (e->real, &w, &h);
156 return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
161 * img.set_size(x, y) => nil
163 * Returns an array containing the size of <i>img</i>.
165 * img.set_size(100, 200) #=> nil
166 * img.get_size #=> [100, 200]
168 static VALUE c_set_size (VALUE self, VALUE w, VALUE h)
170 GET_OBJ (self, RbEvasObject, e);
172 Check_Type (w, T_FIXNUM);
173 Check_Type (h, T_FIXNUM);
175 evas_object_image_size_set (e->real, FIX2INT (w), FIX2INT (h));
182 * img.get_fill => array
184 * Returns an array containing the dimensions of the rectangle
185 * on <i>img</i> that the image will be drawn to.
187 * img.set_fill(1, 2, 3, 4) #=> nil
188 * img.get_fill #=> [1, 2, 3, 4]
190 static VALUE c_get_fill (VALUE self)
192 Evas_Coord x = 0, y = 0, w = 0, h = 0;
194 GET_OBJ (self, RbEvasObject, e);
196 evas_object_image_fill_get (e->real, &x, &y, &w, &h);
198 return rb_ary_new3 (4, INT2FIX ((int) x), INT2FIX ((int) y),
199 INT2FIX ((int) w), INT2FIX ((int) h));
204 * img.set_fill(x, y, w, h) => nil
206 * Sets the dimensions of the rectangle on <i>img</i> that
207 * the image will be drawn to.
209 * img.set_fill(1, 2, 3, 4) #=> nil
211 static VALUE c_set_fill (VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
213 GET_OBJ (self, RbEvasObject, e);
215 Check_Type (x, T_FIXNUM);
216 Check_Type (y, T_FIXNUM);
217 Check_Type (w, T_FIXNUM);
218 Check_Type (h, T_FIXNUM);
220 evas_object_image_fill_set (e->real, FIX2INT (x), FIX2INT (y),
221 FIX2INT (w), FIX2INT (h));
230 * Reloads <i>img</i>.
232 static VALUE c_reload (VALUE self)
234 GET_OBJ (self, RbEvasObject, e);
236 evas_object_image_reload (e->real);
241 void Init_Image (void)
243 VALUE c = rb_define_class_under (mEvas, "Image", cEvasObject);
245 rb_define_singleton_method (c, "new", c_new, 1);
246 rb_define_method (c, "get_file", c_get_file, -1);
247 rb_define_method (c, "set_file", c_set_file, -1);
248 rb_define_method (c, "has_alpha?", c_has_alpha_get, 0);
249 rb_define_method (c, "has_alpha=", c_has_alpha_set, 1);
250 rb_define_method (c, "get_size", c_get_size, 0);
251 rb_define_method (c, "set_size", c_set_size, 2);
252 rb_define_method (c, "get_fill", c_get_fill, 0);
253 rb_define_method (c, "set_fill", c_set_fill, 4);
254 rb_define_method (c, "reload", c_reload, 0);