"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-path.c
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2010 Intel Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see
20  * <http://www.gnu.org/licenses/>.
21  *
22  * Authors:
23  *  Robert Bragg <robert@linux.intel.com>
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "cogl-util.h"
31 #include "cogl-internal.h"
32 #include "cogl-context-private.h"
33 #include "cogl2-path.h"
34
35 #include <string.h>
36 #include <math.h>
37
38 #undef cogl_path_set_fill_rule
39 #undef cogl_path_get_fill_rule
40 #undef cogl_path_fill
41 #undef cogl_path_fill_preserve
42 #undef cogl_path_stroke
43 #undef cogl_path_stroke_preserve
44 #undef cogl_path_move_to
45 #undef cogl_path_rel_move_to
46 #undef cogl_path_line_to
47 #undef cogl_path_rel_line_to
48 #undef cogl_path_close
49 #undef cogl_path_new
50 #undef cogl_path_line
51 #undef cogl_path_polyline
52 #undef cogl_path_polygon
53 #undef cogl_path_rectangle
54 #undef cogl_path_arc
55 #undef cogl_path_ellipse
56 #undef cogl_path_round_rectangle
57 #undef cogl_path_curve_to
58 #undef cogl_path_rel_curve_to
59
60 #include "cogl-path-functions.h"
61
62 void
63 cogl_path_set_fill_rule (CoglPathFillRule fill_rule)
64 {
65   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
66
67   cogl2_path_set_fill_rule (ctx->current_path, fill_rule);
68 }
69
70 CoglPathFillRule
71 cogl_path_get_fill_rule (void)
72 {
73   _COGL_GET_CONTEXT (ctx, COGL_PATH_FILL_RULE_EVEN_ODD);
74
75   return cogl2_path_get_fill_rule (ctx->current_path);
76 }
77
78 void
79 cogl_path_fill (void)
80 {
81   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
82
83   cogl2_path_fill (ctx->current_path);
84
85   cogl_object_unref (ctx->current_path);
86   ctx->current_path = cogl2_path_new ();
87 }
88
89 void
90 cogl_path_fill_preserve (void)
91 {
92   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
93
94   cogl2_path_fill (ctx->current_path);
95 }
96
97 void
98 cogl_path_stroke (void)
99 {
100   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
101
102   cogl2_path_stroke (ctx->current_path);
103
104   cogl_object_unref (ctx->current_path);
105   ctx->current_path = cogl2_path_new ();
106 }
107
108 void
109 cogl_path_stroke_preserve (void)
110 {
111   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
112
113   cogl2_path_stroke (ctx->current_path);
114 }
115
116 void
117 cogl_path_move_to (float x,
118                    float y)
119 {
120   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
121
122   cogl2_path_move_to (ctx->current_path, x, y);
123 }
124
125 void
126 cogl_path_rel_move_to (float x,
127                        float y)
128 {
129   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
130
131   cogl2_path_rel_move_to (ctx->current_path, x, y);
132 }
133
134 void
135 cogl_path_line_to (float x,
136                    float y)
137 {
138   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
139
140   cogl2_path_line_to (ctx->current_path, x, y);
141 }
142
143 void
144 cogl_path_rel_line_to (float x,
145                        float y)
146 {
147   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
148
149   cogl2_path_rel_line_to (ctx->current_path, x, y);
150 }
151
152 void
153 cogl_path_close (void)
154 {
155   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
156
157   cogl2_path_close (ctx->current_path);
158 }
159
160 void
161 cogl_path_new (void)
162 {
163   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
164
165   cogl_object_unref (ctx->current_path);
166   ctx->current_path = cogl2_path_new ();
167 }
168
169 void
170 cogl_path_line (float x_1,
171                 float y_1,
172                 float x_2,
173                 float y_2)
174 {
175   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
176
177   cogl2_path_line (ctx->current_path, x_1, y_1, x_2, y_2);
178 }
179
180 void
181 cogl_path_polyline (const float *coords,
182                     int num_points)
183 {
184   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
185
186   cogl2_path_polyline (ctx->current_path, coords, num_points);
187 }
188
189 void
190 cogl_path_polygon (const float *coords,
191                    int num_points)
192 {
193   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
194
195   cogl2_path_polygon (ctx->current_path, coords, num_points);
196 }
197
198 void
199 cogl_path_rectangle (float x_1,
200                      float y_1,
201                      float x_2,
202                      float y_2)
203 {
204   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
205
206   cogl2_path_rectangle (ctx->current_path, x_1, y_1, x_2, y_2);
207 }
208
209 void
210 cogl_path_arc (float center_x,
211                float center_y,
212                float radius_x,
213                float radius_y,
214                float angle_1,
215                float angle_2)
216 {
217   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
218
219   cogl2_path_arc (ctx->current_path,
220                   center_x,
221                   center_y,
222                   radius_x,
223                   radius_y,
224                   angle_1,
225                   angle_2);
226 }
227
228 void
229 cogl_path_ellipse (float center_x,
230                    float center_y,
231                    float radius_x,
232                    float radius_y)
233 {
234   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
235
236   cogl2_path_ellipse (ctx->current_path,
237                       center_x,
238                       center_y,
239                       radius_x,
240                       radius_y);
241 }
242
243 void
244 cogl_path_round_rectangle (float x_1,
245                            float y_1,
246                            float x_2,
247                            float y_2,
248                            float radius,
249                            float arc_step)
250 {
251   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
252
253   cogl2_path_round_rectangle (ctx->current_path,
254                               x_1, y_1, x_2, y_2, radius, arc_step);
255 }
256
257 void
258 cogl_path_curve_to (float x_1,
259                     float y_1,
260                     float x_2,
261                     float y_2,
262                     float x_3,
263                     float y_3)
264 {
265   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
266
267   cogl2_path_curve_to (ctx->current_path,
268                        x_1, y_1, x_2, y_2, x_3, y_3);
269 }
270
271 void
272 cogl_path_rel_curve_to (float x_1,
273                         float y_1,
274                         float x_2,
275                         float y_2,
276                         float x_3,
277                         float y_3)
278 {
279   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
280
281   cogl2_path_rel_curve_to (ctx->current_path,
282                            x_1, y_1, x_2, y_2, x_3, y_3);
283 }
284
285 CoglPath *
286 cogl_get_path (void)
287 {
288   _COGL_GET_CONTEXT (ctx, NULL);
289
290   return ctx->current_path;
291 }
292
293 void
294 cogl_set_path (CoglPath *path)
295 {
296   _COGL_GET_CONTEXT (ctx, NO_RETVAL);
297
298   _COGL_RETURN_IF_FAIL (cogl_is_path (path));
299
300   /* Reference the new object first in case it is the same as the old
301      object */
302   cogl_object_ref (path);
303   cogl_object_unref (ctx->current_path);
304   ctx->current_path = path;
305 }
306