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