MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / UpdateFullscreenResolutions

Function UpdateFullscreenResolutions

src/openrct2-ui/UiContext.cpp:878–926  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

876 }
877
878 void UpdateFullscreenResolutions()
879 {
880 // Query number of display modes
881 int32_t displayIndex = SDL_GetWindowDisplayIndex(_window);
882 int32_t numDisplayModes = SDL_GetNumDisplayModes(displayIndex);
883
884 // Get desktop aspect ratio
885 SDL_DisplayMode mode;
886 SDL_GetDesktopDisplayMode(displayIndex, &mode);
887
888 // Get resolutions
889 auto resolutions = std::vector<Resolution>();
890 float desktopAspectRatio = static_cast<float>(mode.w) / mode.h;
891 for (int32_t i = 0; i < numDisplayModes; i++)
892 {
893 SDL_GetDisplayMode(displayIndex, i, &mode);
894 if (mode.w > 0 && mode.h > 0)
895 {
896 float aspectRatio = static_cast<float>(mode.w) / mode.h;
897 if (std::fabs(desktopAspectRatio - aspectRatio) < 0.1f)
898 {
899 resolutions.push_back({ mode.w, mode.h });
900 }
901 }
902 }
903
904 // Sort by area
905 std::sort(resolutions.begin(), resolutions.end(), [](const Resolution& a, const Resolution& b) -> bool {
906 int32_t areaA = a.Width * a.Height;
907 int32_t areaB = b.Width * b.Height;
908 return areaA < areaB;
909 });
910
911 // Remove duplicates
912 auto last = std::unique(resolutions.begin(), resolutions.end(), [](const Resolution& a, const Resolution& b) -> bool {
913 return (a.Width == b.Width && a.Height == b.Height);
914 });
915 resolutions.erase(last, resolutions.end());
916
917 // Update config fullscreen resolution if not set
918 if (!resolutions.empty()
919 && (Config::Get().general.fullscreenWidth == -1 || Config::Get().general.fullscreenHeight == -1))
920 {
921 Config::Get().general.fullscreenWidth = resolutions.back().Width;
922 Config::Get().general.fullscreenHeight = resolutions.back().Height;
923 }
924
925 _fsResolutions = resolutions;
926 }
927
928 Resolution GetClosestResolution(int32_t inWidth, int32_t inHeight)
929 {

Callers 3

SetFullscreenModeFunction · 0.85
UiContext.cppFile · 0.85
CreateWindowFunction · 0.85

Calls 5

endMethod · 0.65
push_backMethod · 0.45
beginMethod · 0.45
emptyMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected