diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 4b37c8e028..aeb2acf8a9 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -6,6 +6,7 @@ - Feature: [#22213] [Plugin] Allow plugins to focus on textboxes in custom windows. - Feature: [#22301] Loading save games or scenarios now indicates loading progress. - Feature: [OpenMusic#54] Added Progressive ride music style (feat. Approaching Nirvana). +- Change: [#21494] Display pixel density is now taken into account for the initial window scale setting. - Change: [#22230] The plugin/script engine is now initialised off the main thread. - Change: [#22251] Hide author info in the scenery window unless debug tools are active. - Change: [#22309] The scenario editor now supports loading landscapes from .sea save files. diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index da6cafde24..1043ac29e0 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -732,6 +732,24 @@ private: LOG_VERBOSE("SDL2 version: %d.%d.%d", version.major, version.minor, version.patch); } + void InferDisplayDPI() + { + auto& config = Config::Get().general; + if (!config.InferDisplayDPI) + return; + + int wWidth, wHeight; + SDL_GetWindowSize(_window, &wWidth, &wHeight); + + auto renderer = SDL_GetRenderer(_window); + int rWidth, rHeight; + if (SDL_GetRendererOutputSize(renderer, &rWidth, &rHeight) == 0) + config.WindowScale = rWidth / wWidth; + + config.InferDisplayDPI = false; + Config::Save(); + } + void CreateWindow(const ScreenCoordsXY& windowPos) { // Get saved window size @@ -763,6 +781,7 @@ private: // Initialise the surface, palette and draw buffer DrawingEngineInit(); + InferDisplayDPI(); OnResize(width, height); UpdateFullscreenResolutions(); diff --git a/src/openrct2/config/Config.cpp b/src/openrct2/config/Config.cpp index 2baa787821..361d7667cd 100644 --- a/src/openrct2/config/Config.cpp +++ b/src/openrct2/config/Config.cpp @@ -213,6 +213,7 @@ namespace OpenRCT2::Config model->DisableLightningEffect = reader->GetBoolean("disable_lightning_effect", false); model->SteamOverlayPause = reader->GetBoolean("steam_overlay_pause", true); model->WindowScale = reader->GetFloat("window_scale", Platform::GetDefaultScale()); + model->InferDisplayDPI = reader->GetBoolean("infer_display_dpi", true); model->ShowFPS = reader->GetBoolean("show_fps", false); #ifdef _DEBUG // Always have multi-threading disabled in debug builds, this makes things slower. @@ -303,6 +304,7 @@ namespace OpenRCT2::Config writer->WriteBoolean("disable_lightning_effect", model->DisableLightningEffect); writer->WriteBoolean("steam_overlay_pause", model->SteamOverlayPause); writer->WriteFloat("window_scale", model->WindowScale); + writer->WriteBoolean("infer_display_dpi", model->InferDisplayDPI); writer->WriteBoolean("show_fps", model->ShowFPS); writer->WriteBoolean("multithreading", model->MultiThreading); writer->WriteBoolean("trap_cursor", model->TrapCursor); diff --git a/src/openrct2/config/Config.h b/src/openrct2/config/Config.h index ba62b4201a..873422e9bf 100644 --- a/src/openrct2/config/Config.h +++ b/src/openrct2/config/Config.h @@ -36,6 +36,7 @@ namespace OpenRCT2::Config int32_t FullscreenWidth; int32_t FullscreenHeight; float WindowScale; + bool InferDisplayDPI; ::DrawingEngine DrawingEngine; bool UncapFPS; bool UseVSync;