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