mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Auto-scale the UI based on dpi and resolution - Closes #643
Code is taken from Godot's editor, so I assume it should work well.
This commit is contained in:
parent
c8efa7c09a
commit
d69d98dc3b
17
src/Main.gd
17
src/Main.gd
|
@ -14,6 +14,7 @@ onready var right_cursor: Sprite = $RightCursor
|
||||||
|
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
|
Global.shrink = _get_auto_display_scale()
|
||||||
if OS.get_name() == "OSX":
|
if OS.get_name() == "OSX":
|
||||||
_use_osx_shortcuts()
|
_use_osx_shortcuts()
|
||||||
|
|
||||||
|
@ -88,6 +89,22 @@ func _input(event: InputEvent) -> void:
|
||||||
get_focus_owner().release_focus()
|
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:
|
func _setup_application_window_size() -> void:
|
||||||
get_tree().set_screen_stretch(
|
get_tree().set_screen_stretch(
|
||||||
SceneTree.STRETCH_MODE_DISABLED,
|
SceneTree.STRETCH_MODE_DISABLED,
|
||||||
|
|
|
@ -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_container: Container = right_side.get_node("Backup/AutosaveContainer")
|
||||||
onready var autosave_interval: SpinBox = autosave_container.get_node("AutosaveInterval")
|
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_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 themes: BoxContainer = right_side.get_node("Interface/Themes")
|
||||||
onready var shortcuts: Control = right_side.get_node("Shortcuts")
|
onready var shortcuts: Control = right_side.get_node("Shortcuts")
|
||||||
onready var extensions: BoxContainer = right_side.get_node("Extensions")
|
onready var extensions: BoxContainer = right_side.get_node("Extensions")
|
||||||
|
@ -111,6 +112,7 @@ class Preference:
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
# Replace OK since preference changes are being applied immediately, not after OK confirmation
|
# Replace OK since preference changes are being applied immediately, not after OK confirmation
|
||||||
get_ok().text = tr("Close")
|
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():
|
for child in shortcuts.get_children():
|
||||||
if not child is AcceptDialog:
|
if not child is AcceptDialog:
|
||||||
|
|
|
@ -154,6 +154,7 @@ text = "1"
|
||||||
align = 2
|
align = 2
|
||||||
|
|
||||||
[node name="ShrinkHSlider" type="HSlider" parent="HSplitContainer/ScrollContainer/VBoxContainer/Interface/ShrinkContainer"]
|
[node name="ShrinkHSlider" type="HSlider" parent="HSplitContainer/ScrollContainer/VBoxContainer/Interface/ShrinkContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
margin_left = 142.0
|
margin_left = 142.0
|
||||||
margin_right = 446.0
|
margin_right = 446.0
|
||||||
margin_bottom = 16.0
|
margin_bottom = 16.0
|
||||||
|
|
Loading…
Reference in a new issue