1 /*
2 
3 Boost Software License - Version 1.0 - August 17th, 2003
4 
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */
28 module derelict.sdl.sdl;
29 
30 public
31 {
32     import derelict.sdl.sdltypes;
33     import derelict.sdl.sdlfuncs;
34 }
35 
36 private
37 {
38     import derelict.util.loader;
39 
40     version(darwin)
41         version = MacOSX;
42     version(OSX)
43         version = MacOSX;
44 
45     version (MacOSX)
46         import derelict.sdl.macinit.SDLMain;
47 }
48 
49 class DerelictSDLLoader : SharedLibLoader
50 {
51 public:
52     this()
53     {
54         super(
55             "sdl.dll",
56             "libSDL.so, libSDL.so.0, libSDL-1.2.so, libSDL-1.2.so.0",
57             "../Frameworks/SDL.framework/SDL, /Library/Frameworks/SDL.framework/SDL, /System/Library/Frameworks/SDL.framework/SDL"
58         );
59     }
60 
61 protected:
62     override void loadSymbols()
63     {
64         // active.d
65         bindFunc(cast(void**)&SDL_GetAppState, "SDL_GetAppState");
66         // audio.d
67         bindFunc(cast(void**)&SDL_AudioInit, "SDL_AudioInit");
68         bindFunc(cast(void**)&SDL_AudioQuit, "SDL_AudioQuit");
69         bindFunc(cast(void**)&SDL_AudioDriverName, "SDL_AudioDriverName");
70         bindFunc(cast(void**)&SDL_OpenAudio, "SDL_OpenAudio");
71         bindFunc(cast(void**)&SDL_GetAudioStatus, "SDL_GetAudioStatus");
72         bindFunc(cast(void**)&SDL_PauseAudio, "SDL_PauseAudio");
73         bindFunc(cast(void**)&SDL_LoadWAV_RW, "SDL_LoadWAV_RW");
74         bindFunc(cast(void**)&SDL_FreeWAV, "SDL_FreeWAV");
75         bindFunc(cast(void**)&SDL_BuildAudioCVT, "SDL_BuildAudioCVT");
76         bindFunc(cast(void**)&SDL_ConvertAudio, "SDL_ConvertAudio");
77         bindFunc(cast(void**)&SDL_MixAudio, "SDL_MixAudio");
78         bindFunc(cast(void**)&SDL_LockAudio, "SDL_LockAudio");
79         bindFunc(cast(void**)&SDL_UnlockAudio, "SDL_UnlockAudio");
80         bindFunc(cast(void**)&SDL_CloseAudio, "SDL_CloseAudio");
81         // cdrom.d
82         bindFunc(cast(void**)&SDL_CDNumDrives, "SDL_CDNumDrives");
83         bindFunc(cast(void**)&SDL_CDName, "SDL_CDName");
84         bindFunc(cast(void**)&SDL_CDOpen, "SDL_CDOpen");
85         bindFunc(cast(void**)&SDL_CDStatus, "SDL_CDStatus");
86         bindFunc(cast(void**)&SDL_CDPlayTracks, "SDL_CDPlayTracks");
87         bindFunc(cast(void**)&SDL_CDPlay, "SDL_CDPlay");
88         bindFunc(cast(void**)&SDL_CDPause, "SDL_CDPause");
89         bindFunc(cast(void**)&SDL_CDResume, "SDL_CDResume");
90         bindFunc(cast(void**)&SDL_CDStop, "SDL_CDStop");
91         bindFunc(cast(void**)&SDL_CDEject, "SDL_CDEject");
92         bindFunc(cast(void**)&SDL_CDClose, "SDL_CDClose");
93         // cpuinfo.d
94         bindFunc(cast(void**)&SDL_HasRDTSC, "SDL_HasRDTSC");
95         bindFunc(cast(void**)&SDL_HasMMX, "SDL_HasMMX");
96         bindFunc(cast(void**)&SDL_HasMMXExt, "SDL_HasMMXExt");
97         bindFunc(cast(void**)&SDL_Has3DNow, "SDL_Has3DNow");
98         bindFunc(cast(void**)&SDL_Has3DNowExt, "SDL_Has3DNowExt");
99         bindFunc(cast(void**)&SDL_HasSSE, "SDL_HasSSE");
100         bindFunc(cast(void**)&SDL_HasSSE2, "SDL_HasSSE2");
101         bindFunc(cast(void**)&SDL_HasAltiVec, "SDL_HasAltiVec");
102         // error.d
103         bindFunc(cast(void**)&SDL_SetError, "SDL_SetError");
104         bindFunc(cast(void**)&SDL_GetError, "SDL_GetError");
105         bindFunc(cast(void**)&SDL_ClearError, "SDL_ClearError");
106         // events.d
107         bindFunc(cast(void**)&SDL_PumpEvents, "SDL_PumpEvents");
108         bindFunc(cast(void**)&SDL_PeepEvents, "SDL_PeepEvents");
109         bindFunc(cast(void**)&SDL_PollEvent, "SDL_PollEvent");
110         bindFunc(cast(void**)&SDL_WaitEvent, "SDL_WaitEvent");
111         bindFunc(cast(void**)&SDL_PushEvent, "SDL_PushEvent");
112         bindFunc(cast(void**)&SDL_SetEventFilter, "SDL_SetEventFilter");
113         bindFunc(cast(void**)&SDL_GetEventFilter, "SDL_GetEventFilter");
114         bindFunc(cast(void**)&SDL_EventState, "SDL_EventState");
115         // joystick.d
116         bindFunc(cast(void**)&SDL_NumJoysticks, "SDL_NumJoysticks");
117         bindFunc(cast(void**)&SDL_JoystickName, "SDL_JoystickName");
118         bindFunc(cast(void**)&SDL_JoystickOpen, "SDL_JoystickOpen");
119         bindFunc(cast(void**)&SDL_JoystickOpened, "SDL_JoystickOpened");
120         bindFunc(cast(void**)&SDL_JoystickIndex, "SDL_JoystickIndex");
121         bindFunc(cast(void**)&SDL_JoystickNumAxes, "SDL_JoystickNumAxes");
122         bindFunc(cast(void**)&SDL_JoystickNumBalls, "SDL_JoystickNumBalls");
123         bindFunc(cast(void**)&SDL_JoystickNumHats, "SDL_JoystickNumHats");
124         bindFunc(cast(void**)&SDL_JoystickNumButtons, "SDL_JoystickNumButtons");
125         bindFunc(cast(void**)&SDL_JoystickUpdate, "SDL_JoystickUpdate");
126         bindFunc(cast(void**)&SDL_JoystickEventState, "SDL_JoystickEventState");
127         bindFunc(cast(void**)&SDL_JoystickGetAxis, "SDL_JoystickGetAxis");
128         bindFunc(cast(void**)&SDL_JoystickGetHat, "SDL_JoystickGetHat");
129         bindFunc(cast(void**)&SDL_JoystickGetBall, "SDL_JoystickGetBall");
130         bindFunc(cast(void**)&SDL_JoystickGetButton, "SDL_JoystickGetButton");
131         bindFunc(cast(void**)&SDL_JoystickClose, "SDL_JoystickClose");
132         // keyboard.d
133         bindFunc(cast(void**)&SDL_EnableUNICODE, "SDL_EnableUNICODE");
134         bindFunc(cast(void**)&SDL_EnableKeyRepeat, "SDL_EnableKeyRepeat");
135         bindFunc(cast(void**)&SDL_GetKeyRepeat, "SDL_GetKeyRepeat");
136         bindFunc(cast(void**)&SDL_GetKeyState, "SDL_GetKeyState");
137         bindFunc(cast(void**)&SDL_GetModState, "SDL_GetModState");
138         bindFunc(cast(void**)&SDL_SetModState, "SDL_SetModState");
139         bindFunc(cast(void**)&SDL_GetKeyName, "SDL_GetKeyName");
140         // loadso.d
141         bindFunc(cast(void**)&SDL_LoadObject, "SDL_LoadObject");
142         bindFunc(cast(void**)&SDL_LoadFunction, "SDL_LoadFunction");
143         bindFunc(cast(void**)&SDL_UnloadObject, "SDL_UnloadObject");
144         // mouse.d
145         bindFunc(cast(void**)&SDL_GetMouseState, "SDL_GetMouseState");
146         bindFunc(cast(void**)&SDL_GetRelativeMouseState, "SDL_GetRelativeMouseState");
147         bindFunc(cast(void**)&SDL_WarpMouse, "SDL_WarpMouse");
148         bindFunc(cast(void**)&SDL_CreateCursor, "SDL_CreateCursor");
149         bindFunc(cast(void**)&SDL_SetCursor, "SDL_SetCursor");
150         bindFunc(cast(void**)&SDL_GetCursor, "SDL_GetCursor");
151         bindFunc(cast(void**)&SDL_FreeCursor, "SDL_FreeCursor");
152         bindFunc(cast(void**)&SDL_ShowCursor, "SDL_ShowCursor");
153         // mutex.d
154         bindFunc(cast(void**)&SDL_CreateMutex, "SDL_CreateMutex");
155         bindFunc(cast(void**)&SDL_mutexP, "SDL_mutexP");
156         bindFunc(cast(void**)&SDL_mutexV, "SDL_mutexV");
157         bindFunc(cast(void**)&SDL_DestroyMutex, "SDL_DestroyMutex");
158         bindFunc(cast(void**)&SDL_CreateSemaphore, "SDL_CreateSemaphore");
159         bindFunc(cast(void**)&SDL_DestroySemaphore, "SDL_DestroySemaphore");
160         bindFunc(cast(void**)&SDL_SemWait, "SDL_SemWait");
161         bindFunc(cast(void**)&SDL_SemTryWait, "SDL_SemTryWait");
162         bindFunc(cast(void**)&SDL_SemWaitTimeout, "SDL_SemWaitTimeout");
163         bindFunc(cast(void**)&SDL_SemPost, "SDL_SemPost");
164         bindFunc(cast(void**)&SDL_SemValue, "SDL_SemValue");
165         bindFunc(cast(void**)&SDL_CreateCond, "SDL_CreateCond");
166         bindFunc(cast(void**)&SDL_DestroyCond, "SDL_DestroyCond");
167         bindFunc(cast(void**)&SDL_CondSignal, "SDL_CondSignal");
168         bindFunc(cast(void**)&SDL_CondBroadcast, "SDL_CondBroadcast");
169         bindFunc(cast(void**)&SDL_CondWait, "SDL_CondWait");
170         bindFunc(cast(void**)&SDL_CondWaitTimeout, "SDL_CondWaitTimeout");
171         // rwops.d
172         bindFunc(cast(void**)&SDL_RWFromFile, "SDL_RWFromFile");
173         bindFunc(cast(void**)&SDL_RWFromFP, "SDL_RWFromFP");
174         bindFunc(cast(void**)&SDL_RWFromMem, "SDL_RWFromMem");
175         bindFunc(cast(void**)&SDL_RWFromConstMem, "SDL_RWFromConstMem");
176         bindFunc(cast(void**)&SDL_AllocRW, "SDL_AllocRW");
177         bindFunc(cast(void**)&SDL_FreeRW, "SDL_FreeRW");
178         bindFunc(cast(void**)&SDL_ReadLE16, "SDL_ReadLE16");
179         bindFunc(cast(void**)&SDL_ReadBE16, "SDL_ReadBE16");
180         bindFunc(cast(void**)&SDL_ReadLE32, "SDL_ReadLE32");
181         bindFunc(cast(void**)&SDL_ReadBE32, "SDL_ReadBE32");
182         bindFunc(cast(void**)&SDL_ReadLE64, "SDL_ReadLE64");
183         bindFunc(cast(void**)&SDL_ReadBE64, "SDL_ReadBE64");
184         bindFunc(cast(void**)&SDL_WriteLE16, "SDL_WriteLE16");
185         bindFunc(cast(void**)&SDL_WriteBE16, "SDL_WriteBE16");
186         bindFunc(cast(void**)&SDL_WriteLE32, "SDL_WriteLE32");
187         bindFunc(cast(void**)&SDL_WriteBE32, "SDL_WriteBE32");
188         bindFunc(cast(void**)&SDL_WriteLE64, "SDL_WriteLE64");
189         bindFunc(cast(void**)&SDL_WriteBE64, "SDL_WriteBE64");
190         // sdlversion.d
191         bindFunc(cast(void**)&SDL_Linked_Version, "SDL_Linked_Version");
192         // thread.d
193         bindFunc(cast(void**)&SDL_CreateThread, "SDL_CreateThread");
194         bindFunc(cast(void**)&SDL_ThreadID, "SDL_ThreadID");
195         bindFunc(cast(void**)&SDL_GetThreadID, "SDL_GetThreadID");
196         bindFunc(cast(void**)&SDL_WaitThread, "SDL_WaitThread");
197         bindFunc(cast(void**)&SDL_KillThread, "SDL_KillThread");
198         // timer.d
199         bindFunc(cast(void**)&SDL_GetTicks, "SDL_GetTicks");
200         bindFunc(cast(void**)&SDL_Delay, "SDL_Delay");
201         bindFunc(cast(void**)&SDL_SetTimer, "SDL_SetTimer");
202         bindFunc(cast(void**)&SDL_AddTimer, "SDL_AddTimer");
203         bindFunc(cast(void**)&SDL_RemoveTimer, "SDL_RemoveTimer");
204         // video.d
205         bindFunc(cast(void**)&SDL_VideoInit, "SDL_VideoInit");
206         bindFunc(cast(void**)&SDL_VideoQuit, "SDL_VideoQuit");
207         bindFunc(cast(void**)&SDL_VideoDriverName, "SDL_VideoDriverName");
208         bindFunc(cast(void**)&SDL_GetVideoSurface, "SDL_GetVideoSurface");
209         bindFunc(cast(void**)&SDL_GetVideoInfo, "SDL_GetVideoInfo");
210         bindFunc(cast(void**)&SDL_VideoModeOK, "SDL_VideoModeOK");
211         bindFunc(cast(void**)&SDL_ListModes, "SDL_ListModes");
212         bindFunc(cast(void**)&SDL_SetVideoMode, "SDL_SetVideoMode");
213         bindFunc(cast(void**)&SDL_UpdateRects, "SDL_UpdateRects");
214         bindFunc(cast(void**)&SDL_UpdateRect, "SDL_UpdateRect");
215         bindFunc(cast(void**)&SDL_Flip, "SDL_Flip");
216         bindFunc(cast(void**)&SDL_SetGamma, "SDL_SetGamma");
217         bindFunc(cast(void**)&SDL_SetGammaRamp, "SDL_SetGammaRamp");
218         bindFunc(cast(void**)&SDL_GetGammaRamp, "SDL_GetGammaRamp");
219         bindFunc(cast(void**)&SDL_SetColors, "SDL_SetColors");
220         bindFunc(cast(void**)&SDL_SetPalette, "SDL_SetPalette");
221         bindFunc(cast(void**)&SDL_MapRGB, "SDL_MapRGB");
222         bindFunc(cast(void**)&SDL_MapRGBA, "SDL_MapRGBA");
223         bindFunc(cast(void**)&SDL_GetRGB, "SDL_GetRGB");
224         bindFunc(cast(void**)&SDL_GetRGBA, "SDL_GetRGBA");
225         bindFunc(cast(void**)&SDL_CreateRGBSurface, "SDL_CreateRGBSurface");
226         bindFunc(cast(void**)&SDL_CreateRGBSurfaceFrom, "SDL_CreateRGBSurfaceFrom");
227         bindFunc(cast(void**)&SDL_FreeSurface, "SDL_FreeSurface");
228         bindFunc(cast(void**)&SDL_LockSurface, "SDL_LockSurface");
229         bindFunc(cast(void**)&SDL_UnlockSurface, "SDL_UnlockSurface");
230         bindFunc(cast(void**)&SDL_LoadBMP_RW, "SDL_LoadBMP_RW");
231         bindFunc(cast(void**)&SDL_SaveBMP_RW, "SDL_SaveBMP_RW");
232         bindFunc(cast(void**)&SDL_SetColorKey, "SDL_SetColorKey");
233         bindFunc(cast(void**)&SDL_SetAlpha, "SDL_SetAlpha");
234         bindFunc(cast(void**)&SDL_SetClipRect, "SDL_SetClipRect");
235         bindFunc(cast(void**)&SDL_GetClipRect, "SDL_GetClipRect");
236         bindFunc(cast(void**)&SDL_ConvertSurface, "SDL_ConvertSurface");
237         bindFunc(cast(void**)&SDL_UpperBlit, "SDL_UpperBlit");
238         bindFunc(cast(void**)&SDL_LowerBlit, "SDL_LowerBlit");
239         bindFunc(cast(void**)&SDL_FillRect, "SDL_FillRect");
240         bindFunc(cast(void**)&SDL_DisplayFormat, "SDL_DisplayFormat");
241         bindFunc(cast(void**)&SDL_DisplayFormatAlpha, "SDL_DisplayFormatAlpha");
242         bindFunc(cast(void**)&SDL_CreateYUVOverlay, "SDL_CreateYUVOverlay");
243         bindFunc(cast(void**)&SDL_LockYUVOverlay, "SDL_LockYUVOverlay");
244         bindFunc(cast(void**)&SDL_UnlockYUVOverlay, "SDL_UnlockYUVOverlay");
245         bindFunc(cast(void**)&SDL_DisplayYUVOverlay, "SDL_DisplayYUVOverlay");
246         bindFunc(cast(void**)&SDL_FreeYUVOverlay, "SDL_FreeYUVOverlay");
247         bindFunc(cast(void**)&SDL_GL_LoadLibrary, "SDL_GL_LoadLibrary");
248         bindFunc(cast(void**)&SDL_GL_GetProcAddress, "SDL_GL_GetProcAddress");
249         bindFunc(cast(void**)&SDL_GL_SetAttribute, "SDL_GL_SetAttribute");
250         bindFunc(cast(void**)&SDL_GL_GetAttribute, "SDL_GL_GetAttribute");
251         bindFunc(cast(void**)&SDL_GL_SwapBuffers, "SDL_GL_SwapBuffers");
252         bindFunc(cast(void**)&SDL_GL_UpdateRects, "SDL_GL_UpdateRects");
253         bindFunc(cast(void**)&SDL_GL_Lock, "SDL_GL_Lock");
254         bindFunc(cast(void**)&SDL_GL_Unlock, "SDL_GL_Unlock");
255         bindFunc(cast(void**)&SDL_WM_SetCaption, "SDL_WM_SetCaption");
256         bindFunc(cast(void**)&SDL_WM_GetCaption, "SDL_WM_GetCaption");
257         bindFunc(cast(void**)&SDL_WM_SetIcon, "SDL_WM_SetIcon");
258         bindFunc(cast(void**)&SDL_WM_IconifyWindow, "SDL_WM_IconifyWindow");
259         bindFunc(cast(void**)&SDL_WM_ToggleFullScreen, "SDL_WM_ToggleFullScreen");
260         bindFunc(cast(void**)&SDL_WM_GrabInput, "SDL_WM_GrabInput");
261         // sdl.d
262         bindFunc(cast(void**)&SDL_Init, "SDL_Init");
263         bindFunc(cast(void**)&SDL_InitSubSystem, "SDL_InitSubSystem");
264         bindFunc(cast(void**)&SDL_QuitSubSystem, "SDL_QuitSubSystem");
265         bindFunc(cast(void**)&SDL_WasInit, "SDL_WasInit");
266         bindFunc(cast(void**)&SDL_Quit, "SDL_Quit");
267 
268         // syswm.d
269         version(Windows) bindFunc(cast(void**)&SDL_GetWMInfo, "SDL_GetWMInfo");
270     }
271 }
272 
273 DerelictSDLLoader DerelictSDL;
274 
275 static this()
276 {
277     DerelictSDL = new DerelictSDLLoader();
278 }
279 
280 static ~this()
281 {
282     if(SharedLibLoader.isAutoUnloadEnabled())
283         DerelictSDL.unload();
284 }