actual version
[sdl-headers.git] / sdl2.pas
1 unit SDL2;
2
3 {
4   Simple DirectMedia Layer
5   Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
6
7   Pascal-Header-Conversion
8   Copyright (C) 2012/13 Tim Blume aka End/EV1313
9
10   SDL.pas is based on the files:
11   "sdl.h",
12   "sdl_audio.h",
13   "sdl_blendmode.h",
14   "sdl_events.h",
15   "sdl_error.h",
16   "sdl_gesture.h",
17   "sdl_haptic.h",
18   "sdl_hints.h",
19   "sdl_joystick.h",
20   "sdl_keyboard.h",
21   "sdl_keycode.h",
22   "sdl_loadso.h"
23   "sdl_pixels.h",
24   "sdl_power.h",
25   "sdl_main.h",
26   "sdl_messagebox.h",
27   "sdl_mouse.h",
28   "sdl_mutex.h",
29   "sdl_rect.h",
30   "sdl_render.h",
31   "sdl_rwops.h",
32   "sdl_scancode.h",
33   "sdl_shape.h",
34   "sdl_stdinc.h",
35   "sdl_surface.h",
36   "sdl_thread.h",
37   "sdl_timer.h",
38   "sdl_touch.h",
39   "sdl_version.h",
40   "sdl_video.h",
41   "sdltype_s.h"
42
43   I will not translate:
44   "sdl_opengl.h",
45   "sdl_opengles.h"
46   "sdl_opengles2.h"
47
48   cause there's a much better OpenGL-Header avaible at delphigl.com:
49
50   the dglopengl.pas
51
52   Parts of the SDL.pas are from the SDL-1.2-Headerconversion from the JEDI-Team,
53   written by Domenique Louis and others.
54
55   I've changed the names of the dll for 32 & 64-Bit, so theres no conflict
56   between 32 & 64 bit Libraries.
57
58   This software is provided 'as-is', without any express or implied
59   warranty.  In no case will the authors be held liable for any damages
60   arising from the use of this software.
61
62   Permission is granted to anyone to use this software for any purpose,
63   including commercial applications, and to alter it and redistribute it
64   freely, subject to the following restrictions:
65
66   1. The origin of this software must not be misrepresented; you must not
67      claim that you wrote the original software. If you use this software
68      in a product, an acknowledgment in the product documentation would be
69      appreciated but is not required.
70   2. Altered source versions must be plainly marked as such, and must not be
71      misrepresented as being the original software.
72   3. This notice may not be removed or altered from any source distribution.
73
74   Special Thanks to:
75
76    - DelphiGL.com - Community
77    - Domenique Louis and everyone else from the JEDI-Team
78    - Sam Latinga and everyone else from the SDL-Team
79 }
80
81 {
82   Changelog:
83   ----------
84   v.1.73-stable; 08.11.2013: added sdl_hints.h and some keystate helpers
85                              thx to Cybermonkey!
86   v.1.72-stable; 23.09.2013: fixed bug with procedures without parameters
87                              (they must have brakets)
88   v.1.70-stable; 17.09.2013: added "sdl_messagebox.h" and "sdl_haptic.h"
89   v.1.63-stable; 16.09.2013: added libs sdl2_image and sdl2_ttf and added sdl_audio.h
90   v.1.62-stable; 03.09.2013: fixed.
91   v.1.61-stable; 02.09.2013: now it should REALLY work with Mac...
92   v.1.60-stable; 01.09.2013: now it should work with Delphi XE4 for Windows and
93                             MacOS and of course Lazarus. thx to kotai :D
94   v.1.55-Alpha; 24.08.2013: fixed bug with SDL_GetEventState thx to d.l.i.w.
95   v.1.54-Alpha; 24.08.2013: added sdl_loadso.h
96   v.1.53-Alpha; 24.08.2013: renamed *really* and fixed linux comp.
97   v.1.52-Alpha; 24.08.2013: renamed sdl.pas to sdl2.pas
98   v.1.51-Alpha; 24.08.2013: added sdl_platform.h
99   v.1.50-Alpha; 24.08.2013: the header is now modular. thx for the hint from d.l.i.w.
100   v.1.40-Alpha; 13.08.2013: Added MacOS compatibility (thx to stoney-fd)
101   v.1.34-Alpha; 05.08.2013: Added missing functions from sdl_thread.h
102   v.1.33-Alpha; 31.07.2013: Added missing units for Linux. thx to Cybermonkey
103   v.1.32-Alpha; 31.07.2013: Fixed three bugs, thx to grieferatwork
104   v.1.31-Alpha; 30.07.2013: Added "sdl_power.h"
105   v.1.30-Alpha; 26.07.2013: Added "sdl_thread.h" and "sdl_mutex.h"
106   v.1.25-Alpha; 29.07.2013: Added Makros for SDL_RWops
107   v.1.24-Alpha; 28.07.2013: Fixed bug with RWops and size_t
108   v.1.23-Alpha; 27.07.2013: Fixed two bugs, thx to GrieferAtWork
109   v.1.22-Alpha; 24.07.2013: Added "sdl_shape.h" and TSDL_Window
110                             (and ordered the translated header list ^^)
111   v.1.21-Alpha; 23.07.2013: Added TSDL_Error
112   v.1.20-Alpha; 19.07.2013: Added "sdl_timer.h"
113   v.1.10-Alpha; 09.07.2013: Added "sdl_render.h"
114   v.1.00-Alpha; 05.07.2013: Initial Alpha-Release.
115 }
116
117 {$DEFINE SDL}
118
119 {$I jedi.inc}
120
121 interface
122
123   {$IFDEF WINDOWS}
124     uses
125       Windows;
126   {$ENDIF}
127
128   {$IFDEF LINUX}
129     uses
130       X,
131       XLib;
132   {$ENDIF}
133
134 const
135
136   {$IFDEF WINDOWS}
137     SDL_LibName = 'SDL2.dll';
138   {$ENDIF}
139
140   {$IFDEF UNIX}
141     {$IFDEF DARWIN}
142       SDL_LibName = 'libSDL2.dylib';
143     {$ELSE}
144       {$IFDEF FPC}
145         SDL_LibName = 'libSDL2.so';
146       {$ELSE}
147         SDL_LibName = 'libSDL2.so.0';
148       {$ENDIF}
149     {$ENDIF}
150   {$ENDIF}
151
152   {$IFDEF MACOS}
153     SDL_LibName = 'SDL2';
154     {$IFDEF FPC}
155       {$linklib libSDL2}
156     {$ENDIF}
157   {$ENDIF}
158
159 {$I sdltype.inc}
160 {$I sdlversion.inc}
161 {$I sdlerror.inc}
162 {$I sdlplatform.inc}
163 {$I sdlpower.inc}
164 {$I sdlthread.inc}
165 {$I sdlmutex.inc}
166 {$I sdltimer.inc}
167 {$I sdlpixels.inc}
168 {$I sdlrect.inc}
169 {$I sdlrwops.inc}
170 {$I sdlaudio.inc}
171 {$I sdlblendmode.inc}
172 {$I sdlsurface.inc}
173 {$I sdlshape.inc}
174 {$I sdlvideo.inc}
175 {$I sdlhints.inc}
176 {$I sdlmessagebox.inc}
177 {$I sdlrenderer.inc}
178 {$I sdlscancode.inc}
179 {$I sdlkeyboard.inc}
180 {$I sdlmouse.inc}
181 {$I sdljoystick.inc}
182 {$I sdlhaptic.inc}
183 {$I sdltouch.inc}
184 {$I sdlgesture.inc}
185 {$I sdlevents.inc}
186 {$I sdl.inc}
187
188 implementation
189
190 //from "sdl_version.h"
191 procedure SDL_VERSION(x: PSDL_Version);
192 begin
193   x.major := SDL_MAJOR_VERSION;
194   x.minor := SDL_MINOR_VERSION;
195   x.patch := SDL_PATCHLEVEL;
196 end;
197
198 function SDL_VERSIONNUM(X,Y,Z: UInt32): Cardinal;
199 begin
200   Result := X*1000 + Y*100 + Z;
201 end;
202
203 function SDL_COMPILEDVERSION: Cardinal;
204 begin
205   Result := SDL_VERSIONNUM(SDL_MAJOR_VERSION,
206                            SDL_MINOR_VERSION,
207                            SDL_PATCHLEVEL);
208 end;
209
210 function SDL_VERSION_ATLEAST(X,Y,Z: Cardinal): Boolean;
211 begin
212   Result := SDL_COMPILEDVERSION >= SDL_VERSIONNUM(X,Y,Z);
213 end;
214
215 {$IFDEF WINDOWS}
216 //from "sdl_thread.h"
217
218 function SDL_CreateThread(fn: TSDL_ThreadFunction; name: PAnsiChar; data: Pointer): PSDL_Thread; overload;
219 begin
220   Result := SDL_CreateThread(fn,name,data,nil,nil);
221 end;
222
223 {$ENDIF}
224
225 //from "sdl_rect.h"
226 function SDL_RectEmpty(X: TSDL_Rect): Boolean;
227 begin
228   Result := (X.w <= 0) or (X.h <= 0);
229 end;
230
231 function SDL_RectEquals(A: TSDL_Rect; B: TSDL_Rect): Boolean;
232 begin
233   Result := (A.x = B.x) and (A.y = B.y) and (A.w = B.w) and (A.h = B.h);
234 end;
235
236 //from "sdl_rwops.h"
237
238 function SDL_RWsize(ctx: PSDL_RWops): SInt64;
239 begin
240   Result := ctx^.size(ctx);
241 end;
242
243 function SDL_RWseek(ctx: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64;
244 begin
245   Result := ctx^.seek(ctx,offset,whence);
246 end;
247
248 function SDL_RWtell(ctx: PSDL_RWops): SInt64;
249 begin
250   Result := ctx^.seek(ctx, 0, RW_SEEK_CUR);
251 end;
252
253 function SDL_RWread(ctx: PSDL_RWops; ptr: Pointer; size: size_t; n: size_t): size_t;
254 begin
255   Result := ctx^.read(ctx, ptr, size, n);
256 end;
257
258 function SDL_RWwrite(ctx: PSDL_RWops; ptr: Pointer; size: size_t; n: size_t): size_t;
259 begin
260   Result := ctx^.write(ctx, ptr, size, n);
261 end;
262
263 function SDL_RWclose(ctx: PSDL_RWops): SInt32;
264 begin
265   Result := ctx^.close(ctx);
266 end;
267
268 //from "sdl_audio.h"
269
270 function SDL_LoadWAV(_file: PAnsiChar; spec: PSDL_AudioSpec; audio_buf: PPUInt8; audio_len: PUInt32): PSDL_AudioSpec;
271 begin
272   Result := SDL_LoadWAV_RW(SDL_RWFromFile(_file, 'rb'), 1, spec, audio_buf, audio_len);
273 end;
274   
275 function SDL_AUDIO_BITSIZE(x: Cardinal): Cardinal;
276 begin
277   Result := x and SDL_AUDIO_MASK_BITSIZE;
278 end;
279
280 function SDL_AUDIO_ISFLOAT(x: Cardinal): Cardinal;
281 begin
282   Result := x and SDL_AUDIO_MASK_DATATYPE;
283 end;
284
285 function SDL_AUDIO_ISBIGENDIAN(x: Cardinal): Cardinal;
286 begin
287   Result := x and SDL_AUDIO_MASK_ENDIAN;
288 end;
289
290 function SDL_AUDIO_ISSIGNED(x: Cardinal): Cardinal;
291 begin
292   Result := x and SDL_AUDIO_MASK_SIGNED;
293 end;
294
295 function SDL_AUDIO_ISINT(x: Cardinal): Cardinal;
296 begin
297   Result := not SDL_AUDIO_ISFLOAT(x);
298 end;
299
300 function SDL_AUDIO_ISLITTLEENDIAN(x: Cardinal): Cardinal;
301 begin
302   Result := not SDL_AUDIO_ISLITTLEENDIAN(x);
303 end;
304
305 function SDL_AUDIO_ISUNSIGNED(x: Cardinal): Cardinal;
306 begin
307   Result := not SDL_AUDIO_ISSIGNED(x);
308 end;
309
310 //from "sdl_pixels.h"
311
312 function SDL_PIXELFLAG(X: Cardinal): Boolean;
313 begin
314   Result := (X shr 28) = $0F;
315 end;
316
317 function SDL_PIXELTYPE(X: Cardinal): Boolean;
318 begin
319   Result := (X shr 24) = $0F;
320 end;
321
322 function SDL_PIXELORDER(X: Cardinal): Boolean;
323 begin
324   Result := (X shr 20) = $0F;
325 end;
326
327 function SDL_PIXELLAYOUT(X: Cardinal): Boolean;
328 begin
329   Result := (X shr 16) = $0F;
330 end;
331
332 function SDL_BITSPERPIXEL(X: Cardinal): Boolean;
333 begin
334   Result := (X shr 8) = $FF;
335 end;
336
337 function SDL_IsPixelFormat_FOURCC(format: Variant): Boolean;
338 begin
339   {* The flag is set to 1 because 0x1? is not in the printable ASCII range *}
340   Result := format and SDL_PIXELFLAG(format) <> 1;
341 end;
342
343 //from "sdl_surface.h"
344 function SDL_LoadBMP(_file: PAnsiChar): PSDL_Surface;
345 begin
346   Result := SDL_LoadBMP_RW(SDL_RWFromFile(_file, 'rb'), 1);
347 end;
348
349 //from "sdl_video.h"
350 function SDL_WindowPos_IsUndefined(X: Variant): Variant;
351 begin
352   Result := (X and $FFFF0000) = SDL_WINDOWPOS_UNDEFINED_MASK;
353 end;
354
355 function SDL_WindowPos_IsCentered(X: Variant): Variant;
356 begin
357   Result := (X and $FFFF0000) = SDL_WINDOWPOS_CENTERED_MASK;
358 end;
359
360 //from "sdl_events.h"
361
362 function SDL_GetEventState(type_: UInt32): UInt8;
363 begin
364   Result := SDL_EventState(type_, SDL_QUERY);
365 end;
366
367 end.