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