Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 1fddae038bc8 |
children | 9857d21967bb |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
130 }; | 130 }; |
131 | 131 |
132 static SDL_VideoDevice *_this = NULL; | 132 static SDL_VideoDevice *_this = NULL; |
133 | 133 |
134 /* Various local functions */ | 134 /* Various local functions */ |
135 int SDL_VideoInit (const char *driver_name, Uint32 flags); | 135 int SDL_VideoInit(const char *driver_name, Uint32 flags); |
136 void SDL_VideoQuit (void); | 136 void SDL_VideoQuit(void); |
137 | 137 |
138 static int | 138 static int |
139 cmpmodes (const void *A, const void *B) | 139 cmpmodes(const void *A, const void *B) |
140 { | 140 { |
141 SDL_DisplayMode a = *(const SDL_DisplayMode *) A; | 141 SDL_DisplayMode a = *(const SDL_DisplayMode *) A; |
142 SDL_DisplayMode b = *(const SDL_DisplayMode *) B; | 142 SDL_DisplayMode b = *(const SDL_DisplayMode *) B; |
143 | 143 |
144 if (a.w != b.w) { | 144 if (a.w != b.w) { |
145 return b.w - a.w; | 145 return b.w - a.w; |
146 } | 146 } |
147 if (a.h != b.h) { | 147 if (a.h != b.h) { |
148 return b.h - a.h; | 148 return b.h - a.h; |
149 } | 149 } |
150 if (SDL_BITSPERPIXEL (a.format) != SDL_BITSPERPIXEL (b.format)) { | 150 if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) { |
151 return SDL_BITSPERPIXEL (b.format) - SDL_BITSPERPIXEL (a.format); | 151 return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format); |
152 } | 152 } |
153 if (a.refresh_rate != b.refresh_rate) { | 153 if (a.refresh_rate != b.refresh_rate) { |
154 return b.refresh_rate - a.refresh_rate; | 154 return b.refresh_rate - a.refresh_rate; |
155 } | 155 } |
156 return 0; | 156 return 0; |
157 } | 157 } |
158 | 158 |
159 int | 159 int |
160 SDL_GetNumVideoDrivers (void) | 160 SDL_GetNumVideoDrivers(void) |
161 { | 161 { |
162 return SDL_arraysize (bootstrap) - 1; | 162 return SDL_arraysize(bootstrap) - 1; |
163 } | 163 } |
164 | 164 |
165 const char * | 165 const char * |
166 SDL_GetVideoDriver (int index) | 166 SDL_GetVideoDriver(int index) |
167 { | 167 { |
168 if (index >= 0 && index < SDL_GetNumVideoDrivers ()) { | 168 if (index >= 0 && index < SDL_GetNumVideoDrivers()) { |
169 return bootstrap[index]->name; | 169 return bootstrap[index]->name; |
170 } | 170 } |
171 return NULL; | 171 return NULL; |
172 } | 172 } |
173 | 173 |
174 /* | 174 /* |
175 * Initialize the video and event subsystems -- determine native pixel format | 175 * Initialize the video and event subsystems -- determine native pixel format |
176 */ | 176 */ |
177 int | 177 int |
178 SDL_VideoInit (const char *driver_name, Uint32 flags) | 178 SDL_VideoInit(const char *driver_name, Uint32 flags) |
179 { | 179 { |
180 SDL_VideoDevice *video; | 180 SDL_VideoDevice *video; |
181 int index; | 181 int index; |
182 int i; | 182 int i; |
183 int bpp; | 183 int bpp; |
186 /* Toggle the event thread flags, based on OS requirements */ | 186 /* Toggle the event thread flags, based on OS requirements */ |
187 #if defined(MUST_THREAD_EVENTS) | 187 #if defined(MUST_THREAD_EVENTS) |
188 flags |= SDL_INIT_EVENTTHREAD; | 188 flags |= SDL_INIT_EVENTTHREAD; |
189 #elif defined(CANT_THREAD_EVENTS) | 189 #elif defined(CANT_THREAD_EVENTS) |
190 if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { | 190 if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { |
191 SDL_SetError ("OS doesn't support threaded events"); | 191 SDL_SetError("OS doesn't support threaded events"); |
192 return -1; | 192 return -1; |
193 } | 193 } |
194 #endif | 194 #endif |
195 | 195 |
196 /* Check to make sure we don't overwrite '_this' */ | 196 /* Check to make sure we don't overwrite '_this' */ |
197 if (_this != NULL) { | 197 if (_this != NULL) { |
198 SDL_VideoQuit (); | 198 SDL_VideoQuit(); |
199 } | 199 } |
200 | 200 |
201 /* Select the proper video driver */ | 201 /* Select the proper video driver */ |
202 index = 0; | 202 index = 0; |
203 video = NULL; | 203 video = NULL; |
204 if (driver_name != NULL) { | 204 if (driver_name != NULL) { |
205 for (i = 0; bootstrap[i]; ++i) { | 205 for (i = 0; bootstrap[i]; ++i) { |
206 if (SDL_strncmp (bootstrap[i]->name, driver_name, | 206 if (SDL_strncmp(bootstrap[i]->name, driver_name, |
207 SDL_strlen (bootstrap[i]->name)) == 0) { | 207 SDL_strlen(bootstrap[i]->name)) == 0) { |
208 if (bootstrap[i]->available ()) { | 208 if (bootstrap[i]->available()) { |
209 video = bootstrap[i]->create (index); | 209 video = bootstrap[i]->create(index); |
210 } | 210 } |
211 break; | 211 break; |
212 } | 212 } |
213 } | 213 } |
214 } else { | 214 } else { |
215 for (i = 0; bootstrap[i]; ++i) { | 215 for (i = 0; bootstrap[i]; ++i) { |
216 if (bootstrap[i]->available ()) { | 216 if (bootstrap[i]->available()) { |
217 video = bootstrap[i]->create (index); | 217 video = bootstrap[i]->create(index); |
218 if (video != NULL) { | 218 if (video != NULL) { |
219 break; | 219 break; |
220 } | 220 } |
221 } | 221 } |
222 } | 222 } |
223 } | 223 } |
224 if (video == NULL) { | 224 if (video == NULL) { |
225 if (driver_name) { | 225 if (driver_name) { |
226 SDL_SetError ("%s not available", driver_name); | 226 SDL_SetError("%s not available", driver_name); |
227 } else { | 227 } else { |
228 SDL_SetError ("No available video device"); | 228 SDL_SetError("No available video device"); |
229 } | 229 } |
230 return -1; | 230 return -1; |
231 } | 231 } |
232 _this = video; | 232 _this = video; |
233 _this->name = bootstrap[i]->name; | 233 _this->name = bootstrap[i]->name; |
253 _this->gl_config.multisamplesamples = 0; | 253 _this->gl_config.multisamplesamples = 0; |
254 _this->gl_config.accelerated = -1; /* not known, don't set */ | 254 _this->gl_config.accelerated = -1; /* not known, don't set */ |
255 _this->gl_config.swap_control = -1; /* not known, don't set */ | 255 _this->gl_config.swap_control = -1; /* not known, don't set */ |
256 | 256 |
257 /* Initialize the video subsystem */ | 257 /* Initialize the video subsystem */ |
258 if (_this->VideoInit (_this) < 0) { | 258 if (_this->VideoInit(_this) < 0) { |
259 SDL_VideoQuit (); | 259 SDL_VideoQuit(); |
260 return -1; | 260 return -1; |
261 } | 261 } |
262 | 262 |
263 /* Make sure some displays were added */ | 263 /* Make sure some displays were added */ |
264 if (_this->num_displays == 0) { | 264 if (_this->num_displays == 0) { |
265 SDL_SetError ("The video driver did not add any displays"); | 265 SDL_SetError("The video driver did not add any displays"); |
266 SDL_VideoQuit (); | 266 SDL_VideoQuit(); |
267 return (-1); | 267 return (-1); |
268 } | 268 } |
269 | 269 |
270 /* Sort the video modes */ | 270 /* Sort the video modes */ |
271 for (i = 0; i < _this->num_displays; ++i) { | 271 for (i = 0; i < _this->num_displays; ++i) { |
272 SDL_qsort (_this->displays[i].display_modes, | 272 SDL_qsort(_this->displays[i].display_modes, |
273 _this->displays[i].num_display_modes, | 273 _this->displays[i].num_display_modes, |
274 sizeof (SDL_DisplayMode), cmpmodes); | 274 sizeof(SDL_DisplayMode), cmpmodes); |
275 } | 275 } |
276 | 276 |
277 /* Start the event loop */ | 277 /* Start the event loop */ |
278 if (SDL_StartEventLoop (flags) < 0) { | 278 if (SDL_StartEventLoop(flags) < 0) { |
279 SDL_VideoQuit (); | 279 SDL_VideoQuit(); |
280 return -1; | 280 return -1; |
281 } | 281 } |
282 SDL_CursorInit (flags & SDL_INIT_EVENTTHREAD); | 282 SDL_CursorInit(flags & SDL_INIT_EVENTTHREAD); |
283 | 283 |
284 /* We're ready to go! */ | 284 /* We're ready to go! */ |
285 return 0; | 285 return 0; |
286 } | 286 } |
287 | 287 |
288 const char * | 288 const char * |
289 SDL_GetCurrentVideoDriver () | 289 SDL_GetCurrentVideoDriver() |
290 { | 290 { |
291 if (!_this) { | 291 if (!_this) { |
292 return NULL; | 292 return NULL; |
293 } | 293 } |
294 return _this->name; | 294 return _this->name; |
295 } | 295 } |
296 | 296 |
297 SDL_VideoDevice * | 297 SDL_VideoDevice * |
298 SDL_GetVideoDevice () | 298 SDL_GetVideoDevice() |
299 { | 299 { |
300 return _this; | 300 return _this; |
301 } | 301 } |
302 | 302 |
303 const SDL_VideoInfo * | 303 const SDL_VideoInfo * |
304 SDL_GetVideoInfo (void) | 304 SDL_GetVideoInfo(void) |
305 { | 305 { |
306 if (!_this) { | 306 if (!_this) { |
307 return NULL; | 307 return NULL; |
308 } | 308 } |
309 return &_this->info; | 309 return &_this->info; |
310 } | 310 } |
311 | 311 |
312 void | 312 void |
313 SDL_AddBasicVideoDisplay (const SDL_DisplayMode * desktop_mode) | 313 SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode) |
314 { | 314 { |
315 SDL_VideoDisplay display; | 315 SDL_VideoDisplay display; |
316 | 316 |
317 SDL_zero (display); | 317 SDL_zero(display); |
318 if (desktop_mode) { | 318 if (desktop_mode) { |
319 display.desktop_mode = *desktop_mode; | 319 display.desktop_mode = *desktop_mode; |
320 } | 320 } |
321 display.current_mode = display.desktop_mode; | 321 display.current_mode = display.desktop_mode; |
322 display.max_windows = 1; | 322 display.max_windows = 1; |
323 | 323 |
324 SDL_AddVideoDisplay (&display); | 324 SDL_AddVideoDisplay(&display); |
325 } | 325 } |
326 | 326 |
327 void | 327 void |
328 SDL_AddVideoDisplay (SDL_VideoDisplay * display) | 328 SDL_AddVideoDisplay(SDL_VideoDisplay * display) |
329 { | 329 { |
330 SDL_VideoDisplay *displays; | 330 SDL_VideoDisplay *displays; |
331 | 331 |
332 displays = | 332 displays = |
333 SDL_realloc (_this->displays, | 333 SDL_realloc(_this->displays, |
334 (_this->num_displays + 1) * sizeof (*displays)); | 334 (_this->num_displays + 1) * sizeof(*displays)); |
335 if (displays) { | 335 if (displays) { |
336 displays[_this->num_displays] = *display; | 336 displays[_this->num_displays] = *display; |
337 _this->displays = displays; | 337 _this->displays = displays; |
338 _this->num_displays++; | 338 _this->num_displays++; |
339 } | 339 } |
340 } | 340 } |
341 | 341 |
342 int | 342 int |
343 SDL_GetNumVideoDisplays (void) | 343 SDL_GetNumVideoDisplays(void) |
344 { | 344 { |
345 if (!_this) { | 345 if (!_this) { |
346 return 0; | 346 return 0; |
347 } | 347 } |
348 return _this->num_displays; | 348 return _this->num_displays; |
349 } | 349 } |
350 | 350 |
351 int | 351 int |
352 SDL_SelectVideoDisplay (int index) | 352 SDL_SelectVideoDisplay(int index) |
353 { | 353 { |
354 if (!_this) { | 354 if (!_this) { |
355 SDL_SetError ("Video subsystem has not been initialized"); | 355 SDL_SetError("Video subsystem has not been initialized"); |
356 return (-1); | 356 return (-1); |
357 } | 357 } |
358 if (index >= 0) { | 358 if (index >= 0) { |
359 if (index >= _this->num_displays) { | 359 if (index >= _this->num_displays) { |
360 SDL_SetError ("index must be in the range 0 - %d", | 360 SDL_SetError("index must be in the range 0 - %d", |
361 _this->num_displays - 1); | 361 _this->num_displays - 1); |
362 return -1; | 362 return -1; |
363 } | 363 } |
364 _this->current_display = index; | 364 _this->current_display = index; |
365 } | 365 } |
366 return _this->current_display; | 366 return _this->current_display; |
367 } | 367 } |
368 | 368 |
369 void | 369 void |
370 SDL_AddDisplayMode (int display, const SDL_DisplayMode * mode) | 370 SDL_AddDisplayMode(int display, const SDL_DisplayMode * mode) |
371 { | 371 { |
372 SDL_DisplayMode *modes; | 372 SDL_DisplayMode *modes; |
373 int i, nmodes; | 373 int i, nmodes; |
374 | 374 |
375 /* Make sure we don't already have the mode in the list */ | 375 /* Make sure we don't already have the mode in the list */ |
376 modes = SDL_CurrentDisplay.display_modes; | 376 modes = SDL_CurrentDisplay.display_modes; |
377 nmodes = SDL_CurrentDisplay.num_display_modes; | 377 nmodes = SDL_CurrentDisplay.num_display_modes; |
378 for (i = 0; i < nmodes; ++i) { | 378 for (i = 0; i < nmodes; ++i) { |
379 if (SDL_memcmp (mode, &modes[i], sizeof (*mode)) == 0) { | 379 if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) { |
380 return; | 380 return; |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 /* Go ahead and add the new mode */ | 384 /* Go ahead and add the new mode */ |
385 modes = SDL_realloc (modes, (nmodes + 1) * sizeof (*mode)); | 385 modes = SDL_realloc(modes, (nmodes + 1) * sizeof(*mode)); |
386 if (modes) { | 386 if (modes) { |
387 SDL_CurrentDisplay.display_modes = modes; | 387 SDL_CurrentDisplay.display_modes = modes; |
388 modes[nmodes] = *mode; | 388 modes[nmodes] = *mode; |
389 SDL_CurrentDisplay.num_display_modes++; | 389 SDL_CurrentDisplay.num_display_modes++; |
390 } | 390 } |
391 } | 391 } |
392 | 392 |
393 int | 393 int |
394 SDL_GetNumDisplayModes () | 394 SDL_GetNumDisplayModes() |
395 { | 395 { |
396 if (_this) { | 396 if (_this) { |
397 return SDL_CurrentDisplay.num_display_modes; | 397 return SDL_CurrentDisplay.num_display_modes; |
398 } | 398 } |
399 return 0; | 399 return 0; |
400 } | 400 } |
401 | 401 |
402 const SDL_DisplayMode * | 402 const SDL_DisplayMode * |
403 SDL_GetDisplayMode (int index) | 403 SDL_GetDisplayMode(int index) |
404 { | 404 { |
405 if (index < 0 || index >= SDL_GetNumDisplayModes ()) { | 405 if (index < 0 || index >= SDL_GetNumDisplayModes()) { |
406 SDL_SetError ("index must be in the range of 0 - %d", | 406 SDL_SetError("index must be in the range of 0 - %d", |
407 SDL_GetNumDisplayModes ()); | 407 SDL_GetNumDisplayModes()); |
408 return NULL; | 408 return NULL; |
409 } | 409 } |
410 return &SDL_CurrentDisplay.display_modes[index]; | 410 return &SDL_CurrentDisplay.display_modes[index]; |
411 } | 411 } |
412 | 412 |
413 const SDL_DisplayMode * | 413 const SDL_DisplayMode * |
414 SDL_GetDesktopDisplayMode (void) | 414 SDL_GetDesktopDisplayMode(void) |
415 { | 415 { |
416 if (_this) { | 416 if (_this) { |
417 return &SDL_CurrentDisplay.desktop_mode; | 417 return &SDL_CurrentDisplay.desktop_mode; |
418 } | 418 } |
419 return NULL; | 419 return NULL; |
420 } | 420 } |
421 | 421 |
422 const SDL_DisplayMode * | 422 const SDL_DisplayMode * |
423 SDL_GetCurrentDisplayMode (void) | 423 SDL_GetCurrentDisplayMode(void) |
424 { | 424 { |
425 if (_this) { | 425 if (_this) { |
426 return &SDL_CurrentDisplay.current_mode; | 426 return &SDL_CurrentDisplay.current_mode; |
427 } | 427 } |
428 return NULL; | 428 return NULL; |
429 } | 429 } |
430 | 430 |
431 SDL_DisplayMode * | 431 SDL_DisplayMode * |
432 SDL_GetClosestDisplayMode (const SDL_DisplayMode * mode, | 432 SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode, |
433 SDL_DisplayMode * closest) | 433 SDL_DisplayMode * closest) |
434 { | 434 { |
435 Uint32 target_format; | 435 Uint32 target_format; |
436 int target_refresh_rate; | 436 int target_refresh_rate; |
437 int i; | 437 int i; |
438 SDL_DisplayMode *current, *match; | 438 SDL_DisplayMode *current, *match; |
469 continue; | 469 continue; |
470 } | 470 } |
471 if (current->format != match->format) { | 471 if (current->format != match->format) { |
472 /* Sorted highest depth to lowest */ | 472 /* Sorted highest depth to lowest */ |
473 if (current->format == target_format || | 473 if (current->format == target_format || |
474 (SDL_BITSPERPIXEL (current->format) >= | 474 (SDL_BITSPERPIXEL(current->format) >= |
475 SDL_BITSPERPIXEL (target_format) | 475 SDL_BITSPERPIXEL(target_format) |
476 && SDL_PIXELTYPE (current->format) == | 476 && SDL_PIXELTYPE(current->format) == |
477 SDL_PIXELTYPE (target_format))) { | 477 SDL_PIXELTYPE(target_format))) { |
478 match = current; | 478 match = current; |
479 } | 479 } |
480 continue; | 480 continue; |
481 } | 481 } |
482 if (current->refresh_rate != match->refresh_rate) { | 482 if (current->refresh_rate != match->refresh_rate) { |
508 } | 508 } |
509 return NULL; | 509 return NULL; |
510 } | 510 } |
511 | 511 |
512 int | 512 int |
513 SDL_SetDisplayMode (const SDL_DisplayMode * mode) | 513 SDL_SetDisplayMode(const SDL_DisplayMode * mode) |
514 { | 514 { |
515 SDL_VideoDisplay *display; | 515 SDL_VideoDisplay *display; |
516 SDL_DisplayMode display_mode; | 516 SDL_DisplayMode display_mode; |
517 int i; | 517 int i; |
518 | 518 |
519 if (!_this) { | 519 if (!_this) { |
520 SDL_SetError ("Video subsystem has not been initialized"); | 520 SDL_SetError("Video subsystem has not been initialized"); |
521 return -1; | 521 return -1; |
522 } | 522 } |
523 | 523 |
524 /* Make sure there's an actual display mode to set */ | 524 /* Make sure there's an actual display mode to set */ |
525 if (!mode) { | 525 if (!mode) { |
526 SDL_SetError ("No mode passed to SDL_SetDisplayMode"); | 526 SDL_SetError("No mode passed to SDL_SetDisplayMode"); |
527 return -1; | 527 return -1; |
528 } | 528 } |
529 display = &SDL_CurrentDisplay; | 529 display = &SDL_CurrentDisplay; |
530 display_mode = *mode; | 530 display_mode = *mode; |
531 | 531 |
542 if (!display_mode.refresh_rate) { | 542 if (!display_mode.refresh_rate) { |
543 display_mode.refresh_rate = display->current_mode.refresh_rate; | 543 display_mode.refresh_rate = display->current_mode.refresh_rate; |
544 } | 544 } |
545 | 545 |
546 /* Get a good video mode, the closest one possible */ | 546 /* Get a good video mode, the closest one possible */ |
547 if (!SDL_GetClosestDisplayMode (&display_mode, &display_mode)) { | 547 if (!SDL_GetClosestDisplayMode(&display_mode, &display_mode)) { |
548 SDL_SetError ("No video mode large enough for %dx%d", | 548 SDL_SetError("No video mode large enough for %dx%d", |
549 display_mode.w, display_mode.h); | 549 display_mode.w, display_mode.h); |
550 return -1; | 550 return -1; |
551 } | 551 } |
552 | 552 |
553 /* See if there's anything left to do */ | 553 /* See if there's anything left to do */ |
554 if (SDL_memcmp | 554 if (SDL_memcmp |
555 (&display_mode, SDL_GetCurrentDisplayMode (), | 555 (&display_mode, SDL_GetCurrentDisplayMode(), |
556 sizeof (display_mode)) == 0) { | 556 sizeof(display_mode)) == 0) { |
557 return 0; | 557 return 0; |
558 } | 558 } |
559 | 559 |
560 /* Free any previous window surfaces */ | 560 /* Free any previous window surfaces */ |
561 for (i = 0; i < display->num_windows; ++i) { | 561 for (i = 0; i < display->num_windows; ++i) { |
562 SDL_Window *window = &display->windows[i]; | 562 SDL_Window *window = &display->windows[i]; |
563 if (window->shadow) { | 563 if (window->shadow) { |
564 SDL_FreeSurface (window->shadow); | 564 SDL_FreeSurface(window->shadow); |
565 window->shadow = NULL; | 565 window->shadow = NULL; |
566 } | 566 } |
567 if (window->surface) { | 567 if (window->surface) { |
568 SDL_FreeSurface (window->surface); | 568 SDL_FreeSurface(window->surface); |
569 window->surface = NULL; | 569 window->surface = NULL; |
570 } | 570 } |
571 } | 571 } |
572 | 572 |
573 return _this->SetDisplayMode (_this, &display_mode); | 573 return _this->SetDisplayMode(_this, &display_mode); |
574 } | 574 } |
575 | 575 |
576 SDL_WindowID | 576 SDL_WindowID |
577 SDL_CreateWindow (const char *title, int x, int y, int w, int h, Uint32 flags) | 577 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) |
578 { | 578 { |
579 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | | 579 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | |
580 SDL_WINDOW_BORDERLESS | | 580 SDL_WINDOW_BORDERLESS | |
581 SDL_WINDOW_SHOWN | | 581 SDL_WINDOW_SHOWN | |
582 SDL_WINDOW_OPENGL | | 582 SDL_WINDOW_OPENGL | |
587 SDL_Window window; | 587 SDL_Window window; |
588 int num_windows; | 588 int num_windows; |
589 SDL_Window *windows; | 589 SDL_Window *windows; |
590 | 590 |
591 if (!_this) { | 591 if (!_this) { |
592 SDL_SetError ("Video subsystem has not been initialized"); | 592 SDL_SetError("Video subsystem has not been initialized"); |
593 return 0; | 593 return 0; |
594 } | 594 } |
595 | 595 |
596 SDL_zero (window); | 596 SDL_zero(window); |
597 window.id = _this->next_window_id++; | 597 window.id = _this->next_window_id++; |
598 window.title = title ? SDL_strdup (title) : NULL; | 598 window.title = title ? SDL_strdup(title) : NULL; |
599 window.x = x; | 599 window.x = x; |
600 window.y = y; | 600 window.y = y; |
601 window.w = w; | 601 window.w = w; |
602 window.h = h; | 602 window.h = h; |
603 window.flags = (flags & allowed_flags); | 603 window.flags = (flags & allowed_flags); |
604 | 604 |
605 if (_this->CreateWindow && _this->CreateWindow (_this, &window) < 0) { | 605 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { |
606 if (window.title) { | 606 if (window.title) { |
607 SDL_free (window.title); | 607 SDL_free(window.title); |
608 } | 608 } |
609 return 0; | 609 return 0; |
610 } | 610 } |
611 | 611 |
612 num_windows = SDL_CurrentDisplay.num_windows; | 612 num_windows = SDL_CurrentDisplay.num_windows; |
613 windows = | 613 windows = |
614 SDL_realloc (SDL_CurrentDisplay.windows, | 614 SDL_realloc(SDL_CurrentDisplay.windows, |
615 (num_windows + 1) * sizeof (*windows)); | 615 (num_windows + 1) * sizeof(*windows)); |
616 if (!windows) { | 616 if (!windows) { |
617 if (_this->DestroyWindow) { | 617 if (_this->DestroyWindow) { |
618 _this->DestroyWindow (_this, &window); | 618 _this->DestroyWindow(_this, &window); |
619 } | 619 } |
620 if (window.title) { | 620 if (window.title) { |
621 SDL_free (window.title); | 621 SDL_free(window.title); |
622 } | 622 } |
623 return 0; | 623 return 0; |
624 } | 624 } |
625 windows[num_windows] = window; | 625 windows[num_windows] = window; |
626 SDL_CurrentDisplay.windows = windows; | 626 SDL_CurrentDisplay.windows = windows; |
628 | 628 |
629 return window.id; | 629 return window.id; |
630 } | 630 } |
631 | 631 |
632 SDL_WindowID | 632 SDL_WindowID |
633 SDL_CreateWindowFrom (void *data) | 633 SDL_CreateWindowFrom(void *data) |
634 { | 634 { |
635 SDL_Window window; | 635 SDL_Window window; |
636 int num_windows; | 636 int num_windows; |
637 SDL_Window *windows; | 637 SDL_Window *windows; |
638 | 638 |
639 if (!_this) { | 639 if (!_this) { |
640 SDL_SetError ("Video subsystem has not been initialized"); | 640 SDL_SetError("Video subsystem has not been initialized"); |
641 return (0); | 641 return (0); |
642 } | 642 } |
643 | 643 |
644 SDL_zero (window); | 644 SDL_zero(window); |
645 window.id = _this->next_window_id++; | 645 window.id = _this->next_window_id++; |
646 | 646 |
647 if (!_this->CreateWindowFrom || | 647 if (!_this->CreateWindowFrom || |
648 _this->CreateWindowFrom (_this, &window, data) < 0) { | 648 _this->CreateWindowFrom(_this, &window, data) < 0) { |
649 return 0; | 649 return 0; |
650 } | 650 } |
651 | 651 |
652 num_windows = SDL_CurrentDisplay.num_windows; | 652 num_windows = SDL_CurrentDisplay.num_windows; |
653 windows = | 653 windows = |
654 SDL_realloc (SDL_CurrentDisplay.windows, | 654 SDL_realloc(SDL_CurrentDisplay.windows, |
655 (num_windows + 1) * sizeof (*windows)); | 655 (num_windows + 1) * sizeof(*windows)); |
656 if (!windows) { | 656 if (!windows) { |
657 if (_this->DestroyWindow) { | 657 if (_this->DestroyWindow) { |
658 _this->DestroyWindow (_this, &window); | 658 _this->DestroyWindow(_this, &window); |
659 } | 659 } |
660 if (window.title) { | 660 if (window.title) { |
661 SDL_free (window.title); | 661 SDL_free(window.title); |
662 } | 662 } |
663 return 0; | 663 return 0; |
664 } | 664 } |
665 windows[num_windows] = window; | 665 windows[num_windows] = window; |
666 SDL_CurrentDisplay.windows = windows; | 666 SDL_CurrentDisplay.windows = windows; |
668 | 668 |
669 return window.id; | 669 return window.id; |
670 } | 670 } |
671 | 671 |
672 static __inline__ SDL_Window * | 672 static __inline__ SDL_Window * |
673 SDL_GetWindowFromID (SDL_WindowID windowID) | 673 SDL_GetWindowFromID(SDL_WindowID windowID) |
674 { | 674 { |
675 int i, j; | 675 int i, j; |
676 | 676 |
677 if (!_this) { | 677 if (!_this) { |
678 return NULL; | 678 return NULL; |
689 } | 689 } |
690 return NULL; | 690 return NULL; |
691 } | 691 } |
692 | 692 |
693 SDL_Window * | 693 SDL_Window * |
694 SDL_GetWindowFromSurface (SDL_Surface * surface) | 694 SDL_GetWindowFromSurface(SDL_Surface * surface) |
695 { | 695 { |
696 int i, j; | 696 int i, j; |
697 | 697 |
698 if (!_this || !surface) { | 698 if (!_this || !surface) { |
699 return NULL; | 699 return NULL; |
711 return NULL; | 711 return NULL; |
712 } | 712 } |
713 | 713 |
714 | 714 |
715 Uint32 | 715 Uint32 |
716 SDL_GetWindowFlags (SDL_WindowID windowID) | 716 SDL_GetWindowFlags(SDL_WindowID windowID) |
717 { | 717 { |
718 SDL_Window *window = SDL_GetWindowFromID (windowID); | 718 SDL_Window *window = SDL_GetWindowFromID(windowID); |
719 | 719 |
720 if (!window) { | 720 if (!window) { |
721 return 0; | 721 return 0; |
722 } | 722 } |
723 return window->flags; | 723 return window->flags; |
724 } | 724 } |
725 | 725 |
726 void | 726 void |
727 SDL_SetWindowTitle (SDL_WindowID windowID, const char *title) | 727 SDL_SetWindowTitle(SDL_WindowID windowID, const char *title) |
728 { | 728 { |
729 SDL_Window *window = SDL_GetWindowFromID (windowID); | 729 SDL_Window *window = SDL_GetWindowFromID(windowID); |
730 | 730 |
731 if (!window) { | 731 if (!window) { |
732 return; | 732 return; |
733 } | 733 } |
734 if (window->title) { | 734 if (window->title) { |
735 SDL_free (window->title); | 735 SDL_free(window->title); |
736 } | 736 } |
737 window->title = SDL_strdup (title); | 737 window->title = SDL_strdup(title); |
738 | 738 |
739 if (_this->SetWindowTitle) { | 739 if (_this->SetWindowTitle) { |
740 _this->SetWindowTitle (_this, window); | 740 _this->SetWindowTitle(_this, window); |
741 } | 741 } |
742 } | 742 } |
743 | 743 |
744 const char * | 744 const char * |
745 SDL_GetWindowTitle (SDL_WindowID windowID) | 745 SDL_GetWindowTitle(SDL_WindowID windowID) |
746 { | 746 { |
747 SDL_Window *window = SDL_GetWindowFromID (windowID); | 747 SDL_Window *window = SDL_GetWindowFromID(windowID); |
748 | 748 |
749 if (!window) { | 749 if (!window) { |
750 return NULL; | 750 return NULL; |
751 } | 751 } |
752 return window->title; | 752 return window->title; |
753 } | 753 } |
754 | 754 |
755 void | 755 void |
756 SDL_SetWindowData (SDL_WindowID windowID, void *userdata) | 756 SDL_SetWindowData(SDL_WindowID windowID, void *userdata) |
757 { | 757 { |
758 SDL_Window *window = SDL_GetWindowFromID (windowID); | 758 SDL_Window *window = SDL_GetWindowFromID(windowID); |
759 | 759 |
760 if (!window) { | 760 if (!window) { |
761 return; | 761 return; |
762 } | 762 } |
763 window->userdata = userdata; | 763 window->userdata = userdata; |
764 } | 764 } |
765 | 765 |
766 void * | 766 void * |
767 SDL_GetWindowData (SDL_WindowID windowID) | 767 SDL_GetWindowData(SDL_WindowID windowID) |
768 { | 768 { |
769 SDL_Window *window = SDL_GetWindowFromID (windowID); | 769 SDL_Window *window = SDL_GetWindowFromID(windowID); |
770 | 770 |
771 if (!window) { | 771 if (!window) { |
772 return NULL; | 772 return NULL; |
773 } | 773 } |
774 return window->userdata; | 774 return window->userdata; |
775 } | 775 } |
776 | 776 |
777 void | 777 void |
778 SDL_SetWindowPosition (SDL_WindowID windowID, int x, int y) | 778 SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y) |
779 { | 779 { |
780 SDL_Window *window = SDL_GetWindowFromID (windowID); | 780 SDL_Window *window = SDL_GetWindowFromID(windowID); |
781 | 781 |
782 if (!window) { | 782 if (!window) { |
783 return; | 783 return; |
784 } | 784 } |
785 | 785 |
786 window->x = x; | 786 window->x = x; |
787 window->y = y; | 787 window->y = y; |
788 | 788 |
789 if (_this->SetWindowPosition) { | 789 if (_this->SetWindowPosition) { |
790 _this->SetWindowPosition (_this, window); | 790 _this->SetWindowPosition(_this, window); |
791 } | 791 } |
792 } | 792 } |
793 | 793 |
794 void | 794 void |
795 SDL_GetWindowPosition (SDL_WindowID windowID, int *x, int *y) | 795 SDL_GetWindowPosition(SDL_WindowID windowID, int *x, int *y) |
796 { | 796 { |
797 SDL_Window *window = SDL_GetWindowFromID (windowID); | 797 SDL_Window *window = SDL_GetWindowFromID(windowID); |
798 | 798 |
799 if (!window) { | 799 if (!window) { |
800 return; | 800 return; |
801 } | 801 } |
802 if (x) { | 802 if (x) { |
806 *y = window->y; | 806 *y = window->y; |
807 } | 807 } |
808 } | 808 } |
809 | 809 |
810 void | 810 void |
811 SDL_SetWindowSize (SDL_WindowID windowID, int w, int h) | 811 SDL_SetWindowSize(SDL_WindowID windowID, int w, int h) |
812 { | 812 { |
813 SDL_Window *window = SDL_GetWindowFromID (windowID); | 813 SDL_Window *window = SDL_GetWindowFromID(windowID); |
814 | 814 |
815 if (!window) { | 815 if (!window) { |
816 return; | 816 return; |
817 } | 817 } |
818 | 818 |
819 window->w = w; | 819 window->w = w; |
820 window->h = h; | 820 window->h = h; |
821 | 821 |
822 if (_this->SetWindowSize) { | 822 if (_this->SetWindowSize) { |
823 _this->SetWindowSize (_this, window); | 823 _this->SetWindowSize(_this, window); |
824 } | 824 } |
825 } | 825 } |
826 | 826 |
827 void | 827 void |
828 SDL_GetWindowSize (SDL_WindowID windowID, int *w, int *h) | 828 SDL_GetWindowSize(SDL_WindowID windowID, int *w, int *h) |
829 { | 829 { |
830 SDL_Window *window = SDL_GetWindowFromID (windowID); | 830 SDL_Window *window = SDL_GetWindowFromID(windowID); |
831 | 831 |
832 if (!window) { | 832 if (!window) { |
833 return; | 833 return; |
834 } | 834 } |
835 if (w) { | 835 if (w) { |
839 *h = window->h; | 839 *h = window->h; |
840 } | 840 } |
841 } | 841 } |
842 | 842 |
843 void | 843 void |
844 SDL_ShowWindow (SDL_WindowID windowID) | 844 SDL_ShowWindow(SDL_WindowID windowID) |
845 { | 845 { |
846 SDL_Window *window = SDL_GetWindowFromID (windowID); | 846 SDL_Window *window = SDL_GetWindowFromID(windowID); |
847 | 847 |
848 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { | 848 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { |
849 return; | 849 return; |
850 } | 850 } |
851 | 851 |
852 window->flags |= SDL_WINDOW_SHOWN; | 852 window->flags |= SDL_WINDOW_SHOWN; |
853 | 853 |
854 if (_this->ShowWindow) { | 854 if (_this->ShowWindow) { |
855 _this->ShowWindow (_this, window); | 855 _this->ShowWindow(_this, window); |
856 } | 856 } |
857 } | 857 } |
858 | 858 |
859 void | 859 void |
860 SDL_HideWindow (SDL_WindowID windowID) | 860 SDL_HideWindow(SDL_WindowID windowID) |
861 { | 861 { |
862 SDL_Window *window = SDL_GetWindowFromID (windowID); | 862 SDL_Window *window = SDL_GetWindowFromID(windowID); |
863 | 863 |
864 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { | 864 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { |
865 return; | 865 return; |
866 } | 866 } |
867 | 867 |
868 window->flags &= ~SDL_WINDOW_SHOWN; | 868 window->flags &= ~SDL_WINDOW_SHOWN; |
869 | 869 |
870 if (_this->HideWindow) { | 870 if (_this->HideWindow) { |
871 _this->HideWindow (_this, window); | 871 _this->HideWindow(_this, window); |
872 } | 872 } |
873 } | 873 } |
874 | 874 |
875 void | 875 void |
876 SDL_RaiseWindow (SDL_WindowID windowID) | 876 SDL_RaiseWindow(SDL_WindowID windowID) |
877 { | 877 { |
878 SDL_Window *window = SDL_GetWindowFromID (windowID); | 878 SDL_Window *window = SDL_GetWindowFromID(windowID); |
879 | 879 |
880 if (!window) { | 880 if (!window) { |
881 return; | 881 return; |
882 } | 882 } |
883 | 883 |
884 if (_this->RaiseWindow) { | 884 if (_this->RaiseWindow) { |
885 _this->RaiseWindow (_this, window); | 885 _this->RaiseWindow(_this, window); |
886 } | 886 } |
887 } | 887 } |
888 | 888 |
889 void | 889 void |
890 SDL_MaximizeWindow (SDL_WindowID windowID) | 890 SDL_MaximizeWindow(SDL_WindowID windowID) |
891 { | 891 { |
892 SDL_Window *window = SDL_GetWindowFromID (windowID); | 892 SDL_Window *window = SDL_GetWindowFromID(windowID); |
893 | 893 |
894 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { | 894 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { |
895 return; | 895 return; |
896 } | 896 } |
897 | 897 |
898 window->flags |= SDL_WINDOW_MAXIMIZED; | 898 window->flags |= SDL_WINDOW_MAXIMIZED; |
899 | 899 |
900 if (_this->MaximizeWindow) { | 900 if (_this->MaximizeWindow) { |
901 _this->MaximizeWindow (_this, window); | 901 _this->MaximizeWindow(_this, window); |
902 } | 902 } |
903 } | 903 } |
904 | 904 |
905 void | 905 void |
906 SDL_MinimizeWindow (SDL_WindowID windowID) | 906 SDL_MinimizeWindow(SDL_WindowID windowID) |
907 { | 907 { |
908 SDL_Window *window = SDL_GetWindowFromID (windowID); | 908 SDL_Window *window = SDL_GetWindowFromID(windowID); |
909 | 909 |
910 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { | 910 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { |
911 return; | 911 return; |
912 } | 912 } |
913 | 913 |
914 window->flags |= SDL_WINDOW_MINIMIZED; | 914 window->flags |= SDL_WINDOW_MINIMIZED; |
915 | 915 |
916 if (_this->MinimizeWindow) { | 916 if (_this->MinimizeWindow) { |
917 _this->MinimizeWindow (_this, window); | 917 _this->MinimizeWindow(_this, window); |
918 } | 918 } |
919 } | 919 } |
920 | 920 |
921 void | 921 void |
922 SDL_RestoreWindow (SDL_WindowID windowID) | 922 SDL_RestoreWindow(SDL_WindowID windowID) |
923 { | 923 { |
924 SDL_Window *window = SDL_GetWindowFromID (windowID); | 924 SDL_Window *window = SDL_GetWindowFromID(windowID); |
925 | 925 |
926 if (!window | 926 if (!window |
927 || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { | 927 || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { |
928 return; | 928 return; |
929 } | 929 } |
930 | 930 |
931 window->flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED); | 931 window->flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED); |
932 | 932 |
933 if (_this->RestoreWindow) { | 933 if (_this->RestoreWindow) { |
934 _this->RestoreWindow (_this, window); | 934 _this->RestoreWindow(_this, window); |
935 } | 935 } |
936 } | 936 } |
937 | 937 |
938 void | 938 void |
939 SDL_SetWindowGrab (SDL_WindowID windowID, int mode) | 939 SDL_SetWindowGrab(SDL_WindowID windowID, int mode) |
940 { | 940 { |
941 SDL_Window *window = SDL_GetWindowFromID (windowID); | 941 SDL_Window *window = SDL_GetWindowFromID(windowID); |
942 | 942 |
943 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { | 943 if (!window || (!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { |
944 return; | 944 return; |
945 } | 945 } |
946 | 946 |
949 } else { | 949 } else { |
950 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; | 950 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; |
951 } | 951 } |
952 | 952 |
953 if (_this->SetWindowGrab) { | 953 if (_this->SetWindowGrab) { |
954 _this->SetWindowGrab (_this, window); | 954 _this->SetWindowGrab(_this, window); |
955 } | 955 } |
956 } | 956 } |
957 | 957 |
958 int | 958 int |
959 SDL_GetWindowGrab (SDL_WindowID windowID) | 959 SDL_GetWindowGrab(SDL_WindowID windowID) |
960 { | 960 { |
961 SDL_Window *window = SDL_GetWindowFromID (windowID); | 961 SDL_Window *window = SDL_GetWindowFromID(windowID); |
962 | 962 |
963 if (!window) { | 963 if (!window) { |
964 return 0; | 964 return 0; |
965 } | 965 } |
966 | 966 |
967 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); | 967 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); |
968 } | 968 } |
969 | 969 |
970 void | 970 void |
971 SDL_DestroyWindow (SDL_WindowID windowID) | 971 SDL_DestroyWindow(SDL_WindowID windowID) |
972 { | 972 { |
973 int i, j; | 973 int i, j; |
974 | 974 |
975 if (!_this) { | 975 if (!_this) { |
976 return; | 976 return; |
983 if (window->id != windowID) { | 983 if (window->id != windowID) { |
984 continue; | 984 continue; |
985 } | 985 } |
986 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { | 986 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { |
987 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; | 987 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; |
988 _this->SetWindowGrab (_this, window); | 988 _this->SetWindowGrab(_this, window); |
989 } | 989 } |
990 if (window->shadow) { | 990 if (window->shadow) { |
991 SDL_FreeSurface (window->shadow); | 991 SDL_FreeSurface(window->shadow); |
992 } | 992 } |
993 if (window->surface) { | 993 if (window->surface) { |
994 SDL_FreeSurface (window->surface); | 994 SDL_FreeSurface(window->surface); |
995 } | 995 } |
996 if (_this->DestroyWindow) { | 996 if (_this->DestroyWindow) { |
997 _this->DestroyWindow (_this, window); | 997 _this->DestroyWindow(_this, window); |
998 } | 998 } |
999 if (window->title) { | 999 if (window->title) { |
1000 SDL_free (window->title); | 1000 SDL_free(window->title); |
1001 } | 1001 } |
1002 if (window->gamma) { | 1002 if (window->gamma) { |
1003 SDL_free (window->gamma); | 1003 SDL_free(window->gamma); |
1004 } | 1004 } |
1005 if (j != display->num_windows - 1) { | 1005 if (j != display->num_windows - 1) { |
1006 SDL_memcpy (&display->windows[i], | 1006 SDL_memcpy(&display->windows[i], |
1007 &display->windows[i + 1], | 1007 &display->windows[i + 1], |
1008 (display->num_windows - i - | 1008 (display->num_windows - i - 1) * sizeof(*window)); |
1009 1) * sizeof (*window)); | |
1010 } | 1009 } |
1011 --display->num_windows; | 1010 --display->num_windows; |
1012 return; | 1011 return; |
1013 } | 1012 } |
1014 } | 1013 } |
1015 } | 1014 } |
1016 | 1015 |
1017 SDL_Surface * | 1016 SDL_Surface * |
1018 SDL_CreateWindowSurface (SDL_WindowID windowID, Uint32 format, Uint32 flags) | 1017 SDL_CreateWindowSurface(SDL_WindowID windowID, Uint32 format, Uint32 flags) |
1019 { | 1018 { |
1020 SDL_Window *window = SDL_GetWindowFromID (windowID); | 1019 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1021 Uint32 black; | 1020 Uint32 black; |
1022 SDL_Surface *surface; | 1021 SDL_Surface *surface; |
1023 | 1022 |
1024 if (!window) { | 1023 if (!window) { |
1025 return NULL; | 1024 return NULL; |
1028 if (!_this->CreateWindowSurface) { | 1027 if (!_this->CreateWindowSurface) { |
1029 return NULL; | 1028 return NULL; |
1030 } | 1029 } |
1031 | 1030 |
1032 if (!window->surface) { | 1031 if (!window->surface) { |
1033 _this->CreateWindowSurface (_this, window, flags); | 1032 _this->CreateWindowSurface(_this, window, flags); |
1034 if (!window->surface) { | 1033 if (!window->surface) { |
1035 return NULL; | 1034 return NULL; |
1036 } | 1035 } |
1037 window->surface->flags |= SDL_SCREEN_SURFACE; | 1036 window->surface->flags |= SDL_SCREEN_SURFACE; |
1038 } | 1037 } |
1039 surface = window->surface; | 1038 surface = window->surface; |
1040 | 1039 |
1041 if (window->shadow) { | 1040 if (window->shadow) { |
1042 SDL_FreeSurface (window->shadow); | 1041 SDL_FreeSurface(window->shadow); |
1043 window->shadow = NULL; | 1042 window->shadow = NULL; |
1044 } | 1043 } |
1045 | 1044 |
1046 /* Create a shadow surface if necessary */ | 1045 /* Create a shadow surface if necessary */ |
1047 if ((!(flags & SDL_ANYFORMAT) | 1046 if ((!(flags & SDL_ANYFORMAT) |
1048 && (format != SDL_GetCurrentDisplayMode ()->format)) | 1047 && (format != SDL_GetCurrentDisplayMode()->format)) |
1049 || ((flags & SDL_HWPALETTE) | 1048 || ((flags & SDL_HWPALETTE) |
1050 && !(window->surface->flags & SDL_HWPALETTE))) { | 1049 && !(window->surface->flags & SDL_HWPALETTE))) { |
1051 int bpp; | 1050 int bpp; |
1052 Uint32 Rmask, Gmask, Bmask, Amask; | 1051 Uint32 Rmask, Gmask, Bmask, Amask; |
1053 | 1052 |
1054 SDL_PixelFormatEnumToMasks (format, &bpp, &Amask, &Gmask, &Bmask, | 1053 SDL_PixelFormatEnumToMasks(format, &bpp, &Amask, &Gmask, &Bmask, |
1055 &Amask); | 1054 &Amask); |
1056 window->shadow = | 1055 window->shadow = |
1057 SDL_CreateRGBSurface (SDL_SWSURFACE, surface->w, surface->h, bpp, | 1056 SDL_CreateRGBSurface(SDL_SWSURFACE, surface->w, surface->h, bpp, |
1058 Rmask, Gmask, Bmask, Amask); | 1057 Rmask, Gmask, Bmask, Amask); |
1059 if (window->shadow == NULL) { | 1058 if (window->shadow == NULL) { |
1060 return NULL; | 1059 return NULL; |
1061 } | 1060 } |
1062 window->shadow->flags |= SDL_SHADOW_SURFACE; | 1061 window->shadow->flags |= SDL_SHADOW_SURFACE; |
1063 surface = window->shadow; | 1062 surface = window->shadow; |
1064 | 1063 |
1065 /* 8-bit shadow surfaces report that they have exclusive palette */ | 1064 /* 8-bit shadow surfaces report that they have exclusive palette */ |
1066 if (surface->format->palette) { | 1065 if (surface->format->palette) { |
1067 surface->flags |= SDL_HWPALETTE; | 1066 surface->flags |= SDL_HWPALETTE; |
1068 if (format == SDL_GetCurrentDisplayMode ()->format) { | 1067 if (format == SDL_GetCurrentDisplayMode()->format) { |
1069 SDL_memcpy (surface->format->palette->colors, | 1068 SDL_memcpy(surface->format->palette->colors, |
1070 window->surface->format->palette->colors, | 1069 window->surface->format->palette->colors, |
1071 window->surface->format->palette->ncolors * | 1070 window->surface->format->palette->ncolors * |
1072 sizeof (SDL_Color)); | 1071 sizeof(SDL_Color)); |
1073 } else { | 1072 } else { |
1074 SDL_DitherColors (surface->format->palette->colors, bpp); | 1073 SDL_DitherColors(surface->format->palette->colors, bpp); |
1075 } | 1074 } |
1076 } | 1075 } |
1077 } | 1076 } |
1078 | 1077 |
1079 /* Clear the surface for display */ | 1078 /* Clear the surface for display */ |
1080 { | 1079 { |
1081 Uint32 black = SDL_MapRGB (surface->format, 0, 0, 0); | 1080 Uint32 black = SDL_MapRGB(surface->format, 0, 0, 0); |
1082 SDL_FillRect (surface, NULL, black); | 1081 SDL_FillRect(surface, NULL, black); |
1083 if (surface->flags & SDL_DOUBLEBUF) { | 1082 if (surface->flags & SDL_DOUBLEBUF) { |
1084 SDL_Flip (surface); | 1083 SDL_Flip(surface); |
1085 SDL_FillRect (surface, NULL, black); | 1084 SDL_FillRect(surface, NULL, black); |
1086 } | 1085 } |
1087 SDL_Flip (surface); | 1086 SDL_Flip(surface); |
1088 } | 1087 } |
1089 | 1088 |
1090 return surface; | 1089 return surface; |
1091 } | 1090 } |
1092 | 1091 |
1093 /* | 1092 /* |
1094 * Convert a surface into the video pixel format. | 1093 * Convert a surface into the video pixel format. |
1095 */ | 1094 */ |
1096 SDL_Surface * | 1095 SDL_Surface * |
1097 SDL_DisplayFormat (SDL_Surface * surface) | 1096 SDL_DisplayFormat(SDL_Surface * surface) |
1098 { | 1097 { |
1099 Uint32 flags; | 1098 Uint32 flags; |
1100 | 1099 |
1101 if (!SDL_PublicSurface) { | 1100 if (!SDL_PublicSurface) { |
1102 SDL_SetError ("No video mode has been set"); | 1101 SDL_SetError("No video mode has been set"); |
1103 return (NULL); | 1102 return (NULL); |
1104 } | 1103 } |
1105 /* Set the flags appropriate for copying to display surface */ | 1104 /* Set the flags appropriate for copying to display surface */ |
1106 if (((SDL_PublicSurface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) | 1105 if (((SDL_PublicSurface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) |
1107 && _this->info.blit_hw) | 1106 && _this->info.blit_hw) |
1113 flags |= SDL_RLEACCELOK; | 1112 flags |= SDL_RLEACCELOK; |
1114 #else | 1113 #else |
1115 flags |= | 1114 flags |= |
1116 surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK); | 1115 surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK); |
1117 #endif | 1116 #endif |
1118 return (SDL_ConvertSurface (surface, SDL_PublicSurface->format, flags)); | 1117 return (SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags)); |
1119 } | 1118 } |
1120 | 1119 |
1121 /* | 1120 /* |
1122 * Convert a surface into a format that's suitable for blitting to | 1121 * Convert a surface into a format that's suitable for blitting to |
1123 * the screen, but including an alpha channel. | 1122 * the screen, but including an alpha channel. |
1124 */ | 1123 */ |
1125 SDL_Surface * | 1124 SDL_Surface * |
1126 SDL_DisplayFormatAlpha (SDL_Surface * surface) | 1125 SDL_DisplayFormatAlpha(SDL_Surface * surface) |
1127 { | 1126 { |
1128 SDL_PixelFormat *vf; | 1127 SDL_PixelFormat *vf; |
1129 SDL_PixelFormat *format; | 1128 SDL_PixelFormat *format; |
1130 SDL_Surface *converted; | 1129 SDL_Surface *converted; |
1131 Uint32 flags; | 1130 Uint32 flags; |
1134 Uint32 rmask = 0x00ff0000; | 1133 Uint32 rmask = 0x00ff0000; |
1135 Uint32 gmask = 0x0000ff00; | 1134 Uint32 gmask = 0x0000ff00; |
1136 Uint32 bmask = 0x000000ff; | 1135 Uint32 bmask = 0x000000ff; |
1137 | 1136 |
1138 if (!SDL_PublicSurface) { | 1137 if (!SDL_PublicSurface) { |
1139 SDL_SetError ("No video mode has been set"); | 1138 SDL_SetError("No video mode has been set"); |
1140 return (NULL); | 1139 return (NULL); |
1141 } | 1140 } |
1142 vf = SDL_PublicSurface->format; | 1141 vf = SDL_PublicSurface->format; |
1143 | 1142 |
1144 switch (vf->BytesPerPixel) { | 1143 switch (vf->BytesPerPixel) { |
1166 default: | 1165 default: |
1167 /* We have no other optimised formats right now. When/if a new | 1166 /* We have no other optimised formats right now. When/if a new |
1168 optimised alpha format is written, add the converter here */ | 1167 optimised alpha format is written, add the converter here */ |
1169 break; | 1168 break; |
1170 } | 1169 } |
1171 format = SDL_AllocFormat (32, rmask, gmask, bmask, amask); | 1170 format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); |
1172 flags = SDL_PublicSurface->flags & SDL_HWSURFACE; | 1171 flags = SDL_PublicSurface->flags & SDL_HWSURFACE; |
1173 flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); | 1172 flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); |
1174 converted = SDL_ConvertSurface (surface, format, flags); | 1173 converted = SDL_ConvertSurface(surface, format, flags); |
1175 SDL_FreeFormat (format); | 1174 SDL_FreeFormat(format); |
1176 return (converted); | 1175 return (converted); |
1177 } | 1176 } |
1178 | 1177 |
1179 /* | 1178 /* |
1180 * Update a specific portion of the physical screen | 1179 * Update a specific portion of the physical screen |
1181 */ | 1180 */ |
1182 void | 1181 void |
1183 SDL_UpdateRect (SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) | 1182 SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) |
1184 { | 1183 { |
1185 if (screen) { | 1184 if (screen) { |
1186 SDL_Rect rect; | 1185 SDL_Rect rect; |
1187 | 1186 |
1188 /* Perform some checking */ | 1187 /* Perform some checking */ |
1198 /* Fill the rectangle */ | 1197 /* Fill the rectangle */ |
1199 rect.x = (Sint16) x; | 1198 rect.x = (Sint16) x; |
1200 rect.y = (Sint16) y; | 1199 rect.y = (Sint16) y; |
1201 rect.w = (Uint16) w; | 1200 rect.w = (Uint16) w; |
1202 rect.h = (Uint16) h; | 1201 rect.h = (Uint16) h; |
1203 SDL_UpdateRects (screen, 1, &rect); | 1202 SDL_UpdateRects(screen, 1, &rect); |
1204 } | 1203 } |
1205 } | 1204 } |
1206 void | 1205 void |
1207 SDL_UpdateRects (SDL_Surface * screen, int numrects, SDL_Rect * rects) | 1206 SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects) |
1208 { | 1207 { |
1209 int i; | 1208 int i; |
1210 SDL_Window *window; | 1209 SDL_Window *window; |
1211 | 1210 |
1212 /* Find the window corresponding to this surface */ | 1211 /* Find the window corresponding to this surface */ |
1213 window = SDL_GetWindowFromSurface (screen); | 1212 window = SDL_GetWindowFromSurface(screen); |
1214 if (!window) { | 1213 if (!window) { |
1215 SDL_SetError ("Couldn't find window associated with surface"); | 1214 SDL_SetError("Couldn't find window associated with surface"); |
1216 return; | 1215 return; |
1217 } | 1216 } |
1218 | 1217 |
1219 if (screen->flags & SDL_SHADOW_SURFACE) { | 1218 if (screen->flags & SDL_SHADOW_SURFACE) { |
1220 if (SHOULD_DRAWCURSOR (SDL_cursorstate)) { | 1219 if (SHOULD_DRAWCURSOR(SDL_cursorstate)) { |
1221 SDL_LockCursor (); | 1220 SDL_LockCursor(); |
1222 SDL_DrawCursor (screen); | 1221 SDL_DrawCursor(screen); |
1223 for (i = 0; i < numrects; ++i) { | 1222 for (i = 0; i < numrects; ++i) { |
1224 SDL_LowerBlit (screen, &rects[i], window->surface, &rects[i]); | 1223 SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]); |
1225 } | 1224 } |
1226 SDL_EraseCursor (screen); | 1225 SDL_EraseCursor(screen); |
1227 SDL_UnlockCursor (); | 1226 SDL_UnlockCursor(); |
1228 } else { | 1227 } else { |
1229 for (i = 0; i < numrects; ++i) { | 1228 for (i = 0; i < numrects; ++i) { |
1230 SDL_LowerBlit (screen, &rects[i], window->surface, &rects[i]); | 1229 SDL_LowerBlit(screen, &rects[i], window->surface, &rects[i]); |
1231 } | 1230 } |
1232 } | 1231 } |
1233 | 1232 |
1234 /* Fall through to video surface update */ | 1233 /* Fall through to video surface update */ |
1235 screen = window->surface; | 1234 screen = window->surface; |
1241 int offset_x = screen->offset % screen->pitch; | 1240 int offset_x = screen->offset % screen->pitch; |
1242 for (i = 0; i < numrects; ++i) { | 1241 for (i = 0; i < numrects; ++i) { |
1243 rects[i].x += offset_x; | 1242 rects[i].x += offset_x; |
1244 rects[i].y += offset_y; | 1243 rects[i].y += offset_y; |
1245 } | 1244 } |
1246 _this->UpdateWindowSurface (_this, window, numrects, rects); | 1245 _this->UpdateWindowSurface(_this, window, numrects, rects); |
1247 for (i = 0; i < numrects; ++i) { | 1246 for (i = 0; i < numrects; ++i) { |
1248 rects[i].x -= offset_x; | 1247 rects[i].x -= offset_x; |
1249 rects[i].y -= offset_y; | 1248 rects[i].y -= offset_y; |
1250 } | 1249 } |
1251 } else { | 1250 } else { |
1252 _this->UpdateWindowSurface (_this, window, numrects, rects); | 1251 _this->UpdateWindowSurface(_this, window, numrects, rects); |
1253 } | 1252 } |
1254 } | 1253 } |
1255 } | 1254 } |
1256 | 1255 |
1257 /* | 1256 /* |
1258 * Performs hardware double buffering, if possible, or a full update if not. | 1257 * Performs hardware double buffering, if possible, or a full update if not. |
1259 */ | 1258 */ |
1260 int | 1259 int |
1261 SDL_Flip (SDL_Surface * screen) | 1260 SDL_Flip(SDL_Surface * screen) |
1262 { | 1261 { |
1263 SDL_Window *window; | 1262 SDL_Window *window; |
1264 | 1263 |
1265 /* Find the window corresponding to this surface */ | 1264 /* Find the window corresponding to this surface */ |
1266 window = SDL_GetWindowFromSurface (screen); | 1265 window = SDL_GetWindowFromSurface(screen); |
1267 if (!window) { | 1266 if (!window) { |
1268 SDL_SetError ("Couldn't find window associated with surface"); | 1267 SDL_SetError("Couldn't find window associated with surface"); |
1269 return; | 1268 return; |
1270 } | 1269 } |
1271 | 1270 |
1272 /* Copy the shadow surface to the video surface */ | 1271 /* Copy the shadow surface to the video surface */ |
1273 if (screen->flags & SDL_SHADOW_SURFACE) { | 1272 if (screen->flags & SDL_SHADOW_SURFACE) { |
1275 | 1274 |
1276 rect.x = 0; | 1275 rect.x = 0; |
1277 rect.y = 0; | 1276 rect.y = 0; |
1278 rect.w = screen->w; | 1277 rect.w = screen->w; |
1279 rect.h = screen->h; | 1278 rect.h = screen->h; |
1280 if (SHOULD_DRAWCURSOR (SDL_cursorstate)) { | 1279 if (SHOULD_DRAWCURSOR(SDL_cursorstate)) { |
1281 SDL_LockCursor (); | 1280 SDL_LockCursor(); |
1282 SDL_DrawCursor (screen); | 1281 SDL_DrawCursor(screen); |
1283 SDL_LowerBlit (screen, &rect, window->surface, &rect); | 1282 SDL_LowerBlit(screen, &rect, window->surface, &rect); |
1284 SDL_EraseCursor (screen); | 1283 SDL_EraseCursor(screen); |
1285 SDL_UnlockCursor (); | 1284 SDL_UnlockCursor(); |
1286 } else { | 1285 } else { |
1287 SDL_LowerBlit (screen, &rect, window->surface, &rect); | 1286 SDL_LowerBlit(screen, &rect, window->surface, &rect); |
1288 } | 1287 } |
1289 | 1288 |
1290 /* Fall through to video surface update */ | 1289 /* Fall through to video surface update */ |
1291 screen = window->surface; | 1290 screen = window->surface; |
1292 } | 1291 } |
1293 if (screen->flags & SDL_DOUBLEBUF) { | 1292 if (screen->flags & SDL_DOUBLEBUF) { |
1294 _this->FlipWindowSurface (_this, window); | 1293 _this->FlipWindowSurface(_this, window); |
1295 } else { | 1294 } else { |
1296 SDL_UpdateRect (screen, 0, 0, 0, 0); | 1295 SDL_UpdateRect(screen, 0, 0, 0, 0); |
1297 } | 1296 } |
1298 return (0); | 1297 return (0); |
1299 } | 1298 } |
1300 | 1299 |
1301 int | 1300 int |
1302 SDL_SetColors (SDL_Surface * screen, SDL_Color * colors, int firstcolor, | 1301 SDL_SetColors(SDL_Surface * screen, SDL_Color * colors, int firstcolor, |
1303 int ncolors) | 1302 int ncolors) |
1304 { | 1303 { |
1305 SDL_Window *window = NULL; | 1304 SDL_Window *window = NULL; |
1306 SDL_Palette *pal; | 1305 SDL_Palette *pal; |
1307 int gotall; | 1306 int gotall; |
1308 int palsize; | 1307 int palsize; |
1318 ncolors = (palsize - firstcolor); | 1317 ncolors = (palsize - firstcolor); |
1319 gotall = 0; | 1318 gotall = 0; |
1320 } | 1319 } |
1321 | 1320 |
1322 if (colors != (pal->colors + firstcolor)) { | 1321 if (colors != (pal->colors + firstcolor)) { |
1323 SDL_memcpy (pal->colors + firstcolor, colors, | 1322 SDL_memcpy(pal->colors + firstcolor, colors, |
1324 ncolors * sizeof (*colors)); | 1323 ncolors * sizeof(*colors)); |
1325 } | 1324 } |
1326 SDL_FormatChanged (screen); | 1325 SDL_FormatChanged(screen); |
1327 | 1326 |
1328 if (screen->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) { | 1327 if (screen->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) { |
1329 window = SDL_GetWindowFromSurface (screen); | 1328 window = SDL_GetWindowFromSurface(screen); |
1330 if (!window) { | 1329 if (!window) { |
1331 return 0; | 1330 return 0; |
1332 } | 1331 } |
1333 } | 1332 } |
1334 | 1333 |
1340 /* This is a shadow surface, and the physical | 1339 /* This is a shadow surface, and the physical |
1341 * framebuffer is also indexed. Propagate the | 1340 * framebuffer is also indexed. Propagate the |
1342 * changes to its logical palette so that | 1341 * changes to its logical palette so that |
1343 * updates are always identity blits | 1342 * updates are always identity blits |
1344 */ | 1343 */ |
1345 SDL_memcpy (vidpal->colors + firstcolor, colors, | 1344 SDL_memcpy(vidpal->colors + firstcolor, colors, |
1346 ncolors * sizeof (*colors)); | 1345 ncolors * sizeof(*colors)); |
1347 } | 1346 } |
1348 if (window->surface->flags & SDL_HWPALETTE) { | 1347 if (window->surface->flags & SDL_HWPALETTE) { |
1349 /* Set the physical palette */ | 1348 /* Set the physical palette */ |
1350 screen = window->surface; | 1349 screen = window->surface; |
1351 } else { | 1350 } else { |
1352 SDL_UpdateRect (screen, 0, 0, 0, 0); | 1351 SDL_UpdateRect(screen, 0, 0, 0, 0); |
1353 } | 1352 } |
1354 } | 1353 } |
1355 | 1354 |
1356 if (screen->flags & SDL_SCREEN_SURFACE) { | 1355 if (screen->flags & SDL_SCREEN_SURFACE) { |
1357 if (_this->SetWindowColors) { | 1356 if (_this->SetWindowColors) { |
1358 gotall = | 1357 gotall = |
1359 _this->SetWindowColors (_this, window, firstcolor, ncolors, | 1358 _this->SetWindowColors(_this, window, firstcolor, ncolors, |
1360 colors); | 1359 colors); |
1361 if (!gotall) { | 1360 if (!gotall) { |
1362 /* The video flags shouldn't have SDL_HWPALETTE, and | 1361 /* The video flags shouldn't have SDL_HWPALETTE, and |
1363 the video driver is responsible for copying back the | 1362 the video driver is responsible for copying back the |
1364 correct colors into the video surface palette. | 1363 correct colors into the video surface palette. |
1365 */ | 1364 */ |
1366 ; | 1365 ; |
1367 } | 1366 } |
1368 } | 1367 } |
1369 SDL_CursorPaletteChanged (); | 1368 SDL_CursorPaletteChanged(); |
1370 } | 1369 } |
1371 | 1370 |
1372 return gotall; | 1371 return gotall; |
1373 } | 1372 } |
1374 | 1373 |
1375 void | 1374 void |
1376 SDL_VideoQuit (void) | 1375 SDL_VideoQuit(void) |
1377 { | 1376 { |
1378 int i, j; | 1377 int i, j; |
1379 | 1378 |
1380 if (!_this) { | 1379 if (!_this) { |
1381 return; | 1380 return; |
1382 } | 1381 } |
1383 | 1382 |
1384 /* Halt event processing before doing anything else */ | 1383 /* Halt event processing before doing anything else */ |
1385 SDL_StopEventLoop (); | 1384 SDL_StopEventLoop(); |
1386 | 1385 |
1387 /* Clean up allocated window manager items */ | 1386 /* Clean up allocated window manager items */ |
1388 SDL_CursorQuit (); | 1387 SDL_CursorQuit(); |
1389 | 1388 |
1390 /* Clean up the system video */ | 1389 /* Clean up the system video */ |
1391 for (i = _this->num_displays; i--;) { | 1390 for (i = _this->num_displays; i--;) { |
1392 SDL_VideoDisplay *display = &_this->displays[i]; | 1391 SDL_VideoDisplay *display = &_this->displays[i]; |
1393 for (j = display->num_windows; j--;) { | 1392 for (j = display->num_windows; j--;) { |
1394 SDL_DestroyWindow (display->windows[i].id); | 1393 SDL_DestroyWindow(display->windows[i].id); |
1395 } | 1394 } |
1396 if (display->windows) { | 1395 if (display->windows) { |
1397 SDL_free (display->windows); | 1396 SDL_free(display->windows); |
1398 display->windows = NULL; | 1397 display->windows = NULL; |
1399 } | 1398 } |
1400 } | 1399 } |
1401 _this->VideoQuit (_this); | 1400 _this->VideoQuit(_this); |
1402 if (_this->displays) { | 1401 if (_this->displays) { |
1403 SDL_free (_this->displays); | 1402 SDL_free(_this->displays); |
1404 } | 1403 } |
1405 _this->free (_this); | 1404 _this->free(_this); |
1406 _this = NULL; | 1405 _this = NULL; |
1407 } | 1406 } |
1408 | 1407 |
1409 /* Load the GL driver library */ | 1408 /* Load the GL driver library */ |
1410 int | 1409 int |
1411 SDL_GL_LoadLibrary (const char *path) | 1410 SDL_GL_LoadLibrary(const char *path) |
1412 { | 1411 { |
1413 int retval; | 1412 int retval; |
1414 | 1413 |
1415 retval = -1; | 1414 retval = -1; |
1416 if (_this == NULL) { | 1415 if (_this == NULL) { |
1417 SDL_SetError ("Video subsystem has not been initialized"); | 1416 SDL_SetError("Video subsystem has not been initialized"); |
1418 } else { | 1417 } else { |
1419 if (_this->GL_LoadLibrary) { | 1418 if (_this->GL_LoadLibrary) { |
1420 retval = _this->GL_LoadLibrary (_this, path); | 1419 retval = _this->GL_LoadLibrary(_this, path); |
1421 } else { | 1420 } else { |
1422 SDL_SetError ("No dynamic GL support in video driver"); | 1421 SDL_SetError("No dynamic GL support in video driver"); |
1423 } | 1422 } |
1424 } | 1423 } |
1425 return (retval); | 1424 return (retval); |
1426 } | 1425 } |
1427 | 1426 |
1428 void * | 1427 void * |
1429 SDL_GL_GetProcAddress (const char *proc) | 1428 SDL_GL_GetProcAddress(const char *proc) |
1430 { | 1429 { |
1431 void *func; | 1430 void *func; |
1432 | 1431 |
1433 func = NULL; | 1432 func = NULL; |
1434 if (_this->GL_GetProcAddress) { | 1433 if (_this->GL_GetProcAddress) { |
1435 if (_this->gl_config.driver_loaded) { | 1434 if (_this->gl_config.driver_loaded) { |
1436 func = _this->GL_GetProcAddress (_this, proc); | 1435 func = _this->GL_GetProcAddress(_this, proc); |
1437 } else { | 1436 } else { |
1438 SDL_SetError ("No GL driver has been loaded"); | 1437 SDL_SetError("No GL driver has been loaded"); |
1439 } | 1438 } |
1440 } else { | 1439 } else { |
1441 SDL_SetError ("No dynamic GL support in video driver"); | 1440 SDL_SetError("No dynamic GL support in video driver"); |
1442 } | 1441 } |
1443 return func; | 1442 return func; |
1444 } | 1443 } |
1445 | 1444 |
1446 /* Set the specified GL attribute for setting up a GL video mode */ | 1445 /* Set the specified GL attribute for setting up a GL video mode */ |
1447 int | 1446 int |
1448 SDL_GL_SetAttribute (SDL_GLattr attr, int value) | 1447 SDL_GL_SetAttribute(SDL_GLattr attr, int value) |
1449 { | 1448 { |
1450 int retval; | 1449 int retval; |
1451 | 1450 |
1452 retval = 0; | 1451 retval = 0; |
1453 switch (attr) { | 1452 switch (attr) { |
1501 break; | 1500 break; |
1502 case SDL_GL_SWAP_CONTROL: | 1501 case SDL_GL_SWAP_CONTROL: |
1503 _this->gl_config.swap_control = value; | 1502 _this->gl_config.swap_control = value; |
1504 break; | 1503 break; |
1505 default: | 1504 default: |
1506 SDL_SetError ("Unknown OpenGL attribute"); | 1505 SDL_SetError("Unknown OpenGL attribute"); |
1507 retval = -1; | 1506 retval = -1; |
1508 break; | 1507 break; |
1509 } | 1508 } |
1510 return (retval); | 1509 return (retval); |
1511 } | 1510 } |
1512 | 1511 |
1513 /* Retrieve an attribute value from the windowing system. */ | 1512 /* Retrieve an attribute value from the windowing system. */ |
1514 int | 1513 int |
1515 SDL_GL_GetAttribute (SDL_GLattr attr, int *value) | 1514 SDL_GL_GetAttribute(SDL_GLattr attr, int *value) |
1516 { | 1515 { |
1517 int retval = -1; | 1516 int retval = -1; |
1518 | 1517 |
1519 if (_this->GL_GetAttribute) { | 1518 if (_this->GL_GetAttribute) { |
1520 retval = _this->GL_GetAttribute (_this, attr, value); | 1519 retval = _this->GL_GetAttribute(_this, attr, value); |
1521 } else { | 1520 } else { |
1522 *value = 0; | 1521 *value = 0; |
1523 SDL_SetError ("GL_GetAttribute not supported"); | 1522 SDL_SetError("GL_GetAttribute not supported"); |
1524 } | 1523 } |
1525 return retval; | 1524 return retval; |
1526 } | 1525 } |
1527 | 1526 |
1528 /* Perform a GL buffer swap on the current GL context */ | 1527 /* Perform a GL buffer swap on the current GL context */ |
1529 void | 1528 void |
1530 SDL_GL_SwapBuffers (void) | 1529 SDL_GL_SwapBuffers(void) |
1531 { | 1530 { |
1532 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) { | 1531 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) { |
1533 _this->GL_SwapBuffers (_this); | 1532 _this->GL_SwapBuffers(_this); |
1534 } else { | 1533 } else { |
1535 SDL_SetError ("OpenGL video mode has not been set"); | 1534 SDL_SetError("OpenGL video mode has not been set"); |
1536 } | 1535 } |
1537 } | 1536 } |
1538 | 1537 |
1539 #if 0 // FIXME | 1538 #if 0 // FIXME |
1540 /* Utility function used by SDL_WM_SetIcon(); | 1539 /* Utility function used by SDL_WM_SetIcon(); |
1541 * flags & 1 for color key, flags & 2 for alpha channel. */ | 1540 * flags & 1 for color key, flags & 2 for alpha channel. */ |
1542 static void | 1541 static void |
1543 CreateMaskFromColorKeyOrAlpha (SDL_Surface * icon, Uint8 * mask, int flags) | 1542 CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags) |
1544 { | 1543 { |
1545 int x, y; | 1544 int x, y; |
1546 Uint32 colorkey; | 1545 Uint32 colorkey; |
1547 #define SET_MASKBIT(icon, x, y, mask) \ | 1546 #define SET_MASKBIT(icon, x, y, mask) \ |
1548 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) | 1547 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) |
1554 Uint8 *pixels; | 1553 Uint8 *pixels; |
1555 for (y = 0; y < icon->h; ++y) { | 1554 for (y = 0; y < icon->h; ++y) { |
1556 pixels = (Uint8 *) icon->pixels + y * icon->pitch; | 1555 pixels = (Uint8 *) icon->pixels + y * icon->pitch; |
1557 for (x = 0; x < icon->w; ++x) { | 1556 for (x = 0; x < icon->w; ++x) { |
1558 if (*pixels++ == colorkey) { | 1557 if (*pixels++ == colorkey) { |
1559 SET_MASKBIT (icon, x, y, mask); | 1558 SET_MASKBIT(icon, x, y, mask); |
1560 } | 1559 } |
1561 } | 1560 } |
1562 } | 1561 } |
1563 } | 1562 } |
1564 break; | 1563 break; |
1568 Uint16 *pixels; | 1567 Uint16 *pixels; |
1569 for (y = 0; y < icon->h; ++y) { | 1568 for (y = 0; y < icon->h; ++y) { |
1570 pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2; | 1569 pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2; |
1571 for (x = 0; x < icon->w; ++x) { | 1570 for (x = 0; x < icon->w; ++x) { |
1572 if ((flags & 1) && *pixels == colorkey) { | 1571 if ((flags & 1) && *pixels == colorkey) { |
1573 SET_MASKBIT (icon, x, y, mask); | 1572 SET_MASKBIT(icon, x, y, mask); |
1574 } else if ((flags & 2) | 1573 } else if ((flags & 2) |
1575 && (*pixels & icon->format->Amask) == 0) { | 1574 && (*pixels & icon->format->Amask) == 0) { |
1576 SET_MASKBIT (icon, x, y, mask); | 1575 SET_MASKBIT(icon, x, y, mask); |
1577 } | 1576 } |
1578 pixels++; | 1577 pixels++; |
1579 } | 1578 } |
1580 } | 1579 } |
1581 } | 1580 } |
1586 Uint32 *pixels; | 1585 Uint32 *pixels; |
1587 for (y = 0; y < icon->h; ++y) { | 1586 for (y = 0; y < icon->h; ++y) { |
1588 pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4; | 1587 pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4; |
1589 for (x = 0; x < icon->w; ++x) { | 1588 for (x = 0; x < icon->w; ++x) { |
1590 if ((flags & 1) && *pixels == colorkey) { | 1589 if ((flags & 1) && *pixels == colorkey) { |
1591 SET_MASKBIT (icon, x, y, mask); | 1590 SET_MASKBIT(icon, x, y, mask); |
1592 } else if ((flags & 2) | 1591 } else if ((flags & 2) |
1593 && (*pixels & icon->format->Amask) == 0) { | 1592 && (*pixels & icon->format->Amask) == 0) { |
1594 SET_MASKBIT (icon, x, y, mask); | 1593 SET_MASKBIT(icon, x, y, mask); |
1595 } | 1594 } |
1596 pixels++; | 1595 pixels++; |
1597 } | 1596 } |
1598 } | 1597 } |
1599 } | 1598 } |
1603 | 1602 |
1604 /* | 1603 /* |
1605 * Sets the window manager icon for the display window. | 1604 * Sets the window manager icon for the display window. |
1606 */ | 1605 */ |
1607 void | 1606 void |
1608 SDL_WM_SetIcon (SDL_Surface * icon, Uint8 * mask) | 1607 SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) |
1609 { | 1608 { |
1610 if (icon && _this->SetIcon) { | 1609 if (icon && _this->SetIcon) { |
1611 /* Generate a mask if necessary, and create the icon! */ | 1610 /* Generate a mask if necessary, and create the icon! */ |
1612 if (mask == NULL) { | 1611 if (mask == NULL) { |
1613 int mask_len = icon->h * (icon->w + 7) / 8; | 1612 int mask_len = icon->h * (icon->w + 7) / 8; |
1614 int flags = 0; | 1613 int flags = 0; |
1615 mask = (Uint8 *) SDL_malloc (mask_len); | 1614 mask = (Uint8 *) SDL_malloc(mask_len); |
1616 if (mask == NULL) { | 1615 if (mask == NULL) { |
1617 return; | 1616 return; |
1618 } | 1617 } |
1619 SDL_memset (mask, ~0, mask_len); | 1618 SDL_memset(mask, ~0, mask_len); |
1620 if (icon->flags & SDL_SRCCOLORKEY) | 1619 if (icon->flags & SDL_SRCCOLORKEY) |
1621 flags |= 1; | 1620 flags |= 1; |
1622 if (icon->flags & SDL_SRCALPHA) | 1621 if (icon->flags & SDL_SRCALPHA) |
1623 flags |= 2; | 1622 flags |= 2; |
1624 if (flags) { | 1623 if (flags) { |
1625 CreateMaskFromColorKeyOrAlpha (icon, mask, flags); | 1624 CreateMaskFromColorKeyOrAlpha(icon, mask, flags); |
1626 } | 1625 } |
1627 _this->SetIcon (_this, icon, mask); | 1626 _this->SetIcon(_this, icon, mask); |
1628 SDL_free (mask); | 1627 SDL_free(mask); |
1629 } else { | 1628 } else { |
1630 _this->SetIcon (_this, icon, mask); | 1629 _this->SetIcon(_this, icon, mask); |
1631 } | 1630 } |
1632 } | 1631 } |
1633 } | 1632 } |
1634 #endif | 1633 #endif |
1635 | 1634 |
1636 SDL_bool | 1635 SDL_bool |
1637 SDL_GetWindowWMInfo (SDL_WindowID windowID, SDL_SysWMinfo * info) | 1636 SDL_GetWindowWMInfo(SDL_WindowID windowID, SDL_SysWMinfo * info) |
1638 { | 1637 { |
1639 SDL_Window *window = SDL_GetWindowFromID (windowID); | 1638 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1640 | 1639 |
1641 if (!window || !_this->GetWindowWMInfo) { | 1640 if (!window || !_this->GetWindowWMInfo) { |
1642 return SDL_FALSE; | 1641 return SDL_FALSE; |
1643 } | 1642 } |
1644 return (_this->GetWindowWMInfo (_this, window, info)); | 1643 return (_this->GetWindowWMInfo(_this, window, info)); |
1645 } | 1644 } |
1646 | 1645 |
1647 /* vi: set ts=4 sw=4 expandtab: */ | 1646 /* vi: set ts=4 sw=4 expandtab: */ |