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