Skip to content

Commit

Permalink
wzMainScreenSetup: Improve desired window size / display scale sanity…
Browse files Browse the repository at this point in the history
… checking

If the desired window size is below the minimum required size (for the current display scale setting), do not immediately reduce display scale to 100% - attempt to use the maximum display scale for the desired window size (if possible).
  • Loading branch information
past-due committed Apr 11, 2019
1 parent a5813fa commit aedc207
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/sdl/main_sdl.cpp
Expand Up @@ -473,6 +473,7 @@ std::vector<unsigned int> wzAvailableDisplayScales()

void setDisplayScale(unsigned int displayScale)
{
ASSERT(displayScale >= 100, "Invalid display scale: %u", displayScale);
current_displayScale = displayScale;
current_displayScaleFactor = (float)displayScale / 100.f;
}
Expand Down Expand Up @@ -1787,16 +1788,17 @@ bool wzMainScreenSetup(int antialiasing, bool fullscreen, bool vsync, bool highD

if ((windowWidth < minWindowWidth) || (windowHeight < minWindowHeight))
{
// The current window width and/or height is lower than the required minimum for the current display scale.
//
// Reset the display scale to 100%, and recalculate the required minimum window size.
setDisplayScale(100);
war_SetDisplayScale(100); // save the new display scale configuration
// The desired window width and/or height is lower than the required minimum for the current display scale.
// Reduce the display scale to the maximum supported (for the desired window size), and recalculate the required minimum window size.
unsigned int maxDisplayScale = wzGetMaximumDisplayScaleForWindowSize(windowWidth, windowHeight);
maxDisplayScale = std::max(100u, maxDisplayScale); // if wzGetMaximumDisplayScaleForWindowSize fails, it returns < 100
setDisplayScale(maxDisplayScale);
war_SetDisplayScale(maxDisplayScale); // save the new display scale configuration
wzGetMinimumWindowSizeForDisplayScaleFactor(&minWindowWidth, &minWindowHeight);
}

windowWidth = MAX(windowWidth, minWindowWidth);
windowHeight = MAX(windowHeight, minWindowHeight);
windowWidth = std::max(windowWidth, minWindowWidth);
windowHeight = std::max(windowHeight, minWindowHeight);

//// The flags to pass to SDL_CreateWindow
int video_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
Expand Down

0 comments on commit aedc207

Please sign in to comment.