Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #21494: Automatically set window scaling based on DPI #21907

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/openrct2-ui/UiContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <openrct2-ui/interface/Window.h>
#include <openrct2/Context.h>
#include <openrct2/Input.h>
#include <openrct2/PlatformEnvironment.h>
#include <openrct2/Version.h>
#include <openrct2/audio/AudioContext.h>
#include <openrct2/audio/AudioMixer.h>
Expand Down Expand Up @@ -119,6 +120,20 @@ class UiContext final : public IUiContext
{
SDLException::Throw("SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK)");
}
if (gConfigGeneral.RefreshDPIScaling)
{
float ddpi, hdpi, vdpi;
if (!SDL_GetDisplayDPI(0, &ddpi, &hdpi, &vdpi))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!SDL_GetDisplayDPI(0, &ddpi, &hdpi, &vdpi))
if (SDL_GetDisplayDPI(0, &ddpi, &hdpi, &vdpi) == 0)

! implies a bool.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns an error code, 0 in this case means success.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know. What I was saying is that an explicit check for that code makes it clearer it is a code and not a bool.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I thought the suggestion is the actual diff, my bad.

{
// If DPI can be read, divide DPI by regular DPI (96.0f) and round to nearest 0.25
gConfigGeneral.WindowScale = std::round(ddpi / 96.0f * 4.0) / 4.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gConfigGeneral.WindowScale = std::round(ddpi / 96.0f * 4.0) / 4.0;
constexpr auto regularDPI = 96.0f;
gConfigGeneral.WindowScale = std::round((ddpi / regularDPI) * 4.0) / 4.0;

That also makes the comment redundant. (The general rule is to try and make the code speak, if that is not feasible, a comment is fine)


LOG_VERBOSE("Changing DPI scaling to %f\n", gConfigGeneral.WindowScale);
}
gConfigGeneral.RefreshDPIScaling = false;
auto configPath = env->GetFilePath(PATHID::CONFIG);
ConfigSave(configPath.c_str());
}
_cursorRepository.LoadCursors();
_shortcutManager.LoadUserBindings();
}
Expand Down
2 changes: 2 additions & 0 deletions src/openrct2/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ namespace 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->RefreshDPIScaling = reader->GetBoolean("refresh_dpi_scaling", true);
model->ShowFPS = reader->GetBoolean("show_fps", false);
#ifdef _DEBUG
// Always have multi-threading disabled in debug builds, this makes things slower.
Expand Down Expand Up @@ -290,6 +291,7 @@ namespace Config
writer->WriteBoolean("disable_lightning_effect", model->DisableLightningEffect);
writer->WriteBoolean("steam_overlay_pause", model->SteamOverlayPause);
writer->WriteFloat("window_scale", model->WindowScale);
writer->WriteBoolean("refresh_dpi_scaling", model->RefreshDPIScaling);
writer->WriteBoolean("show_fps", model->ShowFPS);
writer->WriteBoolean("multithreading", model->MultiThreading);
writer->WriteBoolean("trap_cursor", model->TrapCursor);
Expand Down
1 change: 1 addition & 0 deletions src/openrct2/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct GeneralConfiguration
int32_t FullscreenWidth;
int32_t FullscreenHeight;
float WindowScale;
bool RefreshDPIScaling;
::DrawingEngine DrawingEngine;
bool UncapFPS;
bool UseVSync;
Expand Down
Loading