Mercurial > sdl-ios-xcode
comparison src/SDL_compat.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 1fddae038bc8 |
children | 9857d21967bb |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
30 | 30 |
31 static SDL_WindowID window; | 31 static SDL_WindowID window; |
32 static char *wm_title; | 32 static char *wm_title; |
33 | 33 |
34 char * | 34 char * |
35 SDL_AudioDriverName (char *namebuf, int maxlen) | 35 SDL_AudioDriverName(char *namebuf, int maxlen) |
36 { | 36 { |
37 const char *name = SDL_GetCurrentAudioDriver (); | 37 const char *name = SDL_GetCurrentAudioDriver(); |
38 if (name) { | 38 if (name) { |
39 SDL_strlcpy (namebuf, name, maxlen); | 39 SDL_strlcpy(namebuf, name, maxlen); |
40 return namebuf; | 40 return namebuf; |
41 } | 41 } |
42 return NULL; | 42 return NULL; |
43 } | 43 } |
44 | 44 |
45 char * | 45 char * |
46 SDL_VideoDriverName (char *namebuf, int maxlen) | 46 SDL_VideoDriverName(char *namebuf, int maxlen) |
47 { | 47 { |
48 const char *name = SDL_GetCurrentVideoDriver (); | 48 const char *name = SDL_GetCurrentVideoDriver(); |
49 if (name) { | 49 if (name) { |
50 SDL_strlcpy (namebuf, name, maxlen); | 50 SDL_strlcpy(namebuf, name, maxlen); |
51 return namebuf; | 51 return namebuf; |
52 } | 52 } |
53 return NULL; | 53 return NULL; |
54 } | 54 } |
55 | 55 |
56 int | 56 int |
57 SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags) | 57 SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags) |
58 { | 58 { |
59 int i, actual_bpp = 0; | 59 int i, actual_bpp = 0; |
60 | 60 |
61 if (!SDL_GetVideoDevice ()) { | 61 if (!SDL_GetVideoDevice()) { |
62 return 0; | 62 return 0; |
63 } | 63 } |
64 | 64 |
65 if (!(flags & SDL_FULLSCREEN)) { | 65 if (!(flags & SDL_FULLSCREEN)) { |
66 return SDL_BITSPERPIXEL (SDL_GetDesktopDisplayMode ()->format); | 66 return SDL_BITSPERPIXEL(SDL_GetDesktopDisplayMode()->format); |
67 } | 67 } |
68 | 68 |
69 for (i = 0; i < SDL_GetNumDisplayModes (); ++i) { | 69 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { |
70 const SDL_DisplayMode *mode = SDL_GetDisplayMode (i); | 70 const SDL_DisplayMode *mode = SDL_GetDisplayMode(i); |
71 if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) { | 71 if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) { |
72 if (!mode->format) { | 72 if (!mode->format) { |
73 return bpp; | 73 return bpp; |
74 } | 74 } |
75 if (SDL_BITSPERPIXEL (mode->format) >= bpp) { | 75 if (SDL_BITSPERPIXEL(mode->format) >= bpp) { |
76 actual_bpp = SDL_BITSPERPIXEL (mode->format); | 76 actual_bpp = SDL_BITSPERPIXEL(mode->format); |
77 } | 77 } |
78 } | 78 } |
79 } | 79 } |
80 return actual_bpp; | 80 return actual_bpp; |
81 } | 81 } |
82 | 82 |
83 SDL_Rect ** | 83 SDL_Rect ** |
84 SDL_ListModes (SDL_PixelFormat * format, Uint32 flags) | 84 SDL_ListModes(SDL_PixelFormat * format, Uint32 flags) |
85 { | 85 { |
86 int i, nmodes; | 86 int i, nmodes; |
87 SDL_Rect **modes; | 87 SDL_Rect **modes; |
88 | 88 |
89 if (!SDL_GetVideoDevice ()) { | 89 if (!SDL_GetVideoDevice()) { |
90 return NULL; | 90 return NULL; |
91 } | 91 } |
92 | 92 |
93 if (!(flags & SDL_FULLSCREEN)) { | 93 if (!(flags & SDL_FULLSCREEN)) { |
94 return (SDL_Rect **) (-1); | 94 return (SDL_Rect **) (-1); |
95 } | 95 } |
96 | 96 |
97 /* Memory leak, but this is a compatibility function, who cares? */ | 97 /* Memory leak, but this is a compatibility function, who cares? */ |
98 nmodes = 0; | 98 nmodes = 0; |
99 for (i = 0; i < SDL_GetNumDisplayModes (); ++i) { | 99 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { |
100 const SDL_DisplayMode *mode = SDL_GetDisplayMode (i); | 100 const SDL_DisplayMode *mode = SDL_GetDisplayMode(i); |
101 if (!mode->w || !mode->h) { | 101 if (!mode->w || !mode->h) { |
102 return (SDL_Rect **) (-1); | 102 return (SDL_Rect **) (-1); |
103 } | 103 } |
104 if (SDL_BITSPERPIXEL (mode->format) != format->BitsPerPixel) { | 104 if (SDL_BITSPERPIXEL(mode->format) != format->BitsPerPixel) { |
105 continue; | 105 continue; |
106 } | 106 } |
107 if (nmodes > 0 && modes[nmodes - 1]->w == mode->w | 107 if (nmodes > 0 && modes[nmodes - 1]->w == mode->w |
108 && modes[nmodes - 1]->h == mode->h) { | 108 && modes[nmodes - 1]->h == mode->h) { |
109 continue; | 109 continue; |
110 } | 110 } |
111 | 111 |
112 modes = SDL_realloc (modes, (nmodes + 2) * sizeof (*modes)); | 112 modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes)); |
113 if (!modes) { | 113 if (!modes) { |
114 return NULL; | 114 return NULL; |
115 } | 115 } |
116 modes[nmodes] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect)); | 116 modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect)); |
117 if (!modes[nmodes]) { | 117 if (!modes[nmodes]) { |
118 return NULL; | 118 return NULL; |
119 } | 119 } |
120 modes[nmodes]->x = 0; | 120 modes[nmodes]->x = 0; |
121 modes[nmodes]->y = 0; | 121 modes[nmodes]->y = 0; |
128 } | 128 } |
129 return modes; | 129 return modes; |
130 } | 130 } |
131 | 131 |
132 SDL_Surface * | 132 SDL_Surface * |
133 SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) | 133 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) |
134 { | 134 { |
135 SDL_DisplayMode mode; | 135 SDL_DisplayMode mode; |
136 int i; | 136 int i; |
137 Uint32 window_flags; | 137 Uint32 window_flags; |
138 Uint32 desktop_format; | 138 Uint32 desktop_format; |
139 Uint32 desired_format; | 139 Uint32 desired_format; |
140 | 140 |
141 if (!SDL_GetVideoDevice ()) { | 141 if (!SDL_GetVideoDevice()) { |
142 if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { | 142 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { |
143 return NULL; | 143 return NULL; |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 /* Destroy existing window */ | 147 /* Destroy existing window */ |
148 SDL_DestroyWindow (window); | 148 SDL_DestroyWindow(window); |
149 | 149 |
150 /* Create a new window */ | 150 /* Create a new window */ |
151 window_flags = SDL_WINDOW_SHOWN; | 151 window_flags = SDL_WINDOW_SHOWN; |
152 if (flags & SDL_FULLSCREEN) { | 152 if (flags & SDL_FULLSCREEN) { |
153 window_flags |= SDL_WINDOW_FULLSCREEN; | 153 window_flags |= SDL_WINDOW_FULLSCREEN; |
159 window_flags |= SDL_WINDOW_RESIZABLE; | 159 window_flags |= SDL_WINDOW_RESIZABLE; |
160 } | 160 } |
161 if (flags & SDL_NOFRAME) { | 161 if (flags & SDL_NOFRAME) { |
162 window_flags |= SDL_WINDOW_BORDERLESS; | 162 window_flags |= SDL_WINDOW_BORDERLESS; |
163 } | 163 } |
164 window = SDL_CreateWindow (wm_title, 0, 0, width, height, window_flags); | 164 window = SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags); |
165 if (!window) { | 165 if (!window) { |
166 return NULL; | 166 return NULL; |
167 } | 167 } |
168 | 168 |
169 /* Set up the desired display mode */ | 169 /* Set up the desired display mode */ |
170 desktop_format = SDL_GetDesktopDisplayMode ()->format; | 170 desktop_format = SDL_GetDesktopDisplayMode()->format; |
171 if ((bpp == SDL_BITSPERPIXEL(desktop_format)) || | 171 if ((bpp == SDL_BITSPERPIXEL(desktop_format)) || |
172 (desktop_format && (flags & SDL_ANYFORMAT))) { | 172 (desktop_format && (flags & SDL_ANYFORMAT))) { |
173 desired_format = desktop_format; | 173 desired_format = desktop_format; |
174 } else { | 174 } else { |
175 switch (bpp) { | 175 switch (bpp) { |
187 break; | 187 break; |
188 case 32: | 188 case 32: |
189 desired_format = SDL_PixelFormat_RGB888; | 189 desired_format = SDL_PixelFormat_RGB888; |
190 break; | 190 break; |
191 default: | 191 default: |
192 SDL_SetError ("Unsupported bpp in SDL_SetVideoMode()"); | 192 SDL_SetError("Unsupported bpp in SDL_SetVideoMode()"); |
193 return NULL; | 193 return NULL; |
194 } | 194 } |
195 } | 195 } |
196 mode.format = desired_format; | 196 mode.format = desired_format; |
197 mode.w = width; | 197 mode.w = width; |
198 mode.h = height; | 198 mode.h = height; |
199 mode.refresh_rate = 0; | 199 mode.refresh_rate = 0; |
200 | 200 |
201 /* Set the desired display mode */ | 201 /* Set the desired display mode */ |
202 if (flags & SDL_FULLSCREEN) { | 202 if (flags & SDL_FULLSCREEN) { |
203 if (!SDL_GetClosestDisplayMode (&mode, &mode)) { | 203 if (!SDL_GetClosestDisplayMode(&mode, &mode)) { |
204 return NULL; | 204 return NULL; |
205 } | 205 } |
206 } else { | 206 } else { |
207 mode = *SDL_GetDesktopDisplayMode (); | 207 mode = *SDL_GetDesktopDisplayMode(); |
208 } | 208 } |
209 if (SDL_SetDisplayMode (&mode) < 0) { | 209 if (SDL_SetDisplayMode(&mode) < 0) { |
210 return NULL; | 210 return NULL; |
211 } | 211 } |
212 | 212 |
213 /* Create the display surface */ | 213 /* Create the display surface */ |
214 return SDL_CreateWindowSurface (window, desired_format, flags); | 214 return SDL_CreateWindowSurface(window, desired_format, flags); |
215 } | 215 } |
216 | 216 |
217 SDL_Surface * | 217 SDL_Surface * |
218 SDL_GetVideoSurface (void) | 218 SDL_GetVideoSurface(void) |
219 { | 219 { |
220 SDL_VideoDevice *_this = SDL_GetVideoDevice (); | 220 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
221 | 221 |
222 return SDL_VideoSurface; | 222 return SDL_VideoSurface; |
223 } | 223 } |
224 | 224 |
225 void | 225 void |
226 SDL_WM_SetCaption (const char *title, const char *icon) | 226 SDL_WM_SetCaption(const char *title, const char *icon) |
227 { | 227 { |
228 if (wm_title) { | 228 if (wm_title) { |
229 SDL_free (wm_title); | 229 SDL_free(wm_title); |
230 } else { | 230 } else { |
231 wm_title = SDL_strdup (title); | 231 wm_title = SDL_strdup(title); |
232 } | 232 } |
233 SDL_SetWindowTitle (window, wm_title); | 233 SDL_SetWindowTitle(window, wm_title); |
234 } | 234 } |
235 | 235 |
236 void | 236 void |
237 SDL_WM_GetCaption (char **title, char **icon) | 237 SDL_WM_GetCaption(char **title, char **icon) |
238 { | 238 { |
239 if (title) { | 239 if (title) { |
240 *title = wm_title; | 240 *title = wm_title; |
241 } | 241 } |
242 if (icon) { | 242 if (icon) { |
243 *icon = ""; | 243 *icon = ""; |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void | 247 void |
248 SDL_WM_SetIcon (SDL_Surface * icon, Uint8 * mask) | 248 SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) |
249 { | 249 { |
250 /* FIXME */ | 250 /* FIXME */ |
251 } | 251 } |
252 | 252 |
253 int | 253 int |
254 SDL_WM_IconifyWindow (void) | 254 SDL_WM_IconifyWindow(void) |
255 { | 255 { |
256 SDL_MinimizeWindow (window); | 256 SDL_MinimizeWindow(window); |
257 } | 257 } |
258 | 258 |
259 int | 259 int |
260 SDL_WM_ToggleFullScreen (SDL_Surface * surface) | 260 SDL_WM_ToggleFullScreen(SDL_Surface * surface) |
261 { | 261 { |
262 return 0; | 262 return 0; |
263 } | 263 } |
264 | 264 |
265 SDL_GrabMode | 265 SDL_GrabMode |
266 SDL_WM_GrabInput (SDL_GrabMode mode) | 266 SDL_WM_GrabInput(SDL_GrabMode mode) |
267 { | 267 { |
268 if (mode != SDL_GRAB_QUERY) { | 268 if (mode != SDL_GRAB_QUERY) { |
269 SDL_SetWindowGrab (window, mode); | 269 SDL_SetWindowGrab(window, mode); |
270 } | 270 } |
271 return (SDL_GrabMode) SDL_GetWindowGrab (window); | 271 return (SDL_GrabMode) SDL_GetWindowGrab(window); |
272 } | 272 } |
273 | 273 |
274 Uint8 | 274 Uint8 |
275 SDL_GetAppState (void) | 275 SDL_GetAppState(void) |
276 { | 276 { |
277 Uint8 state = 0; | 277 Uint8 state = 0; |
278 Uint32 flags = 0; | 278 Uint32 flags = 0; |
279 | 279 |
280 flags = SDL_GetWindowFlags (window); | 280 flags = SDL_GetWindowFlags(window); |
281 if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) { | 281 if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) { |
282 state |= SDL_APPACTIVE; | 282 state |= SDL_APPACTIVE; |
283 } | 283 } |
284 if (flags & SDL_WINDOW_KEYBOARD_FOCUS) { | 284 if (flags & SDL_WINDOW_KEYBOARD_FOCUS) { |
285 state |= SDL_APPINPUTFOCUS; | 285 state |= SDL_APPINPUTFOCUS; |
289 } | 289 } |
290 return state; | 290 return state; |
291 } | 291 } |
292 | 292 |
293 const SDL_version * | 293 const SDL_version * |
294 SDL_Linked_Version (void) | 294 SDL_Linked_Version(void) |
295 { | 295 { |
296 static SDL_version version; | 296 static SDL_version version; |
297 SDL_VERSION (&version); | 297 SDL_VERSION(&version); |
298 return &version; | 298 return &version; |
299 } | 299 } |
300 | 300 |
301 int | 301 int |
302 SDL_SetPalette (SDL_Surface * surface, int flags, SDL_Color * colors, | 302 SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors, |
303 int firstcolor, int ncolors) | 303 int firstcolor, int ncolors) |
304 { | 304 { |
305 SDL_SetColors (surface, colors, firstcolor, ncolors); | 305 SDL_SetColors(surface, colors, firstcolor, ncolors); |
306 } | 306 } |
307 | 307 |
308 int | 308 int |
309 SDL_GetWMInfo (SDL_SysWMinfo * info) | 309 SDL_GetWMInfo(SDL_SysWMinfo * info) |
310 { | 310 { |
311 return SDL_GetWindowWMInfo (window, info); | 311 return SDL_GetWindowWMInfo(window, info); |
312 } | 312 } |
313 | 313 |
314 /* vi: set ts=4 sw=4 expandtab: */ | 314 /* vi: set ts=4 sw=4 expandtab: */ |