diff --git a/src/GlobalSettings.gd b/src/GlobalSettings.gd index 9adebc0d..d0a64df5 100644 --- a/src/GlobalSettings.gd +++ b/src/GlobalSettings.gd @@ -191,9 +191,8 @@ func _enter_tree() -> void: default_input_events[action] = InputMap.action_get_events(action) load_settings() load_user_data() - get_window().wrap_controls = true # Prevents the main window from getting too small. + get_window().dpi_changed.connect(update_ui_scale) update_ui_scale() - get_window().size_changed.connect(update_ui_scale) ThemeGenerator.generate_theme() @@ -247,26 +246,67 @@ func get_validity_color(error_condition: bool, warning_condition := false) -> Co func update_ui_scale() -> void: - await get_tree().process_frame var window := get_window() - var min_size: Vector2 = window.get_contents_minimum_size() - var actual_ui_scale: float = ui_scale - if auto_ui_scale: - actual_ui_scale = _calculate_auto_scale(min_size, window.size) - min_size *= actual_ui_scale - window.min_size = min_size - window.content_scale_factor = actual_ui_scale - - -func _calculate_auto_scale(min_size: Vector2, size: Vector2i) -> float: - var div: Vector2 = (Vector2(size - Vector2i(10, 10)) / min_size) - var desired: float = div[div.min_axis_index()] * 0.5 * ui_scale - if desired > 4.0: return 4.0 - if desired > 3.0: return 3.0 - if desired > 2.5: return 2.5 - if desired > 2.0: return 2.0 - if desired > 1.75: return 1.75 - if desired > 1.5: return 1.5 - if desired > 1.25: return 1.25 - if desired > 1.0: return 1.0 - return 0.75 + if not window.is_node_ready(): + await window.ready + + var usable_screen_size := Vector2( + DisplayServer.screen_get_usable_rect(DisplayServer.window_get_current_screen()).size + # Subtract window decoration size. + - (window.get_size_with_decorations() - window.size) + ) + + # How much can window content size be multiplied by before it extends over the usable screen size. + var diff := usable_screen_size / window.get_contents_minimum_size() + var max_scale := floorf(minf(diff.x, diff.y) * 4.0) / 4.0 + var desired_scale: float = ui_scale * _calculate_auto_scale() + + if not desired_scale > max_scale: + window.min_size = window.get_contents_minimum_size() * desired_scale + window.content_scale_factor = desired_scale + else: + window.min_size = usable_screen_size + window.content_scale_factor = max_scale + + +func _calculate_auto_scale() -> float: + if not auto_ui_scale: + return 1.0 + + # Credit: Godots (MIT, by MakovWait and contributors) + + var screen := DisplayServer.window_get_current_screen() + if DisplayServer.screen_get_size(screen) == Vector2i(): + return 1.0 + + # Use the smallest dimension to use a correct display scale on portrait displays. + var smallest_dimension := mini( + DisplayServer.screen_get_size(screen).x, + DisplayServer.screen_get_size(screen).y + ) + + var dpi := DisplayServer.screen_get_dpi(screen) + if dpi != 72: + if dpi < 72: + return 0.75 + elif dpi <= 96: + return 1.0 + elif dpi <= 120: + return 1.25 + elif dpi <= 160: + return 1.5 + elif dpi <= 200: + return 2.0 + elif dpi <= 240: + return 2.5 + elif dpi <= 320: + return 3.0 + elif dpi <= 480: + return 4.0 + else: # dpi > 480 + return 5.0 + elif smallest_dimension >= 1700: + # Likely a hiDPI display, but we aren't certain due to the returned DPI. + # Use an intermediate scale to handle this situation. + return 1.5 + return 1.0 diff --git a/src/ui_parts/settings_menu.gd b/src/ui_parts/settings_menu.gd index 307bb7d7..7d76b196 100644 --- a/src/ui_parts/settings_menu.gd +++ b/src/ui_parts/settings_menu.gd @@ -80,7 +80,7 @@ func setup_setting_labels() -> void: var auto_ui_scale := %Misc/AutoUIScale auto_ui_scale.label.text = tr("Auto UI scale") - auto_ui_scale.tooltip_text = tr("Scale the user interface based on the window size.") + auto_ui_scale.tooltip_text = tr("Scales the user interface based on the screen size.") %GeneralVBox/NumberPrecision.label.text = tr("Number precision digits") %GeneralVBox/AnglePrecision.label.text = tr("Angle precision digits") diff --git a/src/ui_parts/settings_menu.tscn b/src/ui_parts/settings_menu.tscn index 0f12d1a9..d8082275 100644 --- a/src/ui_parts/settings_menu.tscn +++ b/src/ui_parts/settings_menu.tscn @@ -539,11 +539,11 @@ number_max = 2.5 layout_mode = 2 section_name = "other" setting_name = "ui_scale" -values = Array[String](["0.75", "1.0", "1.25", "1.5", "1.75", "2.0"]) +values = Array[String](["0.75", "1.0", "1.25", "1.5", "1.75", "2.0", "2.5", "3.0", "4.0"]) type = 3 restricted = false number_min = 0.5 -number_max = 2.5 +number_max = 10.0 [node name="AutoUIScale" parent="VBoxContainer/HBoxContainer/MainPanel/ContentContainer/Other/OtherSettings/Misc" instance=ExtResource("4_2qeh2")] layout_mode = 2 diff --git a/translations/GodSVG.pot b/translations/GodSVG.pot index 98e56d96..fc7b240a 100644 --- a/translations/GodSVG.pot +++ b/translations/GodSVG.pot @@ -44,6 +44,7 @@ msgstr "" msgid "" "If turned on, scrolling will pan the view. To zoom, hold CTRL while " "scrolling." +msgstr "" msgid "UI scale" msgstr "" @@ -51,6 +52,12 @@ msgstr "" msgid "Changes the scale of the visual user interface." msgstr "" +msgid "Auto UI scale" +msgstr "" + +msgid "Scales the user interface based on the screen size." +msgstr "" + msgid "Input" msgstr "" diff --git a/translations/bg.po b/translations/bg.po index 25c8704d..50ff48be 100644 --- a/translations/bg.po +++ b/translations/bg.po @@ -56,6 +56,13 @@ msgstr "Мащаб" msgid "Changes the scale of the visual user interface." msgstr "" +#, fuzzy +msgid "Auto UI scale" +msgstr "Мащаб" + +msgid "Scales the user interface based on the screen size." +msgstr "" + msgid "Input" msgstr "Входни сигнали" diff --git a/translations/de.po b/translations/de.po index 41a35f49..f674b4b0 100644 --- a/translations/de.po +++ b/translations/de.po @@ -57,6 +57,13 @@ msgstr "Skalieren" msgid "Changes the scale of the visual user interface." msgstr "" +#, fuzzy +msgid "Auto UI scale" +msgstr "Skalieren" + +msgid "Scales the user interface based on the screen size." +msgstr "" + msgid "Input" msgstr "Eingabe" diff --git a/translations/en.po b/translations/en.po index ebb34235..5a43f984 100644 --- a/translations/en.po +++ b/translations/en.po @@ -53,6 +53,12 @@ msgstr "" msgid "Changes the scale of the visual user interface." msgstr "" +msgid "Auto UI scale" +msgstr "" + +msgid "Scales the user interface based on the screen size." +msgstr "" + msgid "Input" msgstr "" diff --git a/translations/ru.po b/translations/ru.po index 5de84905..628cc7f2 100644 --- a/translations/ru.po +++ b/translations/ru.po @@ -57,6 +57,13 @@ msgstr "Масштаб интерфейса" msgid "Changes the scale of the visual user interface." msgstr "Изменить масштаб пользовательского интерфейса." +#, fuzzy +msgid "Auto UI scale" +msgstr "Масштаб" + +msgid "Scales the user interface based on the screen size." +msgstr "" + msgid "Input" msgstr "Устройства ввода" diff --git a/translations/uk.po b/translations/uk.po index 7a5b42c0..496c3301 100644 --- a/translations/uk.po +++ b/translations/uk.po @@ -51,6 +51,13 @@ msgstr "Масштаб інтерфейсу" msgid "Changes the scale of the visual user interface." msgstr "Змінити масштаб інтерфейсу користувача." +#, fuzzy +msgid "Auto UI scale" +msgstr "Масштаб" + +msgid "Scales the user interface based on the screen size." +msgstr "" + msgid "Input" msgstr "Пристрої вводу"