diff --git a/src/game.cpp b/src/game.cpp index 3be49218..beccec42 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -481,7 +481,7 @@ bool Game::InitGUI() settings.Get(optionmap); gui.SetOptions(optionmap); - // Set driver/edit num to update gui explicitely + // Set driver/edit num to update gui explicitly // as they are not stored in settings gui.SetOptionValue("game.car_edit", "0"); gui.SetOptionValue("game.driver", ""); @@ -2089,9 +2089,9 @@ static void PopulateTrackSet( template struct SortPairBySecond { - bool operator()(const std::pair & first, const std::pair & second) + bool operator()(const std::pair & a, const std::pair & b) { - return first.second < second.second; + return a.second < b.second; } }; @@ -2306,6 +2306,36 @@ void Game::PopulateAntialiasList(GuiOption::List & antialiaslist) } } +void Game::PopulateResolutionList(GuiOption::List & resolutionlist) +{ + resolutionlist.clear(); + int w = 0, h = 0; + int n = window.GetNumSupportedResolutions(error_output); + std::vector res(n); + for (int i = 0; i < n; i++) + { + window.GetSupportedResolution(i, w, h, error_output); + assert(w <= 0xFFFF && h <= 0xFFFF); + res[i] = (w << 16) | h; + } + std::sort(res.begin(), res.end()); + int wp = 0, hp = 0; + for (int i = 0; i < n; i++) + { + w = res[i] >> 16; + h = res[i] & 0xFFFF; + if (w != wp || h != hp) + { + std::ostringstream ds, vs; + ds << w << " X " << h; + vs << w << ',' << h; + resolutionlist.push_back(std::make_pair(vs.str(), ds.str())); + wp = w; + hp = h; + } + } +} + void Game::PopulateValueLists(std::map & valuelists) { PopulateTrackList(valuelists["tracks"]); @@ -2334,6 +2364,8 @@ void Game::PopulateValueLists(std::map & valuelist PopulateAntialiasList(valuelists["antialiasing"]); + PopulateResolutionList(valuelists["resolution"]); + // PopulateJoystickList valuelists["joy_indices"].push_back(std::make_pair("0", "0")); } diff --git a/src/game.h b/src/game.h index ca9a5002..6513b244 100644 --- a/src/game.h +++ b/src/game.h @@ -180,6 +180,8 @@ friend class GameDownloader; void PopulateAntialiasList(GuiOption::List & antialiaslist); + void PopulateResolutionList(GuiOption::List & resolutionlist); + void UpdateTrackMap(); void ShowLoadingScreen(float progress, float progress_max, const std::string & optional_text); diff --git a/src/window.cpp b/src/window.cpp index 677ff7d9..48dbe393 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -169,6 +169,30 @@ static int GetVideoDisplay() return 0; } +int Window::GetNumSupportedResolutions(std::ostream & error_output) +{ + int display = GetVideoDisplay(); + int i = SDL_GetNumDisplayModes(display); + if (i < 0) { + error_output << SDL_GetError() << std::endl; + return 0; + } + return i; +} + +void Window::GetSupportedResolution(int i, int & w, int & h, std::ostream & error_output) +{ + SDL_DisplayMode mode; + int display = GetVideoDisplay(); + int err = SDL_GetDisplayMode(display, i, &mode); + if (err) { + error_output << SDL_GetError() << std::endl; + return; + } + w = mode.w; + h = mode.h; +} + bool Window::ResizeWindow(int width, int height) { // We can't resize something we don't have. diff --git a/src/window.h b/src/window.h index 6216e2ce..ed7462a2 100644 --- a/src/window.h +++ b/src/window.h @@ -56,6 +56,10 @@ class Window int GetH() const; + int GetNumSupportedResolutions(std::ostream & error_output); + + void GetSupportedResolution(int i, int & w, int & h, std::ostream & error_output); + private: SDL_Window * window; void * glcontext;