Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 1733:0b1070f2f94d SDL-1.3
Implemented gamma correction on Windows.
Added general code to restore the video mode and gamma when windows lose focus.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 09 Jul 2006 09:02:26 +0000 |
parents | 0ef52d56e8bb |
children | f7c667ded87d |
comparison
equal
deleted
inserted
replaced
1732:fd65f12b6de6 | 1733:0b1070f2f94d |
---|---|
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 */ | |
271 for (i = 0; i < _this->num_displays; ++i) { | |
272 SDL_qsort(_this->displays[i].display_modes, | |
273 _this->displays[i].num_display_modes, | |
274 sizeof(SDL_DisplayMode), cmpmodes); | |
275 } | |
276 | |
277 /* The software renderer is always available */ | 270 /* The software renderer is always available */ |
278 for (i = 0; i < _this->num_displays; ++i) { | 271 for (i = 0; i < _this->num_displays; ++i) { |
279 if (_this->displays[i].num_render_drivers > 0) { | 272 if (_this->displays[i].num_render_drivers > 0) { |
280 SDL_AddRenderDriver(i, &SDL_SW_RenderDriver); | 273 SDL_AddRenderDriver(i, &SDL_SW_RenderDriver); |
281 } | 274 } |
396 | 389 |
397 int | 390 int |
398 SDL_GetNumDisplayModes() | 391 SDL_GetNumDisplayModes() |
399 { | 392 { |
400 if (_this) { | 393 if (_this) { |
401 return SDL_CurrentDisplay.num_display_modes; | 394 SDL_VideoDisplay *display = &SDL_CurrentDisplay; |
395 if (!display->num_display_modes && _this->GetDisplayModes) { | |
396 _this->GetDisplayModes(_this); | |
397 SDL_qsort(display->display_modes, display->num_display_modes, | |
398 sizeof(SDL_DisplayMode), cmpmodes); | |
399 } | |
400 return display->num_display_modes; | |
402 } | 401 } |
403 return 0; | 402 return 0; |
404 } | 403 } |
405 | 404 |
406 const SDL_DisplayMode * | 405 const SDL_DisplayMode * |
458 } else { | 457 } else { |
459 target_refresh_rate = SDL_CurrentDisplay.desktop_mode.refresh_rate; | 458 target_refresh_rate = SDL_CurrentDisplay.desktop_mode.refresh_rate; |
460 } | 459 } |
461 | 460 |
462 match = NULL; | 461 match = NULL; |
463 for (i = 0; i < SDL_CurrentDisplay.num_display_modes; ++i) { | 462 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { |
464 current = &SDL_CurrentDisplay.display_modes[i]; | 463 current = &SDL_CurrentDisplay.display_modes[i]; |
465 | 464 |
466 if ((current->w && current->h) && | 465 if ((current->w && current->h) && |
467 (current->w < mode->w || current->h < mode->h)) { | 466 (current->w < mode->w || current->h < mode->h)) { |
468 /* Out of sorted modes large enough here */ | 467 /* Out of sorted modes large enough here */ |
600 } | 599 } |
601 | 600 |
602 /* Move any fullscreen windows into position */ | 601 /* Move any fullscreen windows into position */ |
603 for (i = 0; i < display->num_windows; ++i) { | 602 for (i = 0; i < display->num_windows; ++i) { |
604 SDL_Window *window = &display->windows[i]; | 603 SDL_Window *window = &display->windows[i]; |
605 if (window->flags & SDL_WINDOW_FULLSCREEN) { | 604 if (FULLSCREEN_VISIBLE(window)) { |
606 SDL_SetWindowPosition(window->id, | 605 SDL_SetWindowPosition(window->id, |
607 ((display_mode.w - window->w) / 2), | 606 ((display_mode.w - window->w) / 2), |
608 ((display_mode.h - window->h) / 2)); | 607 ((display_mode.h - window->h) / 2)); |
609 } | 608 } |
610 } | 609 } |
611 | 610 |
612 return 0; | 611 return 0; |
612 } | |
613 | |
614 int | |
615 SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode) | |
616 { | |
617 SDL_VideoDisplay *display; | |
618 int i; | |
619 | |
620 if (!_this) { | |
621 SDL_SetError("Video subsystem has not been initialized"); | |
622 return -1; | |
623 } | |
624 | |
625 display = &SDL_CurrentDisplay; | |
626 if (mode) { | |
627 SDL_GetClosestDisplayMode(mode, &display->desired_mode); | |
628 display->fullscreen_mode = &display->desired_mode; | |
629 } else { | |
630 display->fullscreen_mode = NULL; | |
631 } | |
632 | |
633 /* Actually set the mode if we have a fullscreen window visible */ | |
634 for (i = 0; i < display->num_windows; ++i) { | |
635 SDL_Window *window = &display->windows[i]; | |
636 if (FULLSCREEN_VISIBLE(window)) { | |
637 return SDL_SetDisplayMode(display->fullscreen_mode); | |
638 } | |
639 } | |
640 return 0; | |
641 } | |
642 | |
643 const SDL_DisplayMode * | |
644 SDL_GetFullscreenDisplayMode(void) | |
645 { | |
646 if (_this) { | |
647 return SDL_CurrentDisplay.fullscreen_mode; | |
648 } | |
649 return NULL; | |
613 } | 650 } |
614 | 651 |
615 int | 652 int |
616 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors) | 653 SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors) |
617 { | 654 { |
937 | 974 |
938 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { | 975 if (!window || (window->flags & SDL_WINDOW_SHOWN)) { |
939 return; | 976 return; |
940 } | 977 } |
941 | 978 |
942 window->flags |= SDL_WINDOW_SHOWN; | 979 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0); |
943 | 980 |
944 if (_this->ShowWindow) { | 981 if (_this->ShowWindow) { |
945 _this->ShowWindow(_this, window); | 982 _this->ShowWindow(_this, window); |
946 } | 983 } |
947 } | 984 } |
953 | 990 |
954 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { | 991 if (!window || !(window->flags & SDL_WINDOW_SHOWN)) { |
955 return; | 992 return; |
956 } | 993 } |
957 | 994 |
958 window->flags &= ~SDL_WINDOW_SHOWN; | 995 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0); |
959 | 996 |
960 if (_this->HideWindow) { | 997 if (_this->HideWindow) { |
961 _this->HideWindow(_this, window); | 998 _this->HideWindow(_this, window); |
962 } | 999 } |
963 } | 1000 } |
983 | 1020 |
984 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { | 1021 if (!window || (window->flags & SDL_WINDOW_MAXIMIZED)) { |
985 return; | 1022 return; |
986 } | 1023 } |
987 | 1024 |
988 window->flags |= SDL_WINDOW_MAXIMIZED; | 1025 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); |
989 | 1026 |
990 if (_this->MaximizeWindow) { | 1027 if (_this->MaximizeWindow) { |
991 _this->MaximizeWindow(_this, window); | 1028 _this->MaximizeWindow(_this, window); |
992 } | 1029 } |
993 } | 1030 } |
999 | 1036 |
1000 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { | 1037 if (!window || (window->flags & SDL_WINDOW_MINIMIZED)) { |
1001 return; | 1038 return; |
1002 } | 1039 } |
1003 | 1040 |
1004 window->flags |= SDL_WINDOW_MINIMIZED; | 1041 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
1005 | 1042 |
1006 if (_this->MinimizeWindow) { | 1043 if (_this->MinimizeWindow) { |
1007 _this->MinimizeWindow(_this, window); | 1044 _this->MinimizeWindow(_this, window); |
1008 } | 1045 } |
1009 } | 1046 } |
1016 if (!window | 1053 if (!window |
1017 || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { | 1054 || (window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { |
1018 return; | 1055 return; |
1019 } | 1056 } |
1020 | 1057 |
1021 window->flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED); | 1058 SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0); |
1022 | 1059 |
1023 if (_this->RestoreWindow) { | 1060 if (_this->RestoreWindow) { |
1024 _this->RestoreWindow(_this, window); | 1061 _this->RestoreWindow(_this, window); |
1025 } | 1062 } |
1026 } | 1063 } |
1053 if (!window) { | 1090 if (!window) { |
1054 return 0; | 1091 return 0; |
1055 } | 1092 } |
1056 | 1093 |
1057 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); | 1094 return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); |
1095 } | |
1096 | |
1097 void | |
1098 SDL_OnWindowShown(SDL_Window * window) | |
1099 { | |
1100 } | |
1101 | |
1102 void | |
1103 SDL_OnWindowHidden(SDL_Window * window) | |
1104 { | |
1105 } | |
1106 | |
1107 void | |
1108 SDL_OnWindowFocusGained(SDL_Window * window) | |
1109 { | |
1110 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | |
1111 | |
1112 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
1113 SDL_SetDisplayMode(display->fullscreen_mode); | |
1114 } | |
1115 if (display->gamma && _this->SetDisplayGammaRamp) { | |
1116 _this->SetDisplayGammaRamp(_this, display->gamma); | |
1117 } | |
1118 } | |
1119 | |
1120 void | |
1121 SDL_OnWindowFocusLost(SDL_Window * window) | |
1122 { | |
1123 SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window); | |
1124 | |
1125 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
1126 SDL_SetDisplayMode(NULL); | |
1127 SDL_MinimizeWindow(window->id); | |
1128 } | |
1129 if (display->gamma && _this->SetDisplayGammaRamp) { | |
1130 _this->SetDisplayGammaRamp(_this, display->saved_gamma); | |
1131 } | |
1058 } | 1132 } |
1059 | 1133 |
1060 void | 1134 void |
1061 SDL_DestroyWindow(SDL_WindowID windowID) | 1135 SDL_DestroyWindow(SDL_WindowID windowID) |
1062 { | 1136 { |
1071 for (j = 0; j < display->num_windows; ++j) { | 1145 for (j = 0; j < display->num_windows; ++j) { |
1072 SDL_Window *window = &display->windows[j]; | 1146 SDL_Window *window = &display->windows[j]; |
1073 if (window->id != windowID) { | 1147 if (window->id != windowID) { |
1074 continue; | 1148 continue; |
1075 } | 1149 } |
1150 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
1151 SDL_SetDisplayMode(NULL); | |
1152 } | |
1153 if (display->gamma && _this->SetDisplayGammaRamp) { | |
1154 _this->SetDisplayGammaRamp(_this, display->saved_gamma); | |
1155 } | |
1076 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { | 1156 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { |
1077 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; | 1157 window->flags &= ~SDL_WINDOW_INPUT_GRABBED; |
1078 _this->SetWindowGrab(_this, window); | 1158 _this->SetWindowGrab(_this, window); |
1079 } | 1159 } |
1080 if (window->renderer) { | 1160 if (window->renderer) { |
1083 if (_this->DestroyWindow) { | 1163 if (_this->DestroyWindow) { |
1084 _this->DestroyWindow(_this, window); | 1164 _this->DestroyWindow(_this, window); |
1085 } | 1165 } |
1086 if (window->title) { | 1166 if (window->title) { |
1087 SDL_free(window->title); | 1167 SDL_free(window->title); |
1088 } | |
1089 if (window->gamma) { | |
1090 SDL_free(window->gamma); | |
1091 } | 1168 } |
1092 if (j != display->num_windows - 1) { | 1169 if (j != display->num_windows - 1) { |
1093 SDL_memcpy(&display->windows[i], | 1170 SDL_memcpy(&display->windows[i], |
1094 &display->windows[i + 1], | 1171 &display->windows[i + 1], |
1095 (display->num_windows - i - 1) * sizeof(*window)); | 1172 (display->num_windows - i - 1) * sizeof(*window)); |
1865 display->desktop_mode.driverdata = NULL; | 1942 display->desktop_mode.driverdata = NULL; |
1866 } | 1943 } |
1867 if (display->palette) { | 1944 if (display->palette) { |
1868 SDL_FreePalette(display->palette); | 1945 SDL_FreePalette(display->palette); |
1869 display->palette = NULL; | 1946 display->palette = NULL; |
1947 } | |
1948 if (display->gamma) { | |
1949 SDL_free(display->gamma); | |
1950 } | |
1951 if (display->driverdata) { | |
1952 SDL_free(display->driverdata); | |
1870 } | 1953 } |
1871 } | 1954 } |
1872 if (_this->displays) { | 1955 if (_this->displays) { |
1873 SDL_free(_this->displays); | 1956 SDL_free(_this->displays); |
1874 _this->displays = NULL; | 1957 _this->displays = NULL; |