Removed RCS-style IDs.
[ruby-evas.git] / src / rb_image.c
index e88eddcb0f71e87ca8fb7e161f693b53b159bf9b..6efca2853fc81471bc6befeb49532e0b4c241bd4 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: rb_image.c 32 2004-07-10 14:07:49Z tilman $
- *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
  * This library is free software; you can redistribute it and/or
 #include "rb_evas.h"
 #include "rb_evas_object.h"
 
-static VALUE c_new (VALUE klass, VALUE evas)
+/*
+ * call-seq:
+ *  Evas::Image.new(evas) => img
+ *
+ * Creates an Evas::Image object.
+ */
+static VALUE c_init (VALUE self, VALUE evas)
 {
-       VALUE self, argv[1];
-       Evas_Object **rect;
-
        CHECK_CLASS (evas, cEvas);
-       GET_OBJ (evas, Evas, e);
+       GET_OBJ (evas, RbEvas, e);
+       GET_OBJ (self, RbEvasObject, img);
 
-       self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark,
-                                c_evas_object_free, rect);
-       *rect = evas_object_image_add (*e);
+       img->real = evas_object_image_add (e->real);
 
-       argv[0] = evas;
-       rb_obj_call_init (self, 1, argv);
+       rb_call_super (1, &evas);
 
        return self;
 }
 
+/*
+ * call-seq:
+ *  img.get_file => array
+ *
+ * Returns an array containing the filename and the key of <i>img</i>.
+ *
+ *  img.set_file("foo", "bar") #=> nil
+ *  img.get_file               #=> ["foo", "bar"]
+ */
+static VALUE c_get_file (VALUE self)
+{
+       char *file = NULL, *key = NULL;
+
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_file_get (e->real, &file, &key);
+
+       return rb_ary_new3 (2, file ? rb_str_new2 (file) : Qnil,
+                           key ? rb_str_new2 (key) : Qnil);
+}
+
+/*
+ * call-seq:
+ *  img.set_file(file [, key]) => nil
+ *
+ * Sets the filename and optionally the key of <i>img</i>.
+ *
+ *  img.set_file("foo.png")             #=> nil
+ *  img.set_file("foo.edb", "/bar/baz") #=> nil
+ */
+static VALUE c_set_file (int argc, VALUE *argv, VALUE self)
+{
+       VALUE file, key;
+       char *k = NULL;
+
+       GET_OBJ (self, RbEvasObject, e);
+
+       rb_scan_args (argc, argv, "11", &file, &key);
+
+       if (!NIL_P (key))
+               k = StringValuePtr (key);
+
+       evas_object_image_file_set (e->real, StringValuePtr (file), k);
+
+       return Qnil;
+}
+
+/*
+ * call-seq:
+ *  img.has_alpha? => true or false
+ *
+ * Returns true if <i>img</i> has an alpha channel, else returns false.
+ */
+static VALUE c_has_alpha_get (VALUE self)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       return evas_object_image_alpha_get (e->real) ? Qtrue : Qfalse;
+}
+
+/*
+ * call-seq:
+ *  img.has_alpha(true or false)
+ *
+ * Sets whether <i>img</i> has an alpha channel.
+ */
+static VALUE c_has_alpha_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       CHECK_BOOL (val);
+
+       evas_object_image_alpha_set (e->real, val == Qtrue);
+
+       return Qnil;
+}
+
+/*
+ * call-seq:
+ *  img.get_size => array
+ *
+ * Returns an array containing the size of <i>img</i>.
+ *
+ *  img.set_size(100, 200) #=> nil
+ *  img.get_size           #=> [100, 200]
+ */
+static VALUE c_get_size (VALUE self)
+{
+       int w = 0, h = 0;
+
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_size_get (e->real, &w, &h);
+
+       return rb_ary_new3 (2, INT2FIX (w), INT2FIX (h));
+}
+
+/*
+ * call-seq:
+ *  img.set_size(x, y) => nil
+ *
+ * Returns an array containing the size of <i>img</i>.
+ *
+ *  img.set_size(100, 200) #=> nil
+ *  img.get_size           #=> [100, 200]
+ */
+static VALUE c_set_size (VALUE self, VALUE w, VALUE h)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       Check_Type (w, T_FIXNUM);
+       Check_Type (h, T_FIXNUM);
+
+       evas_object_image_size_set (e->real, FIX2INT (w), FIX2INT (h));
+
+       return Qnil;
+}
+
+/*
+ * call-seq:
+ *  img.get_fill => array
+ *
+ * Returns an array containing the dimensions of the rectangle
+ * on <i>img</i> that the image will be drawn to.
+ *
+ *  img.set_fill(1, 2, 3, 4) #=> nil
+ *  img.get_fill             #=> [1, 2, 3, 4]
+ */
+static VALUE c_get_fill (VALUE self)
+{
+       Evas_Coord x = 0, y = 0, w = 0, h = 0;
+
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_fill_get (e->real, &x, &y, &w, &h);
+
+       return rb_ary_new3 (4, INT2FIX ((int) x), INT2FIX ((int) y),
+                           INT2FIX ((int) w), INT2FIX ((int) h));
+}
+
+/*
+ * call-seq:
+ *  img.set_fill(x, y, w, h) => nil
+ *
+ * Sets the dimensions of the rectangle on <i>img</i> that
+ * the image will be drawn to.
+ *
+ *  img.set_fill(1, 2, 3, 4) #=> nil
+ */
+static VALUE c_set_fill (VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       Check_Type (x, T_FIXNUM);
+       Check_Type (y, T_FIXNUM);
+       Check_Type (w, T_FIXNUM);
+       Check_Type (h, T_FIXNUM);
+
+       evas_object_image_fill_set (e->real, FIX2INT (x), FIX2INT (y),
+                                   FIX2INT (w), FIX2INT (h));
+
+       return Qnil;
+}
+
+static VALUE c_get_border (VALUE self)
+{
+       int x = 0, y = 0, w = 0, h = 0;
+
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_border_get (e->real, &x, &y, &w, &h);
+
+       return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
+                           INT2FIX (w), INT2FIX (h));
+}
+
+static VALUE c_set_border (VALUE self, VALUE x, VALUE y, VALUE w, VALUE h)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       Check_Type (x, T_FIXNUM);
+       Check_Type (y, T_FIXNUM);
+       Check_Type (w, T_FIXNUM);
+       Check_Type (h, T_FIXNUM);
+
+       evas_object_image_border_set (e->real, FIX2INT (x), FIX2INT (y),
+                                     FIX2INT (w), FIX2INT (h));
+
+       return Qnil;
+}
+
+/*
+ * call-seq:
+ *  img.reload => nil
+ *
+ * Reloads <i>img</i>.
+ */
+static VALUE c_reload (VALUE self)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_reload (e->real);
+
+       return Qnil;
+}
+
+static VALUE c_data_get (int argc, VALUE *argv, VALUE self)
+{
+       VALUE read_write = Qfalse;
+       void *data;
+       int w = 0, h = 0;
+
+       GET_OBJ (self, RbEvasObject, e);
+
+       rb_scan_args (argc, argv, "01", &read_write);
+
+       if (NIL_P (read_write))
+               read_write = Qfalse;
+
+       data = evas_object_image_data_get (e->real, read_write == Qtrue);
+       evas_object_image_size_get (e->real, &w, &h);
+
+       return rb_str_new (data, h * w * 4);
+}
+
+static VALUE c_data_set (VALUE self, VALUE data)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_data_set (e->real, StringValuePtr (data));
+
+       return Qnil;
+}
+
+static VALUE c_data_update_add (VALUE self, VALUE x, VALUE y,
+                                VALUE w, VALUE h)
+{
+       GET_OBJ (self, RbEvasObject, e);
+
+       evas_object_image_data_update_add (e->real,
+                                          FIX2INT (x), FIX2INT (y),
+                                          FIX2INT (w), FIX2INT (h));
+
+       return Qnil;
+}
+
 void Init_Image (void)
 {
-       VALUE cImage = rb_define_class_under (mEvas, "Image", cEvasObject);
+       VALUE c = rb_define_class_under (mEvas, "Image", cEvasObject);
 
-       rb_define_singleton_method (cImage, "new", c_new, 1);
+       rb_define_method (c, "initialize", c_init, 1);
+       rb_define_method (c, "get_file", c_get_file, -1);
+       rb_define_method (c, "set_file", c_set_file, -1);
+       rb_define_method (c, "has_alpha?", c_has_alpha_get, 0);
+       rb_define_method (c, "has_alpha=", c_has_alpha_set, 1);
+       rb_define_method (c, "get_size", c_get_size, 0);
+       rb_define_method (c, "set_size", c_set_size, 2);
+       rb_define_method (c, "get_fill", c_get_fill, 0);
+       rb_define_method (c, "set_fill", c_set_fill, 4);
+       rb_define_method (c, "get_border", c_get_border, 0);
+       rb_define_method (c, "set_border", c_set_border, 4);
+       rb_define_method (c, "reload", c_reload, 0);
+       rb_define_method (c, "data", c_data_get, -1);
+       rb_define_method (c, "data=", c_data_set, 1);
+       rb_define_method (c, "data_update_add", c_data_update_add, 4);
 }