comparison src/video/windib/SDL_dibvideo.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 14717b52abc0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
41 #include "../wincommon/SDL_wingl_c.h" 41 #include "../wincommon/SDL_wingl_c.h"
42 42
43 #ifdef _WIN32_WCE 43 #ifdef _WIN32_WCE
44 #define NO_GETDIBITS 44 #define NO_GETDIBITS
45 #define NO_GAMMA_SUPPORT 45 #define NO_GAMMA_SUPPORT
46 #if _WIN32_WCE < 420 46 #if _WIN32_WCE < 420
47 #define NO_CHANGEDISPLAYSETTINGS 47 #define NO_CHANGEDISPLAYSETTINGS
48 #else 48 #else
49 #define ChangeDisplaySettings(lpDevMode, dwFlags) ChangeDisplaySettingsEx(NULL, (lpDevMode), 0, (dwFlags), 0) 49 #define ChangeDisplaySettings(lpDevMode, dwFlags) ChangeDisplaySettingsEx(NULL, (lpDevMode), 0, (dwFlags), 0)
50 #endif 50 #endif
51 #endif 51 #endif
52 #ifndef WS_MAXIMIZE 52 #ifndef WS_MAXIMIZE
53 #define WS_MAXIMIZE 0 53 #define WS_MAXIMIZE 0
54 #endif 54 #endif
55 #ifndef WS_THICKFRAME 55 #ifndef WS_THICKFRAME
66 // defined and used in SDL_sysevents.c 66 // defined and used in SDL_sysevents.c
67 extern HINSTANCE aygshell; 67 extern HINSTANCE aygshell;
68 #endif 68 #endif
69 69
70 /* Initialization/Query functions */ 70 /* Initialization/Query functions */
71 static int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat); 71 static int DIB_VideoInit (_THIS, SDL_PixelFormat * vformat);
72 static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 72 static SDL_Rect **DIB_ListModes (_THIS, SDL_PixelFormat * format,
73 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 73 Uint32 flags);
74 static int DIB_SetColors(_THIS, int firstcolor, int ncolors, 74 SDL_Surface *DIB_SetVideoMode (_THIS, SDL_Surface * current, int width,
75 SDL_Color *colors); 75 int height, int bpp, Uint32 flags);
76 static void DIB_CheckGamma(_THIS); 76 static int DIB_SetColors (_THIS, int firstcolor, int ncolors,
77 void DIB_SwapGamma(_THIS); 77 SDL_Color * colors);
78 void DIB_QuitGamma(_THIS); 78 static void DIB_CheckGamma (_THIS);
79 int DIB_SetGammaRamp(_THIS, Uint16 *ramp); 79 void DIB_SwapGamma (_THIS);
80 int DIB_GetGammaRamp(_THIS, Uint16 *ramp); 80 void DIB_QuitGamma (_THIS);
81 static void DIB_VideoQuit(_THIS); 81 int DIB_SetGammaRamp (_THIS, Uint16 * ramp);
82 int DIB_GetGammaRamp (_THIS, Uint16 * ramp);
83 static void DIB_VideoQuit (_THIS);
82 84
83 /* Hardware surface functions */ 85 /* Hardware surface functions */
84 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface); 86 static int DIB_AllocHWSurface (_THIS, SDL_Surface * surface);
85 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface); 87 static int DIB_LockHWSurface (_THIS, SDL_Surface * surface);
86 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface); 88 static void DIB_UnlockHWSurface (_THIS, SDL_Surface * surface);
87 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface); 89 static void DIB_FreeHWSurface (_THIS, SDL_Surface * surface);
88 90
89 /* Windows message handling functions */ 91 /* Windows message handling functions */
90 static void DIB_RealizePalette(_THIS); 92 static void DIB_RealizePalette (_THIS);
91 static void DIB_PaletteChanged(_THIS, HWND window); 93 static void DIB_PaletteChanged (_THIS, HWND window);
92 static void DIB_WinPAINT(_THIS, HDC hdc); 94 static void DIB_WinPAINT (_THIS, HDC hdc);
93 95
94 /* helper fn */ 96 /* helper fn */
95 static int DIB_SussScreenDepth(); 97 static int DIB_SussScreenDepth ();
96 98
97 /* DIB driver bootstrap functions */ 99 /* DIB driver bootstrap functions */
98 100
99 static int DIB_Available(void) 101 static int
100 { 102 DIB_Available (void)
101 return(1); 103 {
102 } 104 return (1);
103 105 }
104 static void DIB_DeleteDevice(SDL_VideoDevice *device) 106
105 { 107 static void
106 if ( device ) { 108 DIB_DeleteDevice (SDL_VideoDevice * device)
107 if ( device->hidden ) { 109 {
108 SDL_free(device->hidden); 110 if (device) {
109 } 111 if (device->hidden) {
110 if ( device->gl_data ) { 112 SDL_free (device->hidden);
111 SDL_free(device->gl_data); 113 }
112 } 114 if (device->gl_data) {
113 SDL_free(device); 115 SDL_free (device->gl_data);
114 } 116 }
115 } 117 SDL_free (device);
116 118 }
117 static SDL_VideoDevice *DIB_CreateDevice(int devindex) 119 }
118 { 120
119 SDL_VideoDevice *device; 121 static SDL_VideoDevice *
120 122 DIB_CreateDevice (int devindex)
121 /* Initialize all variables that we clean on shutdown */ 123 {
122 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 124 SDL_VideoDevice *device;
123 if ( device ) { 125
124 SDL_memset(device, 0, (sizeof *device)); 126 /* Initialize all variables that we clean on shutdown */
125 device->hidden = (struct SDL_PrivateVideoData *) 127 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
126 SDL_malloc((sizeof *device->hidden)); 128 if (device) {
127 device->gl_data = (struct SDL_PrivateGLData *) 129 SDL_memset (device, 0, (sizeof *device));
128 SDL_malloc((sizeof *device->gl_data)); 130 device->hidden = (struct SDL_PrivateVideoData *)
129 } 131 SDL_malloc ((sizeof *device->hidden));
130 if ( (device == NULL) || (device->hidden == NULL) || 132 device->gl_data = (struct SDL_PrivateGLData *)
131 (device->gl_data == NULL) ) { 133 SDL_malloc ((sizeof *device->gl_data));
132 SDL_OutOfMemory(); 134 }
133 DIB_DeleteDevice(device); 135 if ((device == NULL) || (device->hidden == NULL) ||
134 return(NULL); 136 (device->gl_data == NULL)) {
135 } 137 SDL_OutOfMemory ();
136 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 138 DIB_DeleteDevice (device);
137 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data)); 139 return (NULL);
138 140 }
139 /* Set the function pointers */ 141 SDL_memset (device->hidden, 0, (sizeof *device->hidden));
140 device->VideoInit = DIB_VideoInit; 142 SDL_memset (device->gl_data, 0, (sizeof *device->gl_data));
141 device->ListModes = DIB_ListModes; 143
142 device->SetVideoMode = DIB_SetVideoMode; 144 /* Set the function pointers */
143 device->UpdateMouse = WIN_UpdateMouse; 145 device->VideoInit = DIB_VideoInit;
144 device->SetColors = DIB_SetColors; 146 device->ListModes = DIB_ListModes;
145 device->UpdateRects = NULL; 147 device->SetVideoMode = DIB_SetVideoMode;
146 device->VideoQuit = DIB_VideoQuit; 148 device->UpdateMouse = WIN_UpdateMouse;
147 device->AllocHWSurface = DIB_AllocHWSurface; 149 device->SetColors = DIB_SetColors;
148 device->CheckHWBlit = NULL; 150 device->UpdateRects = NULL;
149 device->FillHWRect = NULL; 151 device->VideoQuit = DIB_VideoQuit;
150 device->SetHWColorKey = NULL; 152 device->AllocHWSurface = DIB_AllocHWSurface;
151 device->SetHWAlpha = NULL; 153 device->CheckHWBlit = NULL;
152 device->LockHWSurface = DIB_LockHWSurface; 154 device->FillHWRect = NULL;
153 device->UnlockHWSurface = DIB_UnlockHWSurface; 155 device->SetHWColorKey = NULL;
154 device->FlipHWSurface = NULL; 156 device->SetHWAlpha = NULL;
155 device->FreeHWSurface = DIB_FreeHWSurface; 157 device->LockHWSurface = DIB_LockHWSurface;
156 device->SetGammaRamp = DIB_SetGammaRamp; 158 device->UnlockHWSurface = DIB_UnlockHWSurface;
157 device->GetGammaRamp = DIB_GetGammaRamp; 159 device->FlipHWSurface = NULL;
160 device->FreeHWSurface = DIB_FreeHWSurface;
161 device->SetGammaRamp = DIB_SetGammaRamp;
162 device->GetGammaRamp = DIB_GetGammaRamp;
158 #if SDL_VIDEO_OPENGL 163 #if SDL_VIDEO_OPENGL
159 device->GL_LoadLibrary = WIN_GL_LoadLibrary; 164 device->GL_LoadLibrary = WIN_GL_LoadLibrary;
160 device->GL_GetProcAddress = WIN_GL_GetProcAddress; 165 device->GL_GetProcAddress = WIN_GL_GetProcAddress;
161 device->GL_GetAttribute = WIN_GL_GetAttribute; 166 device->GL_GetAttribute = WIN_GL_GetAttribute;
162 device->GL_MakeCurrent = WIN_GL_MakeCurrent; 167 device->GL_MakeCurrent = WIN_GL_MakeCurrent;
163 device->GL_SwapBuffers = WIN_GL_SwapBuffers; 168 device->GL_SwapBuffers = WIN_GL_SwapBuffers;
164 #endif 169 #endif
165 device->SetCaption = WIN_SetWMCaption; 170 device->SetCaption = WIN_SetWMCaption;
166 device->SetIcon = WIN_SetWMIcon; 171 device->SetIcon = WIN_SetWMIcon;
167 device->IconifyWindow = WIN_IconifyWindow; 172 device->IconifyWindow = WIN_IconifyWindow;
168 device->GrabInput = WIN_GrabInput; 173 device->GrabInput = WIN_GrabInput;
169 device->GetWMInfo = WIN_GetWMInfo; 174 device->GetWMInfo = WIN_GetWMInfo;
170 device->FreeWMCursor = WIN_FreeWMCursor; 175 device->FreeWMCursor = WIN_FreeWMCursor;
171 device->CreateWMCursor = WIN_CreateWMCursor; 176 device->CreateWMCursor = WIN_CreateWMCursor;
172 device->ShowWMCursor = WIN_ShowWMCursor; 177 device->ShowWMCursor = WIN_ShowWMCursor;
173 device->WarpWMCursor = WIN_WarpWMCursor; 178 device->WarpWMCursor = WIN_WarpWMCursor;
174 device->CheckMouseMode = WIN_CheckMouseMode; 179 device->CheckMouseMode = WIN_CheckMouseMode;
175 device->InitOSKeymap = DIB_InitOSKeymap; 180 device->InitOSKeymap = DIB_InitOSKeymap;
176 device->PumpEvents = DIB_PumpEvents; 181 device->PumpEvents = DIB_PumpEvents;
177 182
178 /* Set up the windows message handling functions */ 183 /* Set up the windows message handling functions */
179 WIN_RealizePalette = DIB_RealizePalette; 184 WIN_RealizePalette = DIB_RealizePalette;
180 WIN_PaletteChanged = DIB_PaletteChanged; 185 WIN_PaletteChanged = DIB_PaletteChanged;
181 WIN_WinPAINT = DIB_WinPAINT; 186 WIN_WinPAINT = DIB_WinPAINT;
182 HandleMessage = DIB_HandleMessage; 187 HandleMessage = DIB_HandleMessage;
183 188
184 device->free = DIB_DeleteDevice; 189 device->free = DIB_DeleteDevice;
185 190
186 /* We're finally ready */ 191 /* We're finally ready */
187 return device; 192 return device;
188 } 193 }
189 194
190 VideoBootStrap WINDIB_bootstrap = { 195 VideoBootStrap WINDIB_bootstrap = {
191 "windib", "Win95/98/NT/2000/CE GDI", 196 "windib", "Win95/98/NT/2000/CE GDI",
192 DIB_Available, DIB_CreateDevice 197 DIB_Available, DIB_CreateDevice
193 }; 198 };
194 199
195 static int cmpmodes(const void *va, const void *vb) 200 static int
196 { 201 cmpmodes (const void *va, const void *vb)
197 SDL_Rect *a = *(SDL_Rect **)va; 202 {
198 SDL_Rect *b = *(SDL_Rect **)vb; 203 SDL_Rect *a = *(SDL_Rect **) va;
199 if ( a->w == b->w ) 204 SDL_Rect *b = *(SDL_Rect **) vb;
205 if (a->w == b->w)
200 return b->h - a->h; 206 return b->h - a->h;
201 else 207 else
202 return b->w - a->w; 208 return b->w - a->w;
203 } 209 }
204 210
205 static int DIB_AddMode(_THIS, int bpp, int w, int h) 211 static int
206 { 212 DIB_AddMode (_THIS, int bpp, int w, int h)
207 SDL_Rect *mode; 213 {
208 int i, index; 214 SDL_Rect *mode;
209 int next_mode; 215 int i, index;
210 216 int next_mode;
211 /* Check to see if we already have this mode */ 217
212 if ( bpp < 8 ) { /* Not supported */ 218 /* Check to see if we already have this mode */
213 return(0); 219 if (bpp < 8) { /* Not supported */
214 } 220 return (0);
215 index = ((bpp+7)/8)-1; 221 }
216 for ( i=0; i<SDL_nummodes[index]; ++i ) { 222 index = ((bpp + 7) / 8) - 1;
217 mode = SDL_modelist[index][i]; 223 for (i = 0; i < SDL_nummodes[index]; ++i) {
218 if ( (mode->w == w) && (mode->h == h) ) { 224 mode = SDL_modelist[index][i];
219 return(0); 225 if ((mode->w == w) && (mode->h == h)) {
220 } 226 return (0);
221 } 227 }
222 228 }
223 /* Set up the new video mode rectangle */ 229
224 mode = (SDL_Rect *)SDL_malloc(sizeof *mode); 230 /* Set up the new video mode rectangle */
225 if ( mode == NULL ) { 231 mode = (SDL_Rect *) SDL_malloc (sizeof *mode);
226 SDL_OutOfMemory(); 232 if (mode == NULL) {
227 return(-1); 233 SDL_OutOfMemory ();
228 } 234 return (-1);
229 mode->x = 0; 235 }
230 mode->y = 0; 236 mode->x = 0;
231 mode->w = w; 237 mode->y = 0;
232 mode->h = h; 238 mode->w = w;
233 239 mode->h = h;
234 /* Allocate the new list of modes, and fill in the new mode */ 240
235 next_mode = SDL_nummodes[index]; 241 /* Allocate the new list of modes, and fill in the new mode */
236 SDL_modelist[index] = (SDL_Rect **) 242 next_mode = SDL_nummodes[index];
237 SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); 243 SDL_modelist[index] = (SDL_Rect **)
238 if ( SDL_modelist[index] == NULL ) { 244 SDL_realloc (SDL_modelist[index],
239 SDL_OutOfMemory(); 245 (1 + next_mode + 1) * sizeof (SDL_Rect *));
240 SDL_nummodes[index] = 0; 246 if (SDL_modelist[index] == NULL) {
241 SDL_free(mode); 247 SDL_OutOfMemory ();
242 return(-1); 248 SDL_nummodes[index] = 0;
243 } 249 SDL_free (mode);
244 SDL_modelist[index][next_mode] = mode; 250 return (-1);
245 SDL_modelist[index][next_mode+1] = NULL; 251 }
246 SDL_nummodes[index]++; 252 SDL_modelist[index][next_mode] = mode;
247 253 SDL_modelist[index][next_mode + 1] = NULL;
248 return(0); 254 SDL_nummodes[index]++;
249 } 255
250 256 return (0);
251 static HPALETTE DIB_CreatePalette(int bpp) 257 }
258
259 static HPALETTE
260 DIB_CreatePalette (int bpp)
252 { 261 {
253 /* RJR: March 28, 2000 262 /* RJR: March 28, 2000
254 moved palette creation here from "DIB_VideoInit" */ 263 moved palette creation here from "DIB_VideoInit" */
255 264
256 HPALETTE handle = NULL; 265 HPALETTE handle = NULL;
257 266
258 if ( bpp <= 8 ) 267 if (bpp <= 8) {
259 { 268 LOGPALETTE *palette;
260 LOGPALETTE *palette; 269 HDC hdc;
261 HDC hdc; 270 int ncolors;
262 int ncolors; 271 int i;
263 int i; 272
264 273 ncolors = 1;
265 ncolors = 1; 274 for (i = 0; i < bpp; ++i) {
266 for ( i=0; i<bpp; ++i ) { 275 ncolors *= 2;
267 ncolors *= 2; 276 }
268 } 277 palette = (LOGPALETTE *) SDL_malloc (sizeof (*palette) +
269 palette = (LOGPALETTE *)SDL_malloc(sizeof(*palette)+ 278 ncolors * sizeof (PALETTEENTRY));
270 ncolors*sizeof(PALETTEENTRY)); 279 palette->palVersion = 0x300;
271 palette->palVersion = 0x300; 280 palette->palNumEntries = ncolors;
272 palette->palNumEntries = ncolors; 281 hdc = GetDC (SDL_Window);
273 hdc = GetDC(SDL_Window); 282 GetSystemPaletteEntries (hdc, 0, ncolors, palette->palPalEntry);
274 GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry); 283 ReleaseDC (SDL_Window, hdc);
275 ReleaseDC(SDL_Window, hdc); 284 handle = CreatePalette (palette);
276 handle = CreatePalette(palette); 285 SDL_free (palette);
277 SDL_free(palette); 286 }
278 } 287
279 288 return handle;
280 return handle; 289 }
281 } 290
282 291 int
283 int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat) 292 DIB_VideoInit (_THIS, SDL_PixelFormat * vformat)
284 { 293 {
285 #ifndef NO_CHANGEDISPLAYSETTINGS 294 #ifndef NO_CHANGEDISPLAYSETTINGS
286 int i; 295 int i;
287 DEVMODE settings; 296 DEVMODE settings;
288 #endif 297 #endif
289 298
290 /* Create the window */ 299 /* Create the window */
291 if ( DIB_CreateWindow(this) < 0 ) { 300 if (DIB_CreateWindow (this) < 0) {
292 return(-1); 301 return (-1);
293 } 302 }
294
295 #if !SDL_AUDIO_DISABLED 303 #if !SDL_AUDIO_DISABLED
296 DX5_SoundFocus(SDL_Window); 304 DX5_SoundFocus (SDL_Window);
297 #endif 305 #endif
298 306
299 /* Determine the screen depth */ 307 /* Determine the screen depth */
300 vformat->BitsPerPixel = DIB_SussScreenDepth(); 308 vformat->BitsPerPixel = DIB_SussScreenDepth ();
301 switch (vformat->BitsPerPixel) { 309 switch (vformat->BitsPerPixel) {
302 case 15: 310 case 15:
303 vformat->Rmask = 0x00007c00; 311 vformat->Rmask = 0x00007c00;
304 vformat->Gmask = 0x000003e0; 312 vformat->Gmask = 0x000003e0;
305 vformat->Bmask = 0x0000001f; 313 vformat->Bmask = 0x0000001f;
306 vformat->BitsPerPixel = 16; 314 vformat->BitsPerPixel = 16;
307 break; 315 break;
308 case 16: 316 case 16:
309 vformat->Rmask = 0x0000f800; 317 vformat->Rmask = 0x0000f800;
310 vformat->Gmask = 0x000007e0; 318 vformat->Gmask = 0x000007e0;
311 vformat->Bmask = 0x0000001f; 319 vformat->Bmask = 0x0000001f;
312 break; 320 break;
313 case 24: 321 case 24:
314 case 32: 322 case 32:
315 /* GDI defined as 8-8-8 */ 323 /* GDI defined as 8-8-8 */
316 vformat->Rmask = 0x00ff0000; 324 vformat->Rmask = 0x00ff0000;
317 vformat->Gmask = 0x0000ff00; 325 vformat->Gmask = 0x0000ff00;
318 vformat->Bmask = 0x000000ff; 326 vformat->Bmask = 0x000000ff;
319 break; 327 break;
320 default: 328 default:
321 break; 329 break;
322 } 330 }
323 331
324 /* See if gamma is supported on this screen */ 332 /* See if gamma is supported on this screen */
325 DIB_CheckGamma(this); 333 DIB_CheckGamma (this);
326 334
327 #ifndef NO_CHANGEDISPLAYSETTINGS 335 #ifndef NO_CHANGEDISPLAYSETTINGS
328 336
329 settings.dmSize = sizeof(DEVMODE); 337 settings.dmSize = sizeof (DEVMODE);
330 settings.dmDriverExtra = 0; 338 settings.dmDriverExtra = 0;
331 #ifdef _WIN32_WCE 339 #ifdef _WIN32_WCE
332 settings.dmFields = DM_DISPLAYQUERYORIENTATION; 340 settings.dmFields = DM_DISPLAYQUERYORIENTATION;
333 this->hidden->supportRotation = ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL) == DISP_CHANGE_SUCCESSFUL; 341 this->hidden->supportRotation =
334 #endif 342 ChangeDisplaySettingsEx (NULL, &settings, NULL, CDS_TEST,
335 /* Query for the desktop resolution */ 343 NULL) == DISP_CHANGE_SUCCESSFUL;
336 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode); 344 #endif
337 this->info.current_w = SDL_desktop_mode.dmPelsWidth; 345 /* Query for the desktop resolution */
338 this->info.current_h = SDL_desktop_mode.dmPelsHeight; 346 EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
339 347 this->info.current_w = SDL_desktop_mode.dmPelsWidth;
340 /* Query for the list of available video modes */ 348 this->info.current_h = SDL_desktop_mode.dmPelsHeight;
341 for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) { 349
342 DIB_AddMode(this, settings.dmBitsPerPel, 350 /* Query for the list of available video modes */
343 settings.dmPelsWidth, settings.dmPelsHeight); 351 for (i = 0; EnumDisplaySettings (NULL, i, &settings); ++i) {
344 #ifdef _WIN32_WCE 352 DIB_AddMode (this, settings.dmBitsPerPel,
345 if( this->hidden->supportRotation ) 353 settings.dmPelsWidth, settings.dmPelsHeight);
346 DIB_AddMode(this, settings.dmBitsPerPel, 354 #ifdef _WIN32_WCE
347 settings.dmPelsHeight, settings.dmPelsWidth); 355 if (this->hidden->supportRotation)
348 #endif 356 DIB_AddMode (this, settings.dmBitsPerPel,
349 } 357 settings.dmPelsHeight, settings.dmPelsWidth);
350 /* Sort the mode lists */ 358 #endif
351 for ( i=0; i<NUM_MODELISTS; ++i ) { 359 }
352 if ( SDL_nummodes[i] > 0 ) { 360 /* Sort the mode lists */
353 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); 361 for (i = 0; i < NUM_MODELISTS; ++i) {
354 } 362 if (SDL_nummodes[i] > 0) {
355 } 363 SDL_qsort (SDL_modelist[i], SDL_nummodes[i],
364 sizeof *SDL_modelist[i], cmpmodes);
365 }
366 }
356 #else 367 #else
357 // WinCE and fullscreen mode: 368 // WinCE and fullscreen mode:
358 // We use only vformat->BitsPerPixel that allow SDL to 369 // We use only vformat->BitsPerPixel that allow SDL to
359 // emulate other bpp (8, 32) and use triple buffer, 370 // emulate other bpp (8, 32) and use triple buffer,
360 // because SDL surface conversion is much faster than the WinCE one. 371 // because SDL surface conversion is much faster than the WinCE one.
361 // Although it should be tested on devices with graphics accelerator. 372 // Although it should be tested on devices with graphics accelerator.
362 373
363 DIB_AddMode(this, vformat->BitsPerPixel, 374 DIB_AddMode (this, vformat->BitsPerPixel,
364 GetDeviceCaps(GetDC(NULL), HORZRES), 375 GetDeviceCaps (GetDC (NULL), HORZRES),
365 GetDeviceCaps(GetDC(NULL), VERTRES)); 376 GetDeviceCaps (GetDC (NULL), VERTRES));
366 377
367 #endif /* !NO_CHANGEDISPLAYSETTINGS */ 378 #endif /* !NO_CHANGEDISPLAYSETTINGS */
368 379
369 /* Grab an identity palette if we are in a palettized mode */ 380 /* Grab an identity palette if we are in a palettized mode */
370 if ( vformat->BitsPerPixel <= 8 ) { 381 if (vformat->BitsPerPixel <= 8) {
371 /* RJR: March 28, 2000 382 /* RJR: March 28, 2000
372 moved palette creation to "DIB_CreatePalette" */ 383 moved palette creation to "DIB_CreatePalette" */
373 screen_pal = DIB_CreatePalette(vformat->BitsPerPixel); 384 screen_pal = DIB_CreatePalette (vformat->BitsPerPixel);
374 } 385 }
375 386
376 /* Fill in some window manager capabilities */ 387 /* Fill in some window manager capabilities */
377 this->info.wm_available = 1; 388 this->info.wm_available = 1;
378 389
379 #ifdef _WIN32_WCE 390 #ifdef _WIN32_WCE
380 this->hidden->origRotation = -1; 391 this->hidden->origRotation = -1;
381 #endif 392 #endif
382 393
383 /* We're done! */ 394 /* We're done! */
384 return(0); 395 return (0);
385 } 396 }
386 397
387 /* We support any format at any dimension */ 398 /* We support any format at any dimension */
388 SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 399 SDL_Rect **
389 { 400 DIB_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
390 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 401 {
391 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); 402 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
392 } else { 403 return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
393 return((SDL_Rect **)-1); 404 } else {
394 } 405 return ((SDL_Rect **) - 1);
406 }
395 } 407 }
396 408
397 409
398 /* 410 /*
399 Helper fn to work out which screen depth windows is currently using. 411 Helper fn to work out which screen depth windows is currently using.
400 15 bit mode is considered 555 format, 16 bit is 565. 412 15 bit mode is considered 555 format, 16 bit is 565.
401 returns 0 for unknown mode. 413 returns 0 for unknown mode.
402 (Derived from code in sept 1999 Windows Developer Journal 414 (Derived from code in sept 1999 Windows Developer Journal
403 http://www.wdj.com/code/archive.html) 415 http://www.wdj.com/code/archive.html)
404 */ 416 */
405 static int DIB_SussScreenDepth() 417 static int
418 DIB_SussScreenDepth ()
406 { 419 {
407 #ifdef NO_GETDIBITS 420 #ifdef NO_GETDIBITS
408 int depth; 421 int depth;
409 HDC hdc; 422 HDC hdc;
410 423
411 hdc = GetDC(SDL_Window); 424 hdc = GetDC (SDL_Window);
412 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); 425 depth = GetDeviceCaps (hdc, PLANES) * GetDeviceCaps (hdc, BITSPIXEL);
413 ReleaseDC(SDL_Window, hdc); 426 ReleaseDC (SDL_Window, hdc);
414 return(depth); 427 return (depth);
415 #else 428 #else
416 int dib_size; 429 int dib_size;
417 LPBITMAPINFOHEADER dib_hdr; 430 LPBITMAPINFOHEADER dib_hdr;
418 HDC hdc; 431 HDC hdc;
419 HBITMAP hbm; 432 HBITMAP hbm;
420 433
421 /* Allocate enough space for a DIB header plus palette (for 434 /* Allocate enough space for a DIB header plus palette (for
422 * 8-bit modes) or bitfields (for 16- and 32-bit modes) 435 * 8-bit modes) or bitfields (for 16- and 32-bit modes)
423 */ 436 */
424 dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); 437 dib_size = sizeof (BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD);
425 dib_hdr = (LPBITMAPINFOHEADER) SDL_malloc(dib_size); 438 dib_hdr = (LPBITMAPINFOHEADER) SDL_malloc (dib_size);
426 SDL_memset(dib_hdr, 0, dib_size); 439 SDL_memset (dib_hdr, 0, dib_size);
427 dib_hdr->biSize = sizeof(BITMAPINFOHEADER); 440 dib_hdr->biSize = sizeof (BITMAPINFOHEADER);
428 441
429 /* Get a device-dependent bitmap that's compatible with the 442 /* Get a device-dependent bitmap that's compatible with the
430 screen. 443 screen.
431 */ 444 */
432 hdc = GetDC(NULL); 445 hdc = GetDC (NULL);
433 hbm = CreateCompatibleBitmap( hdc, 1, 1 ); 446 hbm = CreateCompatibleBitmap (hdc, 1, 1);
434 447
435 /* Convert the DDB to a DIB. We need to call GetDIBits twice: 448 /* Convert the DDB to a DIB. We need to call GetDIBits twice:
436 * the first call just fills in the BITMAPINFOHEADER; the 449 * the first call just fills in the BITMAPINFOHEADER; the
437 * second fills in the bitfields or palette. 450 * second fills in the bitfields or palette.
438 */ 451 */
439 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); 452 GetDIBits (hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS);
440 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); 453 GetDIBits (hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS);
441 DeleteObject(hbm); 454 DeleteObject (hbm);
442 ReleaseDC(NULL, hdc); 455 ReleaseDC (NULL, hdc);
443 456
444 switch( dib_hdr->biBitCount ) 457 switch (dib_hdr->biBitCount) {
445 { 458 case 8:
446 case 8: return 8; 459 return 8;
447 case 24: return 24; 460 case 24:
448 case 32: return 32; 461 return 24;
462 case 32:
463 return 32;
449 case 16: 464 case 16:
450 if( dib_hdr->biCompression == BI_BITFIELDS ) { 465 if (dib_hdr->biCompression == BI_BITFIELDS) {
451 /* check the red mask */ 466 /* check the red mask */
452 switch( ((DWORD*)((char*)dib_hdr + dib_hdr->biSize))[0] ) { 467 switch (((DWORD *) ((char *) dib_hdr + dib_hdr->biSize))[0]) {
453 case 0xf800: return 16; /* 565 */ 468 case 0xf800:
454 case 0x7c00: return 15; /* 555 */ 469 return 16; /* 565 */
470 case 0x7c00:
471 return 15; /* 555 */
455 } 472 }
456 } 473 }
457 } 474 }
458 return 0; /* poo. */ 475 return 0; /* poo. */
459 #endif /* NO_GETDIBITS */ 476 #endif /* NO_GETDIBITS */
460 } 477 }
461 478
462 479
463 /* Various screen update functions available */ 480 /* Various screen update functions available */
464 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); 481 static void DIB_NormalUpdate (_THIS, int numrects, SDL_Rect * rects);
465 482
466 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, 483 SDL_Surface *
467 int width, int height, int bpp, Uint32 flags) 484 DIB_SetVideoMode (_THIS, SDL_Surface * current,
468 { 485 int width, int height, int bpp, Uint32 flags)
469 SDL_Surface *video; 486 {
470 Uint32 prev_flags; 487 SDL_Surface *video;
471 DWORD style; 488 Uint32 prev_flags;
472 const DWORD directstyle = 489 DWORD style;
473 (WS_POPUP); 490 const DWORD directstyle = (WS_POPUP);
474 const DWORD windowstyle = 491 const DWORD windowstyle =
475 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); 492 (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
476 const DWORD resizestyle = 493 const DWORD resizestyle = (WS_THICKFRAME | WS_MAXIMIZEBOX);
477 (WS_THICKFRAME|WS_MAXIMIZEBOX); 494 int binfo_size;
478 int binfo_size; 495 BITMAPINFO *binfo;
479 BITMAPINFO *binfo; 496 HDC hdc;
480 HDC hdc; 497 RECT bounds;
481 RECT bounds; 498 int x, y;
482 int x, y; 499 Uint32 Rmask, Gmask, Bmask;
483 Uint32 Rmask, Gmask, Bmask; 500
484 501 /* Clean up any GL context that may be hanging around */
485 /* Clean up any GL context that may be hanging around */ 502 if (current->flags & SDL_INTERNALOPENGL) {
486 if ( current->flags & SDL_INTERNALOPENGL ) { 503 WIN_GL_ShutDown (this);
487 WIN_GL_ShutDown(this); 504 }
488 } 505 SDL_resizing = 1;
489 SDL_resizing = 1; 506
490 507 /* Recalculate the bitmasks if necessary */
491 /* Recalculate the bitmasks if necessary */ 508 if (bpp == current->format->BitsPerPixel) {
492 if ( bpp == current->format->BitsPerPixel ) { 509 video = current;
493 video = current; 510 } else {
494 } else { 511 switch (bpp) {
495 switch (bpp) { 512 case 15:
496 case 15: 513 case 16:
497 case 16: 514 if (DIB_SussScreenDepth () == 15) {
498 if ( DIB_SussScreenDepth() == 15 ) { 515 /* 5-5-5 */
499 /* 5-5-5 */ 516 Rmask = 0x00007c00;
500 Rmask = 0x00007c00; 517 Gmask = 0x000003e0;
501 Gmask = 0x000003e0; 518 Bmask = 0x0000001f;
502 Bmask = 0x0000001f; 519 } else {
503 } else { 520 /* 5-6-5 */
504 /* 5-6-5 */ 521 Rmask = 0x0000f800;
505 Rmask = 0x0000f800; 522 Gmask = 0x000007e0;
506 Gmask = 0x000007e0; 523 Bmask = 0x0000001f;
507 Bmask = 0x0000001f; 524 }
508 } 525 break;
509 break; 526 case 24:
510 case 24: 527 case 32:
511 case 32: 528 /* GDI defined as 8-8-8 */
512 /* GDI defined as 8-8-8 */ 529 Rmask = 0x00ff0000;
513 Rmask = 0x00ff0000; 530 Gmask = 0x0000ff00;
514 Gmask = 0x0000ff00; 531 Bmask = 0x000000ff;
515 Bmask = 0x000000ff; 532 break;
516 break; 533 default:
517 default: 534 Rmask = 0x00000000;
518 Rmask = 0x00000000; 535 Gmask = 0x00000000;
519 Gmask = 0x00000000; 536 Bmask = 0x00000000;
520 Bmask = 0x00000000; 537 break;
521 break; 538 }
522 } 539 video = SDL_CreateRGBSurface (SDL_SWSURFACE,
523 video = SDL_CreateRGBSurface(SDL_SWSURFACE, 540 0, 0, bpp, Rmask, Gmask, Bmask, 0);
524 0, 0, bpp, Rmask, Gmask, Bmask, 0); 541 if (video == NULL) {
525 if ( video == NULL ) { 542 SDL_OutOfMemory ();
526 SDL_OutOfMemory(); 543 return (NULL);
527 return(NULL); 544 }
528 } 545 }
529 } 546
530 547 /* Fill in part of the video surface */
531 /* Fill in part of the video surface */ 548 prev_flags = video->flags;
532 prev_flags = video->flags; 549 video->flags = 0; /* Clear flags */
533 video->flags = 0; /* Clear flags */ 550 video->w = width;
534 video->w = width; 551 video->h = height;
535 video->h = height; 552 video->pitch = SDL_CalculatePitch (video);
536 video->pitch = SDL_CalculatePitch(video); 553
537 554 /* Small fix for WinCE/Win32 - when activating window
538 /* Small fix for WinCE/Win32 - when activating window 555 SDL_VideoSurface is equal to zero, so activating code
539 SDL_VideoSurface is equal to zero, so activating code 556 is not called properly for fullscreen windows because
540 is not called properly for fullscreen windows because 557 macros WINDIB_FULLSCREEN uses SDL_VideoSurface
541 macros WINDIB_FULLSCREEN uses SDL_VideoSurface 558 */
542 */ 559 SDL_VideoSurface = video;
543 SDL_VideoSurface = video;
544 560
545 #if defined(_WIN32_WCE) 561 #if defined(_WIN32_WCE)
546 if ( flags & SDL_FULLSCREEN ) 562 if (flags & SDL_FULLSCREEN)
547 video->flags |= SDL_FULLSCREEN; 563 video->flags |= SDL_FULLSCREEN;
548 #endif 564 #endif
549 565
550 #ifndef NO_CHANGEDISPLAYSETTINGS 566 #ifndef NO_CHANGEDISPLAYSETTINGS
551 /* Set fullscreen mode if appropriate */ 567 /* Set fullscreen mode if appropriate */
552 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 568 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
553 DEVMODE settings; 569 DEVMODE settings;
554 BOOL changed; 570 BOOL changed;
555 571
556 SDL_memset(&settings, 0, sizeof(DEVMODE)); 572 SDL_memset (&settings, 0, sizeof (DEVMODE));
557 settings.dmSize = sizeof(DEVMODE); 573 settings.dmSize = sizeof (DEVMODE);
558 574
559 #ifdef _WIN32_WCE 575 #ifdef _WIN32_WCE
560 // try to rotate screen to fit requested resolution 576 // try to rotate screen to fit requested resolution
561 if( this->hidden->supportRotation ) 577 if (this->hidden->supportRotation) {
562 { 578 DWORD rotation;
563 DWORD rotation; 579
564 580 // ask current mode
565 // ask current mode 581 settings.dmFields = DM_DISPLAYORIENTATION;
566 settings.dmFields = DM_DISPLAYORIENTATION; 582 ChangeDisplaySettingsEx (NULL, &settings, NULL, CDS_TEST, NULL);
567 ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL); 583 rotation = settings.dmDisplayOrientation;
568 rotation = settings.dmDisplayOrientation; 584
569 585 if ((width > GetDeviceCaps (GetDC (NULL), HORZRES))
570 if( (width > GetDeviceCaps(GetDC(NULL), HORZRES)) 586 && (height < GetDeviceCaps (GetDC (NULL), VERTRES))) {
571 && (height < GetDeviceCaps(GetDC(NULL), VERTRES))) 587 switch (rotation) {
572 { 588 case DMDO_0:
573 switch( rotation ) 589 settings.dmDisplayOrientation = DMDO_90;
574 { 590 break;
575 case DMDO_0: 591 case DMDO_270:
576 settings.dmDisplayOrientation = DMDO_90; 592 settings.dmDisplayOrientation = DMDO_180;
577 break; 593 break;
578 case DMDO_270: 594 }
579 settings.dmDisplayOrientation = DMDO_180; 595 if (settings.dmDisplayOrientation != rotation) {
580 break; 596 // go to landscape
581 } 597 this->hidden->origRotation = rotation;
582 if( settings.dmDisplayOrientation != rotation ) 598 ChangeDisplaySettingsEx (NULL, &settings, NULL,
583 { 599 CDS_RESET, NULL);
584 // go to landscape 600 }
585 this->hidden->origRotation = rotation; 601 }
586 ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL); 602 if ((width < GetDeviceCaps (GetDC (NULL), HORZRES))
587 } 603 && (height > GetDeviceCaps (GetDC (NULL), VERTRES))) {
588 } 604 switch (rotation) {
589 if( (width < GetDeviceCaps(GetDC(NULL), HORZRES)) 605 case DMDO_90:
590 && (height > GetDeviceCaps(GetDC(NULL), VERTRES))) 606 settings.dmDisplayOrientation = DMDO_0;
591 { 607 break;
592 switch( rotation ) 608 case DMDO_180:
593 { 609 settings.dmDisplayOrientation = DMDO_270;
594 case DMDO_90: 610 break;
595 settings.dmDisplayOrientation = DMDO_0; 611 }
596 break; 612 if (settings.dmDisplayOrientation != rotation) {
597 case DMDO_180: 613 // go to portrait
598 settings.dmDisplayOrientation = DMDO_270; 614 this->hidden->origRotation = rotation;
599 break; 615 ChangeDisplaySettingsEx (NULL, &settings, NULL,
600 } 616 CDS_RESET, NULL);
601 if( settings.dmDisplayOrientation != rotation ) 617 }
602 { 618 }
603 // go to portrait 619
604 this->hidden->origRotation = rotation; 620 }
605 ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL);
606 }
607 }
608
609 }
610 #endif 621 #endif
611 622
612 #ifndef _WIN32_WCE 623 #ifndef _WIN32_WCE
613 settings.dmBitsPerPel = video->format->BitsPerPixel; 624 settings.dmBitsPerPel = video->format->BitsPerPixel;
614 settings.dmPelsWidth = width; 625 settings.dmPelsWidth = width;
615 settings.dmPelsHeight = height; 626 settings.dmPelsHeight = height;
616 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; 627 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
617 if ( width <= (int)SDL_desktop_mode.dmPelsWidth && 628 if (width <= (int) SDL_desktop_mode.dmPelsWidth &&
618 height <= (int)SDL_desktop_mode.dmPelsHeight ) { 629 height <= (int) SDL_desktop_mode.dmPelsHeight) {
619 settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency; 630 settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;
620 settings.dmFields |= DM_DISPLAYFREQUENCY; 631 settings.dmFields |= DM_DISPLAYFREQUENCY;
621 } 632 }
622 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); 633 changed =
623 if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { 634 (ChangeDisplaySettings (&settings, CDS_FULLSCREEN) ==
624 settings.dmFields &= ~DM_DISPLAYFREQUENCY; 635 DISP_CHANGE_SUCCESSFUL);
625 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); 636 if (!changed && (settings.dmFields & DM_DISPLAYFREQUENCY)) {
626 } 637 settings.dmFields &= ~DM_DISPLAYFREQUENCY;
638 changed =
639 (ChangeDisplaySettings (&settings, CDS_FULLSCREEN) ==
640 DISP_CHANGE_SUCCESSFUL);
641 }
627 #else 642 #else
628 changed = 1; 643 changed = 1;
629 #endif 644 #endif
630 if ( changed ) { 645 if (changed) {
631 video->flags |= SDL_FULLSCREEN; 646 video->flags |= SDL_FULLSCREEN;
632 SDL_fullscreen_mode = settings; 647 SDL_fullscreen_mode = settings;
633 } 648 }
634 649
635 } 650 }
636 #endif /* !NO_CHANGEDISPLAYSETTINGS */ 651 #endif /* !NO_CHANGEDISPLAYSETTINGS */
637 652
638 /* Reset the palette and create a new one if necessary */ 653 /* Reset the palette and create a new one if necessary */
639 if ( screen_pal != NULL ) { 654 if (screen_pal != NULL) {
640 /* RJR: March 28, 2000 655 /* RJR: March 28, 2000
641 delete identity palette if switching from a palettized mode */ 656 delete identity palette if switching from a palettized mode */
642 DeleteObject(screen_pal); 657 DeleteObject (screen_pal);
643 screen_pal = NULL; 658 screen_pal = NULL;
644 } 659 }
645 if ( bpp <= 8 ) 660 if (bpp <= 8) {
646 { 661 /* RJR: March 28, 2000
647 /* RJR: March 28, 2000 662 create identity palette switching to a palettized mode */
648 create identity palette switching to a palettized mode */ 663 screen_pal = DIB_CreatePalette (bpp);
649 screen_pal = DIB_CreatePalette(bpp); 664 }
650 } 665
651 666 style = GetWindowLong (SDL_Window, GWL_STYLE);
652 style = GetWindowLong(SDL_Window, GWL_STYLE); 667 style &= ~(resizestyle | WS_MAXIMIZE);
653 style &= ~(resizestyle|WS_MAXIMIZE); 668 if ((video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
654 if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 669 style &= ~windowstyle;
655 style &= ~windowstyle; 670 style |= directstyle;
656 style |= directstyle; 671 } else {
657 } else {
658 #ifndef NO_CHANGEDISPLAYSETTINGS 672 #ifndef NO_CHANGEDISPLAYSETTINGS
659 if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 673 if ((prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
660 ChangeDisplaySettings(NULL, 0); 674 ChangeDisplaySettings (NULL, 0);
661 } 675 }
662 #endif 676 #endif
663 if ( flags & SDL_NOFRAME ) { 677 if (flags & SDL_NOFRAME) {
664 style &= ~windowstyle; 678 style &= ~windowstyle;
665 style |= directstyle; 679 style |= directstyle;
666 video->flags |= SDL_NOFRAME; 680 video->flags |= SDL_NOFRAME;
667 } else { 681 } else {
668 style &= ~directstyle; 682 style &= ~directstyle;
669 style |= windowstyle; 683 style |= windowstyle;
670 if ( flags & SDL_RESIZABLE ) { 684 if (flags & SDL_RESIZABLE) {
671 style |= resizestyle; 685 style |= resizestyle;
672 video->flags |= SDL_RESIZABLE; 686 video->flags |= SDL_RESIZABLE;
673 } 687 }
674 } 688 }
675 #if WS_MAXIMIZE 689 #if WS_MAXIMIZE
676 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; 690 if (IsZoomed (SDL_Window))
677 #endif 691 style |= WS_MAXIMIZE;
678 } 692 #endif
679 693 }
680 /* DJM: Don't piss of anyone who has setup his own window */ 694
681 if ( !SDL_windowid ) 695 /* DJM: Don't piss of anyone who has setup his own window */
682 SetWindowLong(SDL_Window, GWL_STYLE, style); 696 if (!SDL_windowid)
683 697 SetWindowLong (SDL_Window, GWL_STYLE, style);
684 /* Delete the old bitmap if necessary */ 698
685 if ( screen_bmp != NULL ) { 699 /* Delete the old bitmap if necessary */
686 DeleteObject(screen_bmp); 700 if (screen_bmp != NULL) {
687 } 701 DeleteObject (screen_bmp);
688 if ( ! (flags & SDL_INTERNALOPENGL) ) { 702 }
689 BOOL is16bitmode = (video->format->BytesPerPixel == 2); 703 if (!(flags & SDL_INTERNALOPENGL)) {
690 704 BOOL is16bitmode = (video->format->BytesPerPixel == 2);
691 /* Suss out the bitmap info header */ 705
692 binfo_size = sizeof(*binfo); 706 /* Suss out the bitmap info header */
693 if( is16bitmode ) { 707 binfo_size = sizeof (*binfo);
694 /* 16bit modes, palette area used for rgb bitmasks */ 708 if (is16bitmode) {
695 binfo_size += 3*sizeof(DWORD); 709 /* 16bit modes, palette area used for rgb bitmasks */
696 } else if ( video->format->palette ) { 710 binfo_size += 3 * sizeof (DWORD);
697 binfo_size += video->format->palette->ncolors * 711 } else if (video->format->palette) {
698 sizeof(RGBQUAD); 712 binfo_size += video->format->palette->ncolors * sizeof (RGBQUAD);
699 } 713 }
700 binfo = (BITMAPINFO *)SDL_malloc(binfo_size); 714 binfo = (BITMAPINFO *) SDL_malloc (binfo_size);
701 if ( ! binfo ) { 715 if (!binfo) {
702 if ( video != current ) { 716 if (video != current) {
703 SDL_FreeSurface(video); 717 SDL_FreeSurface (video);
704 } 718 }
705 SDL_OutOfMemory(); 719 SDL_OutOfMemory ();
706 return(NULL); 720 return (NULL);
707 } 721 }
708 722
709 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 723 binfo->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
710 binfo->bmiHeader.biWidth = video->w; 724 binfo->bmiHeader.biWidth = video->w;
711 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ 725 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */
712 binfo->bmiHeader.biPlanes = 1; 726 binfo->bmiHeader.biPlanes = 1;
713 binfo->bmiHeader.biSizeImage = video->h * video->pitch; 727 binfo->bmiHeader.biSizeImage = video->h * video->pitch;
714 binfo->bmiHeader.biXPelsPerMeter = 0; 728 binfo->bmiHeader.biXPelsPerMeter = 0;
715 binfo->bmiHeader.biYPelsPerMeter = 0; 729 binfo->bmiHeader.biYPelsPerMeter = 0;
716 binfo->bmiHeader.biClrUsed = 0; 730 binfo->bmiHeader.biClrUsed = 0;
717 binfo->bmiHeader.biClrImportant = 0; 731 binfo->bmiHeader.biClrImportant = 0;
718 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; 732 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel;
719 733
720 if ( is16bitmode ) { 734 if (is16bitmode) {
721 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ 735 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */
722 binfo->bmiHeader.biCompression = BI_BITFIELDS; 736 binfo->bmiHeader.biCompression = BI_BITFIELDS;
723 ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; 737 ((Uint32 *) binfo->bmiColors)[0] = video->format->Rmask;
724 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; 738 ((Uint32 *) binfo->bmiColors)[1] = video->format->Gmask;
725 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; 739 ((Uint32 *) binfo->bmiColors)[2] = video->format->Bmask;
726 } else { 740 } else {
727 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ 741 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */
728 if ( video->format->palette ) { 742 if (video->format->palette) {
729 SDL_memset(binfo->bmiColors, 0, 743 SDL_memset (binfo->bmiColors, 0,
730 video->format->palette->ncolors*sizeof(RGBQUAD)); 744 video->format->palette->ncolors *
731 } 745 sizeof (RGBQUAD));
732 } 746 }
733 747 }
734 /* Create the offscreen bitmap buffer */ 748
735 hdc = GetDC(SDL_Window); 749 /* Create the offscreen bitmap buffer */
736 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, 750 hdc = GetDC (SDL_Window);
737 (void **)(&video->pixels), NULL, 0); 751 screen_bmp = CreateDIBSection (hdc, binfo, DIB_RGB_COLORS,
738 ReleaseDC(SDL_Window, hdc); 752 (void **) (&video->pixels), NULL, 0);
739 SDL_free(binfo); 753 ReleaseDC (SDL_Window, hdc);
740 if ( screen_bmp == NULL ) { 754 SDL_free (binfo);
741 if ( video != current ) { 755 if (screen_bmp == NULL) {
742 SDL_FreeSurface(video); 756 if (video != current) {
743 } 757 SDL_FreeSurface (video);
744 SDL_SetError("Couldn't create DIB section"); 758 }
745 return(NULL); 759 SDL_SetError ("Couldn't create DIB section");
746 } 760 return (NULL);
747 this->UpdateRects = DIB_NormalUpdate; 761 }
748 762 this->UpdateRects = DIB_NormalUpdate;
749 /* Set video surface flags */ 763
750 if ( bpp <= 8 ) { 764 /* Set video surface flags */
751 /* BitBlt() maps colors for us */ 765 if (bpp <= 8) {
752 video->flags |= SDL_HWPALETTE; 766 /* BitBlt() maps colors for us */
753 } 767 video->flags |= SDL_HWPALETTE;
754 } 768 }
769 }
755 #ifndef _WIN32_WCE 770 #ifndef _WIN32_WCE
756 /* Resize the window */ 771 /* Resize the window */
757 if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { 772 if (!SDL_windowid && !IsZoomed (SDL_Window)) {
758 #else 773 #else
759 if ( !SDL_windowid ) { 774 if (!SDL_windowid) {
760 #endif 775 #endif
761 HWND top; 776 HWND top;
762 UINT swp_flags; 777 UINT swp_flags;
763 const char *window = NULL; 778 const char *window = NULL;
764 const char *center = NULL; 779 const char *center = NULL;
765 780
766 if ( !SDL_windowX && !SDL_windowY ) { 781 if (!SDL_windowX && !SDL_windowY) {
767 window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); 782 window = SDL_getenv ("SDL_VIDEO_WINDOW_POS");
768 center = SDL_getenv("SDL_VIDEO_CENTERED"); 783 center = SDL_getenv ("SDL_VIDEO_CENTERED");
769 if ( window ) { 784 if (window) {
770 if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) { 785 if (SDL_sscanf (window, "%d,%d", &x, &y) == 2) {
771 SDL_windowX = x; 786 SDL_windowX = x;
772 SDL_windowY = y; 787 SDL_windowY = y;
773 } 788 }
774 if ( SDL_strcmp(window, "center") == 0 ) { 789 if (SDL_strcmp (window, "center") == 0) {
775 center = window; 790 center = window;
776 } 791 }
777 } 792 }
778 } 793 }
779 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); 794 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
780 795
781 bounds.left = SDL_windowX; 796 bounds.left = SDL_windowX;
782 bounds.top = SDL_windowY; 797 bounds.top = SDL_windowY;
783 bounds.right = SDL_windowX+video->w; 798 bounds.right = SDL_windowX + video->w;
784 bounds.bottom = SDL_windowY+video->h; 799 bounds.bottom = SDL_windowY + video->h;
785 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE, 0); 800 AdjustWindowRectEx (&bounds, GetWindowLong (SDL_Window, GWL_STYLE),
786 width = bounds.right-bounds.left; 801 FALSE, 0);
787 height = bounds.bottom-bounds.top; 802 width = bounds.right - bounds.left;
788 if ( (flags & SDL_FULLSCREEN) ) { 803 height = bounds.bottom - bounds.top;
789 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 804 if ((flags & SDL_FULLSCREEN)) {
790 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 805 x = (GetSystemMetrics (SM_CXSCREEN) - width) / 2;
791 } else if ( center ) { 806 y = (GetSystemMetrics (SM_CYSCREEN) - height) / 2;
792 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 807 } else if (center) {
793 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 808 x = (GetSystemMetrics (SM_CXSCREEN) - width) / 2;
794 } else if ( SDL_windowX || SDL_windowY || window ) { 809 y = (GetSystemMetrics (SM_CYSCREEN) - height) / 2;
795 x = bounds.left; 810 } else if (SDL_windowX || SDL_windowY || window) {
796 y = bounds.top; 811 x = bounds.left;
797 } else { 812 y = bounds.top;
798 x = y = -1; 813 } else {
799 swp_flags |= SWP_NOMOVE; 814 x = y = -1;
800 } 815 swp_flags |= SWP_NOMOVE;
801 if ( flags & SDL_FULLSCREEN ) { 816 }
802 top = HWND_TOPMOST; 817 if (flags & SDL_FULLSCREEN) {
803 } else { 818 top = HWND_TOPMOST;
804 top = HWND_NOTOPMOST; 819 } else {
805 } 820 top = HWND_NOTOPMOST;
806 SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); 821 }
807 if ( !(flags & SDL_FULLSCREEN) ) { 822 SetWindowPos (SDL_Window, top, x, y, width, height, swp_flags);
808 SDL_windowX = SDL_bounds.left; 823 if (!(flags & SDL_FULLSCREEN)) {
809 SDL_windowY = SDL_bounds.top; 824 SDL_windowX = SDL_bounds.left;
810 } 825 SDL_windowY = SDL_bounds.top;
811 SetForegroundWindow(SDL_Window); 826 }
812 } 827 SetForegroundWindow (SDL_Window);
813 SDL_resizing = 0; 828 }
814 829 SDL_resizing = 0;
815 /* Set up for OpenGL */ 830
816 if ( flags & SDL_INTERNALOPENGL ) { 831 /* Set up for OpenGL */
817 if ( WIN_GL_SetupWindow(this) < 0 ) { 832 if (flags & SDL_INTERNALOPENGL) {
818 return(NULL); 833 if (WIN_GL_SetupWindow (this) < 0) {
819 } 834 return (NULL);
820 video->flags |= SDL_INTERNALOPENGL; 835 }
821 } 836 video->flags |= SDL_INTERNALOPENGL;
822 837 }
823 /* JC 14 Mar 2006 838
824 Flush the message loop or this can cause big problems later 839 /* JC 14 Mar 2006
825 Especially if the user decides to use dialog boxes or assert()! 840 Flush the message loop or this can cause big problems later
826 */ 841 Especially if the user decides to use dialog boxes or assert()!
827 WIN_FlushMessageQueue(); 842 */
828 843 WIN_FlushMessageQueue ();
829 /* We're live! */ 844
830 return(video); 845 /* We're live! */
846 return (video);
831 } 847 }
832 848
833 /* We don't actually allow hardware surfaces in the DIB driver */ 849 /* We don't actually allow hardware surfaces in the DIB driver */
834 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) 850 static int
835 { 851 DIB_AllocHWSurface (_THIS, SDL_Surface * surface)
836 return(-1); 852 {
837 } 853 return (-1);
838 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) 854 }
839 { 855 static void
840 return; 856 DIB_FreeHWSurface (_THIS, SDL_Surface * surface)
841 } 857 {
842 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) 858 return;
843 { 859 }
844 return(0); 860 static int
845 } 861 DIB_LockHWSurface (_THIS, SDL_Surface * surface)
846 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) 862 {
847 { 863 return (0);
848 return; 864 }
849 } 865 static void
850 866 DIB_UnlockHWSurface (_THIS, SDL_Surface * surface)
851 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) 867 {
852 { 868 return;
853 HDC hdc, mdc; 869 }
854 int i; 870
855 871 static void
856 hdc = GetDC(SDL_Window); 872 DIB_NormalUpdate (_THIS, int numrects, SDL_Rect * rects)
857 if ( screen_pal ) { 873 {
858 SelectPalette(hdc, screen_pal, FALSE); 874 HDC hdc, mdc;
859 } 875 int i;
860 mdc = CreateCompatibleDC(hdc); 876
861 SelectObject(mdc, screen_bmp); 877 hdc = GetDC (SDL_Window);
862 for ( i=0; i<numrects; ++i ) { 878 if (screen_pal) {
863 BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, 879 SelectPalette (hdc, screen_pal, FALSE);
864 mdc, rects[i].x, rects[i].y, SRCCOPY); 880 }
865 } 881 mdc = CreateCompatibleDC (hdc);
866 DeleteDC(mdc); 882 SelectObject (mdc, screen_bmp);
867 ReleaseDC(SDL_Window, hdc); 883 for (i = 0; i < numrects; ++i) {
868 } 884 BitBlt (hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h,
869 885 mdc, rects[i].x, rects[i].y, SRCCOPY);
870 886 }
871 int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 887 DeleteDC (mdc);
888 ReleaseDC (SDL_Window, hdc);
889 }
890
891
892 int
893 DIB_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
872 { 894 {
873 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) 895 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
874 HDC hdc, mdc; 896 HDC hdc, mdc;
875 RGBQUAD *pal; 897 RGBQUAD *pal;
876 #else 898 #else
877 HDC hdc; 899 HDC hdc;
878 #endif 900 #endif
879 int i; 901 int i;
880 902
881 /* Update the display palette */ 903 /* Update the display palette */
882 hdc = GetDC(SDL_Window); 904 hdc = GetDC (SDL_Window);
883 if ( screen_pal ) { 905 if (screen_pal) {
884 PALETTEENTRY *entries; 906 PALETTEENTRY *entries;
885 907
886 entries = SDL_stack_alloc(PALETTEENTRY, ncolors); 908 entries = SDL_stack_alloc (PALETTEENTRY, ncolors);
887 for ( i=0; i<ncolors; ++i ) { 909 for (i = 0; i < ncolors; ++i) {
888 entries[i].peRed = colors[i].r; 910 entries[i].peRed = colors[i].r;
889 entries[i].peGreen = colors[i].g; 911 entries[i].peGreen = colors[i].g;
890 entries[i].peBlue = colors[i].b; 912 entries[i].peBlue = colors[i].b;
891 entries[i].peFlags = PC_NOCOLLAPSE; 913 entries[i].peFlags = PC_NOCOLLAPSE;
892 } 914 }
893 SetPaletteEntries(screen_pal, firstcolor, ncolors, entries); 915 SetPaletteEntries (screen_pal, firstcolor, ncolors, entries);
894 SelectPalette(hdc, screen_pal, FALSE); 916 SelectPalette (hdc, screen_pal, FALSE);
895 RealizePalette(hdc); 917 RealizePalette (hdc);
896 SDL_stack_free(entries); 918 SDL_stack_free (entries);
897 } 919 }
898
899 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) 920 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
900 /* Copy palette colors into DIB palette */ 921 /* Copy palette colors into DIB palette */
901 pal = SDL_stack_alloc(RGBQUAD, ncolors); 922 pal = SDL_stack_alloc (RGBQUAD, ncolors);
902 for ( i=0; i<ncolors; ++i ) { 923 for (i = 0; i < ncolors; ++i) {
903 pal[i].rgbRed = colors[i].r; 924 pal[i].rgbRed = colors[i].r;
904 pal[i].rgbGreen = colors[i].g; 925 pal[i].rgbGreen = colors[i].g;
905 pal[i].rgbBlue = colors[i].b; 926 pal[i].rgbBlue = colors[i].b;
906 pal[i].rgbReserved = 0; 927 pal[i].rgbReserved = 0;
907 } 928 }
908 929
909 /* Set the DIB palette and update the display */ 930 /* Set the DIB palette and update the display */
910 mdc = CreateCompatibleDC(hdc); 931 mdc = CreateCompatibleDC (hdc);
911 SelectObject(mdc, screen_bmp); 932 SelectObject (mdc, screen_bmp);
912 SetDIBColorTable(mdc, firstcolor, ncolors, pal); 933 SetDIBColorTable (mdc, firstcolor, ncolors, pal);
913 BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, 934 BitBlt (hdc, 0, 0, this->screen->w, this->screen->h, mdc, 0, 0, SRCCOPY);
914 mdc, 0, 0, SRCCOPY); 935 DeleteDC (mdc);
915 DeleteDC(mdc); 936 SDL_stack_free (pal);
916 SDL_stack_free(pal); 937 #endif
917 #endif 938 ReleaseDC (SDL_Window, hdc);
918 ReleaseDC(SDL_Window, hdc); 939 return (1);
919 return(1); 940 }
920 } 941
921 942
922 943 static void
923 static void DIB_CheckGamma(_THIS) 944 DIB_CheckGamma (_THIS)
924 { 945 {
925 #ifndef NO_GAMMA_SUPPORT 946 #ifndef NO_GAMMA_SUPPORT
926 HDC hdc; 947 HDC hdc;
927 WORD ramp[3*256]; 948 WORD ramp[3 * 256];
928 949
929 /* If we fail to get gamma, disable gamma control */ 950 /* If we fail to get gamma, disable gamma control */
930 hdc = GetDC(SDL_Window); 951 hdc = GetDC (SDL_Window);
931 if ( ! GetDeviceGammaRamp(hdc, ramp) ) { 952 if (!GetDeviceGammaRamp (hdc, ramp)) {
932 this->GetGammaRamp = NULL; 953 this->GetGammaRamp = NULL;
933 this->SetGammaRamp = NULL; 954 this->SetGammaRamp = NULL;
934 } 955 }
935 ReleaseDC(SDL_Window, hdc); 956 ReleaseDC (SDL_Window, hdc);
936 #endif /* !NO_GAMMA_SUPPORT */ 957 #endif /* !NO_GAMMA_SUPPORT */
937 } 958 }
938 void DIB_SwapGamma(_THIS) 959
960 void
961 DIB_SwapGamma (_THIS)
939 { 962 {
940 #ifndef NO_GAMMA_SUPPORT 963 #ifndef NO_GAMMA_SUPPORT
941 HDC hdc; 964 HDC hdc;
942 965
943 if ( gamma_saved ) { 966 if (gamma_saved) {
944 hdc = GetDC(SDL_Window); 967 hdc = GetDC (SDL_Window);
945 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { 968 if (SDL_GetAppState () & SDL_APPINPUTFOCUS) {
946 /* About to leave active state, restore gamma */ 969 /* About to leave active state, restore gamma */
947 SetDeviceGammaRamp(hdc, gamma_saved); 970 SetDeviceGammaRamp (hdc, gamma_saved);
948 } else { 971 } else {
949 /* About to enter active state, set game gamma */ 972 /* About to enter active state, set game gamma */
950 GetDeviceGammaRamp(hdc, gamma_saved); 973 GetDeviceGammaRamp (hdc, gamma_saved);
951 SetDeviceGammaRamp(hdc, this->gamma); 974 SetDeviceGammaRamp (hdc, this->gamma);
952 } 975 }
953 ReleaseDC(SDL_Window, hdc); 976 ReleaseDC (SDL_Window, hdc);
954 } 977 }
955 #endif /* !NO_GAMMA_SUPPORT */ 978 #endif /* !NO_GAMMA_SUPPORT */
956 } 979 }
957 void DIB_QuitGamma(_THIS) 980 void
981 DIB_QuitGamma (_THIS)
958 { 982 {
959 #ifndef NO_GAMMA_SUPPORT 983 #ifndef NO_GAMMA_SUPPORT
960 if ( gamma_saved ) { 984 if (gamma_saved) {
961 /* Restore the original gamma if necessary */ 985 /* Restore the original gamma if necessary */
962 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { 986 if (SDL_GetAppState () & SDL_APPINPUTFOCUS) {
963 HDC hdc; 987 HDC hdc;
964 988
965 hdc = GetDC(SDL_Window); 989 hdc = GetDC (SDL_Window);
966 SetDeviceGammaRamp(hdc, gamma_saved); 990 SetDeviceGammaRamp (hdc, gamma_saved);
967 ReleaseDC(SDL_Window, hdc); 991 ReleaseDC (SDL_Window, hdc);
968 } 992 }
969 993
970 /* Free the saved gamma memory */ 994 /* Free the saved gamma memory */
971 SDL_free(gamma_saved); 995 SDL_free (gamma_saved);
972 gamma_saved = 0; 996 gamma_saved = 0;
973 } 997 }
974 #endif /* !NO_GAMMA_SUPPORT */ 998 #endif /* !NO_GAMMA_SUPPORT */
975 } 999 }
976 1000
977 int DIB_SetGammaRamp(_THIS, Uint16 *ramp) 1001 int
1002 DIB_SetGammaRamp (_THIS, Uint16 * ramp)
978 { 1003 {
979 #ifdef NO_GAMMA_SUPPORT 1004 #ifdef NO_GAMMA_SUPPORT
980 SDL_SetError("SDL compiled without gamma ramp support"); 1005 SDL_SetError ("SDL compiled without gamma ramp support");
981 return -1; 1006 return -1;
982 #else 1007 #else
983 HDC hdc; 1008 HDC hdc;
984 BOOL succeeded; 1009 BOOL succeeded;
985 1010
986 /* Set the ramp for the display */ 1011 /* Set the ramp for the display */
987 if ( ! gamma_saved ) { 1012 if (!gamma_saved) {
988 gamma_saved = (WORD *)SDL_malloc(3*256*sizeof(*gamma_saved)); 1013 gamma_saved = (WORD *) SDL_malloc (3 * 256 * sizeof (*gamma_saved));
989 if ( ! gamma_saved ) { 1014 if (!gamma_saved) {
990 SDL_OutOfMemory(); 1015 SDL_OutOfMemory ();
991 return -1; 1016 return -1;
992 } 1017 }
993 hdc = GetDC(SDL_Window); 1018 hdc = GetDC (SDL_Window);
994 GetDeviceGammaRamp(hdc, gamma_saved); 1019 GetDeviceGammaRamp (hdc, gamma_saved);
995 ReleaseDC(SDL_Window, hdc); 1020 ReleaseDC (SDL_Window, hdc);
996 } 1021 }
997 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { 1022 if (SDL_GetAppState () & SDL_APPINPUTFOCUS) {
998 hdc = GetDC(SDL_Window); 1023 hdc = GetDC (SDL_Window);
999 succeeded = SetDeviceGammaRamp(hdc, ramp); 1024 succeeded = SetDeviceGammaRamp (hdc, ramp);
1000 ReleaseDC(SDL_Window, hdc); 1025 ReleaseDC (SDL_Window, hdc);
1001 } else { 1026 } else {
1002 succeeded = TRUE; 1027 succeeded = TRUE;
1003 } 1028 }
1004 return succeeded ? 0 : -1; 1029 return succeeded ? 0 : -1;
1005 #endif /* !NO_GAMMA_SUPPORT */ 1030 #endif /* !NO_GAMMA_SUPPORT */
1006 } 1031 }
1007 1032
1008 int DIB_GetGammaRamp(_THIS, Uint16 *ramp) 1033 int
1034 DIB_GetGammaRamp (_THIS, Uint16 * ramp)
1009 { 1035 {
1010 #ifdef NO_GAMMA_SUPPORT 1036 #ifdef NO_GAMMA_SUPPORT
1011 SDL_SetError("SDL compiled without gamma ramp support"); 1037 SDL_SetError ("SDL compiled without gamma ramp support");
1012 return -1; 1038 return -1;
1013 #else 1039 #else
1014 HDC hdc; 1040 HDC hdc;
1015 BOOL succeeded; 1041 BOOL succeeded;
1016 1042
1017 /* Get the ramp from the display */ 1043 /* Get the ramp from the display */
1018 hdc = GetDC(SDL_Window); 1044 hdc = GetDC (SDL_Window);
1019 succeeded = GetDeviceGammaRamp(hdc, ramp); 1045 succeeded = GetDeviceGammaRamp (hdc, ramp);
1020 ReleaseDC(SDL_Window, hdc); 1046 ReleaseDC (SDL_Window, hdc);
1021 return succeeded ? 0 : -1; 1047 return succeeded ? 0 : -1;
1022 #endif /* !NO_GAMMA_SUPPORT */ 1048 #endif /* !NO_GAMMA_SUPPORT */
1023 } 1049 }
1024 1050
1025 void DIB_VideoQuit(_THIS) 1051 void
1026 { 1052 DIB_VideoQuit (_THIS)
1027 /* Destroy the window and everything associated with it */ 1053 {
1028 if ( SDL_Window ) { 1054 /* Destroy the window and everything associated with it */
1029 /* Delete the screen bitmap (also frees screen->pixels) */ 1055 if (SDL_Window) {
1030 if ( this->screen ) { 1056 /* Delete the screen bitmap (also frees screen->pixels) */
1057 if (this->screen) {
1031 #ifndef NO_CHANGEDISPLAYSETTINGS 1058 #ifndef NO_CHANGEDISPLAYSETTINGS
1032 if ( this->screen->flags & SDL_FULLSCREEN ) { 1059 if (this->screen->flags & SDL_FULLSCREEN) {
1033 ChangeDisplaySettings(NULL, 0); 1060 ChangeDisplaySettings (NULL, 0);
1034 ShowWindow(SDL_Window, SW_HIDE); 1061 ShowWindow (SDL_Window, SW_HIDE);
1035 } 1062 }
1036 #endif 1063 #endif
1037 if ( this->screen->flags & SDL_INTERNALOPENGL ) { 1064 if (this->screen->flags & SDL_INTERNALOPENGL) {
1038 WIN_GL_ShutDown(this); 1065 WIN_GL_ShutDown (this);
1039 } 1066 }
1040 this->screen->pixels = NULL; 1067 this->screen->pixels = NULL;
1041 } 1068 }
1042 if ( screen_bmp ) { 1069 if (screen_bmp) {
1043 DeleteObject(screen_bmp); 1070 DeleteObject (screen_bmp);
1044 screen_bmp = NULL; 1071 screen_bmp = NULL;
1045 } 1072 }
1046 if ( screen_icn ) { 1073 if (screen_icn) {
1047 DestroyIcon(screen_icn); 1074 DestroyIcon (screen_icn);
1048 screen_icn = NULL; 1075 screen_icn = NULL;
1049 } 1076 }
1050 DIB_QuitGamma(this); 1077 DIB_QuitGamma (this);
1051 DIB_DestroyWindow(this); 1078 DIB_DestroyWindow (this);
1052 1079
1053 SDL_Window = NULL; 1080 SDL_Window = NULL;
1054 1081
1055 #if defined(_WIN32_WCE) 1082 #if defined(_WIN32_WCE)
1056 1083
1057 // Unload wince aygshell library to prevent leak 1084 // Unload wince aygshell library to prevent leak
1058 if( aygshell ) 1085 if (aygshell) {
1059 { 1086 FreeLibrary (aygshell);
1060 FreeLibrary(aygshell); 1087 aygshell = NULL;
1061 aygshell = NULL; 1088 }
1062 } 1089 #endif
1063 #endif 1090
1064 1091 }
1065 }
1066 } 1092 }
1067 1093
1068 /* Exported for the windows message loop only */ 1094 /* Exported for the windows message loop only */
1069 static void DIB_FocusPalette(_THIS, int foreground) 1095 static void
1070 { 1096 DIB_FocusPalette (_THIS, int foreground)
1071 if ( screen_pal != NULL ) { 1097 {
1072 HDC hdc; 1098 if (screen_pal != NULL) {
1073 1099 HDC hdc;
1074 hdc = GetDC(SDL_Window); 1100
1075 SelectPalette(hdc, screen_pal, FALSE); 1101 hdc = GetDC (SDL_Window);
1076 if ( RealizePalette(hdc) ) 1102 SelectPalette (hdc, screen_pal, FALSE);
1077 InvalidateRect(SDL_Window, NULL, FALSE); 1103 if (RealizePalette (hdc))
1078 ReleaseDC(SDL_Window, hdc); 1104 InvalidateRect (SDL_Window, NULL, FALSE);
1079 } 1105 ReleaseDC (SDL_Window, hdc);
1080 } 1106 }
1081 static void DIB_RealizePalette(_THIS) 1107 }
1082 { 1108 static void
1083 DIB_FocusPalette(this, 1); 1109 DIB_RealizePalette (_THIS)
1084 } 1110 {
1085 static void DIB_PaletteChanged(_THIS, HWND window) 1111 DIB_FocusPalette (this, 1);
1086 { 1112 }
1087 if ( window != SDL_Window ) { 1113 static void
1088 DIB_FocusPalette(this, 0); 1114 DIB_PaletteChanged (_THIS, HWND window)
1089 } 1115 {
1116 if (window != SDL_Window) {
1117 DIB_FocusPalette (this, 0);
1118 }
1090 } 1119 }
1091 1120
1092 /* Exported for the windows message loop only */ 1121 /* Exported for the windows message loop only */
1093 static void DIB_WinPAINT(_THIS, HDC hdc) 1122 static void
1094 { 1123 DIB_WinPAINT (_THIS, HDC hdc)
1095 HDC mdc; 1124 {
1096 1125 HDC mdc;
1097 if ( screen_pal ) { 1126
1098 SelectPalette(hdc, screen_pal, FALSE); 1127 if (screen_pal) {
1099 } 1128 SelectPalette (hdc, screen_pal, FALSE);
1100 mdc = CreateCompatibleDC(hdc); 1129 }
1101 SelectObject(mdc, screen_bmp); 1130 mdc = CreateCompatibleDC (hdc);
1102 BitBlt(hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h, 1131 SelectObject (mdc, screen_bmp);
1103 mdc, 0, 0, SRCCOPY); 1132 BitBlt (hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h,
1104 DeleteDC(mdc); 1133 mdc, 0, 0, SRCCOPY);
1134 DeleteDC (mdc);
1105 } 1135 }
1106 1136
1107 /* Stub in case DirectX isn't available */ 1137 /* Stub in case DirectX isn't available */
1108 #if !SDL_AUDIO_DRIVER_DSOUND 1138 #if !SDL_AUDIO_DRIVER_DSOUND
1109 void DX5_SoundFocus(HWND hwnd) 1139 void
1110 { 1140 DX5_SoundFocus (HWND hwnd)
1111 return; 1141 {
1112 } 1142 return;
1113 #endif 1143 }
1144 #endif
1145 /* vi: set ts=4 sw=4 expandtab: */