2
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 Sam Lantinga
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "SDL_config.h"
24
/* This file contains functions for backwards compatibility with SDL 1.2 */
28
#include "video/SDL_sysvideo.h"
31
static SDL_WindowID window;
32
static char *wm_title;
35
SDL_AudioDriverName (char *namebuf, int maxlen)
37
const char *name = SDL_GetCurrentAudioDriver ();
39
SDL_strlcpy (namebuf, name, maxlen);
46
SDL_VideoDriverName (char *namebuf, int maxlen)
48
const char *name = SDL_GetCurrentVideoDriver ();
50
SDL_strlcpy (namebuf, name, maxlen);
57
SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags)
59
int i, actual_bpp = 0;
61
if (!SDL_GetVideoDevice ()) {
65
if (!(flags & SDL_FULLSCREEN)) {
66
return SDL_BITSPERPIXEL (SDL_GetDesktopDisplayMode ()->format);
69
for (i = 0; i < SDL_GetNumDisplayModes (); ++i) {
70
const SDL_DisplayMode *mode = SDL_GetDisplayMode (i);
71
if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) {
75
if (SDL_BITSPERPIXEL (mode->format) >= bpp) {
76
actual_bpp = SDL_BITSPERPIXEL (mode->format);
84
SDL_ListModes (SDL_PixelFormat * format, Uint32 flags)
89
if (!SDL_GetVideoDevice ()) {
93
if (!(flags & SDL_FULLSCREEN)) {
94
return (SDL_Rect **) (-1);
97
/* Memory leak, but this is a compatibility function, who cares? */
99
for (i = 0; i < SDL_GetNumDisplayModes (); ++i) {
100
const SDL_DisplayMode *mode = SDL_GetDisplayMode (i);
101
if (!mode->w || !mode->h) {
102
return (SDL_Rect **) (-1);
104
if (SDL_BITSPERPIXEL (mode->format) != format->BitsPerPixel) {
107
if (nmodes > 0 && modes[nmodes - 1]->w == mode->w
108
&& modes[nmodes - 1]->h == mode->h) {
112
modes = SDL_realloc (modes, (nmodes + 2) * sizeof (*modes));
116
modes[nmodes] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
117
if (!modes[nmodes]) {
120
modes[nmodes]->x = 0;
121
modes[nmodes]->y = 0;
122
modes[nmodes]->w = mode->w;
123
modes[nmodes]->h = mode->h;
127
modes[nmodes] = NULL;
133
SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
135
SDL_DisplayMode mode;
138
Uint32 desktop_format;
139
Uint32 desired_format;
141
if (!SDL_GetVideoDevice ()) {
142
if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
147
/* Destroy existing window */
148
SDL_DestroyWindow (window);
150
/* Create a new window */
151
window_flags = SDL_WINDOW_SHOWN;
152
if (flags & SDL_FULLSCREEN) {
153
window_flags |= SDL_WINDOW_FULLSCREEN;
155
if (flags & SDL_OPENGL) {
156
window_flags |= SDL_WINDOW_OPENGL;
158
if (flags & SDL_RESIZABLE) {
159
window_flags |= SDL_WINDOW_RESIZABLE;
161
if (flags & SDL_NOFRAME) {
162
window_flags |= SDL_WINDOW_BORDERLESS;
164
window = SDL_CreateWindow (wm_title, 0, 0, width, height, window_flags);
169
/* Set up the desired display mode */
170
desktop_format = SDL_GetDesktopDisplayMode ()->format;
171
if ((bpp == SDL_BITSPERPIXEL(desktop_format)) ||
172
(desktop_format && (flags & SDL_ANYFORMAT))) {
173
desired_format = desktop_format;
177
desired_format = SDL_PixelFormat_Index8;
180
desired_format = SDL_PixelFormat_RGB555;
183
desired_format = SDL_PixelFormat_RGB565;
186
desired_format = SDL_PixelFormat_RGB24;
189
desired_format = SDL_PixelFormat_RGB888;
192
SDL_SetError ("Unsupported bpp in SDL_SetVideoMode()");
196
mode.format = desired_format;
199
mode.refresh_rate = 0;
201
/* Set the desired display mode */
202
if (flags & SDL_FULLSCREEN) {
203
if (!SDL_GetClosestDisplayMode (&mode, &mode)) {
207
mode = *SDL_GetDesktopDisplayMode ();
209
if (SDL_SetDisplayMode (&mode) < 0) {
213
/* Create the display surface */
214
return SDL_CreateWindowSurface (window, desired_format, flags);
218
SDL_GetVideoSurface (void)
220
SDL_VideoDevice *_this = SDL_GetVideoDevice ();
222
return SDL_VideoSurface;
226
SDL_WM_SetCaption (const char *title, const char *icon)
231
wm_title = SDL_strdup (title);
233
SDL_SetWindowTitle (window, wm_title);
237
SDL_WM_GetCaption (char **title, char **icon)
248
SDL_WM_SetIcon (SDL_Surface * icon, Uint8 * mask)
254
SDL_WM_IconifyWindow (void)
256
SDL_MinimizeWindow (window);
260
SDL_WM_ToggleFullScreen (SDL_Surface * surface)
266
SDL_WM_GrabInput (SDL_GrabMode mode)
268
if (mode != SDL_GRAB_QUERY) {
269
SDL_SetWindowGrab (window, mode);
271
return (SDL_GrabMode) SDL_GetWindowGrab (window);
275
SDL_GetAppState (void)
280
flags = SDL_GetWindowFlags (window);
281
if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
282
state |= SDL_APPACTIVE;
284
if (flags & SDL_WINDOW_KEYBOARD_FOCUS) {
285
state |= SDL_APPINPUTFOCUS;
287
if (flags & SDL_WINDOW_MOUSE_FOCUS) {
288
state |= SDL_APPMOUSEFOCUS;
294
SDL_Linked_Version (void)
296
static SDL_version version;
297
SDL_VERSION (&version);
302
SDL_SetPalette (SDL_Surface * surface, int flags, SDL_Color * colors,
303
int firstcolor, int ncolors)
305
SDL_SetColors (surface, colors, firstcolor, ncolors);
309
SDL_GetWMInfo (SDL_SysWMinfo * info)
311
return SDL_GetWindowWMInfo (window, info);
314
/* vi: set ts=4 sw=4 expandtab: */