From f773996a937b976a8c6982da6bafea1dc7bf67c5 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Fri, 16 Feb 2018 18:52:04 +1100 Subject: [PATCH] Minor cleanups to some resolution/window size code * Cleaned up preferences::resolution() implementation. * Don't call the above twice on SDL window init. * Made a variable name clearer. --- src/preferences/general.cpp | 19 ++++++++++--------- src/video.cpp | 16 ++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/preferences/general.cpp b/src/preferences/general.cpp index f6dd6d029ee1..7a12b3c612ef 100644 --- a/src/preferences/general.cpp +++ b/src/preferences/general.cpp @@ -374,17 +374,18 @@ void set_scroll_to_action(bool ison) point resolution() { - const std::string& x = prefs["xresolution"], y = prefs["yresolution"]; - - if (!x.empty() && !y.empty()) { - try { - return point( - std::max(std::stoi(x), min_window_width), - std::max(std::stoi(y), min_window_height)); - } catch(std::invalid_argument&) {} + const unsigned x_res = prefs["xresolution"].to_unsigned(); + const unsigned y_res = prefs["yresolution"].to_unsigned(); + + // Either resolution was unspecified, return default. + if(x_res == 0 || y_res == 0) { + return point(def_window_width, def_window_height); } - return point(def_window_width, def_window_height); + return point( + std::max(x_res, min_window_width), + std::max(y_res, min_window_height) + ); } bool maximized() diff --git a/src/video.cpp b/src/video.cpp index f5ddc828dba1..ad5c2eda1312 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -223,23 +223,23 @@ void CVideo::init_window() const int y = preferences::fullscreen() ? SDL_WINDOWPOS_UNDEFINED : SDL_WINDOWPOS_CENTERED; // Dimensions - const int w = preferences::resolution().x; - const int h = preferences::resolution().y; + const point res = preferences::resolution(); + const int w = res.x; + const int h = res.y; - // Video flags - int video_flags = 0; + uint32_t window_flags = 0; // Add any more default flags here - video_flags |= SDL_WINDOW_RESIZABLE; + window_flags |= SDL_WINDOW_RESIZABLE; if(preferences::fullscreen()) { - video_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; } else if(preferences::maximized()) { - video_flags |= SDL_WINDOW_MAXIMIZED; + window_flags |= SDL_WINDOW_MAXIMIZED; } // Initialize window - window.reset(new sdl::window("", x, y, w, h, video_flags, SDL_RENDERER_SOFTWARE)); + window.reset(new sdl::window("", x, y, w, h, window_flags, SDL_RENDERER_SOFTWARE)); std::cerr << "Setting mode to " << w << "x" << h << std::endl;