Skip to content

Commit

Permalink
Minor cleanups to some resolution/window size code
Browse files Browse the repository at this point in the history
* Cleaned up preferences::resolution() implementation.
* Don't call the above twice on SDL window init.
* Made a variable name clearer.
  • Loading branch information
Vultraz committed Feb 16, 2018
1 parent a8bc737 commit f773996
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
19 changes: 10 additions & 9 deletions src/preferences/general.cpp
Expand Up @@ -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<unsigned>(x_res, min_window_width),
std::max<unsigned>(y_res, min_window_height)
);
}

bool maximized()
Expand Down
16 changes: 8 additions & 8 deletions src/video.cpp
Expand Up @@ -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;

Expand Down

0 comments on commit f773996

Please sign in to comment.