Btk
SDL2_gfxPrimitives.h
1 /*
2 
3 SDL2_gfxPrimitives.h: graphics primitives for SDL
4 
5 Copyright (C) 2012-2014 Andreas Schiffler
6 
7 This software is provided 'as-is', without any express or implied
8 warranty. In no event will the authors be held liable for any damages
9 arising from the use of this software.
10 
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute it
13 freely, subject to the following restrictions:
14 
15 1. The origin of this software must not be misrepresented; you must not
16 claim that you wrote the original software. If you use this software
17 in a product, an acknowledgment in the product documentation would be
18 appreciated but is not required.
19 
20 2. Altered source versions must be plainly marked as such, and must not be
21 misrepresented as being the original software.
22 
23 3. This notice may not be removed or altered from any source
24 distribution.
25 
26 Andreas Schiffler -- aschiffler at ferzkopp dot net
27 
28 */
29 
30 #ifndef _SDL2_gfxPrimitives_h
31 #define _SDL2_gfxPrimitives_h
32 
33 #include <math.h>
34 #ifndef M_PI
35 #define M_PI 3.1415926535897932384626433832795
36 #endif
37 
38 #include <SDL2/SDL.h>
39 #include "../render.hpp"
40 /* Set up for C function definitions, even when using C++ */
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /*Using our abstruct renderer*/
46 #define SDL_Texture BtkTexture
47 #define SDL_Renderer BtkRenderer
48 /*To prevent naming conflict to std SDL2_gfx,We need to change the name */
49 #define pixelColor _BGFX_pixelColor
50 #define pixelRGBA _BGFX_pixelRGBA
51 #define hlineColor _BGFX_hlineColor
52 #define hlineRGBA _BGFX_hlineRGBA
53 
54 #define vlineColor _BGFX_vlineColor
55 #define vlineRGBA _BGFX_vlineRGBA
56 
57 #define lineColor _BGFX_lineColor
58 #define lineRGBA _BGFX_lineRGBA
59 
60 #define thickLineColor _BGFX_thickLineColor
61 #define thickLineRGBA _BGFX_thickLineRGBA
62 
63 #define aalineColor _BGFX_aalineColor
64 #define aalineRGBA _BGFX_aalineRGBA
65 
66 #define rectangleColor _BGFX_rectangleColor
67 #define rectangleRGBA _BGFX_rectangleRGBA
68 
69 #define roundedRectangleColor _BGFX_roundedRectangleColor
70 #define roundedRectangleRGBA _BGFX_roundedRectangleRGBA
71 
72 #define boxColor _BGFX_boxColor
73 #define boxRGBA _BGFX_boxRGBA
74 
75 #define circleColor _BGFX_circleColor
76 #define circleRGBA _BGFX_circleRGBA
77 
78 #define aacircleColor _BGFX_aacircleColor
79 #define aacircleRGBA _BGFX_aacircleRGBA
80 
81 #define filledCircleColor _BGFX_filledCircleColor
82 #define filledCircleRGBA _BGFX_filledCircleRGBA
83 
84 #define arcColor _BGFX_arcColor
85 #define arcRGBA _BGFX_arcRGBA
86 
87 #define pieColor _BGFX_pieColor
88 #define pieRGBA _BGFX_pieRGBA
89 
90 #define filledPieColor _BGFX_filledPieColor
91 #define filledPieRGBA _BGFX_filledPieRGBA
92 
93 #define ellipseColor _BGFX_ellipseColor
94 #define ellipseRGBA _BGFX_ellipseRGBA
95 
96 #define aaellipseColor _BGFX_aaellipseColor
97 #define aaellipseRGBA _BGFX_aaellipseRGBA
98 
99 #define trigonColor _BGFX_trigonColor
100 #define trigonRGBA _BGFX_trigonRGBA
101 
102 #define aatrigonColor _BGFX_aatrigonColor
103 #define aatrigonRGBA _BGFX_aatrigonRGBA
104 
105 
106 #define roundedBoxColor _BGFX_roundedBoxColor
107 #define roundedBoxRGBA _BGFX_roundedBoxRGBA
108 
109 #define filledEllipseColor _BGFX_filledEllipseColor
110 #define filledEllipseRGBA _BGFX_filledEllipseRGBA
111 
112 #define filledTrigonColor _BGFX_filledTrigonColor
113 #define filledTrigonRGBA _BGFX_filledTrigonRGBA
114 
115 #define polygonColor _BGFX_polygonColor
116 #define polygonRGBA _BGFX_polygonRGBA
117 
118 #define aapolygonColor _BGFX_aapolygonColor
119 #define aapolygonRGBA _BGFX_aapolygonRGBA
120 
121 #define filledPolygonColor _BGFX_filledPolygonColor
122 #define filledPolygonRGBA _BGFX_filledPolygonRGBA
123 
124 #define bezierColor _BGFX_bezierColor
125 #define bezierRGBA _BGFX_bezierRGBA
126 
127 #define texturedPolygon _BGFX_texturedPolygon
128 
129  /* ----- Versioning */
130 
131 #define SDL2_GFXPRIMITIVES_MAJOR 1
132 #define SDL2_GFXPRIMITIVES_MINOR 0
133 #define SDL2_GFXPRIMITIVES_MICRO 4
134 
135 
136  /* ---- Function Prototypes */
137 
138 #ifdef _MSC_VER
139 # if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
140 # define SDL2_GFXPRIMITIVES_SCOPE __declspec(dllexport)
141 # else
142 # ifdef LIBSDL2_GFX_DLL_IMPORT
143 # define SDL2_GFXPRIMITIVES_SCOPE __declspec(dllimport)
144 # endif
145 # endif
146 #endif
147 #ifndef SDL2_GFXPRIMITIVES_SCOPE
148 # define SDL2_GFXPRIMITIVES_SCOPE extern
149 #endif
150 
151  /* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA */
152 
153  /* Pixel */
154 
155  SDL2_GFXPRIMITIVES_SCOPE int pixelColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint32 color);
156  SDL2_GFXPRIMITIVES_SCOPE int pixelRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
157 
158  /* Horizontal line */
159 
160  SDL2_GFXPRIMITIVES_SCOPE int hlineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color);
161  SDL2_GFXPRIMITIVES_SCOPE int hlineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
162 
163  /* Vertical line */
164 
165  SDL2_GFXPRIMITIVES_SCOPE int vlineColor(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color);
166  SDL2_GFXPRIMITIVES_SCOPE int vlineRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
167 
168  /* Rectangle */
169 
170  SDL2_GFXPRIMITIVES_SCOPE int rectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
171  SDL2_GFXPRIMITIVES_SCOPE int rectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
172  Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
173 
174  /* Rounded-Corner Rectangle */
175 
176  SDL2_GFXPRIMITIVES_SCOPE int roundedRectangleColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color);
177  SDL2_GFXPRIMITIVES_SCOPE int roundedRectangleRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
178  Sint16 x2, Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
179 
180  /* Filled rectangle (Box) */
181 
182  SDL2_GFXPRIMITIVES_SCOPE int boxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
183  SDL2_GFXPRIMITIVES_SCOPE int boxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2,
184  Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
185 
186  /* Rounded-Corner Filled rectangle (Box) */
187 
188  SDL2_GFXPRIMITIVES_SCOPE int roundedBoxColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 rad, Uint32 color);
189  SDL2_GFXPRIMITIVES_SCOPE int roundedBoxRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2,
190  Sint16 y2, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
191 
192  /* Line */
193 
194  SDL2_GFXPRIMITIVES_SCOPE int lineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
195  SDL2_GFXPRIMITIVES_SCOPE int lineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
196  Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
197 
198  /* AA Line */
199 
200  SDL2_GFXPRIMITIVES_SCOPE int aalineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
201  SDL2_GFXPRIMITIVES_SCOPE int aalineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1,
202  Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
203 
204  /* Thick Line */
205  SDL2_GFXPRIMITIVES_SCOPE int thickLineColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
206  Uint8 width, Uint32 color);
207  SDL2_GFXPRIMITIVES_SCOPE int thickLineRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,
208  Uint8 width, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
209 
210  /* Circle */
211 
212  SDL2_GFXPRIMITIVES_SCOPE int circleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color);
213  SDL2_GFXPRIMITIVES_SCOPE int circleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
214 
215  /* Arc */
216 
217  SDL2_GFXPRIMITIVES_SCOPE int arcColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint32 color);
218  SDL2_GFXPRIMITIVES_SCOPE int arcRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end,
219  Uint8 r, Uint8 g, Uint8 b, Uint8 a);
220 
221  /* AA Circle */
222 
223  SDL2_GFXPRIMITIVES_SCOPE int aacircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color);
224  SDL2_GFXPRIMITIVES_SCOPE int aacircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
225  Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
226 
227  /* Filled Circle */
228 
229  SDL2_GFXPRIMITIVES_SCOPE int filledCircleColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
230  SDL2_GFXPRIMITIVES_SCOPE int filledCircleRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
231  Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
232 
233  /* Ellipse */
234 
235  SDL2_GFXPRIMITIVES_SCOPE int ellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
236  SDL2_GFXPRIMITIVES_SCOPE int ellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
237  Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
238 
239  /* AA Ellipse */
240 
241  SDL2_GFXPRIMITIVES_SCOPE int aaellipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
242  SDL2_GFXPRIMITIVES_SCOPE int aaellipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
243  Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
244 
245  /* Filled Ellipse */
246 
247  SDL2_GFXPRIMITIVES_SCOPE int filledEllipseColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
248  SDL2_GFXPRIMITIVES_SCOPE int filledEllipseRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y,
249  Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
250 
251  /* Pie */
252 
253  SDL2_GFXPRIMITIVES_SCOPE int pieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
254  Sint16 start, Sint16 end, Uint32 color);
255  SDL2_GFXPRIMITIVES_SCOPE int pieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
256  Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
257 
258  /* Filled Pie */
259 
260  SDL2_GFXPRIMITIVES_SCOPE int filledPieColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
261  Sint16 start, Sint16 end, Uint32 color);
262  SDL2_GFXPRIMITIVES_SCOPE int filledPieRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, Sint16 rad,
263  Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
264 
265  /* Trigon */
266 
267  SDL2_GFXPRIMITIVES_SCOPE int trigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
268  SDL2_GFXPRIMITIVES_SCOPE int trigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
269  Uint8 r, Uint8 g, Uint8 b, Uint8 a);
270 
271  /* AA-Trigon */
272 
273  SDL2_GFXPRIMITIVES_SCOPE int aatrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
274  SDL2_GFXPRIMITIVES_SCOPE int aatrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
275  Uint8 r, Uint8 g, Uint8 b, Uint8 a);
276 
277  /* Filled Trigon */
278 
279  SDL2_GFXPRIMITIVES_SCOPE int filledTrigonColor(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
280  SDL2_GFXPRIMITIVES_SCOPE int filledTrigonRGBA(SDL_Renderer * renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
281  Uint8 r, Uint8 g, Uint8 b, Uint8 a);
282 
283  /* Polygon */
284 
285  SDL2_GFXPRIMITIVES_SCOPE int polygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
286  SDL2_GFXPRIMITIVES_SCOPE int polygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
287  int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
288 
289  /* AA-Polygon */
290 
291  SDL2_GFXPRIMITIVES_SCOPE int aapolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
292  SDL2_GFXPRIMITIVES_SCOPE int aapolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
293  int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
294 
295  /* Filled Polygon */
296 
297  SDL2_GFXPRIMITIVES_SCOPE int filledPolygonColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
298  SDL2_GFXPRIMITIVES_SCOPE int filledPolygonRGBA(SDL_Renderer * renderer, const Sint16 * vx,
299  const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
300 
301  /* Textured Polygon */
302 
303  SDL2_GFXPRIMITIVES_SCOPE int texturedPolygon(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface * texture,int texture_dx,int texture_dy);
304 
305  /* Bezier */
306 
307  SDL2_GFXPRIMITIVES_SCOPE int bezierColor(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint32 color);
308  SDL2_GFXPRIMITIVES_SCOPE int bezierRGBA(SDL_Renderer * renderer, const Sint16 * vx, const Sint16 * vy,
309  int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
310 
311  #if 0
312  /* Characters/Strings */
313 
314  SDL2_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFont(const void *fontdata, Uint32 cw, Uint32 ch);
315  SDL2_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFontRotation(Uint32 rotation);
316  SDL2_GFXPRIMITIVES_SCOPE int characterColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint32 color);
317  SDL2_GFXPRIMITIVES_SCOPE int characterRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
318  SDL2_GFXPRIMITIVES_SCOPE int stringColor(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint32 color);
319  SDL2_GFXPRIMITIVES_SCOPE int stringRGBA(SDL_Renderer * renderer, Sint16 x, Sint16 y, const char *s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
320  #endif
321  /* Ends C function definitions when using C++ */
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 #undef SDL_Texture
327 #undef SDL_Renderer
328 #endif /* _SDL2_gfxPrimitives_h */