Mercurial > sdl-ios-xcode
annotate src/video/windib/SDL_dibvideo.c @ 145:29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
and added a function to cache the application handle so DirectInput
still works properly.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 09 Aug 2001 12:21:32 +0000 |
parents | 9ef74357a5fb |
children | 8039a5b760b9 |
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 } | |
289 DX5_SoundFocus(SDL_Window); | |
290 | |
291 /* Determine the screen depth */ | |
292 vformat->BitsPerPixel = DIB_SussScreenDepth(); | |
293 switch (vformat->BitsPerPixel) { | |
294 case 15: | |
295 vformat->Rmask = 0x00007c00; | |
296 vformat->Gmask = 0x000003e0; | |
297 vformat->Bmask = 0x0000001f; | |
298 vformat->BitsPerPixel = 16; | |
299 break; | |
300 case 16: | |
301 vformat->Rmask = 0x0000f800; | |
302 vformat->Gmask = 0x000007e0; | |
303 vformat->Bmask = 0x0000001f; | |
304 break; | |
305 case 24: | |
306 case 32: | |
307 /* GDI defined as 8-8-8 */ | |
308 vformat->Rmask = 0x00ff0000; | |
309 vformat->Gmask = 0x0000ff00; | |
310 vformat->Bmask = 0x000000ff; | |
311 break; | |
312 default: | |
313 break; | |
314 } | |
315 | |
316 /* See if gamma is supported on this screen */ | |
317 DIB_CheckGamma(this); | |
318 | |
319 #ifndef NO_CHANGEDISPLAYSETTINGS | |
320 /* Query for the list of available video modes */ | |
321 for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) { | |
322 DIB_AddMode(this, settings.dmBitsPerPel, | |
323 settings.dmPelsWidth, settings.dmPelsHeight); | |
324 } | |
325 /* Sort the mode lists */ | |
326 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
327 if ( SDL_nummodes[i] > 0 ) { | |
328 qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); | |
329 } | |
330 } | |
331 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
332 | |
333 /* Grab an identity palette if we are in a palettized mode */ | |
334 if ( vformat->BitsPerPixel <= 8 ) { | |
335 /* RJR: March 28, 2000 | |
336 moved palette creation to "DIB_CreatePalette" */ | |
337 screen_pal = DIB_CreatePalette(vformat->BitsPerPixel); | |
338 } | |
339 | |
340 /* Fill in some window manager capabilities */ | |
341 this->info.wm_available = 1; | |
342 | |
343 /* We're done! */ | |
344 return(0); | |
345 } | |
346 | |
347 /* We support any format at any dimension */ | |
348 SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
349 { | |
350 #ifdef NO_CHANGEDISPLAYSETTINGS | |
351 return((SDL_Rect **)-1); | |
352 #else | |
353 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
354 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | |
355 } else { | |
356 return((SDL_Rect **)-1); | |
357 } | |
358 #endif | |
359 } | |
360 | |
361 | |
362 /* | |
363 Helper fn to work out which screen depth windows is currently using. | |
364 15 bit mode is considered 555 format, 16 bit is 565. | |
365 returns 0 for unknown mode. | |
366 (Derived from code in sept 1999 Windows Developer Journal | |
367 http://www.wdj.com/code/archive.html) | |
368 */ | |
369 static int DIB_SussScreenDepth() | |
370 { | |
371 #ifdef NO_GETDIBITS | |
372 int depth; | |
373 HDC hdc; | |
374 | |
375 hdc = GetDC(SDL_Window); | |
376 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); | |
377 ReleaseDC(SDL_Window, hdc); | |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
46
diff
changeset
|
378 #ifndef _WIN32_WCE |
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
46
diff
changeset
|
379 // AFAIK 16 bit CE devices have indeed RGB 565 |
0 | 380 if ( depth == 16 ) { |
381 depth = 15; /* GDI defined as RGB 555 */ | |
382 } | |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
46
diff
changeset
|
383 #endif |
0 | 384 return(depth); |
385 #else | |
386 int dib_size; | |
387 LPBITMAPINFOHEADER dib_hdr; | |
388 HDC hdc; | |
389 HBITMAP hbm; | |
390 | |
391 /* Allocate enough space for a DIB header plus palette (for | |
392 * 8-bit modes) or bitfields (for 16- and 32-bit modes) | |
393 */ | |
394 dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); | |
395 dib_hdr = (LPBITMAPINFOHEADER) malloc(dib_size); | |
396 memset(dib_hdr, 0, dib_size); | |
397 dib_hdr->biSize = sizeof(BITMAPINFOHEADER); | |
398 | |
399 /* Get a device-dependent bitmap that's compatible with the | |
400 screen. | |
401 */ | |
402 hdc = GetDC(NULL); | |
403 hbm = CreateCompatibleBitmap( hdc, 1, 1 ); | |
404 | |
405 /* Convert the DDB to a DIB. We need to call GetDIBits twice: | |
406 * the first call just fills in the BITMAPINFOHEADER; the | |
407 * second fills in the bitfields or palette. | |
408 */ | |
409 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); | |
410 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); | |
411 DeleteObject(hbm); | |
412 ReleaseDC(NULL, hdc); | |
413 | |
414 switch( dib_hdr->biBitCount ) | |
415 { | |
416 case 8: return 8; | |
417 case 24: return 24; | |
418 case 32: return 32; | |
419 case 16: | |
420 if( dib_hdr->biCompression == BI_BITFIELDS ) { | |
421 /* check the red mask */ | |
422 switch( ((DWORD*)((char*)dib_hdr + dib_hdr->biSize))[0] ) { | |
423 case 0xf800: return 16; /* 565 */ | |
424 case 0x7c00: return 15; /* 555 */ | |
425 } | |
426 } | |
427 } | |
428 return 0; /* poo. */ | |
429 #endif /* NO_GETDIBITS */ | |
430 } | |
431 | |
432 | |
433 /* Various screen update functions available */ | |
434 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
435 | |
436 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, | |
437 int width, int height, int bpp, Uint32 flags) | |
438 { | |
439 SDL_Surface *video; | |
440 Uint32 prev_flags; | |
441 DWORD style; | |
442 const DWORD directstyle = | |
443 (WS_POPUP); | |
444 const DWORD windowstyle = | |
445 (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
|
446 #ifndef _WIN32_WCE |
0 | 447 const DWORD resizestyle = |
448 (WS_THICKFRAME|WS_MAXIMIZEBOX); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
449 #endif |
0 | 450 int binfo_size; |
451 BITMAPINFO *binfo; | |
452 HDC hdc; | |
453 RECT bounds; | |
454 int x, y; | |
455 BOOL was_visible; | |
456 Uint32 Rmask, Gmask, Bmask; | |
457 | |
458 /* See whether or not we should center the window */ | |
459 was_visible = IsWindowVisible(SDL_Window); | |
460 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
461 #ifdef HAVE_OPENGL |
0 | 462 /* Clean up any GL context that may be hanging around */ |
463 if ( current->flags & SDL_OPENGL ) { | |
464 WIN_GL_ShutDown(this); | |
465 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
466 #endif /* HAVE_OPENGL */ |
0 | 467 |
468 /* Recalculate the bitmasks if necessary */ | |
469 if ( bpp == current->format->BitsPerPixel ) { | |
470 video = current; | |
471 } else { | |
472 switch (bpp) { | |
473 case 15: | |
474 case 16: | |
475 if ( DIB_SussScreenDepth() == 15 ) { | |
476 /* 5-5-5 */ | |
477 Rmask = 0x00007c00; | |
478 Gmask = 0x000003e0; | |
479 Bmask = 0x0000001f; | |
480 } else { | |
481 /* 5-6-5 */ | |
482 Rmask = 0x0000f800; | |
483 Gmask = 0x000007e0; | |
484 Bmask = 0x0000001f; | |
485 } | |
486 break; | |
487 case 24: | |
488 case 32: | |
489 /* GDI defined as 8-8-8 */ | |
490 Rmask = 0x00ff0000; | |
491 Gmask = 0x0000ff00; | |
492 Bmask = 0x000000ff; | |
493 break; | |
494 default: | |
495 Rmask = 0x00000000; | |
496 Gmask = 0x00000000; | |
497 Bmask = 0x00000000; | |
498 break; | |
499 } | |
500 video = SDL_CreateRGBSurface(SDL_SWSURFACE, | |
501 0, 0, bpp, Rmask, Gmask, Bmask, 0); | |
502 if ( video == NULL ) { | |
503 SDL_OutOfMemory(); | |
504 return(NULL); | |
505 } | |
506 } | |
507 | |
508 /* Fill in part of the video surface */ | |
509 prev_flags = video->flags; | |
510 video->flags = 0; /* Clear flags */ | |
511 video->w = width; | |
512 video->h = height; | |
513 video->pitch = SDL_CalculatePitch(video); | |
514 | |
515 #ifndef NO_CHANGEDISPLAYSETTINGS | |
516 /* Set fullscreen mode if appropriate */ | |
517 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
518 DEVMODE settings; | |
519 | |
520 memset(&settings, 0, sizeof(DEVMODE)); | |
521 settings.dmSize = sizeof(DEVMODE); | |
522 settings.dmBitsPerPel = video->format->BitsPerPixel; | |
523 settings.dmPelsWidth = width; | |
524 settings.dmPelsHeight = height; | |
525 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; | |
526 if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) { | |
527 video->flags |= SDL_FULLSCREEN; | |
528 } | |
529 } | |
530 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
531 | |
45
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
532 /* 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
|
533 if ( screen_pal != NULL ) { |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
534 /* RJR: March 28, 2000 |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
535 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
|
536 DeleteObject(screen_pal); |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
537 screen_pal = NULL; |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
538 } |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
539 if ( bpp <= 8 ) |
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 /* RJR: March 28, 2000 |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
542 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
|
543 screen_pal = DIB_CreatePalette(bpp); |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
544 } |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
545 |
0 | 546 style = GetWindowLong(SDL_Window, GWL_STYLE); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
547 #ifndef _WIN32_WCE |
0 | 548 style &= ~(resizestyle|WS_MAXIMIZE); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
549 #endif |
0 | 550 if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { |
551 style &= ~windowstyle; | |
552 style |= directstyle; | |
553 } else { | |
554 #ifndef NO_CHANGEDISPLAYSETTINGS | |
555 if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
556 ChangeDisplaySettings(NULL, 0); | |
557 } | |
558 #endif | |
559 if ( flags & SDL_NOFRAME ) { | |
560 style &= ~windowstyle; | |
561 style |= directstyle; | |
562 video->flags |= SDL_NOFRAME; | |
563 } else { | |
564 style &= ~directstyle; | |
565 style |= windowstyle; | |
566 if ( flags & SDL_RESIZABLE ) { | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
567 #ifndef _WIN32_WCE |
0 | 568 style |= resizestyle; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
569 #endif |
0 | 570 video->flags |= SDL_RESIZABLE; |
571 } | |
572 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
573 #ifndef _WIN32_WCE |
0 | 574 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
|
575 #endif |
0 | 576 } |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
577 |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
578 /* 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
|
579 if (!SDL_windowid) |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
580 SetWindowLong(SDL_Window, GWL_STYLE, style); |
0 | 581 |
582 /* Delete the old bitmap if necessary */ | |
583 if ( screen_bmp != NULL ) { | |
584 DeleteObject(screen_bmp); | |
585 } | |
586 if ( ! (flags & SDL_OPENGL) ) { | |
587 BOOL is16bitmode = (video->format->BytesPerPixel == 2); | |
588 | |
589 /* Suss out the bitmap info header */ | |
590 binfo_size = sizeof(*binfo); | |
591 if( is16bitmode ) { | |
592 /* 16bit modes, palette area used for rgb bitmasks */ | |
593 binfo_size += 3*sizeof(DWORD); | |
594 } else if ( video->format->palette ) { | |
595 binfo_size += video->format->palette->ncolors * | |
596 sizeof(RGBQUAD); | |
597 } | |
598 binfo = (BITMAPINFO *)malloc(binfo_size); | |
599 if ( ! binfo ) { | |
600 if ( video != current ) { | |
601 SDL_FreeSurface(video); | |
602 } | |
603 SDL_OutOfMemory(); | |
604 return(NULL); | |
605 } | |
606 | |
607 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
608 binfo->bmiHeader.biWidth = video->w; | |
609 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ | |
610 binfo->bmiHeader.biPlanes = 1; | |
611 binfo->bmiHeader.biSizeImage = video->h * video->pitch; | |
612 binfo->bmiHeader.biXPelsPerMeter = 0; | |
613 binfo->bmiHeader.biYPelsPerMeter = 0; | |
614 binfo->bmiHeader.biClrUsed = 0; | |
615 binfo->bmiHeader.biClrImportant = 0; | |
616 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; | |
617 | |
618 if ( is16bitmode ) { | |
619 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ | |
620 binfo->bmiHeader.biCompression = BI_BITFIELDS; | |
621 ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; | |
622 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; | |
623 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; | |
624 } else { | |
625 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ | |
626 if ( video->format->palette ) { | |
627 memset(binfo->bmiColors, 0, | |
628 video->format->palette->ncolors*sizeof(RGBQUAD)); | |
629 } | |
630 } | |
631 | |
632 /* Create the offscreen bitmap buffer */ | |
633 hdc = GetDC(SDL_Window); | |
634 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, | |
635 (void **)(&video->pixels), NULL, 0); | |
636 ReleaseDC(SDL_Window, hdc); | |
637 free(binfo); | |
638 if ( screen_bmp == NULL ) { | |
639 if ( video != current ) { | |
640 SDL_FreeSurface(video); | |
641 } | |
642 SDL_SetError("Couldn't create DIB section"); | |
643 return(NULL); | |
644 } | |
645 this->UpdateRects = DIB_NormalUpdate; | |
646 | |
647 /* Set video surface flags */ | |
648 if ( bpp <= 8 ) { | |
649 /* BitBlt() maps colors for us */ | |
650 video->flags |= SDL_HWPALETTE; | |
651 } | |
652 } | |
653 | |
654 /* Resize the window */ | |
655 if ( SDL_windowid == NULL ) { | |
656 UINT swp_flags; | |
657 | |
658 SDL_resizing = 1; | |
659 bounds.left = 0; | |
660 bounds.top = 0; | |
661 bounds.right = video->w; | |
662 bounds.bottom = video->h; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
663 #ifndef _WIN32_WCE |
0 | 664 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
|
665 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
666 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
|
667 #endif |
0 | 668 width = bounds.right-bounds.left; |
669 height = bounds.bottom-bounds.top; | |
670 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; | |
671 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; | |
672 if ( y < 0 ) { /* Cover up title bar for more client area */ | |
673 y -= GetSystemMetrics(SM_CYCAPTION)/2; | |
674 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
675 #ifndef _WIN32_WCE |
0 | 676 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
|
677 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
678 swp_flags = (SWP_NOZORDER | SWP_SHOWWINDOW); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
679 #endif |
0 | 680 if ( was_visible && !(flags & SDL_FULLSCREEN) ) { |
681 swp_flags |= SWP_NOMOVE; | |
682 } | |
683 SetWindowPos(SDL_Window, NULL, x, y, width, height, swp_flags); | |
684 SDL_resizing = 0; | |
685 SetForegroundWindow(SDL_Window); | |
686 } | |
687 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
688 #ifdef HAVE_OPENGL |
0 | 689 /* Set up for OpenGL */ |
690 if ( flags & SDL_OPENGL ) { | |
691 if ( WIN_GL_SetupWindow(this) < 0 ) { | |
692 return(NULL); | |
693 } | |
694 video->flags |= SDL_OPENGL; | |
695 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
696 #endif /* HAVE_OPENGL */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
697 |
0 | 698 /* We're live! */ |
699 return(video); | |
700 } | |
701 | |
702 /* We don't actually allow hardware surfaces in the DIB driver */ | |
703 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) | |
704 { | |
705 return(-1); | |
706 } | |
707 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) | |
708 { | |
709 return; | |
710 } | |
711 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) | |
712 { | |
713 return(0); | |
714 } | |
715 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
716 { | |
717 return; | |
718 } | |
719 | |
720 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
721 { | |
722 HDC hdc, mdc; | |
723 int i; | |
724 | |
725 hdc = GetDC(SDL_Window); | |
726 if ( screen_pal ) { | |
727 SelectPalette(hdc, screen_pal, FALSE); | |
728 } | |
729 mdc = CreateCompatibleDC(hdc); | |
730 SelectObject(mdc, screen_bmp); | |
731 for ( i=0; i<numrects; ++i ) { | |
732 BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, | |
733 mdc, rects[i].x, rects[i].y, SRCCOPY); | |
734 } | |
735 DeleteDC(mdc); | |
736 ReleaseDC(SDL_Window, hdc); | |
737 } | |
738 | |
739 int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
740 { | |
741 RGBQUAD *pal; | |
742 int i; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
743 #ifndef _WIN32_WCE |
0 | 744 HDC hdc, mdc; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
745 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
746 HDC hdc; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
747 #endif |
0 | 748 |
749 /* Update the display palette */ | |
750 hdc = GetDC(SDL_Window); | |
751 if ( screen_pal ) { | |
752 PALETTEENTRY *entries; | |
753 | |
754 entries = (PALETTEENTRY *)alloca(ncolors*sizeof(PALETTEENTRY)); | |
755 for ( i=0; i<ncolors; ++i ) { | |
756 entries[i].peRed = colors[i].r; | |
757 entries[i].peGreen = colors[i].g; | |
758 entries[i].peBlue = colors[i].b; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
759 #ifndef _WIN32_WCE |
0 | 760 entries[i].peFlags = PC_NOCOLLAPSE; |
46
3dcf26fa9d15
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
45
diff
changeset
|
761 #else |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
762 entries[i].peFlags = 0; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
763 #endif |
0 | 764 } |
765 SetPaletteEntries(screen_pal, firstcolor, ncolors, entries); | |
766 SelectPalette(hdc, screen_pal, FALSE); | |
767 RealizePalette(hdc); | |
768 } | |
769 | |
770 /* Copy palette colors into DIB palette */ | |
771 pal = (RGBQUAD *)alloca(ncolors*sizeof(RGBQUAD)); | |
772 for ( i=0; i<ncolors; ++i ) { | |
773 pal[i].rgbRed = colors[i].r; | |
774 pal[i].rgbGreen = colors[i].g; | |
775 pal[i].rgbBlue = colors[i].b; | |
776 pal[i].rgbReserved = 0; | |
777 } | |
778 | |
779 /* 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
|
780 #ifndef _WIN32_WCE |
0 | 781 mdc = CreateCompatibleDC(hdc); |
782 SelectObject(mdc, screen_bmp); | |
783 SetDIBColorTable(mdc, firstcolor, ncolors, pal); | |
784 BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, | |
785 mdc, 0, 0, SRCCOPY); | |
786 DeleteDC(mdc); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
787 #endif |
0 | 788 ReleaseDC(SDL_Window, hdc); |
789 return(1); | |
790 } | |
791 | |
792 static void DIB_CheckGamma(_THIS) | |
793 { | |
794 #ifndef NO_GAMMA_SUPPORT | |
795 HDC hdc; | |
796 WORD ramp[3*256]; | |
797 | |
798 /* If we fail to get gamma, disable gamma control */ | |
799 hdc = GetDC(SDL_Window); | |
800 if ( ! GetDeviceGammaRamp(hdc, ramp) ) { | |
801 this->GetGammaRamp = NULL; | |
802 this->SetGammaRamp = NULL; | |
803 } | |
804 ReleaseDC(SDL_Window, hdc); | |
805 #endif /* !NO_GAMMA_SUPPORT */ | |
806 } | |
807 static void DIB_SwapGamma(_THIS) | |
808 { | |
809 #ifndef NO_GAMMA_SUPPORT | |
810 HDC hdc; | |
811 | |
812 if ( gamma_saved ) { | |
813 hdc = GetDC(SDL_Window); | |
814 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
815 /* About to leave active state, restore gamma */ | |
816 SetDeviceGammaRamp(hdc, gamma_saved); | |
817 } else { | |
818 /* About to enter active state, set game gamma */ | |
819 GetDeviceGammaRamp(hdc, gamma_saved); | |
820 SetDeviceGammaRamp(hdc, this->gamma); | |
821 } | |
822 ReleaseDC(SDL_Window, hdc); | |
823 } | |
824 #endif /* !NO_GAMMA_SUPPORT */ | |
825 } | |
826 static void DIB_QuitGamma(_THIS) | |
827 { | |
828 #ifndef NO_GAMMA_SUPPORT | |
829 if ( gamma_saved ) { | |
830 /* Restore the original gamma if necessary */ | |
831 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
832 HDC hdc; | |
833 | |
834 hdc = GetDC(SDL_Window); | |
835 SetDeviceGammaRamp(hdc, gamma_saved); | |
836 ReleaseDC(SDL_Window, hdc); | |
837 } | |
838 | |
839 /* Free the saved gamma memory */ | |
840 free(gamma_saved); | |
841 gamma_saved = 0; | |
842 } | |
843 #endif /* !NO_GAMMA_SUPPORT */ | |
844 } | |
845 | |
846 #ifndef NO_GAMMA_SUPPORT | |
847 | |
848 static int DIB_SetGammaRamp(_THIS, Uint16 *ramp) | |
849 { | |
850 HDC hdc; | |
851 BOOL succeeded; | |
852 | |
853 /* Set the ramp for the display */ | |
854 if ( ! gamma_saved ) { | |
855 gamma_saved = (WORD *)malloc(3*256*sizeof(*gamma_saved)); | |
856 if ( ! gamma_saved ) { | |
857 SDL_OutOfMemory(); | |
858 return -1; | |
859 } | |
860 hdc = GetDC(SDL_Window); | |
861 GetDeviceGammaRamp(hdc, gamma_saved); | |
862 ReleaseDC(SDL_Window, hdc); | |
863 } | |
864 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
865 hdc = GetDC(SDL_Window); | |
866 succeeded = SetDeviceGammaRamp(hdc, ramp); | |
867 ReleaseDC(SDL_Window, hdc); | |
868 } else { | |
869 succeeded = TRUE; | |
870 } | |
871 return succeeded ? 0 : -1; | |
872 } | |
873 | |
874 static int DIB_GetGammaRamp(_THIS, Uint16 *ramp) | |
875 { | |
876 HDC hdc; | |
877 BOOL succeeded; | |
878 | |
879 /* Get the ramp from the display */ | |
880 hdc = GetDC(SDL_Window); | |
881 succeeded = GetDeviceGammaRamp(hdc, ramp); | |
882 ReleaseDC(SDL_Window, hdc); | |
883 return succeeded ? 0 : -1; | |
884 } | |
885 | |
886 #endif /* !NO_GAMMA_SUPPORT */ | |
887 | |
888 void DIB_VideoQuit(_THIS) | |
889 { | |
890 /* Destroy the window and everything associated with it */ | |
891 if ( SDL_Window ) { | |
892 /* Delete the screen bitmap (also frees screen->pixels) */ | |
893 if ( this->screen ) { | |
894 #ifndef NO_CHANGEDISPLAYSETTINGS | |
895 if ( this->screen->flags & SDL_FULLSCREEN ) { | |
896 ChangeDisplaySettings(NULL, 0); | |
897 } | |
898 #endif | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
899 #ifdef HAVE_OPENGL |
0 | 900 if ( this->screen->flags & SDL_OPENGL ) { |
901 WIN_GL_ShutDown(this); | |
902 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
903 #endif /* HAVE_OPENGL */ |
0 | 904 this->screen->pixels = NULL; |
905 } | |
906 if ( screen_bmp ) { | |
907 DeleteObject(screen_bmp); | |
908 screen_bmp = NULL; | |
909 } | |
910 if ( screen_icn ) { | |
911 DestroyIcon(screen_icn); | |
912 screen_icn = NULL; | |
913 } | |
914 DIB_QuitGamma(this); | |
915 DIB_DestroyWindow(this); | |
916 | |
917 SDL_Window = NULL; | |
918 } | |
919 } | |
920 | |
921 /* Exported for the windows message loop only */ | |
922 static void DIB_FocusPalette(_THIS, int foreground) | |
923 { | |
924 if ( screen_pal != NULL ) { | |
925 HDC hdc; | |
926 | |
927 hdc = GetDC(SDL_Window); | |
928 SelectPalette(hdc, screen_pal, FALSE); | |
929 if ( RealizePalette(hdc) ) | |
930 InvalidateRect(SDL_Window, NULL, FALSE); | |
931 ReleaseDC(SDL_Window, hdc); | |
932 } | |
933 } | |
934 static void DIB_RealizePalette(_THIS) | |
935 { | |
936 DIB_FocusPalette(this, 1); | |
937 } | |
938 static void DIB_PaletteChanged(_THIS, HWND window) | |
939 { | |
940 if ( window != SDL_Window ) { | |
941 DIB_FocusPalette(this, 0); | |
942 } | |
943 } | |
944 | |
945 /* Exported for the windows message loop only */ | |
946 static void DIB_WinPAINT(_THIS, HDC hdc) | |
947 { | |
948 HDC mdc; | |
949 | |
950 if ( screen_pal ) { | |
951 SelectPalette(hdc, screen_pal, FALSE); | |
952 } | |
953 mdc = CreateCompatibleDC(hdc); | |
954 SelectObject(mdc, screen_bmp); | |
955 BitBlt(hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h, | |
956 mdc, 0, 0, SRCCOPY); | |
957 DeleteDC(mdc); | |
958 } | |
959 | |
960 /* Stub in case DirectX isn't available */ | |
961 #ifndef ENABLE_DIRECTX | |
962 void DX5_SoundFocus(HWND hwnd) | |
963 { | |
964 return; | |
965 } | |
966 #endif |