Use RDoc for README.
[ruby-edje.git] / src / rb_part.c
index 563be555b6430020945c92e24248e5d9ad7b6959..533b1638a40bdaea3c6f5ce8ffb6b5ea668c76b1 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: rb_part.c 51 2004-08-01 10:19:02Z tilman $
- *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
  * This library is free software; you can redistribute it and/or
@@ -67,7 +65,13 @@ VALUE TO_PART (VALUE edje, VALUE name)
        return self;
 }
 
-static VALUE c_get_geometry (VALUE self)
+/*
+ * call-seq:
+ *  part.geometry => array
+ *
+ * Returns an array containing the geometry of <i>part</i>.
+ */
+static VALUE c_geometry_get (VALUE self)
 {
        int x = 0, y = 0, w = 0, h = 0;
 
@@ -80,9 +84,15 @@ static VALUE c_get_geometry (VALUE self)
                                       (Evas_Coord *) &h);
 
        return rb_ary_new3 (4, INT2FIX (x), INT2FIX (y),
-                           INT2FIX (y), INT2FIX (h));
+                           INT2FIX (w), INT2FIX (h));
 }
 
+/*
+ * call-seq:
+ *  part.swallow(evasobject) => nil
+ *
+ * Swallows an <code>Evas::EvasObject</code> into <i>part</i>.
+ */
 static VALUE c_swallow (VALUE self, VALUE target)
 {
        GET_OBJ (GET_EDJE (self), RbEdje, e);
@@ -91,10 +101,18 @@ static VALUE c_swallow (VALUE self, VALUE target)
        GET_OBJ (target, RbEvasObject, t);
 
        edje_object_part_swallow (e->real.real, GET_NAME (self), t->real);
+       rb_iv_set (self, "swallowed_obj", target);
 
        return Qnil;
 }
 
+/*
+ * call-seq:
+ *  part.unswallow => nil
+ *
+ * Unswallows the <code>Evas::EvasObject</code> swallowed by
+ * <i>part</i>.
+ */
 static VALUE c_unswallow (VALUE self)
 {
        Evas_Object *o;
@@ -108,14 +126,22 @@ static VALUE c_unswallow (VALUE self)
        }
 
        edje_object_part_unswallow (e->real.real, o);
+       rb_iv_set (self, "swallowed_obj", Qnil);
 
        return Qnil;
 }
 
+/*
+ * call-seq:
+ *  part.swallowed_object => evasobject or nil
+ *
+ * Returns the <code>Evas::EvasObject</code> swallowed by
+ * <i>part</i> or nil if <i>part</i> didn't swallow an
+ * <code>Evas::EvasObject</code>.
+ */
 static VALUE c_swallowed_object_get (VALUE self)
 {
        Evas_Object *o;
-       void *obj;
 
        GET_OBJ (GET_EDJE (self), RbEdje, e);
 
@@ -123,14 +149,15 @@ static VALUE c_swallowed_object_get (VALUE self)
        if (!o)
                return Qnil;
 
-       if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
-               rb_raise (rb_eException, "EvasObject Ruby object key missing");
-               return Qnil;
-       }
-
-       return (VALUE) obj;
+       return TO_EVAS_OBJECT (o);
 }
 
+/*
+ * call-seq:
+ *  part.text => string
+ *
+ * Returns the text of <i>part</i>.
+ */
 static VALUE c_text_get (VALUE self)
 {
        const char *s;
@@ -142,6 +169,12 @@ static VALUE c_text_get (VALUE self)
        return s ? rb_str_new2 (s) : Qnil;
 }
 
+/*
+ * call-seq:
+ *  part.text(string)
+ *
+ * Sets the text of <i>part</i>.
+ */
 static VALUE c_text_set (VALUE self, VALUE text)
 {
        GET_OBJ (GET_EDJE (self), RbEdje, e);
@@ -154,6 +187,15 @@ static VALUE c_text_set (VALUE self, VALUE text)
        return Qnil;
 }
 
+/*
+ * call-seq:
+ *  part.get_drag_value => array
+ *
+ * Returns the drag value of <i>part</i>.
+ *
+ *  part.set_drag_value(1.5, 2.5) #=> nil
+ *  part.get_drag_value           #=> [1.5, 2.5]
+ */
 static VALUE c_get_drag_value (VALUE self)
 {
        double dx = 0, dy = 0;
@@ -165,6 +207,14 @@ static VALUE c_get_drag_value (VALUE self)
        return rb_ary_new3 (2, rb_float_new (dx), rb_float_new (dy));
 }
 
+/*
+ * call-seq:
+ *  part.set_drag_value(dx, dy) => nil
+ *
+ * Sets the drag value of <i>part</i>.
+ *
+ *  part.set_drag_value(1.5, 2.5) #=> nil
+ */
 static VALUE c_set_drag_value (VALUE self, VALUE dx, VALUE dy)
 {
        GET_OBJ (GET_EDJE (self), RbEdje, e);
@@ -181,6 +231,19 @@ static VALUE c_set_drag_value (VALUE self, VALUE dx, VALUE dy)
        return Qnil;
 }
 
+static VALUE c_state_get (VALUE self)
+{
+       const char *name;
+       double val = 0.0;
+
+       GET_OBJ (GET_EDJE (self), RbEdje, e);
+
+       name = edje_object_part_state_get (e->real.real,
+                                          GET_NAME (self), &val);
+
+       return rb_ary_new3 (2, rb_str_new2 (name), rb_float_new (val));
+}
+
 void Init_Part (void)
 {
        cPart = rb_define_class_under (mEdje, "Part", rb_cObject);
@@ -191,13 +254,14 @@ void Init_Part (void)
        /* not publically instantiable yet */
        rb_define_private_method (rb_singleton_class (cPart),
                                  "new", NULL, 0);
-       rb_define_method (cPart, "get_geometry", c_get_geometry, 0);
+       rb_define_method (cPart, "geometry", c_geometry_get, 0);
        rb_define_method (cPart, "swallow", c_swallow, 1);
        rb_define_method (cPart, "unswallow", c_unswallow, 1);
        rb_define_method (cPart, "swallowed_object",
                          c_swallowed_object_get, 0);
        rb_define_method (cPart, "text", c_text_get, 0);
        rb_define_method (cPart, "text=", c_text_set, 1);
-       rb_define_method (cPart, "get_drag_value", c_get_drag_value, 2);
+       rb_define_method (cPart, "get_drag_value", c_get_drag_value, 0);
        rb_define_method (cPart, "set_drag_value", c_set_drag_value, 2);
+       rb_define_method (cPart, "state", c_state_get, 0);
 }