(svn r27953) -Cleanup: Adjust other languages for r27952
[openttd.git] / src / sdl.cpp
blob79e9ed2927410b570b6a7a1f3ac21f8e1fff3cc1
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file sdl.cpp Implementation of SDL support. */
12 #include "stdafx.h"
14 #ifdef WITH_SDL
16 #include "sdl.h"
17 #include <SDL.h>
19 /** Number of users of the SDL library. */
20 static int _sdl_usage;
22 #ifdef DYNAMICALLY_LOADED_SDL
24 #include "os/windows/win32.h"
26 #define M(x) x "\0"
27 static const char sdl_files[] =
28 M("sdl.dll")
29 M("SDL_Init")
30 M("SDL_InitSubSystem")
31 M("SDL_GetError")
32 M("SDL_QuitSubSystem")
33 M("SDL_UpdateRect")
34 M("SDL_UpdateRects")
35 M("SDL_SetColors")
36 M("SDL_WM_SetCaption")
37 M("SDL_ShowCursor")
38 M("SDL_FreeSurface")
39 M("SDL_PollEvent")
40 M("SDL_WarpMouse")
41 M("SDL_GetTicks")
42 M("SDL_OpenAudio")
43 M("SDL_PauseAudio")
44 M("SDL_CloseAudio")
45 M("SDL_LockSurface")
46 M("SDL_UnlockSurface")
47 M("SDL_GetModState")
48 M("SDL_Delay")
49 M("SDL_Quit")
50 M("SDL_SetVideoMode")
51 M("SDL_EnableKeyRepeat")
52 M("SDL_EnableUNICODE")
53 M("SDL_VideoDriverName")
54 M("SDL_ListModes")
55 M("SDL_GetKeyState")
56 M("SDL_LoadBMP_RW")
57 M("SDL_RWFromFile")
58 M("SDL_SetColorKey")
59 M("SDL_WM_SetIcon")
60 M("SDL_MapRGB")
61 M("SDL_VideoModeOK")
62 M("SDL_Linked_Version")
63 M("")
65 #undef M
67 SDLProcs sdl_proc;
69 static const char *LoadSdlDLL()
71 if (sdl_proc.SDL_Init != NULL) {
72 return NULL;
74 if (!LoadLibraryList((Function *)(void *)&sdl_proc, sdl_files)) {
75 return "Unable to load sdl.dll";
77 return NULL;
80 #endif /* DYNAMICALLY_LOADED_SDL */
82 #include "safeguards.h"
84 /**
85 * Open the SDL library.
86 * @param x The subsystem to load.
88 const char *SdlOpen(uint32 x)
90 #ifdef DYNAMICALLY_LOADED_SDL
92 const char *s = LoadSdlDLL();
93 if (s != NULL) return s;
95 #endif
96 if (_sdl_usage++ == 0) {
97 if (SDL_CALL SDL_Init(x | SDL_INIT_NOPARACHUTE) == -1) return SDL_CALL SDL_GetError();
98 } else if (x != 0) {
99 if (SDL_CALL SDL_InitSubSystem(x) == -1) return SDL_CALL SDL_GetError();
102 return NULL;
106 * Close the SDL library.
107 * @param x The subsystem to close.
109 void SdlClose(uint32 x)
111 if (x != 0) {
112 SDL_CALL SDL_QuitSubSystem(x);
114 if (--_sdl_usage == 0) {
115 SDL_CALL SDL_Quit();
119 #endif