Added more Evas objects.
[ruby-evas.git] / src / rb_line.c
diff --git a/src/rb_line.c b/src/rb_line.c
new file mode 100644 (file)
index 0000000..e75f2bc
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * $Id: rb_line.c 23 2004-06-26 22:55:31Z tilman $
+ *
+ * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <ruby.h>
+
+#include <Evas.h>
+
+#include "rb_evas_main.h"
+#include "rb_evas.h"
+#include "rb_evas_object.h"
+
+static VALUE c_new (VALUE klass, VALUE evas)
+{
+       VALUE self, argv[1];
+       Evas_Object **rect;
+
+       if (!rb_obj_is_kind_of (evas, cEvas)) {
+               rb_raise (rb_eTypeError,
+                         "wrong argument type %s (expected Evas)",
+                         rb_obj_classname (evas));
+               return Qnil;
+       }
+
+       GET_OBJ (evas, Evas, e, "Evas");
+
+       self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark,
+                                c_evas_object_free, rect);
+       *rect = evas_object_line_add (*e);
+
+       argv[0] = evas;
+       rb_obj_call_init (self, 1, argv);
+
+       return self;
+}
+
+static VALUE c_get_xy (VALUE self)
+{
+       int coord[4] = {0, 0, 0, 0};
+
+       GET_OBJ (self, Evas_Object, e, "Line");
+
+       evas_object_line_xy_get (*e, &coord[0], &coord[1],
+                                &coord[2], &coord[3]);
+
+       return rb_ary_new3 (4, INT2FIX (coord[0]), INT2FIX (coord[1]),
+                           INT2FIX (coord[2]), INT2FIX (coord[3]));
+}
+
+static VALUE c_set_xy (VALUE self, VALUE x1, VALUE y1,
+                       VALUE x2, VALUE y2)
+{
+       GET_OBJ (self, Evas_Object, e, "Line");
+
+       Check_Type (x1, T_FIXNUM);
+       Check_Type (y1, T_FIXNUM);
+       Check_Type (x2, T_FIXNUM);
+       Check_Type (y2, T_FIXNUM);
+
+       evas_object_line_xy_set (*e, FIX2INT (x1), FIX2INT (y1),
+                                FIX2INT (x2), FIX2INT (y2));
+
+       return Qnil;
+}
+
+void Init_Line (void)
+{
+       VALUE cLine = rb_define_class_under (mEvas, "Line", cEvasObject);
+
+       rb_define_singleton_method (cLine, "new", c_new, 1);
+       rb_define_method (cLine, "get_xy", c_get_xy, 0);
+       rb_define_method (cLine, "set_xy", c_set_xy, 4);
+}