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