diff --git a/src/Main.gd b/src/Main.gd index 573808bd7..c30f35e1d 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -14,6 +14,7 @@ onready var right_cursor: Sprite = $RightCursor func _init() -> void: + Global.shrink = _get_auto_display_scale() if OS.get_name() == "OSX": _use_osx_shortcuts() @@ -88,6 +89,22 @@ func _input(event: InputEvent) -> void: get_focus_owner().release_focus() +# Taken from https://github.com/godotengine/godot/blob/3.x/editor/editor_settings.cpp#L1474 +func _get_auto_display_scale() -> float: + if OS.get_name() == "OSX": + return OS.get_screen_max_scale() + + var dpi := OS.get_screen_dpi() + var smallest_dimension: int = min(OS.get_screen_size().x, OS.get_screen_size().y) + if dpi >= 192 && smallest_dimension >= 1400: + return 2.0 # hiDPI display. + elif smallest_dimension >= 1700: + return 1.5 # Likely a hiDPI display, but we aren't certain due to the returned DPI. + elif smallest_dimension <= 800: + return 0.75 # Small loDPI display. + return 1.0 + + func _setup_application_window_size() -> void: get_tree().set_screen_stretch( SceneTree.STRETCH_MODE_DISABLED, diff --git a/src/Preferences/PreferencesDialog.gd b/src/Preferences/PreferencesDialog.gd index ea1051061..217f1fe3c 100644 --- a/src/Preferences/PreferencesDialog.gd +++ b/src/Preferences/PreferencesDialog.gd @@ -90,6 +90,7 @@ onready var right_side: VBoxContainer = $HSplitContainer/ScrollContainer/VBoxCon onready var autosave_container: Container = right_side.get_node("Backup/AutosaveContainer") onready var autosave_interval: SpinBox = autosave_container.get_node("AutosaveInterval") onready var shrink_label: Label = right_side.get_node("Interface/ShrinkContainer/ShrinkLabel") +onready var shrink_h_slider: HSlider = $"%ShrinkHSlider" onready var themes: BoxContainer = right_side.get_node("Interface/Themes") onready var shortcuts: Control = right_side.get_node("Shortcuts") onready var extensions: BoxContainer = right_side.get_node("Extensions") @@ -111,6 +112,7 @@ class Preference: func _ready() -> void: # Replace OK since preference changes are being applied immediately, not after OK confirmation get_ok().text = tr("Close") + shrink_h_slider.value = Global.shrink # In case shrink is not equal to 1 for child in shortcuts.get_children(): if not child is AcceptDialog: diff --git a/src/Preferences/PreferencesDialog.tscn b/src/Preferences/PreferencesDialog.tscn index 127be9324..b912fd4cd 100644 --- a/src/Preferences/PreferencesDialog.tscn +++ b/src/Preferences/PreferencesDialog.tscn @@ -154,6 +154,7 @@ text = "1" align = 2 [node name="ShrinkHSlider" type="HSlider" parent="HSplitContainer/ScrollContainer/VBoxContainer/Interface/ShrinkContainer"] +unique_name_in_owner = true margin_left = 142.0 margin_right = 446.0 margin_bottom = 16.0