Small fixup/cleanup to the handling of window flags

* Merged the resolution keys into one pair
* Don't flag maximized off when switching to fullscreen. This fixes a case where
  toggling back from fullscreen on a maximized window wouldn't return to maximized
* Fixed a typo in the maximized getter
This commit is contained in:
Charles Dang 2016-03-05 01:58:04 +11:00
parent dc8e937164
commit becdecd0f5

View File

@ -106,9 +106,9 @@ base_manager::~base_manager()
} }
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
/* /*
* Hook for setting window state variables on window resize and maximize * Hook for setting window state variables on window resize and maximize
* events. Since there is no fullscreen window event, that setter is called * events. Since there is no fullscreen window event, that setter is called
* from the CVideo function instead. * from the CVideo function instead.
*/ */
void prefs_event_handler::handle_window_event(const SDL_Event& event) void prefs_event_handler::handle_window_event(const SDL_Event& event)
@ -129,7 +129,7 @@ void prefs_event_handler::handle_window_event(const SDL_Event& event)
break; break;
case SDL_WINDOWEVENT_RESTORED: case SDL_WINDOWEVENT_RESTORED:
_set_maximized(false); _set_maximized(fullscreen() || false);
break; break;
} }
@ -362,8 +362,7 @@ int min_allowed_height()
std::pair<int,int> resolution() std::pair<int,int> resolution()
{ {
const std::string postfix = fullscreen() ? "resolution" : "windowsize"; const std::string& x = prefs["xresolution"], y = prefs["yresolution"];
std::string x = prefs['x' + postfix], y = prefs['y' + postfix];
if (!x.empty() && !y.empty()) { if (!x.empty() && !y.empty()) {
return std::make_pair( return std::make_pair(
@ -376,7 +375,7 @@ std::pair<int,int> resolution()
bool maximized() bool maximized()
{ {
return get("maximized", (fullscreen() & true)); return get("maximized", !fullscreen());
} }
bool fullscreen() bool fullscreen()
@ -386,9 +385,8 @@ bool fullscreen()
void _set_resolution(const std::pair<int, int>& res) void _set_resolution(const std::pair<int, int>& res)
{ {
const std::string postfix = fullscreen() ? "resolution" : "windowsize"; preferences::set("xresolution", lexical_cast<std::string>(res.first));
preferences::set('x' + postfix, lexical_cast<std::string>(res.first)); preferences::set("yresolution", lexical_cast<std::string>(res.second));
preferences::set('y' + postfix, lexical_cast<std::string>(res.second));
} }
void _set_maximized(bool ison) void _set_maximized(bool ison)
@ -424,7 +422,7 @@ void save_turbo_speed(const double speed)
{ {
prefs["turbo_speed"] = speed; prefs["turbo_speed"] = speed;
} }
int font_scaling() int font_scaling()
{ {
// Clip at 50 because if it's too low it'll cause crashes // Clip at 50 because if it's too low it'll cause crashes