39f1dafa4221e81b53bd49d024ff2fcc78436495
[ruby-evas.git] / src / rb_polygon.c
1 /*
2  * $Id: rb_polygon.c 354 2006-02-10 18:14:08Z tilman $
3  *
4  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <ruby.h>
22
23 #include <Evas.h>
24
25 #include "rb_evas_main.h"
26 #include "rb_evas.h"
27 #include "rb_evas_object.h"
28
29 /*
30  * call-seq:
31  *  Evas::Polygon.new(evas) => polygon
32  *
33  * Creates an new Evas::Polygon object.
34  */
35 static VALUE c_init (VALUE self, VALUE evas)
36 {
37         CHECK_CLASS (evas, cEvas);
38         GET_OBJ (evas, RbEvas, e);
39         GET_OBJ (self, RbEvasObject, poly);
40
41         poly->real = evas_object_polygon_add (e->real);
42
43         rb_call_super (1, &evas);
44
45         return self;
46 }
47
48 /*
49  * call-seq:
50  *  polygon.add_point(x, y) => nil
51  *
52  * Adds a point to <i>polygon</i>.
53  */
54 static VALUE c_add_point (VALUE self, VALUE x, VALUE y)
55 {
56         GET_OBJ (self, RbEvasObject, e);
57
58         Check_Type (x, T_FIXNUM);
59         Check_Type (y, T_FIXNUM);
60
61         evas_object_polygon_point_add (e->real, FIX2INT (x), FIX2INT (y));
62
63         return Qnil;
64 }
65
66 /*
67  * call-seq:
68  *  polygon.clear_points => nil
69  *
70  * Clears the points of <i>polygon</i>.
71  */
72 static VALUE c_clear_points (VALUE self)
73 {
74         GET_OBJ (self, RbEvasObject, e);
75
76         evas_object_polygon_points_clear (e->real);
77
78         return Qnil;
79 }
80
81 void Init_Polygon (void)
82 {
83         VALUE c = rb_define_class_under (mEvas, "Polygon", cEvasObject);
84
85         rb_define_method (c, "initialize", c_init, 1);
86         rb_define_method (c, "add_point", c_add_point, 2);
87         rb_define_method (c, "clear_points", c_clear_points, 0);
88 }