[Tomoe-cvs 941] CVS update: tomoe/ext/ruby

Back to archive index

Kouhei Sutou kous****@users*****
2006年 11月 23日 (木) 23:09:36 JST


Index: tomoe/ext/ruby/tomoe-rb-writing.c
diff -u tomoe/ext/ruby/tomoe-rb-writing.c:1.3 tomoe/ext/ruby/tomoe-rb-writing.c:1.4
--- tomoe/ext/ruby/tomoe-rb-writing.c:1.3	Wed Nov 22 18:04:47 2006
+++ tomoe/ext/ruby/tomoe-rb-writing.c	Thu Nov 23 23:09:36 2006
@@ -32,67 +32,51 @@
 }
 
 static VALUE
-tw_get_number_of_points(VALUE self, VALUE stroke)
+tw_remove_last_stroke(VALUE self)
 {
-    return UINT2NUM(tomoe_writing_get_number_of_points(_SELF(self),
-                                                       NUM2UINT(stroke)));
+    tomoe_writing_remove_last_stroke(_SELF(self));
+    return Qnil;
 }
 
 static VALUE
-tw_get_point(VALUE self, VALUE stroke, VALUE point)
+tw_stroke_to_array(GList *stroke)
 {
-    gint x, y;
+    VALUE array;
+    GList *points;
 
-    if (tomoe_writing_get_point(_SELF(self), NUM2UINT(stroke), NUM2UINT(point),
-                              &x, &y)) {
-        return rb_ary_new3(2, INT2NUM(x), INT2NUM(y));
-    } else {
-        return Qnil;
+    array = rb_ary_new();
+    for (points = stroke; points; points = points->next) {
+        TomoePoint *point;
+
+        point = points->data;
+        rb_ary_push(array,
+                    rb_ary_new3(2, INT2NUM(point->x), INT2NUM(point->y)));
     }
+
+    return array;
 }
 
 static VALUE
-tw_get_last_point(VALUE self)
+tw_get_strokes(VALUE self)
 {
-    gint x, y;
+    VALUE array;
+    TomoeWriting *writing;
+    const GList *strokes, *stroke;
 
-    if (tomoe_writing_get_last_point(_SELF(self), &x, &y)) {
-        return rb_ary_new3(2, INT2NUM(x), INT2NUM(y));
-    } else {
-        return Qnil;
+    writing = _SELF(self);
+    strokes = tomoe_writing_get_strokes(writing);
+    array = rb_ary_new();
+    for (stroke = strokes; stroke; stroke = g_list_next(stroke)) {
+        rb_ary_push(array, tw_stroke_to_array(stroke->data));
     }
-}
 
-static VALUE
-tw_remove_last_stroke(VALUE self)
-{
-    tomoe_writing_remove_last_stroke(_SELF(self));
-    return Qnil;
+    return array;
 }
 
 static VALUE
 tw_each(VALUE self)
 {
-    int i, j;
-    guint number_of_strokes, number_of_points;
-    TomoeWriting *writing;
-
-    writing = _SELF(self);
-    number_of_strokes = tomoe_writing_get_number_of_strokes(writing);
-    for (i = 0; i < number_of_strokes; i++) {
-        VALUE points;
-        number_of_points = tomoe_writing_get_number_of_points(writing, i);
-
-        points = rb_ary_new2(number_of_points);
-        for (j = 0; j < number_of_points; j++) {
-            gint x, y;
-            if (tomoe_writing_get_point(writing, i, j, &x, &y))
-                rb_ary_push(points, rb_ary_new3(2, INT2NUM(x), INT2NUM(y)));
-        }
-        rb_yield(points);
-    }
-
-    return Qnil;
+    return rb_ary_each(tw_get_strokes(self));
 }
 
 void
@@ -109,12 +93,9 @@
     rb_define_method(cTomoeWriting, "clear", tw_clear, 0);
     rb_define_method(cTomoeWriting, "number_of_strokes",
                      tw_get_number_of_strokes, 0);
-    rb_define_method(cTomoeWriting, "get_number_of_points",
-                     tw_get_number_of_points, 1);
-    rb_define_method(cTomoeWriting, "[]", tw_get_point, 2);
-    rb_define_method(cTomoeWriting, "last_point", tw_get_last_point, 0);
     rb_define_method(cTomoeWriting, "remove_last_stroke",
                      tw_remove_last_stroke, 0);
 
+    rb_define_method(cTomoeWriting, "strokes", tw_get_strokes, 0);
     rb_define_method(cTomoeWriting, "each", tw_each, 0);
 }


tomoe-cvs メーリングリストの案内
Back to archive index