1 /*
2 
3  SDL_gfxPrimitives: graphics primitives for SDL
4 
5  LGPL (c) A. Schiffler
6 
7 */
8 
9 #ifndef _SDL_gfxPrimitives_h
10 #define _SDL_gfxPrimitives_h
11 
12 #include <math.h>
13 #ifndef M_PI
14 #define M_PI	3.141592654
15 #endif
16 
17 #include "SDL.h"
18 
19 /* Set up for C function definitions, even when using C++ */
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /* ----- Versioning */
25 
26 #define SDL_GFXPRIMITIVES_MAJOR	2
27 #define SDL_GFXPRIMITIVES_MINOR	0
28 #define SDL_GFXPRIMITIVES_MICRO	17
29 
30 /* ----- W32 DLL interface */
31 
32 #ifdef WIN32
33 #ifdef BUILD_DLL
34 #define DLLINTERFACE __declspec(dllexport)
35 #else
36 #define DLLINTERFACE __declspec(dllimport)
37 #endif
38 #else
39 #define DLLINTERFACE
40 #endif
41 
42 /* ----- Prototypes */
43 
44 /* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA */
45 
46 /* Pixel */
47 
48     DLLINTERFACE int pixelColor(SDL_Surface * dst, Sint16 x, Sint16 y, Uint32 color);
49     DLLINTERFACE int pixelRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
50 
51 /* Horizontal line */
52 
53     DLLINTERFACE int hlineColor(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint32 color);
54     DLLINTERFACE int hlineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 x2, Sint16 y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
55 
56 /* Vertical line */
57 
58     DLLINTERFACE int vlineColor(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint32 color);
59     DLLINTERFACE int vlineRGBA(SDL_Surface * dst, Sint16 x, Sint16 y1, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
60 
61 /* Rectangle */
62 
63     DLLINTERFACE int rectangleColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
64     DLLINTERFACE int rectangleRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
65 				   Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
66 
67 /* Filled rectangle (Box) */
68 
69     DLLINTERFACE int boxColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
70     DLLINTERFACE int boxRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2,
71 			     Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
72 
73 /* Line */
74 
75     DLLINTERFACE int lineColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
76     DLLINTERFACE int lineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
77 			      Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
78 
79 /* AA Line */
80     DLLINTERFACE int aalineColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint32 color);
81     DLLINTERFACE int aalineRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1,
82 				Sint16 x2, Sint16 y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
83 
84 /* Circle */
85 
86     DLLINTERFACE int circleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
87     DLLINTERFACE int circleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
88 
89 /* Circle */
90 
91     DLLINTERFACE int arcColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Sint16 start, Sint16 end, Uint32 color);
92     DLLINTERFACE int arcRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
93 
94 /* AA Circle */
95 
96     DLLINTERFACE int aacircleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
97     DLLINTERFACE int aacircleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
98 				  Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
99 
100 /* Filled Circle */
101 
102     DLLINTERFACE int filledCircleColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 r, Uint32 color);
103     DLLINTERFACE int filledCircleRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
104 				      Sint16 rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
105 
106 /* Ellipse */
107 
108     DLLINTERFACE int ellipseColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
109     DLLINTERFACE int ellipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
110 				 Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
111 
112 /* AA Ellipse */
113 
114     DLLINTERFACE int aaellipseColor(SDL_Surface * dst, Sint16 xc, Sint16 yc, Sint16 rx, Sint16 ry, Uint32 color);
115     DLLINTERFACE int aaellipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
116 				   Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
117 
118 /* Filled Ellipse */
119 
120     DLLINTERFACE int filledEllipseColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rx, Sint16 ry, Uint32 color);
121     DLLINTERFACE int filledEllipseRGBA(SDL_Surface * dst, Sint16 x, Sint16 y,
122 				       Sint16 rx, Sint16 ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
123 
124 #define CLOCKWISE
125 
126 /* Pie */
127 
128     DLLINTERFACE int pieColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
129 			      Sint16 start, Sint16 end, Uint32 color);
130     DLLINTERFACE int pieRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
131 			     Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
132 
133 /* Filled Pie */
134 
135     DLLINTERFACE int filledPieColor(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
136 				    Sint16 start, Sint16 end, Uint32 color);
137     DLLINTERFACE int filledPieRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, Sint16 rad,
138 				   Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
139 
140 /* Trigon */
141 
142     DLLINTERFACE int trigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
143     DLLINTERFACE int trigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
144 				 Uint8 r, Uint8 g, Uint8 b, Uint8 a);
145 
146 /* AA-Trigon */
147 
148     DLLINTERFACE int aatrigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
149     DLLINTERFACE int aatrigonRGBA(SDL_Surface * dst,  Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
150 				   Uint8 r, Uint8 g, Uint8 b, Uint8 a);
151 
152 /* Filled Trigon */
153 
154     DLLINTERFACE int filledTrigonColor(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint32 color);
155     DLLINTERFACE int filledTrigonRGBA(SDL_Surface * dst, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3,
156 				       Uint8 r, Uint8 g, Uint8 b, Uint8 a);
157 
158 /* Polygon */
159 
160     DLLINTERFACE int polygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
161     DLLINTERFACE int polygonRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
162 				 int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
163 
164 /* AA-Polygon */
165 
166     DLLINTERFACE int aapolygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
167     DLLINTERFACE int aapolygonRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
168 				   int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
169 
170 /* Filled Polygon */
171 
172     DLLINTERFACE int filledPolygonColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color);
173     DLLINTERFACE int filledPolygonRGBA(SDL_Surface * dst, const Sint16 * vx,
174 				       const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
175     DLLINTERFACE int texturedPolygon(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface * texture,int texture_dx,int texture_dy);
176 
177 /* (Note: These MT versions are required for multi-threaded operation.) */
178 
179     DLLINTERFACE int filledPolygonColorMT(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, Uint32 color, int **polyInts, int *polyAllocated);
180     DLLINTERFACE int filledPolygonRGBAMT(SDL_Surface * dst, const Sint16 * vx,
181 				       const Sint16 * vy, int n, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
182 				       int **polyInts, int *polyAllocated);
183     DLLINTERFACE int texturedPolygonMT(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, SDL_Surface * texture,int texture_dx,int texture_dy, int **polyInts, int *polyAllocated);
184 
185 /* Bezier */
186 /* (s = number of steps) */
187 
188     DLLINTERFACE int bezierColor(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy, int n, int s, Uint32 color);
189     DLLINTERFACE int bezierRGBA(SDL_Surface * dst, const Sint16 * vx, const Sint16 * vy,
190 				 int n, int s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
191 
192 
193 /* Characters/Strings */
194 
195     DLLINTERFACE int characterColor(SDL_Surface * dst, Sint16 x, Sint16 y, char c, Uint32 color);
196     DLLINTERFACE int characterRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
197     DLLINTERFACE int stringColor(SDL_Surface * dst, Sint16 x, Sint16 y, const char *c, Uint32 color);
198     DLLINTERFACE int stringRGBA(SDL_Surface * dst, Sint16 x, Sint16 y, const char *c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
199 
200     DLLINTERFACE void gfxPrimitivesSetFont(const void *fontdata, int cw, int ch);
201 
202 /* Ends C function definitions when using C++ */
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 #endif				/* _SDL_gfxPrimitives_h */
208