Mercurial > sdl-ios-xcode
annotate src/video/windib/SDL_dibvideo.c @ 1420:2405517b5eab
Added preliminary support for MiNT /dev/mouse driver (disabled atm)
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Thu, 23 Feb 2006 21:51:10 +0000 |
parents | d910939febfa |
children | bb6839704ed6 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1295
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1295
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1295
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1295
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1295
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1295
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1295
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
169
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
24 #include "SDL_windows.h" |
1152
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
25 |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
26 #if defined(_WIN32_WCE) |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
27 |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
28 // defined and used in SDL_sysevents.c |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
29 extern HINSTANCE aygshell; |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
30 |
514
1080bfc4aa96
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
31 #endif |
0 | 32 |
33 /* Not yet in the mingw32 cross-compile headers */ | |
34 #ifndef CDS_FULLSCREEN | |
35 #define CDS_FULLSCREEN 4 | |
36 #endif | |
37 | |
38 #include "SDL_syswm.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
39 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
40 #include "../SDL_pixels_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
41 #include "../../events/SDL_sysevents.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
42 #include "../../events/SDL_events_c.h" |
0 | 43 #include "SDL_dibvideo.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
44 #include "../wincommon/SDL_syswm_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
45 #include "../wincommon/SDL_sysmouse_c.h" |
0 | 46 #include "SDL_dibevents_c.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
47 #include "../wincommon/SDL_wingl_c.h" |
0 | 48 |
49 #ifdef _WIN32_WCE | |
50 #define NO_GETDIBITS | |
51 #define NO_CHANGEDISPLAYSETTINGS | |
52 #define NO_GAMMA_SUPPORT | |
53 #endif | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
54 #ifndef WS_MAXIMIZE |
766
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
515
diff
changeset
|
55 #define WS_MAXIMIZE 0 |
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
515
diff
changeset
|
56 #endif |
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
515
diff
changeset
|
57 #ifndef WS_THICKFRAME |
ed57c876700d
Date: Wed, 26 Nov 2003 01:52:02 +0800
Sam Lantinga <slouken@libsdl.org>
parents:
515
diff
changeset
|
58 #define WS_THICKFRAME 0 |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
59 #endif |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
60 #ifndef SWP_NOCOPYBITS |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
61 #define SWP_NOCOPYBITS 0 |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
62 #endif |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
63 #ifndef PC_NOCOLLAPSE |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
64 #define PC_NOCOLLAPSE 0 |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
65 #endif |
0 | 66 |
67 /* Initialization/Query functions */ | |
68 static int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
69 static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
70 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
71 static int DIB_SetColors(_THIS, int firstcolor, int ncolors, | |
72 SDL_Color *colors); | |
73 static void DIB_CheckGamma(_THIS); | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
74 void DIB_SwapGamma(_THIS); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
75 void DIB_QuitGamma(_THIS); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
76 int DIB_SetGammaRamp(_THIS, Uint16 *ramp); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
77 int DIB_GetGammaRamp(_THIS, Uint16 *ramp); |
0 | 78 static void DIB_VideoQuit(_THIS); |
79 | |
80 /* Hardware surface functions */ | |
81 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface); | |
82 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface); | |
83 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
84 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface); | |
85 | |
86 /* Windows message handling functions */ | |
87 static void DIB_RealizePalette(_THIS); | |
88 static void DIB_PaletteChanged(_THIS, HWND window); | |
89 static void DIB_WinPAINT(_THIS, HDC hdc); | |
90 | |
91 /* helper fn */ | |
92 static int DIB_SussScreenDepth(); | |
93 | |
94 /* DIB driver bootstrap functions */ | |
95 | |
96 static int DIB_Available(void) | |
97 { | |
98 return(1); | |
99 } | |
100 | |
101 static void DIB_DeleteDevice(SDL_VideoDevice *device) | |
102 { | |
103 if ( device ) { | |
104 if ( device->hidden ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
105 SDL_free(device->hidden); |
0 | 106 } |
107 if ( device->gl_data ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
108 SDL_free(device->gl_data); |
0 | 109 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
110 SDL_free(device); |
0 | 111 } |
112 } | |
113 | |
114 static SDL_VideoDevice *DIB_CreateDevice(int devindex) | |
115 { | |
116 SDL_VideoDevice *device; | |
117 | |
118 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
119 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
0 | 120 if ( device ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
121 SDL_memset(device, 0, (sizeof *device)); |
0 | 122 device->hidden = (struct SDL_PrivateVideoData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
123 SDL_malloc((sizeof *device->hidden)); |
0 | 124 device->gl_data = (struct SDL_PrivateGLData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
125 SDL_malloc((sizeof *device->gl_data)); |
0 | 126 } |
127 if ( (device == NULL) || (device->hidden == NULL) || | |
128 (device->gl_data == NULL) ) { | |
129 SDL_OutOfMemory(); | |
130 DIB_DeleteDevice(device); | |
131 return(NULL); | |
132 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
133 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
134 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data)); |
0 | 135 |
136 /* Set the function pointers */ | |
137 device->VideoInit = DIB_VideoInit; | |
138 device->ListModes = DIB_ListModes; | |
139 device->SetVideoMode = DIB_SetVideoMode; | |
140 device->UpdateMouse = WIN_UpdateMouse; | |
141 device->SetColors = DIB_SetColors; | |
142 device->UpdateRects = NULL; | |
143 device->VideoQuit = DIB_VideoQuit; | |
144 device->AllocHWSurface = DIB_AllocHWSurface; | |
145 device->CheckHWBlit = NULL; | |
146 device->FillHWRect = NULL; | |
147 device->SetHWColorKey = NULL; | |
148 device->SetHWAlpha = NULL; | |
149 device->LockHWSurface = DIB_LockHWSurface; | |
150 device->UnlockHWSurface = DIB_UnlockHWSurface; | |
151 device->FlipHWSurface = NULL; | |
152 device->FreeHWSurface = DIB_FreeHWSurface; | |
153 device->SetGammaRamp = DIB_SetGammaRamp; | |
154 device->GetGammaRamp = DIB_GetGammaRamp; | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
155 #if SDL_VIDEO_OPENGL |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
156 device->GL_LoadLibrary = WIN_GL_LoadLibrary; |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
157 device->GL_GetProcAddress = WIN_GL_GetProcAddress; |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
158 device->GL_GetAttribute = WIN_GL_GetAttribute; |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
159 device->GL_MakeCurrent = WIN_GL_MakeCurrent; |
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
160 device->GL_SwapBuffers = WIN_GL_SwapBuffers; |
0 | 161 #endif |
162 device->SetCaption = WIN_SetWMCaption; | |
163 device->SetIcon = WIN_SetWMIcon; | |
164 device->IconifyWindow = WIN_IconifyWindow; | |
165 device->GrabInput = WIN_GrabInput; | |
166 device->GetWMInfo = WIN_GetWMInfo; | |
167 device->FreeWMCursor = WIN_FreeWMCursor; | |
168 device->CreateWMCursor = WIN_CreateWMCursor; | |
169 device->ShowWMCursor = WIN_ShowWMCursor; | |
170 device->WarpWMCursor = WIN_WarpWMCursor; | |
171 device->CheckMouseMode = WIN_CheckMouseMode; | |
172 device->InitOSKeymap = DIB_InitOSKeymap; | |
173 device->PumpEvents = DIB_PumpEvents; | |
174 | |
175 /* Set up the windows message handling functions */ | |
176 WIN_RealizePalette = DIB_RealizePalette; | |
177 WIN_PaletteChanged = DIB_PaletteChanged; | |
178 WIN_WinPAINT = DIB_WinPAINT; | |
179 HandleMessage = DIB_HandleMessage; | |
180 | |
181 device->free = DIB_DeleteDevice; | |
182 | |
183 /* We're finally ready */ | |
184 return device; | |
185 } | |
186 | |
187 VideoBootStrap WINDIB_bootstrap = { | |
1152
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
188 "windib", "Win95/98/NT/2000/CE GDI", |
0 | 189 DIB_Available, DIB_CreateDevice |
190 }; | |
191 | |
192 #ifndef NO_CHANGEDISPLAYSETTINGS | |
193 | |
194 static int cmpmodes(const void *va, const void *vb) | |
195 { | |
196 SDL_Rect *a = *(SDL_Rect **)va; | |
197 SDL_Rect *b = *(SDL_Rect **)vb; | |
966
f72cc0c7305f
Video modes are sorted width first, then height
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
198 if ( a->w == b->w ) |
f72cc0c7305f
Video modes are sorted width first, then height
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
199 return b->h - a->h; |
f72cc0c7305f
Video modes are sorted width first, then height
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
200 else |
f72cc0c7305f
Video modes are sorted width first, then height
Sam Lantinga <slouken@libsdl.org>
parents:
833
diff
changeset
|
201 return b->w - a->w; |
0 | 202 } |
203 | |
204 static int DIB_AddMode(_THIS, int bpp, int w, int h) | |
205 { | |
206 SDL_Rect *mode; | |
207 int i, index; | |
208 int next_mode; | |
209 | |
210 /* Check to see if we already have this mode */ | |
211 if ( bpp < 8 ) { /* Not supported */ | |
212 return(0); | |
213 } | |
214 index = ((bpp+7)/8)-1; | |
215 for ( i=0; i<SDL_nummodes[index]; ++i ) { | |
216 mode = SDL_modelist[index][i]; | |
217 if ( (mode->w == w) && (mode->h == h) ) { | |
218 return(0); | |
219 } | |
220 } | |
221 | |
222 /* Set up the new video mode rectangle */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
223 mode = (SDL_Rect *)SDL_malloc(sizeof *mode); |
0 | 224 if ( mode == NULL ) { |
225 SDL_OutOfMemory(); | |
226 return(-1); | |
227 } | |
228 mode->x = 0; | |
229 mode->y = 0; | |
230 mode->w = w; | |
231 mode->h = h; | |
232 | |
233 /* Allocate the new list of modes, and fill in the new mode */ | |
234 next_mode = SDL_nummodes[index]; | |
235 SDL_modelist[index] = (SDL_Rect **) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
236 SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); |
0 | 237 if ( SDL_modelist[index] == NULL ) { |
238 SDL_OutOfMemory(); | |
239 SDL_nummodes[index] = 0; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
240 SDL_free(mode); |
0 | 241 return(-1); |
242 } | |
243 SDL_modelist[index][next_mode] = mode; | |
244 SDL_modelist[index][next_mode+1] = NULL; | |
245 SDL_nummodes[index]++; | |
246 | |
247 return(0); | |
248 } | |
249 | |
250 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
251 | |
252 static HPALETTE DIB_CreatePalette(int bpp) | |
253 { | |
254 /* RJR: March 28, 2000 | |
255 moved palette creation here from "DIB_VideoInit" */ | |
256 | |
257 HPALETTE handle = NULL; | |
258 | |
259 if ( bpp <= 8 ) | |
260 { | |
261 LOGPALETTE *palette; | |
262 HDC hdc; | |
263 int ncolors; | |
264 int i; | |
265 | |
266 ncolors = 1; | |
267 for ( i=0; i<bpp; ++i ) { | |
268 ncolors *= 2; | |
269 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
270 palette = (LOGPALETTE *)SDL_malloc(sizeof(*palette)+ |
0 | 271 ncolors*sizeof(PALETTEENTRY)); |
272 palette->palVersion = 0x300; | |
273 palette->palNumEntries = ncolors; | |
274 hdc = GetDC(SDL_Window); | |
275 GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry); | |
276 ReleaseDC(SDL_Window, hdc); | |
277 handle = CreatePalette(palette); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
278 SDL_free(palette); |
0 | 279 } |
280 | |
281 return handle; | |
282 } | |
283 | |
284 int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
285 { | |
286 #ifndef NO_CHANGEDISPLAYSETTINGS | |
287 int i; | |
288 DEVMODE settings; | |
289 #endif | |
290 | |
291 /* Create the window */ | |
292 if ( DIB_CreateWindow(this) < 0 ) { | |
293 return(-1); | |
294 } | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
295 #if !SDL_AUDIO_DISABLED |
0 | 296 DX5_SoundFocus(SDL_Window); |
169
8039a5b760b9
Allow building SDL on Windows without audio support
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
297 #endif |
0 | 298 |
299 /* Determine the screen depth */ | |
300 vformat->BitsPerPixel = DIB_SussScreenDepth(); | |
301 switch (vformat->BitsPerPixel) { | |
302 case 15: | |
303 vformat->Rmask = 0x00007c00; | |
304 vformat->Gmask = 0x000003e0; | |
305 vformat->Bmask = 0x0000001f; | |
306 vformat->BitsPerPixel = 16; | |
307 break; | |
308 case 16: | |
309 vformat->Rmask = 0x0000f800; | |
310 vformat->Gmask = 0x000007e0; | |
311 vformat->Bmask = 0x0000001f; | |
312 break; | |
313 case 24: | |
314 case 32: | |
315 /* GDI defined as 8-8-8 */ | |
316 vformat->Rmask = 0x00ff0000; | |
317 vformat->Gmask = 0x0000ff00; | |
318 vformat->Bmask = 0x000000ff; | |
319 break; | |
320 default: | |
321 break; | |
322 } | |
323 | |
324 /* See if gamma is supported on this screen */ | |
325 DIB_CheckGamma(this); | |
326 | |
327 #ifndef NO_CHANGEDISPLAYSETTINGS | |
1295
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
328 /* Query for the desktop resolution */ |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
329 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode); |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
330 |
0 | 331 /* Query for the list of available video modes */ |
332 for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) { | |
333 DIB_AddMode(this, settings.dmBitsPerPel, | |
334 settings.dmPelsWidth, settings.dmPelsHeight); | |
335 } | |
336 /* Sort the mode lists */ | |
337 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
338 if ( SDL_nummodes[i] > 0 ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
339 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); |
0 | 340 } |
341 } | |
342 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
343 | |
344 /* Grab an identity palette if we are in a palettized mode */ | |
345 if ( vformat->BitsPerPixel <= 8 ) { | |
346 /* RJR: March 28, 2000 | |
347 moved palette creation to "DIB_CreatePalette" */ | |
348 screen_pal = DIB_CreatePalette(vformat->BitsPerPixel); | |
349 } | |
350 | |
351 /* Fill in some window manager capabilities */ | |
352 this->info.wm_available = 1; | |
353 | |
354 /* We're done! */ | |
355 return(0); | |
356 } | |
357 | |
358 /* We support any format at any dimension */ | |
359 SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
360 { | |
361 #ifdef NO_CHANGEDISPLAYSETTINGS | |
362 return((SDL_Rect **)-1); | |
363 #else | |
364 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
365 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | |
366 } else { | |
367 return((SDL_Rect **)-1); | |
368 } | |
369 #endif | |
370 } | |
371 | |
372 | |
373 /* | |
374 Helper fn to work out which screen depth windows is currently using. | |
375 15 bit mode is considered 555 format, 16 bit is 565. | |
376 returns 0 for unknown mode. | |
377 (Derived from code in sept 1999 Windows Developer Journal | |
378 http://www.wdj.com/code/archive.html) | |
379 */ | |
380 static int DIB_SussScreenDepth() | |
381 { | |
382 #ifdef NO_GETDIBITS | |
383 int depth; | |
384 HDC hdc; | |
385 | |
386 hdc = GetDC(SDL_Window); | |
387 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); | |
388 ReleaseDC(SDL_Window, hdc); | |
389 return(depth); | |
390 #else | |
391 int dib_size; | |
392 LPBITMAPINFOHEADER dib_hdr; | |
393 HDC hdc; | |
394 HBITMAP hbm; | |
395 | |
396 /* Allocate enough space for a DIB header plus palette (for | |
397 * 8-bit modes) or bitfields (for 16- and 32-bit modes) | |
398 */ | |
399 dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
400 dib_hdr = (LPBITMAPINFOHEADER) SDL_malloc(dib_size); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
401 SDL_memset(dib_hdr, 0, dib_size); |
0 | 402 dib_hdr->biSize = sizeof(BITMAPINFOHEADER); |
403 | |
404 /* Get a device-dependent bitmap that's compatible with the | |
405 screen. | |
406 */ | |
407 hdc = GetDC(NULL); | |
408 hbm = CreateCompatibleBitmap( hdc, 1, 1 ); | |
409 | |
410 /* Convert the DDB to a DIB. We need to call GetDIBits twice: | |
411 * the first call just fills in the BITMAPINFOHEADER; the | |
412 * second fills in the bitfields or palette. | |
413 */ | |
414 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); | |
415 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); | |
416 DeleteObject(hbm); | |
417 ReleaseDC(NULL, hdc); | |
418 | |
419 switch( dib_hdr->biBitCount ) | |
420 { | |
421 case 8: return 8; | |
422 case 24: return 24; | |
423 case 32: return 32; | |
424 case 16: | |
425 if( dib_hdr->biCompression == BI_BITFIELDS ) { | |
426 /* check the red mask */ | |
427 switch( ((DWORD*)((char*)dib_hdr + dib_hdr->biSize))[0] ) { | |
428 case 0xf800: return 16; /* 565 */ | |
429 case 0x7c00: return 15; /* 555 */ | |
430 } | |
431 } | |
432 } | |
433 return 0; /* poo. */ | |
434 #endif /* NO_GETDIBITS */ | |
435 } | |
436 | |
437 | |
438 /* Various screen update functions available */ | |
439 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
440 | |
441 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, | |
442 int width, int height, int bpp, Uint32 flags) | |
443 { | |
444 SDL_Surface *video; | |
445 Uint32 prev_flags; | |
446 DWORD style; | |
447 const DWORD directstyle = | |
448 (WS_POPUP); | |
449 const DWORD windowstyle = | |
450 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); | |
451 const DWORD resizestyle = | |
452 (WS_THICKFRAME|WS_MAXIMIZEBOX); | |
453 int binfo_size; | |
454 BITMAPINFO *binfo; | |
455 HDC hdc; | |
456 RECT bounds; | |
457 int x, y; | |
458 Uint32 Rmask, Gmask, Bmask; | |
459 | |
460 /* Clean up any GL context that may be hanging around */ | |
461 if ( current->flags & SDL_OPENGL ) { | |
462 WIN_GL_ShutDown(this); | |
463 } | |
1291
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
464 SDL_resizing = 1; |
0 | 465 |
466 /* Recalculate the bitmasks if necessary */ | |
467 if ( bpp == current->format->BitsPerPixel ) { | |
468 video = current; | |
469 } else { | |
470 switch (bpp) { | |
471 case 15: | |
472 case 16: | |
473 if ( DIB_SussScreenDepth() == 15 ) { | |
474 /* 5-5-5 */ | |
475 Rmask = 0x00007c00; | |
476 Gmask = 0x000003e0; | |
477 Bmask = 0x0000001f; | |
478 } else { | |
479 /* 5-6-5 */ | |
480 Rmask = 0x0000f800; | |
481 Gmask = 0x000007e0; | |
482 Bmask = 0x0000001f; | |
483 } | |
484 break; | |
485 case 24: | |
486 case 32: | |
487 /* GDI defined as 8-8-8 */ | |
488 Rmask = 0x00ff0000; | |
489 Gmask = 0x0000ff00; | |
490 Bmask = 0x000000ff; | |
491 break; | |
492 default: | |
493 Rmask = 0x00000000; | |
494 Gmask = 0x00000000; | |
495 Bmask = 0x00000000; | |
496 break; | |
497 } | |
498 video = SDL_CreateRGBSurface(SDL_SWSURFACE, | |
499 0, 0, bpp, Rmask, Gmask, Bmask, 0); | |
500 if ( video == NULL ) { | |
501 SDL_OutOfMemory(); | |
502 return(NULL); | |
503 } | |
504 } | |
505 | |
506 /* Fill in part of the video surface */ | |
507 prev_flags = video->flags; | |
508 video->flags = 0; /* Clear flags */ | |
509 video->w = width; | |
510 video->h = height; | |
511 video->pitch = SDL_CalculatePitch(video); | |
512 | |
1152
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
513 /* Small fix for WinCE/Win32 - when activating window |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
514 SDL_VideoSurface is equal to zero, so activating code |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
515 is not called properly for fullscreen windows because |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
516 macros WINDIB_FULLSCREEN uses SDL_VideoSurface |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
517 */ |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
518 SDL_VideoSurface = video; |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
519 |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
520 #if defined(_WIN32_WCE) |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
521 if ( flags & SDL_FULLSCREEN ) |
514
1080bfc4aa96
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
522 video->flags |= SDL_FULLSCREEN; |
1080bfc4aa96
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
453
diff
changeset
|
523 #endif |
1152
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
524 |
0 | 525 #ifndef NO_CHANGEDISPLAYSETTINGS |
526 /* Set fullscreen mode if appropriate */ | |
527 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
528 DEVMODE settings; | |
1295
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
529 BOOL changed; |
0 | 530 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
531 SDL_memset(&settings, 0, sizeof(DEVMODE)); |
0 | 532 settings.dmSize = sizeof(DEVMODE); |
533 settings.dmBitsPerPel = video->format->BitsPerPixel; | |
534 settings.dmPelsWidth = width; | |
535 settings.dmPelsHeight = height; | |
536 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
537 if ( width <= (int)SDL_desktop_mode.dmPelsWidth && |
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
538 height <= (int)SDL_desktop_mode.dmPelsHeight ) { |
1295
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
539 settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency; |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
540 settings.dmFields |= DM_DISPLAYFREQUENCY; |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
541 } |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
542 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
543 if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
544 settings.dmFields &= ~DM_DISPLAYFREQUENCY; |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
545 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
546 } |
c3e36ac8a94c
Date: Sun, 6 Mar 2005 17:06:20 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
1292
diff
changeset
|
547 if ( changed ) { |
0 | 548 video->flags |= SDL_FULLSCREEN; |
304
ec53caed9fb2
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
549 SDL_fullscreen_mode = settings; |
0 | 550 } |
551 } | |
552 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
553 | |
45
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
554 /* Reset the palette and create a new one if necessary */ |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
555 if ( screen_pal != NULL ) { |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
556 /* RJR: March 28, 2000 |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
557 delete identity palette if switching from a palettized mode */ |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
558 DeleteObject(screen_pal); |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
559 screen_pal = NULL; |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
560 } |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
561 if ( bpp <= 8 ) |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
562 { |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
563 /* RJR: March 28, 2000 |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
564 create identity palette switching to a palettized mode */ |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
565 screen_pal = DIB_CreatePalette(bpp); |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
566 } |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
567 |
0 | 568 style = GetWindowLong(SDL_Window, GWL_STYLE); |
569 style &= ~(resizestyle|WS_MAXIMIZE); | |
570 if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
571 style &= ~windowstyle; | |
572 style |= directstyle; | |
573 } else { | |
574 #ifndef NO_CHANGEDISPLAYSETTINGS | |
575 if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
576 ChangeDisplaySettings(NULL, 0); | |
577 } | |
578 #endif | |
579 if ( flags & SDL_NOFRAME ) { | |
580 style &= ~windowstyle; | |
581 style |= directstyle; | |
582 video->flags |= SDL_NOFRAME; | |
583 } else { | |
584 style &= ~directstyle; | |
585 style |= windowstyle; | |
586 if ( flags & SDL_RESIZABLE ) { | |
587 style |= resizestyle; | |
588 video->flags |= SDL_RESIZABLE; | |
589 } | |
590 } | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
591 #if WS_MAXIMIZE |
0 | 592 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
593 #endif |
0 | 594 } |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
595 |
448
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
596 /* DJM: Don't piss of anyone who has setup his own window */ |
1280
f61f045343d3
Re-query the SDL_WINDOWID each time we initialize the video
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
597 if ( !SDL_windowid ) |
448
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
598 SetWindowLong(SDL_Window, GWL_STYLE, style); |
0 | 599 |
600 /* Delete the old bitmap if necessary */ | |
601 if ( screen_bmp != NULL ) { | |
602 DeleteObject(screen_bmp); | |
603 } | |
604 if ( ! (flags & SDL_OPENGL) ) { | |
605 BOOL is16bitmode = (video->format->BytesPerPixel == 2); | |
606 | |
607 /* Suss out the bitmap info header */ | |
608 binfo_size = sizeof(*binfo); | |
609 if( is16bitmode ) { | |
610 /* 16bit modes, palette area used for rgb bitmasks */ | |
611 binfo_size += 3*sizeof(DWORD); | |
612 } else if ( video->format->palette ) { | |
613 binfo_size += video->format->palette->ncolors * | |
614 sizeof(RGBQUAD); | |
615 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
616 binfo = (BITMAPINFO *)SDL_malloc(binfo_size); |
0 | 617 if ( ! binfo ) { |
618 if ( video != current ) { | |
619 SDL_FreeSurface(video); | |
620 } | |
621 SDL_OutOfMemory(); | |
622 return(NULL); | |
623 } | |
624 | |
625 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
626 binfo->bmiHeader.biWidth = video->w; | |
627 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ | |
628 binfo->bmiHeader.biPlanes = 1; | |
629 binfo->bmiHeader.biSizeImage = video->h * video->pitch; | |
630 binfo->bmiHeader.biXPelsPerMeter = 0; | |
631 binfo->bmiHeader.biYPelsPerMeter = 0; | |
632 binfo->bmiHeader.biClrUsed = 0; | |
633 binfo->bmiHeader.biClrImportant = 0; | |
634 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; | |
635 | |
636 if ( is16bitmode ) { | |
637 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ | |
638 binfo->bmiHeader.biCompression = BI_BITFIELDS; | |
639 ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; | |
640 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; | |
641 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; | |
642 } else { | |
643 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ | |
644 if ( video->format->palette ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
645 SDL_memset(binfo->bmiColors, 0, |
0 | 646 video->format->palette->ncolors*sizeof(RGBQUAD)); |
647 } | |
648 } | |
649 | |
650 /* Create the offscreen bitmap buffer */ | |
651 hdc = GetDC(SDL_Window); | |
652 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, | |
653 (void **)(&video->pixels), NULL, 0); | |
654 ReleaseDC(SDL_Window, hdc); | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
655 SDL_free(binfo); |
0 | 656 if ( screen_bmp == NULL ) { |
657 if ( video != current ) { | |
658 SDL_FreeSurface(video); | |
659 } | |
660 SDL_SetError("Couldn't create DIB section"); | |
661 return(NULL); | |
662 } | |
663 this->UpdateRects = DIB_NormalUpdate; | |
664 | |
665 /* Set video surface flags */ | |
666 if ( bpp <= 8 ) { | |
667 /* BitBlt() maps colors for us */ | |
668 video->flags |= SDL_HWPALETTE; | |
669 } | |
670 } | |
671 | |
672 /* Resize the window */ | |
1290
c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
673 if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { |
448
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
674 HWND top; |
0 | 675 UINT swp_flags; |
1290
c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
676 const char *window = NULL; |
c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
677 const char *center = NULL; |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
678 |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
679 if ( !SDL_windowX && !SDL_windowY ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
680 window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
681 center = SDL_getenv("SDL_VIDEO_CENTERED"); |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
682 if ( window ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
683 if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) { |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
684 SDL_windowX = x; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
685 SDL_windowY = y; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
686 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
687 if ( SDL_strcmp(window, "center") == 0 ) { |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
688 center = window; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
689 } |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
690 } |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
691 } |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
692 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); |
0 | 693 |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
694 bounds.left = SDL_windowX; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
695 bounds.top = SDL_windowY; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
696 bounds.right = SDL_windowX+video->w; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
697 bounds.bottom = SDL_windowY+video->h; |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
698 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); |
0 | 699 width = bounds.right-bounds.left; |
700 height = bounds.bottom-bounds.top; | |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
701 if ( (flags & SDL_FULLSCREEN) ) { |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
702 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
703 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; |
971
96671ebc50a4
Date: Mon, 25 Oct 2004 17:30:06 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
966
diff
changeset
|
704 } else if ( center ) { |
96671ebc50a4
Date: Mon, 25 Oct 2004 17:30:06 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
966
diff
changeset
|
705 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; |
96671ebc50a4
Date: Mon, 25 Oct 2004 17:30:06 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
966
diff
changeset
|
706 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
707 } else if ( SDL_windowX || SDL_windowY || window ) { |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
708 x = bounds.left; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
709 y = bounds.top; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
710 } else { |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
711 x = y = -1; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
712 swp_flags |= SWP_NOMOVE; |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
713 } |
448
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
714 if ( flags & SDL_FULLSCREEN ) { |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
715 top = HWND_TOPMOST; |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
716 } else { |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
717 top = HWND_NOTOPMOST; |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
718 } |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
719 SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); |
1291
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
720 if ( !(flags & SDL_FULLSCREEN) ) { |
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
721 SDL_windowX = SDL_bounds.left; |
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
722 SDL_windowY = SDL_bounds.top; |
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
723 } |
0 | 724 SetForegroundWindow(SDL_Window); |
725 } | |
1291
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
726 SDL_resizing = 0; |
0 | 727 |
728 /* Set up for OpenGL */ | |
729 if ( flags & SDL_OPENGL ) { | |
730 if ( WIN_GL_SetupWindow(this) < 0 ) { | |
731 return(NULL); | |
732 } | |
733 video->flags |= SDL_OPENGL; | |
734 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
735 |
0 | 736 /* We're live! */ |
737 return(video); | |
738 } | |
739 | |
740 /* We don't actually allow hardware surfaces in the DIB driver */ | |
741 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) | |
742 { | |
743 return(-1); | |
744 } | |
745 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) | |
746 { | |
747 return; | |
748 } | |
749 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) | |
750 { | |
751 return(0); | |
752 } | |
753 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
754 { | |
755 return; | |
756 } | |
757 | |
758 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
759 { | |
760 HDC hdc, mdc; | |
761 int i; | |
762 | |
763 hdc = GetDC(SDL_Window); | |
764 if ( screen_pal ) { | |
765 SelectPalette(hdc, screen_pal, FALSE); | |
766 } | |
767 mdc = CreateCompatibleDC(hdc); | |
768 SelectObject(mdc, screen_bmp); | |
769 for ( i=0; i<numrects; ++i ) { | |
770 BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, | |
771 mdc, rects[i].x, rects[i].y, SRCCOPY); | |
772 } | |
773 DeleteDC(mdc); | |
774 ReleaseDC(SDL_Window, hdc); | |
775 } | |
776 | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
777 |
0 | 778 int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) |
779 { | |
1292
59c7a470a51e
Fixed palette bug on non-WinCE
Sam Lantinga <slouken@libsdl.org>
parents:
1291
diff
changeset
|
780 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) |
59c7a470a51e
Fixed palette bug on non-WinCE
Sam Lantinga <slouken@libsdl.org>
parents:
1291
diff
changeset
|
781 HDC hdc, mdc; |
0 | 782 RGBQUAD *pal; |
1292
59c7a470a51e
Fixed palette bug on non-WinCE
Sam Lantinga <slouken@libsdl.org>
parents:
1291
diff
changeset
|
783 #else |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
784 HDC hdc; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
785 #endif |
1292
59c7a470a51e
Fixed palette bug on non-WinCE
Sam Lantinga <slouken@libsdl.org>
parents:
1291
diff
changeset
|
786 int i; |
0 | 787 |
788 /* Update the display palette */ | |
789 hdc = GetDC(SDL_Window); | |
790 if ( screen_pal ) { | |
791 PALETTEENTRY *entries; | |
792 | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
793 entries = SDL_stack_alloc(PALETTEENTRY, ncolors); |
0 | 794 for ( i=0; i<ncolors; ++i ) { |
795 entries[i].peRed = colors[i].r; | |
796 entries[i].peGreen = colors[i].g; | |
797 entries[i].peBlue = colors[i].b; | |
798 entries[i].peFlags = PC_NOCOLLAPSE; | |
799 } | |
800 SetPaletteEntries(screen_pal, firstcolor, ncolors, entries); | |
801 SelectPalette(hdc, screen_pal, FALSE); | |
802 RealizePalette(hdc); | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
803 SDL_stack_free(entries); |
0 | 804 } |
805 | |
1292
59c7a470a51e
Fixed palette bug on non-WinCE
Sam Lantinga <slouken@libsdl.org>
parents:
1291
diff
changeset
|
806 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) |
0 | 807 /* Copy palette colors into DIB palette */ |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
808 pal = SDL_stack_alloc(RGBQUAD, ncolors); |
0 | 809 for ( i=0; i<ncolors; ++i ) { |
810 pal[i].rgbRed = colors[i].r; | |
811 pal[i].rgbGreen = colors[i].g; | |
812 pal[i].rgbBlue = colors[i].b; | |
813 pal[i].rgbReserved = 0; | |
814 } | |
815 | |
816 /* Set the DIB palette and update the display */ | |
817 mdc = CreateCompatibleDC(hdc); | |
818 SelectObject(mdc, screen_bmp); | |
819 SetDIBColorTable(mdc, firstcolor, ncolors, pal); | |
820 BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, | |
821 mdc, 0, 0, SRCCOPY); | |
822 DeleteDC(mdc); | |
1330
450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
823 SDL_stack_free(pal); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
824 #endif |
0 | 825 ReleaseDC(SDL_Window, hdc); |
826 return(1); | |
827 } | |
828 | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
829 |
0 | 830 static void DIB_CheckGamma(_THIS) |
831 { | |
832 #ifndef NO_GAMMA_SUPPORT | |
833 HDC hdc; | |
834 WORD ramp[3*256]; | |
835 | |
836 /* If we fail to get gamma, disable gamma control */ | |
837 hdc = GetDC(SDL_Window); | |
838 if ( ! GetDeviceGammaRamp(hdc, ramp) ) { | |
839 this->GetGammaRamp = NULL; | |
840 this->SetGammaRamp = NULL; | |
841 } | |
842 ReleaseDC(SDL_Window, hdc); | |
843 #endif /* !NO_GAMMA_SUPPORT */ | |
844 } | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
845 void DIB_SwapGamma(_THIS) |
0 | 846 { |
847 #ifndef NO_GAMMA_SUPPORT | |
848 HDC hdc; | |
849 | |
850 if ( gamma_saved ) { | |
851 hdc = GetDC(SDL_Window); | |
852 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
853 /* About to leave active state, restore gamma */ | |
854 SetDeviceGammaRamp(hdc, gamma_saved); | |
855 } else { | |
856 /* About to enter active state, set game gamma */ | |
857 GetDeviceGammaRamp(hdc, gamma_saved); | |
858 SetDeviceGammaRamp(hdc, this->gamma); | |
859 } | |
860 ReleaseDC(SDL_Window, hdc); | |
861 } | |
862 #endif /* !NO_GAMMA_SUPPORT */ | |
863 } | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
864 void DIB_QuitGamma(_THIS) |
0 | 865 { |
866 #ifndef NO_GAMMA_SUPPORT | |
867 if ( gamma_saved ) { | |
868 /* Restore the original gamma if necessary */ | |
869 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
870 HDC hdc; | |
871 | |
872 hdc = GetDC(SDL_Window); | |
873 SetDeviceGammaRamp(hdc, gamma_saved); | |
874 ReleaseDC(SDL_Window, hdc); | |
875 } | |
876 | |
877 /* Free the saved gamma memory */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
878 SDL_free(gamma_saved); |
0 | 879 gamma_saved = 0; |
880 } | |
881 #endif /* !NO_GAMMA_SUPPORT */ | |
882 } | |
883 | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
884 int DIB_SetGammaRamp(_THIS, Uint16 *ramp) |
0 | 885 { |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
886 #ifdef NO_GAMMA_SUPPORT |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
887 SDL_SetError("SDL compiled without gamma ramp support"); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
888 return -1; |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
889 #else |
0 | 890 HDC hdc; |
891 BOOL succeeded; | |
892 | |
893 /* Set the ramp for the display */ | |
894 if ( ! gamma_saved ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
895 gamma_saved = (WORD *)SDL_malloc(3*256*sizeof(*gamma_saved)); |
0 | 896 if ( ! gamma_saved ) { |
897 SDL_OutOfMemory(); | |
898 return -1; | |
899 } | |
900 hdc = GetDC(SDL_Window); | |
901 GetDeviceGammaRamp(hdc, gamma_saved); | |
902 ReleaseDC(SDL_Window, hdc); | |
903 } | |
904 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
905 hdc = GetDC(SDL_Window); | |
906 succeeded = SetDeviceGammaRamp(hdc, ramp); | |
907 ReleaseDC(SDL_Window, hdc); | |
908 } else { | |
909 succeeded = TRUE; | |
910 } | |
911 return succeeded ? 0 : -1; | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
912 #endif /* !NO_GAMMA_SUPPORT */ |
0 | 913 } |
914 | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
915 int DIB_GetGammaRamp(_THIS, Uint16 *ramp) |
0 | 916 { |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
917 #ifdef NO_GAMMA_SUPPORT |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
918 SDL_SetError("SDL compiled without gamma ramp support"); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
919 return -1; |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
920 #else |
0 | 921 HDC hdc; |
922 BOOL succeeded; | |
923 | |
924 /* Get the ramp from the display */ | |
925 hdc = GetDC(SDL_Window); | |
926 succeeded = GetDeviceGammaRamp(hdc, ramp); | |
927 ReleaseDC(SDL_Window, hdc); | |
928 return succeeded ? 0 : -1; | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
929 #endif /* !NO_GAMMA_SUPPORT */ |
0 | 930 } |
931 | |
442
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
932 static void FlushMessageQueue() |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
933 { |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
934 MSG msg; |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
935 while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
936 if ( msg.message == WM_QUIT ) break; |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
937 TranslateMessage( &msg ); |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
938 DispatchMessage( &msg ); |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
939 } |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
940 } |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
941 |
0 | 942 void DIB_VideoQuit(_THIS) |
943 { | |
944 /* Destroy the window and everything associated with it */ | |
945 if ( SDL_Window ) { | |
946 /* Delete the screen bitmap (also frees screen->pixels) */ | |
947 if ( this->screen ) { | |
948 #ifndef NO_CHANGEDISPLAYSETTINGS | |
949 if ( this->screen->flags & SDL_FULLSCREEN ) { | |
950 ChangeDisplaySettings(NULL, 0); | |
376
a5f60a847a89
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
374
diff
changeset
|
951 ShowWindow(SDL_Window, SW_HIDE); |
0 | 952 } |
953 #endif | |
954 if ( this->screen->flags & SDL_OPENGL ) { | |
955 WIN_GL_ShutDown(this); | |
956 } | |
957 this->screen->pixels = NULL; | |
958 } | |
959 if ( screen_bmp ) { | |
960 DeleteObject(screen_bmp); | |
961 screen_bmp = NULL; | |
962 } | |
963 if ( screen_icn ) { | |
964 DestroyIcon(screen_icn); | |
965 screen_icn = NULL; | |
966 } | |
967 DIB_QuitGamma(this); | |
968 DIB_DestroyWindow(this); | |
442
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
969 FlushMessageQueue(); |
0 | 970 |
971 SDL_Window = NULL; | |
1152
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
972 |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
973 #if defined(_WIN32_WCE) |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
974 |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
975 // Unload wince aygshell library to prevent leak |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
976 if( aygshell ) |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
977 { |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
978 FreeLibrary(aygshell); |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
979 aygshell = NULL; |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
980 } |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
981 #endif |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
982 |
0 | 983 } |
984 } | |
985 | |
986 /* Exported for the windows message loop only */ | |
987 static void DIB_FocusPalette(_THIS, int foreground) | |
988 { | |
989 if ( screen_pal != NULL ) { | |
990 HDC hdc; | |
991 | |
992 hdc = GetDC(SDL_Window); | |
993 SelectPalette(hdc, screen_pal, FALSE); | |
994 if ( RealizePalette(hdc) ) | |
995 InvalidateRect(SDL_Window, NULL, FALSE); | |
996 ReleaseDC(SDL_Window, hdc); | |
997 } | |
998 } | |
999 static void DIB_RealizePalette(_THIS) | |
1000 { | |
1001 DIB_FocusPalette(this, 1); | |
1002 } | |
1003 static void DIB_PaletteChanged(_THIS, HWND window) | |
1004 { | |
1005 if ( window != SDL_Window ) { | |
1006 DIB_FocusPalette(this, 0); | |
1007 } | |
1008 } | |
1009 | |
1010 /* Exported for the windows message loop only */ | |
1011 static void DIB_WinPAINT(_THIS, HDC hdc) | |
1012 { | |
1013 HDC mdc; | |
1014 | |
1015 if ( screen_pal ) { | |
1016 SelectPalette(hdc, screen_pal, FALSE); | |
1017 } | |
1018 mdc = CreateCompatibleDC(hdc); | |
1019 SelectObject(mdc, screen_bmp); | |
1020 BitBlt(hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h, | |
1021 mdc, 0, 0, SRCCOPY); | |
1022 DeleteDC(mdc); | |
1023 } | |
1024 | |
1025 /* Stub in case DirectX isn't available */ | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
1026 #if !SDL_AUDIO_DRIVER_DSOUND |
0 | 1027 void DX5_SoundFocus(HWND hwnd) |
1028 { | |
1029 return; | |
1030 } | |
1031 #endif |