1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 09:22:42 +01:00

Change: Determine automatic interface scale by window size. (#14627)

Replace OS-dependent interface scaling with scaling dependent on the window size.

This works on all platforms and should provide a more comfortable experience for new players. Manual interface scale setting works as before.
This commit is contained in:
Peter Nelson
2025-09-18 18:52:14 +01:00
committed by GitHub
parent 2d13bcb7b9
commit 17fbe0b911
7 changed files with 24 additions and 68 deletions

View File

@@ -417,10 +417,11 @@ struct GameOptionsWindow : Window {
GameSettings *opt = nullptr;
bool reload = false;
bool gui_scale_changed = false;
int gui_scale = 0;
static inline WidgetID active_tab = WID_GO_TAB_GENERAL;
GameOptionsWindow(WindowDesc &desc) : Window(desc), filter_editbox(50), gui_scale(_gui_scale)
GameOptionsWindow(WindowDesc &desc) : Window(desc), filter_editbox(50)
{
this->opt = &GetGameSettings();
@@ -453,6 +454,7 @@ struct GameOptionsWindow : Window {
void OnInit() override
{
_setting_circle_size = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
this->gui_scale = _gui_scale;
}
void Close([[maybe_unused]] int data = 0) override
@@ -1057,7 +1059,16 @@ struct GameOptionsWindow : Window {
#endif /* HAS_TRUETYPE_FONT */
case WID_GO_GUI_SCALE:
/* Any click on the slider deactivates automatic interface scaling, setting it to the current value before being adjusted. */
if (_gui_scale_cfg == -1) {
_gui_scale_cfg = this->gui_scale;
this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, false);
this->SetWidgetDirty(WID_GO_GUI_SCALE_AUTO);
this->SetWidgetDirty(WID_GO_GUI_SCALE_AUTO_TEXT);
}
if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, _ctrl_pressed ? 0 : SCALE_NMARKS, this->gui_scale)) {
this->gui_scale_changed = true;
this->SetWidgetDirty(widget);
}
@@ -1383,8 +1394,9 @@ struct GameOptionsWindow : Window {
void OnMouseLoop() override
{
if (_left_button_down || this->gui_scale == _gui_scale) return;
if (_left_button_down || !this->gui_scale_changed) return;
this->gui_scale_changed = false;
_gui_scale_cfg = this->gui_scale;
if (AdjustGUIZoom(false)) {