Mercurial > sdl-ios-xcode
annotate src/video/windib/SDL_dibvideo.c @ 1291:31331c444ea2
Only save the window position if we're in windowed mode
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 29 Jan 2006 22:09:26 +0000 |
parents | c4a5a772c5d9 |
children | 59c7a470a51e |
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 } | |
1291
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
471 SDL_resizing = 1; |
0 | 472 |
473 /* Recalculate the bitmasks if necessary */ | |
474 if ( bpp == current->format->BitsPerPixel ) { | |
475 video = current; | |
476 } else { | |
477 switch (bpp) { | |
478 case 15: | |
479 case 16: | |
480 if ( DIB_SussScreenDepth() == 15 ) { | |
481 /* 5-5-5 */ | |
482 Rmask = 0x00007c00; | |
483 Gmask = 0x000003e0; | |
484 Bmask = 0x0000001f; | |
485 } else { | |
486 /* 5-6-5 */ | |
487 Rmask = 0x0000f800; | |
488 Gmask = 0x000007e0; | |
489 Bmask = 0x0000001f; | |
490 } | |
491 break; | |
492 case 24: | |
493 case 32: | |
494 /* GDI defined as 8-8-8 */ | |
495 Rmask = 0x00ff0000; | |
496 Gmask = 0x0000ff00; | |
497 Bmask = 0x000000ff; | |
498 break; | |
499 default: | |
500 Rmask = 0x00000000; | |
501 Gmask = 0x00000000; | |
502 Bmask = 0x00000000; | |
503 break; | |
504 } | |
505 video = SDL_CreateRGBSurface(SDL_SWSURFACE, | |
506 0, 0, bpp, Rmask, Gmask, Bmask, 0); | |
507 if ( video == NULL ) { | |
508 SDL_OutOfMemory(); | |
509 return(NULL); | |
510 } | |
511 } | |
512 | |
513 /* Fill in part of the video surface */ | |
514 prev_flags = video->flags; | |
515 video->flags = 0; /* Clear flags */ | |
516 video->w = width; | |
517 video->h = height; | |
518 video->pitch = SDL_CalculatePitch(video); | |
519 | |
1152
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
520 /* 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
|
521 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
|
522 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
|
523 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
|
524 */ |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
525 SDL_VideoSurface = video; |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
526 |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
527 #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
|
528 if ( flags & SDL_FULLSCREEN ) |
514
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 #endif |
1152
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
531 |
0 | 532 #ifndef NO_CHANGEDISPLAYSETTINGS |
533 /* Set fullscreen mode if appropriate */ | |
534 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
535 DEVMODE settings; | |
536 | |
537 memset(&settings, 0, sizeof(DEVMODE)); | |
538 settings.dmSize = sizeof(DEVMODE); | |
539 settings.dmBitsPerPel = video->format->BitsPerPixel; | |
540 settings.dmPelsWidth = width; | |
541 settings.dmPelsHeight = height; | |
542 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; | |
543 if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) { | |
544 video->flags |= SDL_FULLSCREEN; | |
304
ec53caed9fb2
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
545 SDL_fullscreen_mode = settings; |
0 | 546 } |
547 } | |
548 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
549 | |
45
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
550 /* 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
|
551 if ( screen_pal != NULL ) { |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
552 /* RJR: March 28, 2000 |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
553 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
|
554 DeleteObject(screen_pal); |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
555 screen_pal = NULL; |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
556 } |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
557 if ( bpp <= 8 ) |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
558 { |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
559 /* RJR: March 28, 2000 |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
560 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
|
561 screen_pal = DIB_CreatePalette(bpp); |
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 |
0 | 564 style = GetWindowLong(SDL_Window, GWL_STYLE); |
565 style &= ~(resizestyle|WS_MAXIMIZE); | |
566 if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
567 style &= ~windowstyle; | |
568 style |= directstyle; | |
569 } else { | |
570 #ifndef NO_CHANGEDISPLAYSETTINGS | |
571 if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
572 ChangeDisplaySettings(NULL, 0); | |
573 } | |
574 #endif | |
575 if ( flags & SDL_NOFRAME ) { | |
576 style &= ~windowstyle; | |
577 style |= directstyle; | |
578 video->flags |= SDL_NOFRAME; | |
579 } else { | |
580 style &= ~directstyle; | |
581 style |= windowstyle; | |
582 if ( flags & SDL_RESIZABLE ) { | |
583 style |= resizestyle; | |
584 video->flags |= SDL_RESIZABLE; | |
585 } | |
586 } | |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
587 #if WS_MAXIMIZE |
0 | 588 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
|
589 #endif |
0 | 590 } |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
591 |
448
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
592 /* DJM: Don't piss of anyone who has setup his own window */ |
1280
f61f045343d3
Re-query the SDL_WINDOWID each time we initialize the video
Sam Lantinga <slouken@libsdl.org>
parents:
1251
diff
changeset
|
593 if ( !SDL_windowid ) |
448
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
594 SetWindowLong(SDL_Window, GWL_STYLE, style); |
0 | 595 |
596 /* Delete the old bitmap if necessary */ | |
597 if ( screen_bmp != NULL ) { | |
598 DeleteObject(screen_bmp); | |
599 } | |
600 if ( ! (flags & SDL_OPENGL) ) { | |
601 BOOL is16bitmode = (video->format->BytesPerPixel == 2); | |
602 | |
603 /* Suss out the bitmap info header */ | |
604 binfo_size = sizeof(*binfo); | |
605 if( is16bitmode ) { | |
606 /* 16bit modes, palette area used for rgb bitmasks */ | |
607 binfo_size += 3*sizeof(DWORD); | |
608 } else if ( video->format->palette ) { | |
609 binfo_size += video->format->palette->ncolors * | |
610 sizeof(RGBQUAD); | |
611 } | |
612 binfo = (BITMAPINFO *)malloc(binfo_size); | |
613 if ( ! binfo ) { | |
614 if ( video != current ) { | |
615 SDL_FreeSurface(video); | |
616 } | |
617 SDL_OutOfMemory(); | |
618 return(NULL); | |
619 } | |
620 | |
621 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
622 binfo->bmiHeader.biWidth = video->w; | |
623 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ | |
624 binfo->bmiHeader.biPlanes = 1; | |
625 binfo->bmiHeader.biSizeImage = video->h * video->pitch; | |
626 binfo->bmiHeader.biXPelsPerMeter = 0; | |
627 binfo->bmiHeader.biYPelsPerMeter = 0; | |
628 binfo->bmiHeader.biClrUsed = 0; | |
629 binfo->bmiHeader.biClrImportant = 0; | |
630 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; | |
631 | |
632 if ( is16bitmode ) { | |
633 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ | |
634 binfo->bmiHeader.biCompression = BI_BITFIELDS; | |
635 ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; | |
636 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; | |
637 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; | |
638 } else { | |
639 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ | |
640 if ( video->format->palette ) { | |
641 memset(binfo->bmiColors, 0, | |
642 video->format->palette->ncolors*sizeof(RGBQUAD)); | |
643 } | |
644 } | |
645 | |
646 /* Create the offscreen bitmap buffer */ | |
647 hdc = GetDC(SDL_Window); | |
648 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, | |
649 (void **)(&video->pixels), NULL, 0); | |
650 ReleaseDC(SDL_Window, hdc); | |
651 free(binfo); | |
652 if ( screen_bmp == NULL ) { | |
653 if ( video != current ) { | |
654 SDL_FreeSurface(video); | |
655 } | |
656 SDL_SetError("Couldn't create DIB section"); | |
657 return(NULL); | |
658 } | |
659 this->UpdateRects = DIB_NormalUpdate; | |
660 | |
661 /* Set video surface flags */ | |
662 if ( bpp <= 8 ) { | |
663 /* BitBlt() maps colors for us */ | |
664 video->flags |= SDL_HWPALETTE; | |
665 } | |
666 } | |
667 | |
668 /* Resize the window */ | |
1290
c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
669 if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { |
448
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
670 HWND top; |
0 | 671 UINT swp_flags; |
1290
c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
672 const char *window = NULL; |
c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
673 const char *center = NULL; |
833
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
674 |
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 ( !SDL_windowX && !SDL_windowY ) { |
1290
c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
676 window = getenv("SDL_VIDEO_WINDOW_POS"); |
c4a5a772c5d9
The event code was fine, and calculated the SDL_windowX/Y correctly.
Sam Lantinga <slouken@libsdl.org>
parents:
1288
diff
changeset
|
677 center = getenv("SDL_VIDEO_CENTERED"); |
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 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
|
679 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
|
680 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
|
681 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
|
682 } |
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 ( 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
|
684 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
|
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 } |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
687 } |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
688 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); |
0 | 689 |
833
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.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
|
691 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
|
692 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
|
693 bounds.bottom = SDL_windowY+video->h; |
453
a6fa62b1be09
Updated for embedded Visual C++ 4.0
Sam Lantinga <slouken@libsdl.org>
parents:
448
diff
changeset
|
694 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); |
0 | 695 width = bounds.right-bounds.left; |
696 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
|
697 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
|
698 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
|
699 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
|
700 } else if ( center ) { |
96671ebc50a4
Date: Mon, 25 Oct 2004 17:30:06 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
966
diff
changeset
|
701 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
|
702 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
|
703 } 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
|
704 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
|
705 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
|
706 } else { |
31fa08b36380
Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
766
diff
changeset
|
707 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
|
708 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
|
709 } |
448
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
710 if ( flags & SDL_FULLSCREEN ) { |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
711 top = HWND_TOPMOST; |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
712 } else { |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
713 top = HWND_NOTOPMOST; |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
714 } |
323c766f5a46
Fullscreen windows are always topmost under Windows
Sam Lantinga <slouken@libsdl.org>
parents:
442
diff
changeset
|
715 SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); |
1291
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
716 if ( !(flags & SDL_FULLSCREEN) ) { |
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
717 SDL_windowX = SDL_bounds.left; |
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
718 SDL_windowY = SDL_bounds.top; |
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
719 } |
0 | 720 SetForegroundWindow(SDL_Window); |
721 } | |
1291
31331c444ea2
Only save the window position if we're in windowed mode
Sam Lantinga <slouken@libsdl.org>
parents:
1290
diff
changeset
|
722 SDL_resizing = 0; |
0 | 723 |
724 /* Set up for OpenGL */ | |
725 if ( flags & SDL_OPENGL ) { | |
726 if ( WIN_GL_SetupWindow(this) < 0 ) { | |
727 return(NULL); | |
728 } | |
729 video->flags |= SDL_OPENGL; | |
730 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
731 |
0 | 732 /* We're live! */ |
733 return(video); | |
734 } | |
735 | |
736 /* We don't actually allow hardware surfaces in the DIB driver */ | |
737 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) | |
738 { | |
739 return(-1); | |
740 } | |
741 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) | |
742 { | |
743 return; | |
744 } | |
745 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) | |
746 { | |
747 return(0); | |
748 } | |
749 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
750 { | |
751 return; | |
752 } | |
753 | |
754 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
755 { | |
756 HDC hdc, mdc; | |
757 int i; | |
758 | |
759 hdc = GetDC(SDL_Window); | |
760 if ( screen_pal ) { | |
761 SelectPalette(hdc, screen_pal, FALSE); | |
762 } | |
763 mdc = CreateCompatibleDC(hdc); | |
764 SelectObject(mdc, screen_bmp); | |
765 for ( i=0; i<numrects; ++i ) { | |
766 BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, | |
767 mdc, rects[i].x, rects[i].y, SRCCOPY); | |
768 } | |
769 DeleteDC(mdc); | |
770 ReleaseDC(SDL_Window, hdc); | |
771 } | |
772 | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
773 |
0 | 774 int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) |
775 { | |
776 RGBQUAD *pal; | |
777 int i; | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
778 #if (_WIN32_WCE < 400 ) |
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
779 HDC hdc; |
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
780 #else |
0 | 781 HDC hdc, mdc; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
782 #endif |
0 | 783 |
784 /* Update the display palette */ | |
785 hdc = GetDC(SDL_Window); | |
786 if ( screen_pal ) { | |
787 PALETTEENTRY *entries; | |
788 | |
789 entries = (PALETTEENTRY *)alloca(ncolors*sizeof(PALETTEENTRY)); | |
790 for ( i=0; i<ncolors; ++i ) { | |
791 entries[i].peRed = colors[i].r; | |
792 entries[i].peGreen = colors[i].g; | |
793 entries[i].peBlue = colors[i].b; | |
794 entries[i].peFlags = PC_NOCOLLAPSE; | |
795 } | |
796 SetPaletteEntries(screen_pal, firstcolor, ncolors, entries); | |
797 SelectPalette(hdc, screen_pal, FALSE); | |
798 RealizePalette(hdc); | |
799 } | |
800 | |
801 /* Copy palette colors into DIB palette */ | |
802 pal = (RGBQUAD *)alloca(ncolors*sizeof(RGBQUAD)); | |
803 for ( i=0; i<ncolors; ++i ) { | |
804 pal[i].rgbRed = colors[i].r; | |
805 pal[i].rgbGreen = colors[i].g; | |
806 pal[i].rgbBlue = colors[i].b; | |
807 pal[i].rgbReserved = 0; | |
808 } | |
809 | |
810 /* Set the DIB palette and update the display */ | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
811 #if ( _WIN32_WCE >= 400 ) |
0 | 812 mdc = CreateCompatibleDC(hdc); |
813 SelectObject(mdc, screen_bmp); | |
814 SetDIBColorTable(mdc, firstcolor, ncolors, pal); | |
815 BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, | |
816 mdc, 0, 0, SRCCOPY); | |
817 DeleteDC(mdc); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
818 #endif |
0 | 819 ReleaseDC(SDL_Window, hdc); |
820 return(1); | |
821 } | |
822 | |
1251
86d0d01290ea
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
Ryan C. Gordon <icculus@icculus.org>
parents:
1152
diff
changeset
|
823 |
0 | 824 static void DIB_CheckGamma(_THIS) |
825 { | |
826 #ifndef NO_GAMMA_SUPPORT | |
827 HDC hdc; | |
828 WORD ramp[3*256]; | |
829 | |
830 /* If we fail to get gamma, disable gamma control */ | |
831 hdc = GetDC(SDL_Window); | |
832 if ( ! GetDeviceGammaRamp(hdc, ramp) ) { | |
833 this->GetGammaRamp = NULL; | |
834 this->SetGammaRamp = NULL; | |
835 } | |
836 ReleaseDC(SDL_Window, hdc); | |
837 #endif /* !NO_GAMMA_SUPPORT */ | |
838 } | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
839 void DIB_SwapGamma(_THIS) |
0 | 840 { |
841 #ifndef NO_GAMMA_SUPPORT | |
842 HDC hdc; | |
843 | |
844 if ( gamma_saved ) { | |
845 hdc = GetDC(SDL_Window); | |
846 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
847 /* About to leave active state, restore gamma */ | |
848 SetDeviceGammaRamp(hdc, gamma_saved); | |
849 } else { | |
850 /* About to enter active state, set game gamma */ | |
851 GetDeviceGammaRamp(hdc, gamma_saved); | |
852 SetDeviceGammaRamp(hdc, this->gamma); | |
853 } | |
854 ReleaseDC(SDL_Window, hdc); | |
855 } | |
856 #endif /* !NO_GAMMA_SUPPORT */ | |
857 } | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
858 void DIB_QuitGamma(_THIS) |
0 | 859 { |
860 #ifndef NO_GAMMA_SUPPORT | |
861 if ( gamma_saved ) { | |
862 /* Restore the original gamma if necessary */ | |
863 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
864 HDC hdc; | |
865 | |
866 hdc = GetDC(SDL_Window); | |
867 SetDeviceGammaRamp(hdc, gamma_saved); | |
868 ReleaseDC(SDL_Window, hdc); | |
869 } | |
870 | |
871 /* Free the saved gamma memory */ | |
872 free(gamma_saved); | |
873 gamma_saved = 0; | |
874 } | |
875 #endif /* !NO_GAMMA_SUPPORT */ | |
876 } | |
877 | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
878 int DIB_SetGammaRamp(_THIS, Uint16 *ramp) |
0 | 879 { |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
880 #ifdef NO_GAMMA_SUPPORT |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
881 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
|
882 return -1; |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
883 #else |
0 | 884 HDC hdc; |
885 BOOL succeeded; | |
886 | |
887 /* Set the ramp for the display */ | |
888 if ( ! gamma_saved ) { | |
889 gamma_saved = (WORD *)malloc(3*256*sizeof(*gamma_saved)); | |
890 if ( ! gamma_saved ) { | |
891 SDL_OutOfMemory(); | |
892 return -1; | |
893 } | |
894 hdc = GetDC(SDL_Window); | |
895 GetDeviceGammaRamp(hdc, gamma_saved); | |
896 ReleaseDC(SDL_Window, hdc); | |
897 } | |
898 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
899 hdc = GetDC(SDL_Window); | |
900 succeeded = SetDeviceGammaRamp(hdc, ramp); | |
901 ReleaseDC(SDL_Window, hdc); | |
902 } else { | |
903 succeeded = TRUE; | |
904 } | |
905 return succeeded ? 0 : -1; | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
906 #endif /* !NO_GAMMA_SUPPORT */ |
0 | 907 } |
908 | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
909 int DIB_GetGammaRamp(_THIS, Uint16 *ramp) |
0 | 910 { |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
911 #ifdef NO_GAMMA_SUPPORT |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
912 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
|
913 return -1; |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
914 #else |
0 | 915 HDC hdc; |
916 BOOL succeeded; | |
917 | |
918 /* Get the ramp from the display */ | |
919 hdc = GetDC(SDL_Window); | |
920 succeeded = GetDeviceGammaRamp(hdc, ramp); | |
921 ReleaseDC(SDL_Window, hdc); | |
922 return succeeded ? 0 : -1; | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
923 #endif /* !NO_GAMMA_SUPPORT */ |
0 | 924 } |
925 | |
442
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
926 static void FlushMessageQueue() |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
927 { |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
928 MSG msg; |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
929 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
|
930 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
|
931 TranslateMessage( &msg ); |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
932 DispatchMessage( &msg ); |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
933 } |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
934 } |
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
935 |
0 | 936 void DIB_VideoQuit(_THIS) |
937 { | |
938 /* Destroy the window and everything associated with it */ | |
939 if ( SDL_Window ) { | |
940 /* Delete the screen bitmap (also frees screen->pixels) */ | |
941 if ( this->screen ) { | |
942 #ifndef NO_CHANGEDISPLAYSETTINGS | |
943 if ( this->screen->flags & SDL_FULLSCREEN ) { | |
944 ChangeDisplaySettings(NULL, 0); | |
376
a5f60a847a89
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
374
diff
changeset
|
945 ShowWindow(SDL_Window, SW_HIDE); |
0 | 946 } |
947 #endif | |
948 if ( this->screen->flags & SDL_OPENGL ) { | |
949 WIN_GL_ShutDown(this); | |
950 } | |
951 this->screen->pixels = NULL; | |
952 } | |
953 if ( screen_bmp ) { | |
954 DeleteObject(screen_bmp); | |
955 screen_bmp = NULL; | |
956 } | |
957 if ( screen_icn ) { | |
958 DestroyIcon(screen_icn); | |
959 screen_icn = NULL; | |
960 } | |
961 DIB_QuitGamma(this); | |
962 DIB_DestroyWindow(this); | |
442
b37ce4813ad4
Flush message queue when shutting down video mode on Windows
Sam Lantinga <slouken@libsdl.org>
parents:
376
diff
changeset
|
963 FlushMessageQueue(); |
0 | 964 |
965 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
|
966 |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
967 #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
|
968 |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
969 // 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
|
970 if( aygshell ) |
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 FreeLibrary(aygshell); |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
973 aygshell = NULL; |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
974 } |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
975 #endif |
51a8702d8ecd
Updates to PocketPC (WinCE) support, thanks to Dmitry Yakimov at
Ryan C. Gordon <icculus@icculus.org>
parents:
1145
diff
changeset
|
976 |
0 | 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 |