Change display scaling logic

Window size in editor is now 640x360
The default 2x scale is now obtained by a hook in Common singleton, using shrink.
Window will snap to integer scales (720p = 2x, 1080p = 3x, 1440p = 4x, 3200x1800 = 5x, 2160p = 6x ...) one second after last window resize
This commit is contained in:
Luke Hubmayer-Werner 2023-08-02 19:48:45 +09:30
parent bbd9b639ee
commit fbda1422d5
3 changed files with 34 additions and 3 deletions

View File

@ -12,7 +12,6 @@ anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -640.0
margin_bottom = -360.0
rect_scale = Vector2( 2, 2 )
theme = ExtResource( 2 )
[node name="party_menu" parent="." instance=ExtResource( 5 )]

View File

@ -37,9 +37,11 @@ gdscript/warnings/integer_division=false
[display]
window/size/width=1280
window/size/height=720
window/size/width=640
window/size/height=360
window/dpi/allow_hidpi=true
window/stretch/shrink=2.0
window/size/snap_to_integer=true
[gui]
@ -57,5 +59,6 @@ texture={
[rendering]
quality/driver/driver_name="GLES2"
2d/snapping/use_gpu_pixel_snap=true
environment/default_clear_color=Color( 0, 0, 0, 1 )
environment/default_environment="res://default_env.tres"

View File

@ -1,5 +1,8 @@
extends Node
const base_resolution := Vector2(640, 360)
var shrink_timer := Timer.new()
static func load_json(filename: String) -> Dictionary:
var file := File.new()
var error := file.open(filename, File.READ)
@ -36,3 +39,29 @@ static func load_tsv(filename: String, delimiter: String = '\t') -> Dictionary:
return {}
var SNES_PSX_addresses := load_tsv('res://data/SNES_PSX_addresses.tsv')
func shrink_to_integer():
var size := OS.get_window_size()
var scale_vec := size / base_resolution
var scale_f := max(min(scale_vec.x, scale_vec.y), 1)
var scale := int(scale_f)
OS.window_size = base_resolution*scale
func update_window_scale():
if OS.window_size < base_resolution*2:
OS.window_size = base_resolution*2
var size := OS.get_window_size()
var scale_vec := size / base_resolution
var scale_f := max(min(scale_vec.x, scale_vec.y), 1)
var scale := int(scale_f)
if ProjectSettings.get_setting('display/window/size/snap_to_integer'):
# OS.window_size = base_resolution*scale
shrink_timer.paused = false
shrink_timer.start(1)
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_DISABLED, SceneTree.STRETCH_ASPECT_KEEP, base_resolution*scale, scale)
func _ready():
shrink_timer.connect('timeout', self, 'shrink_to_integer')
add_child(shrink_timer)
get_tree().connect('screen_resized', self, 'update_window_scale')
OS.set_min_window_size(base_resolution*2)