1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-24 00:03:11 +01:00

Automatically set window scaling based on display pixel density (#21907)

Co-authored-by: Aaron van Geffen <aaron@aaronweb.net>
This commit is contained in:
Karsten Van Fossan
2024-07-21 16:10:32 -04:00
committed by GitHub
parent d156c6e1ef
commit 0c318a416e
4 changed files with 23 additions and 0 deletions

View File

@@ -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.

View File

@@ -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();

View File

@@ -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);

View File

@@ -36,6 +36,7 @@ namespace OpenRCT2::Config
int32_t FullscreenWidth;
int32_t FullscreenHeight;
float WindowScale;
bool InferDisplayDPI;
::DrawingEngine DrawingEngine;
bool UncapFPS;
bool UseVSync;