Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 1956:ba0d62354872
Simplified driver window creation code.
Implemented several Cocoa window functions
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 29 Jul 2006 21:51:00 +0000 |
parents | 420716272158 |
children | 2590b68531ef |
comparison
equal
deleted
inserted
replaced
1955:8c6106e45fc1 | 1956:ba0d62354872 |
---|---|
612 | 612 |
613 /* Move any fullscreen windows into position */ | 613 /* Move any fullscreen windows into position */ |
614 for (i = 0; i < display->num_windows; ++i) { | 614 for (i = 0; i < display->num_windows; ++i) { |
615 SDL_Window *window = &display->windows[i]; | 615 SDL_Window *window = &display->windows[i]; |
616 if (FULLSCREEN_VISIBLE(window)) { | 616 if (FULLSCREEN_VISIBLE(window)) { |
617 SDL_SetWindowPosition(window->id, | 617 SDL_SetWindowPosition(window->id, SDL_WINDOWPOS_CENTERED, |
618 ((display_mode.w - window->w) / 2), | 618 SDL_WINDOWPOS_CENTERED); |
619 ((display_mode.h - window->h) / 2)); | |
620 } | 619 } |
621 } | 620 } |
622 | 621 |
623 return 0; | 622 return 0; |
624 } | 623 } |
716 SDL_WindowID | 715 SDL_WindowID |
717 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) | 716 SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) |
718 { | 717 { |
719 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | | 718 const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | |
720 SDL_WINDOW_OPENGL | | 719 SDL_WINDOW_OPENGL | |
721 SDL_WINDOW_SHOWN | | |
722 SDL_WINDOW_BORDERLESS | | 720 SDL_WINDOW_BORDERLESS | |
723 SDL_WINDOW_RESIZABLE | | 721 SDL_WINDOW_RESIZABLE); |
724 SDL_WINDOW_MAXIMIZED | | |
725 SDL_WINDOW_MINIMIZED | | |
726 SDL_WINDOW_INPUT_GRABBED); | |
727 SDL_VideoDisplay *display; | 722 SDL_VideoDisplay *display; |
728 SDL_Window window; | 723 SDL_Window window; |
729 int num_windows; | 724 int num_windows; |
730 SDL_Window *windows; | 725 SDL_Window *windows; |
731 | 726 |
737 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { | 732 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { |
738 SDL_SetError("No OpenGL support in video driver"); | 733 SDL_SetError("No OpenGL support in video driver"); |
739 return 0; | 734 return 0; |
740 } | 735 } |
741 | 736 |
737 /* Fullscreen windows don't have any window decorations */ | |
738 if (flags & SDL_WINDOW_FULLSCREEN) { | |
739 flags |= SDL_WINDOW_BORDERLESS; | |
740 flags &= ~SDL_WINDOW_RESIZABLE; | |
741 } | |
742 | |
742 SDL_zero(window); | 743 SDL_zero(window); |
743 window.id = _this->next_object_id++; | 744 window.id = _this->next_object_id++; |
744 window.title = title ? SDL_strdup(title) : NULL; | |
745 window.x = x; | 745 window.x = x; |
746 window.y = y; | 746 window.y = y; |
747 window.w = w; | 747 window.w = w; |
748 window.h = h; | 748 window.h = h; |
749 window.flags = (flags & allowed_flags); | 749 window.flags = (flags & allowed_flags); |
750 window.display = _this->current_display; | 750 window.display = _this->current_display; |
751 | 751 |
752 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { | 752 if (_this->CreateWindow && _this->CreateWindow(_this, &window) < 0) { |
753 if (window.title) { | |
754 SDL_free(window.title); | |
755 } | |
756 return 0; | 753 return 0; |
757 } | 754 } |
758 | 755 |
759 display = &SDL_CurrentDisplay; | 756 display = &SDL_CurrentDisplay; |
760 num_windows = display->num_windows; | 757 num_windows = display->num_windows; |
762 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); | 759 SDL_realloc(display->windows, (num_windows + 1) * sizeof(*windows)); |
763 if (!windows) { | 760 if (!windows) { |
764 if (_this->DestroyWindow) { | 761 if (_this->DestroyWindow) { |
765 _this->DestroyWindow(_this, &window); | 762 _this->DestroyWindow(_this, &window); |
766 } | 763 } |
767 if (window.title) { | |
768 SDL_free(window.title); | |
769 } | |
770 return 0; | 764 return 0; |
771 } | 765 } |
772 windows[num_windows] = window; | 766 windows[num_windows] = window; |
773 display->windows = windows; | 767 display->windows = windows; |
774 display->num_windows++; | 768 display->num_windows++; |
775 | 769 |
776 if (FULLSCREEN_VISIBLE(&window)) { | 770 if (title) { |
777 /* Hide any other fullscreen windows */ | 771 SDL_SetWindowTitle(window.id, title); |
778 int i; | 772 } |
779 for (i = 0; i < display->num_windows; ++i) { | 773 if (flags & SDL_WINDOW_MAXIMIZED) { |
780 SDL_Window *other = &display->windows[i]; | 774 SDL_MaximizeWindow(window.id); |
781 if (other->id != window.id && FULLSCREEN_VISIBLE(other)) { | 775 } |
782 SDL_MinimizeWindow(other->id); | 776 if (flags & SDL_WINDOW_MINIMIZED) { |
783 } | 777 SDL_MinimizeWindow(window.id); |
784 } | 778 } |
785 SDL_SetDisplayMode(display->fullscreen_mode); | 779 if (flags & SDL_WINDOW_SHOWN) { |
786 } | 780 SDL_ShowWindow(window.id); |
787 | 781 } |
782 if (flags & SDL_WINDOW_INPUT_GRABBED) { | |
783 SDL_SetWindowGrab(window.id, 1); | |
784 } | |
788 return window.id; | 785 return window.id; |
789 } | 786 } |
790 | 787 |
791 SDL_WindowID | 788 SDL_WindowID |
792 SDL_CreateWindowFrom(const void *data) | 789 SDL_CreateWindowFrom(const void *data) |
831 } | 828 } |
832 | 829 |
833 int | 830 int |
834 SDL_RecreateWindow(SDL_Window * window, Uint32 flags) | 831 SDL_RecreateWindow(SDL_Window * window, Uint32 flags) |
835 { | 832 { |
833 char *title = window->title; | |
834 | |
836 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { | 835 if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { |
837 SDL_SetError("No OpenGL support in video driver"); | 836 SDL_SetError("No OpenGL support in video driver"); |
838 return -1; | 837 return -1; |
839 } | 838 } |
839 | |
840 if (_this->DestroyWindow) { | 840 if (_this->DestroyWindow) { |
841 _this->DestroyWindow(_this, window); | 841 _this->DestroyWindow(_this, window); |
842 } | 842 } |
843 window->flags = flags; | 843 |
844 return _this->CreateWindow(_this, window); | 844 window->title = NULL; |
845 window->flags = | |
846 (flags & | |
847 ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED | SDL_WINDOW_SHOWN | | |
848 SDL_WINDOW_INPUT_GRABBED)); | |
849 | |
850 if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) { | |
851 return -1; | |
852 } | |
853 | |
854 if (title) { | |
855 SDL_SetWindowTitle(window->id, title); | |
856 SDL_free(title); | |
857 } | |
858 if (flags & SDL_WINDOW_MAXIMIZED) { | |
859 SDL_MaximizeWindow(window->id); | |
860 } | |
861 if (flags & SDL_WINDOW_MINIMIZED) { | |
862 SDL_MinimizeWindow(window->id); | |
863 } | |
864 if (flags & SDL_WINDOW_SHOWN) { | |
865 SDL_ShowWindow(window->id); | |
866 } | |
867 if (flags & SDL_WINDOW_INPUT_GRABBED) { | |
868 SDL_SetWindowGrab(window->id, 1); | |
869 } | |
870 return 0; | |
845 } | 871 } |
846 | 872 |
847 SDL_Window * | 873 SDL_Window * |
848 SDL_GetWindowFromID(SDL_WindowID windowID) | 874 SDL_GetWindowFromID(SDL_WindowID windowID) |
849 { | 875 { |
871 { | 897 { |
872 if (!_this) { | 898 if (!_this) { |
873 SDL_UninitializedVideo(); | 899 SDL_UninitializedVideo(); |
874 return NULL; | 900 return NULL; |
875 } | 901 } |
902 if (!window) { | |
903 return NULL; | |
904 } | |
876 return &_this->displays[window->display]; | 905 return &_this->displays[window->display]; |
877 } | 906 } |
878 | 907 |
879 Uint32 | 908 Uint32 |
880 SDL_GetWindowFlags(SDL_WindowID windowID) | 909 SDL_GetWindowFlags(SDL_WindowID windowID) |
889 | 918 |
890 void | 919 void |
891 SDL_SetWindowTitle(SDL_WindowID windowID, const char *title) | 920 SDL_SetWindowTitle(SDL_WindowID windowID, const char *title) |
892 { | 921 { |
893 SDL_Window *window = SDL_GetWindowFromID(windowID); | 922 SDL_Window *window = SDL_GetWindowFromID(windowID); |
894 | 923 const char *last_title; |
895 if (!window) { | 924 |
896 return; | 925 if (!window || title == window->title) { |
897 } | 926 return; |
927 } | |
928 | |
898 if (window->title) { | 929 if (window->title) { |
899 SDL_free(window->title); | 930 SDL_free(window->title); |
900 } | 931 } |
901 window->title = SDL_strdup(title); | 932 if (title) { |
933 window->title = SDL_strdup(title); | |
934 } else { | |
935 window->title = NULL; | |
936 } | |
902 | 937 |
903 if (_this->SetWindowTitle) { | 938 if (_this->SetWindowTitle) { |
904 _this->SetWindowTitle(_this, window); | 939 _this->SetWindowTitle(_this, window); |
905 } | 940 } |
906 } | 941 } |
940 | 975 |
941 void | 976 void |
942 SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y) | 977 SDL_SetWindowPosition(SDL_WindowID windowID, int x, int y) |
943 { | 978 { |
944 SDL_Window *window = SDL_GetWindowFromID(windowID); | 979 SDL_Window *window = SDL_GetWindowFromID(windowID); |
980 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | |
945 | 981 |
946 if (!window) { | 982 if (!window) { |
947 return; | 983 return; |
948 } | 984 } |
949 | 985 |
950 if (x != SDL_WINDOWPOS_UNDEFINED) { | 986 if (x == SDL_WINDOWPOS_CENTERED) { |
987 window->x = (display->current_mode.w - window->w) / 2; | |
988 } else if (x != SDL_WINDOWPOS_UNDEFINED) { | |
951 window->x = x; | 989 window->x = x; |
952 } | 990 } |
953 if (y != SDL_WINDOWPOS_UNDEFINED) { | 991 if (y == SDL_WINDOWPOS_CENTERED) { |
992 window->y = (display->current_mode.h - window->h) / 2; | |
993 } else if (y != SDL_WINDOWPOS_UNDEFINED) { | |
954 window->y = y; | 994 window->y = y; |
955 } | 995 } |
956 | 996 |
957 if (_this->SetWindowPosition) { | 997 if (_this->SetWindowPosition) { |
958 _this->SetWindowPosition(_this, window); | 998 _this->SetWindowPosition(_this, window); |
1043 void | 1083 void |
1044 SDL_RaiseWindow(SDL_WindowID windowID) | 1084 SDL_RaiseWindow(SDL_WindowID windowID) |
1045 { | 1085 { |
1046 SDL_Window *window = SDL_GetWindowFromID(windowID); | 1086 SDL_Window *window = SDL_GetWindowFromID(windowID); |
1047 | 1087 |
1048 if (!window) { | 1088 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { |
1049 return; | 1089 return; |
1050 } | 1090 } |
1051 | 1091 |
1052 if (_this->RaiseWindow) { | 1092 if (_this->RaiseWindow) { |
1053 _this->RaiseWindow(_this, window); | 1093 _this->RaiseWindow(_this, window); |