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