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