Implemented some functions of the new Evas::Gradient API.
[ruby-evas.git] / src / rb_gradient.c
1 /*
2  * Copyright (C) 2004-2007 Tilman Sauerbeck (tilman at code-monkey de)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include <ruby.h>
20
21 #include <Evas.h>
22
23 #include "rb_evas_main.h"
24 #include "rb_evas.h"
25 #include "rb_evas_object.h"
26
27 /*
28  * call-seq:
29  *  Evas::Gradient.new(evas) => gradient
30  *
31  * Creates an Evas::Gradient object.
32  */
33 static VALUE c_init (VALUE self, VALUE evas)
34 {
35         CHECK_CLASS (evas, cEvas);
36         GET_OBJ (evas, RbEvas, e);
37         GET_OBJ (self, RbEvasObject, grad);
38
39         grad->real = evas_object_gradient_add (e->real);
40
41         rb_call_super (1, &evas);
42
43         return self;
44 }
45
46 /*
47  * call-seq:
48  *  gradient.add_color(r, g, b, a, distance) => nil
49  *
50  * Adds a color to <i>gradient</i>.
51  */
52 static VALUE c_add_color (VALUE self, VALUE r, VALUE g, VALUE b,
53                           VALUE a, VALUE distance)
54 {
55         GET_OBJ (self, RbEvasObject, e);
56
57         Check_Type (r, T_FIXNUM);
58         Check_Type (g, T_FIXNUM);
59         Check_Type (b, T_FIXNUM);
60         Check_Type (a, T_FIXNUM);
61         Check_Type (distance, T_FIXNUM);
62
63         evas_object_gradient_color_stop_add (e->real, FIX2INT (r),
64                                              FIX2INT (g), FIX2INT (b),
65                                              FIX2INT (a), FIX2INT (distance));
66
67         return Qnil;
68 }
69
70 static VALUE c_add_alpha (VALUE self, VALUE a, VALUE distance)
71 {
72         GET_OBJ (self, RbEvasObject, e);
73
74         Check_Type (a, T_FIXNUM);
75         Check_Type (distance, T_FIXNUM);
76
77         evas_object_gradient_alpha_stop_add (e->real, FIX2INT (a),
78                                              FIX2INT (distance));
79
80         return Qnil;
81 }
82
83 /*
84  * call-seq:
85  *  gradient.clear => nil
86  *
87  * Clears <i>gradient</i>.
88  */
89 static VALUE c_clear (VALUE self)
90 {
91         GET_OBJ (self, RbEvasObject, e);
92
93         evas_object_gradient_clear (e->real);
94
95         return Qnil;
96 }
97
98 /*
99  * call-seq:
100  *  gradient.angle => fixnum
101  *
102  * Returns the angle of <i>gradient</i>.
103  */
104 static VALUE c_angle_get (VALUE self)
105 {
106         GET_OBJ (self, RbEvasObject, e);
107
108         return INT2FIX (evas_object_gradient_angle_get (e->real));
109 }
110
111 /*
112  * call-seq:
113  *  gradient.angle(fixnum)
114  *
115  * Sets the angle of <i>gradient</i>.
116  */
117 static VALUE c_angle_set (VALUE self, VALUE val)
118 {
119         GET_OBJ (self, RbEvasObject, e);
120
121         Check_Type (val, T_FIXNUM);
122
123         evas_object_gradient_angle_set (e->real, FIX2INT (val));
124
125         return Qnil;
126 }
127
128 static VALUE
129 c_direction_get (VALUE self)
130 {
131         GET_OBJ (self, RbEvasObject, e);
132
133         return INT2FIX (evas_object_gradient_direction_get (e->real));
134 }
135
136 static VALUE
137 c_direction_set (VALUE self, VALUE val)
138 {
139         GET_OBJ (self, RbEvasObject, e);
140
141         Check_Type (val, T_FIXNUM);
142
143         evas_object_gradient_direction_set (e->real, FIX2INT (val));
144
145         return Qnil;
146 }
147
148 static VALUE
149 c_offset_get (VALUE self)
150 {
151         GET_OBJ (self, RbEvasObject, e);
152
153         return rb_float_new (evas_object_gradient_offset_get (e->real));
154 }
155
156 static VALUE
157 c_offset_set (VALUE self, VALUE val)
158 {
159         GET_OBJ (self, RbEvasObject, e);
160
161         Check_Type (val, T_FLOAT);
162
163         evas_object_gradient_offset_set (e->real, NUM2DBL (val));
164
165         return Qnil;
166 }
167
168 void Init_Gradient (void)
169 {
170         VALUE c = rb_define_class_under (mEvas, "Gradient", cEvasObject);
171
172         rb_define_method (c, "initialize", c_init, 1);
173         rb_define_method (c, "add_color", c_add_color, 5);
174         rb_define_method (c, "add_alpha", c_add_alpha, 2);
175         rb_define_method (c, "clear", c_clear, 0);
176         rb_define_method (c, "angle", c_angle_get, 0);
177         rb_define_method (c, "angle=", c_angle_set, 1);
178         rb_define_method (c, "direction", c_direction_get, 0);
179         rb_define_method (c, "direction=", c_direction_set, 1);
180         rb_define_method (c, "offset", c_offset_get, 0);
181         rb_define_method (c, "offset=", c_offset_set, 1);
182 }