Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
314 lines (273 loc) · 7.34 KB

SDL_compat.c

File metadata and controls

314 lines (273 loc) · 7.34 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* This file contains functions for backwards compatibility with SDL 1.2 */
#include "SDL.h"
#include "video/SDL_sysvideo.h"
static SDL_WindowID window;
static char *wm_title;
char *
May 29, 2006
May 29, 2006
35
SDL_AudioDriverName(char *namebuf, int maxlen)
36
{
May 29, 2006
May 29, 2006
37
const char *name = SDL_GetCurrentAudioDriver();
38
if (name) {
May 29, 2006
May 29, 2006
39
SDL_strlcpy(namebuf, name, maxlen);
40
41
42
43
44
45
return namebuf;
}
return NULL;
}
char *
May 29, 2006
May 29, 2006
46
SDL_VideoDriverName(char *namebuf, int maxlen)
47
{
May 29, 2006
May 29, 2006
48
const char *name = SDL_GetCurrentVideoDriver();
49
if (name) {
May 29, 2006
May 29, 2006
50
SDL_strlcpy(namebuf, name, maxlen);
51
52
53
54
55
56
return namebuf;
}
return NULL;
}
int
May 29, 2006
May 29, 2006
57
SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
58
59
60
{
int i, actual_bpp = 0;
May 29, 2006
May 29, 2006
61
if (!SDL_GetVideoDevice()) {
62
63
64
65
return 0;
}
if (!(flags & SDL_FULLSCREEN)) {
May 29, 2006
May 29, 2006
66
return SDL_BITSPERPIXEL(SDL_GetDesktopDisplayMode()->format);
67
68
}
May 29, 2006
May 29, 2006
69
70
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
71
72
73
74
if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) {
if (!mode->format) {
return bpp;
}
May 29, 2006
May 29, 2006
75
76
if (SDL_BITSPERPIXEL(mode->format) >= bpp) {
actual_bpp = SDL_BITSPERPIXEL(mode->format);
77
78
79
80
81
82
83
}
}
}
return actual_bpp;
}
SDL_Rect **
May 29, 2006
May 29, 2006
84
SDL_ListModes(SDL_PixelFormat * format, Uint32 flags)
85
86
87
88
{
int i, nmodes;
SDL_Rect **modes;
May 29, 2006
May 29, 2006
89
if (!SDL_GetVideoDevice()) {
90
91
92
93
94
95
96
97
98
return NULL;
}
if (!(flags & SDL_FULLSCREEN)) {
return (SDL_Rect **) (-1);
}
/* Memory leak, but this is a compatibility function, who cares? */
nmodes = 0;
May 29, 2006
May 29, 2006
99
100
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
101
102
103
if (!mode->w || !mode->h) {
return (SDL_Rect **) (-1);
}
May 29, 2006
May 29, 2006
104
if (SDL_BITSPERPIXEL(mode->format) != format->BitsPerPixel) {
105
106
107
108
109
110
111
continue;
}
if (nmodes > 0 && modes[nmodes - 1]->w == mode->w
&& modes[nmodes - 1]->h == mode->h) {
continue;
}
May 29, 2006
May 29, 2006
112
modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
113
114
115
if (!modes) {
return NULL;
}
May 29, 2006
May 29, 2006
116
modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
if (!modes[nmodes]) {
return NULL;
}
modes[nmodes]->x = 0;
modes[nmodes]->y = 0;
modes[nmodes]->w = mode->w;
modes[nmodes]->h = mode->h;
++nmodes;
}
if (modes) {
modes[nmodes] = NULL;
}
return modes;
}
SDL_Surface *
May 29, 2006
May 29, 2006
133
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
134
135
136
137
138
139
140
{
SDL_DisplayMode mode;
int i;
Uint32 window_flags;
Uint32 desktop_format;
Uint32 desired_format;
May 29, 2006
May 29, 2006
141
142
if (!SDL_GetVideoDevice()) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
143
144
145
146
147
return NULL;
}
}
/* Destroy existing window */
May 29, 2006
May 29, 2006
148
SDL_DestroyWindow(window);
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* Create a new window */
window_flags = SDL_WINDOW_SHOWN;
if (flags & SDL_FULLSCREEN) {
window_flags |= SDL_WINDOW_FULLSCREEN;
}
if (flags & SDL_OPENGL) {
window_flags |= SDL_WINDOW_OPENGL;
}
if (flags & SDL_RESIZABLE) {
window_flags |= SDL_WINDOW_RESIZABLE;
}
if (flags & SDL_NOFRAME) {
window_flags |= SDL_WINDOW_BORDERLESS;
}
May 29, 2006
May 29, 2006
164
window = SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags);
165
166
167
168
169
if (!window) {
return NULL;
}
/* Set up the desired display mode */
May 29, 2006
May 29, 2006
170
desktop_format = SDL_GetDesktopDisplayMode()->format;
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
if ((bpp == SDL_BITSPERPIXEL(desktop_format)) ||
(desktop_format && (flags & SDL_ANYFORMAT))) {
desired_format = desktop_format;
} else {
switch (bpp) {
case 8:
desired_format = SDL_PixelFormat_Index8;
break;
case 15:
desired_format = SDL_PixelFormat_RGB555;
break;
case 16:
desired_format = SDL_PixelFormat_RGB565;
break;
case 24:
desired_format = SDL_PixelFormat_RGB24;
break;
case 32:
desired_format = SDL_PixelFormat_RGB888;
break;
default:
May 29, 2006
May 29, 2006
192
SDL_SetError("Unsupported bpp in SDL_SetVideoMode()");
193
194
195
196
197
198
199
200
201
202
return NULL;
}
}
mode.format = desired_format;
mode.w = width;
mode.h = height;
mode.refresh_rate = 0;
/* Set the desired display mode */
if (flags & SDL_FULLSCREEN) {
May 29, 2006
May 29, 2006
203
if (!SDL_GetClosestDisplayMode(&mode, &mode)) {
204
205
206
return NULL;
}
} else {
May 29, 2006
May 29, 2006
207
mode = *SDL_GetDesktopDisplayMode();
208
}
May 29, 2006
May 29, 2006
209
if (SDL_SetDisplayMode(&mode) < 0) {
210
211
212
213
return NULL;
}
/* Create the display surface */
May 29, 2006
May 29, 2006
214
return SDL_CreateWindowSurface(window, desired_format, flags);
215
216
217
}
SDL_Surface *
May 29, 2006
May 29, 2006
218
SDL_GetVideoSurface(void)
219
{
May 29, 2006
May 29, 2006
220
SDL_VideoDevice *_this = SDL_GetVideoDevice();
221
222
223
224
225
return SDL_VideoSurface;
}
void
May 29, 2006
May 29, 2006
226
SDL_WM_SetCaption(const char *title, const char *icon)
227
228
{
if (wm_title) {
May 29, 2006
May 29, 2006
229
SDL_free(wm_title);
230
} else {
May 29, 2006
May 29, 2006
231
wm_title = SDL_strdup(title);
232
}
May 29, 2006
May 29, 2006
233
SDL_SetWindowTitle(window, wm_title);
234
235
236
}
void
May 29, 2006
May 29, 2006
237
SDL_WM_GetCaption(char **title, char **icon)
238
239
240
241
242
243
244
245
246
247
{
if (title) {
*title = wm_title;
}
if (icon) {
*icon = "";
}
}
void
May 29, 2006
May 29, 2006
248
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
249
250
251
252
253
{
/* FIXME */
}
int
May 29, 2006
May 29, 2006
254
SDL_WM_IconifyWindow(void)
255
{
May 29, 2006
May 29, 2006
256
SDL_MinimizeWindow(window);
257
258
259
}
int
May 29, 2006
May 29, 2006
260
SDL_WM_ToggleFullScreen(SDL_Surface * surface)
261
262
263
264
265
{
return 0;
}
SDL_GrabMode
May 29, 2006
May 29, 2006
266
SDL_WM_GrabInput(SDL_GrabMode mode)
267
268
{
if (mode != SDL_GRAB_QUERY) {
May 29, 2006
May 29, 2006
269
SDL_SetWindowGrab(window, mode);
270
}
May 29, 2006
May 29, 2006
271
return (SDL_GrabMode) SDL_GetWindowGrab(window);
272
273
274
}
Uint8
May 29, 2006
May 29, 2006
275
SDL_GetAppState(void)
276
277
278
279
{
Uint8 state = 0;
Uint32 flags = 0;
May 29, 2006
May 29, 2006
280
flags = SDL_GetWindowFlags(window);
281
282
283
284
285
286
287
288
289
290
291
292
293
if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
state |= SDL_APPACTIVE;
}
if (flags & SDL_WINDOW_KEYBOARD_FOCUS) {
state |= SDL_APPINPUTFOCUS;
}
if (flags & SDL_WINDOW_MOUSE_FOCUS) {
state |= SDL_APPMOUSEFOCUS;
}
return state;
}
const SDL_version *
May 29, 2006
May 29, 2006
294
SDL_Linked_Version(void)
295
296
{
static SDL_version version;
May 29, 2006
May 29, 2006
297
SDL_VERSION(&version);
298
299
300
301
return &version;
}
int
May 29, 2006
May 29, 2006
302
303
SDL_SetPalette(SDL_Surface * surface, int flags, SDL_Color * colors,
int firstcolor, int ncolors)
304
{
May 29, 2006
May 29, 2006
305
SDL_SetColors(surface, colors, firstcolor, ncolors);
306
307
308
}
int
May 29, 2006
May 29, 2006
309
SDL_GetWMInfo(SDL_SysWMinfo * info)
310
{
May 29, 2006
May 29, 2006
311
return SDL_GetWindowWMInfo(window, info);
312
313
314
}
/* vi: set ts=4 sw=4 expandtab: */