Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 1667:1fddae038bc8 SDL-1.3
Implemented many compatibility functions
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 03:53:21 +0000 |
parents | 6e7ec5cb83c3 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1666:6e7ec5cb83c3 | 1667:1fddae038bc8 |
---|---|
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_DisplayMode display_mode; | 516 SDL_DisplayMode display_mode; |
517 int i; | |
516 | 518 |
517 if (!_this) { | 519 if (!_this) { |
518 SDL_SetError ("Video subsystem has not been initialized"); | 520 SDL_SetError ("Video subsystem has not been initialized"); |
519 return -1; | 521 return -1; |
520 } | 522 } |
522 /* Make sure there's an actual display mode to set */ | 524 /* Make sure there's an actual display mode to set */ |
523 if (!mode) { | 525 if (!mode) { |
524 SDL_SetError ("No mode passed to SDL_SetDisplayMode"); | 526 SDL_SetError ("No mode passed to SDL_SetDisplayMode"); |
525 return -1; | 527 return -1; |
526 } | 528 } |
529 display = &SDL_CurrentDisplay; | |
527 display_mode = *mode; | 530 display_mode = *mode; |
528 | 531 |
529 /* Default to the current mode */ | 532 /* Default to the current mode */ |
530 if (!display_mode.format) { | 533 if (!display_mode.format) { |
531 display_mode.format = SDL_CurrentDisplay.current_mode.format; | 534 display_mode.format = display->current_mode.format; |
532 } | 535 } |
533 if (!display_mode.w) { | 536 if (!display_mode.w) { |
534 display_mode.w = SDL_CurrentDisplay.current_mode.w; | 537 display_mode.w = display->current_mode.w; |
535 } | 538 } |
536 if (!display_mode.h) { | 539 if (!display_mode.h) { |
537 display_mode.h = SDL_CurrentDisplay.current_mode.h; | 540 display_mode.h = display->current_mode.h; |
538 } | 541 } |
539 if (!display_mode.refresh_rate) { | 542 if (!display_mode.refresh_rate) { |
540 display_mode.refresh_rate = | 543 display_mode.refresh_rate = display->current_mode.refresh_rate; |
541 SDL_CurrentDisplay.current_mode.refresh_rate; | |
542 } | 544 } |
543 | 545 |
544 /* Get a good video mode, the closest one possible */ | 546 /* Get a good video mode, the closest one possible */ |
545 if (!SDL_GetClosestDisplayMode (&display_mode, &display_mode)) { | 547 if (!SDL_GetClosestDisplayMode (&display_mode, &display_mode)) { |
546 SDL_SetError ("No video mode large enough for %dx%d", | 548 SDL_SetError ("No video mode large enough for %dx%d", |
551 /* See if there's anything left to do */ | 553 /* See if there's anything left to do */ |
552 if (SDL_memcmp | 554 if (SDL_memcmp |
553 (&display_mode, SDL_GetCurrentDisplayMode (), | 555 (&display_mode, SDL_GetCurrentDisplayMode (), |
554 sizeof (display_mode)) == 0) { | 556 sizeof (display_mode)) == 0) { |
555 return 0; | 557 return 0; |
558 } | |
559 | |
560 /* Free any previous window surfaces */ | |
561 for (i = 0; i < display->num_windows; ++i) { | |
562 SDL_Window *window = &display->windows[i]; | |
563 if (window->shadow) { | |
564 SDL_FreeSurface (window->shadow); | |
565 window->shadow = NULL; | |
566 } | |
567 if (window->surface) { | |
568 SDL_FreeSurface (window->surface); | |
569 window->surface = NULL; | |
570 } | |
556 } | 571 } |
557 | 572 |
558 return _this->SetDisplayMode (_this, &display_mode); | 573 return _this->SetDisplayMode (_this, &display_mode); |
559 } | 574 } |
560 | 575 |
578 return 0; | 593 return 0; |
579 } | 594 } |
580 | 595 |
581 SDL_zero (window); | 596 SDL_zero (window); |
582 window.id = _this->next_window_id++; | 597 window.id = _this->next_window_id++; |
583 window.title = SDL_strdup (title); | 598 window.title = title ? SDL_strdup (title) : NULL; |
584 window.x = x; | 599 window.x = x; |
585 window.y = y; | 600 window.y = y; |
586 window.w = w; | 601 window.w = w; |
587 window.h = h; | 602 window.h = h; |
588 window.flags = (flags & allowed_flags); | 603 window.flags = (flags & allowed_flags); |
589 | 604 |
590 if (_this->CreateWindow && _this->CreateWindow (_this, &window) < 0) { | 605 if (_this->CreateWindow && _this->CreateWindow (_this, &window) < 0) { |
591 SDL_free (window.title); | 606 if (window.title) { |
607 SDL_free (window.title); | |
608 } | |
592 return 0; | 609 return 0; |
593 } | 610 } |
594 | 611 |
595 num_windows = SDL_CurrentDisplay.num_windows; | 612 num_windows = SDL_CurrentDisplay.num_windows; |
596 windows = | 613 windows = |
598 (num_windows + 1) * sizeof (*windows)); | 615 (num_windows + 1) * sizeof (*windows)); |
599 if (!windows) { | 616 if (!windows) { |
600 if (_this->DestroyWindow) { | 617 if (_this->DestroyWindow) { |
601 _this->DestroyWindow (_this, &window); | 618 _this->DestroyWindow (_this, &window); |
602 } | 619 } |
603 SDL_free (window.title); | 620 if (window.title) { |
621 SDL_free (window.title); | |
622 } | |
604 return 0; | 623 return 0; |
605 } | 624 } |
606 windows[num_windows] = window; | 625 windows[num_windows] = window; |
607 SDL_CurrentDisplay.windows = windows; | 626 SDL_CurrentDisplay.windows = windows; |
608 SDL_CurrentDisplay.num_windows++; | 627 SDL_CurrentDisplay.num_windows++; |
636 (num_windows + 1) * sizeof (*windows)); | 655 (num_windows + 1) * sizeof (*windows)); |
637 if (!windows) { | 656 if (!windows) { |
638 if (_this->DestroyWindow) { | 657 if (_this->DestroyWindow) { |
639 _this->DestroyWindow (_this, &window); | 658 _this->DestroyWindow (_this, &window); |
640 } | 659 } |
641 SDL_free (window.title); | 660 if (window.title) { |
661 SDL_free (window.title); | |
662 } | |
642 return 0; | 663 return 0; |
643 } | 664 } |
644 windows[num_windows] = window; | 665 windows[num_windows] = window; |
645 SDL_CurrentDisplay.windows = windows; | 666 SDL_CurrentDisplay.windows = windows; |
646 SDL_CurrentDisplay.num_windows++; | 667 SDL_CurrentDisplay.num_windows++; |
672 SDL_Window * | 693 SDL_Window * |
673 SDL_GetWindowFromSurface (SDL_Surface * surface) | 694 SDL_GetWindowFromSurface (SDL_Surface * surface) |
674 { | 695 { |
675 int i, j; | 696 int i, j; |
676 | 697 |
677 if (!_this) { | 698 if (!_this || !surface) { |
678 return NULL; | 699 return NULL; |
679 } | 700 } |
680 | 701 |
681 for (i = 0; i < _this->num_displays; ++i) { | 702 for (i = 0; i < _this->num_displays; ++i) { |
682 SDL_VideoDisplay *display = &_this->displays[i]; | 703 SDL_VideoDisplay *display = &_this->displays[i]; |