@@ -8,52 +8,52 @@ var base_window_size = Vector2(ProjectSettings.get_setting("display/window/size/
88
99# These defaults match this demo's project settings. Adjust as needed if adapting this
1010# in your own project.
11- var stretch_mode = SceneTree . STRETCH_MODE_2D
12- var stretch_aspect = SceneTree . STRETCH_ASPECT_EXPAND
11+ var stretch_mode = Window . CONTENT_SCALE_MODE_CANVAS_ITEMS
12+ var stretch_aspect = Window . CONTENT_SCALE_ASPECT_EXPAND
1313
1414var scale_factor = 1.0
1515var gui_aspect_ratio = - 1.0
1616var gui_margin = 0.0
1717
18- onready var panel = $ Panel
19- onready var arc = $ Panel/AspectRatioContainer
18+ @ onready var panel = $ Panel
19+ @ onready var arc = $ Panel/AspectRatioContainer
2020
2121
2222func _ready ():
2323 # The `resized` signal will be emitted when the window size changes, as the root Control node
2424 # is resized whenever the window size changes. This is because the root Control node
2525 # uses a Full Rect anchor, so its size will always be equal to the window size.
2626 # warning-ignore:return_value_discarded
27- connect ("resized" , self , " _on_resized" )
27+ connect ("resized" , self . _on_resized )
2828 update_container ()
2929
3030
3131func update_container ():
3232 # The code within this function needs to be run twice to work around an issue with containers
3333 # having a 1-frame delay with updates.
34- # Otherwise, `panel.rect_size ` returns a value of the previous frame, which results in incorrect
34+ # Otherwise, `panel.size ` returns a value of the previous frame, which results in incorrect
3535 # sizing of the inner AspectRatioContainer when using the Fit to Window setting.
3636 for _i in 2 :
3737 if is_equal_approx (gui_aspect_ratio , - 1.0 ):
3838 # Fit to Window. Tell the AspectRatioContainer to use the same aspect ratio as the window,
3939 # making the AspectRatioContainer not have any visible effect.
40- arc .ratio = panel .rect_size .aspect ()
41- # Apply GUI margin on the AspectRatioContainer's parent (Panel).
42- # This also makes the GUI margin apply on controls located outside the AspectRatioContainer
40+ arc .ratio = panel .size .aspect ()
41+ # Apply GUI offset on the AspectRatioContainer's parent (Panel).
42+ # This also makes the GUI offset apply on controls located outside the AspectRatioContainer
4343 # (such as the inner side label in this demo).
44- panel .margin_top = gui_margin
45- panel .margin_bottom = - gui_margin
44+ panel .offset_top = gui_margin
45+ panel .offset_bottom = - gui_margin
4646 else :
4747 # Constrained aspect ratio.
48- arc .ratio = min (panel .rect_size .aspect (), gui_aspect_ratio )
49- # Adjust top and bottom margins relative to the aspect ratio when it's constrained.
50- # This ensures that GUI margin settings behave exactly as if the window had the
48+ arc .ratio = min (panel .size .aspect (), gui_aspect_ratio )
49+ # Adjust top and bottom offsets relative to the aspect ratio when it's constrained.
50+ # This ensures that GUI offset settings behave exactly as if the window had the
5151 # original aspect ratio size.
52- panel .margin_top = gui_margin / gui_aspect_ratio
53- panel .margin_bottom = - gui_margin / gui_aspect_ratio
52+ panel .offset_top = gui_margin / gui_aspect_ratio
53+ panel .offset_bottom = - gui_margin / gui_aspect_ratio
5454
55- panel .margin_left = gui_margin
56- panel .margin_right = - gui_margin
55+ panel .offset_left = gui_margin
56+ panel .offset_right = - gui_margin
5757
5858
5959func _on_gui_aspect_ratio_item_selected (index ):
@@ -81,8 +81,8 @@ func _on_resized():
8181
8282
8383func _on_gui_margin_drag_ended (_value_changed ):
84- gui_margin = $ "Panel/AspectRatioContainer/ColorRect /CenterContainer/Options/GUIMargin/HSlider" .value
85- $ "Panel/AspectRatioContainer/ColorRect /CenterContainer/Options/GUIMargin/Value" .text = str (gui_margin )
84+ gui_margin = $ "Panel/AspectRatioContainer/Panel /CenterContainer/Options/GUIMargin/HSlider" .value
85+ $ "Panel/AspectRatioContainer/Panel /CenterContainer/Options/GUIMargin/Value" .text = str (gui_margin )
8686 update_container ()
8787
8888
@@ -105,25 +105,25 @@ func _on_window_base_size_item_selected(index):
105105 7 : # 1680×720 (21:9)
106106 base_window_size = Vector2 (1680 , 720 )
107107
108- get_tree ().set_screen_stretch ( stretch_mode , stretch_aspect , base_window_size , scale_factor )
108+ get_viewport ().content_scale_size = base_window_size
109109 update_container ()
110110
111111
112112func _on_window_stretch_mode_item_selected (index ):
113113 stretch_mode = index
114- get_tree ().set_screen_stretch ( stretch_mode , stretch_aspect , base_window_size , scale_factor )
114+ get_viewport ().content_scale_mode = stretch_mode
115115
116116 # Disable irrelevant options when the stretch mode is Disabled.
117- $ "Panel/AspectRatioContainer/ColorRect /CenterContainer/Options/WindowBaseSize/OptionButton" .disabled = stretch_mode == SceneTree . STRETCH_MODE_DISABLED
118- $ "Panel/AspectRatioContainer/ColorRect /CenterContainer/Options/WindowStretchAspect/OptionButton" .disabled = stretch_mode == SceneTree . STRETCH_MODE_DISABLED
117+ $ "Panel/AspectRatioContainer/Panel /CenterContainer/Options/WindowBaseSize/OptionButton" .disabled = stretch_mode == Window . CONTENT_SCALE_MODE_DISABLED
118+ $ "Panel/AspectRatioContainer/Panel /CenterContainer/Options/WindowStretchAspect/OptionButton" .disabled = stretch_mode == Window . CONTENT_SCALE_MODE_DISABLED
119119
120120
121121func _on_window_stretch_aspect_item_selected (index ):
122122 stretch_aspect = index
123- get_tree ().set_screen_stretch ( stretch_mode , stretch_aspect , base_window_size , scale_factor )
123+ get_viewport ().content_scale_aspect = stretch_aspect
124124
125125
126126func _on_window_scale_factor_drag_ended (_value_changed ):
127- scale_factor = $ "Panel/AspectRatioContainer/ColorRect /CenterContainer/Options/WindowScaleFactor/HSlider" .value
128- $ "Panel/AspectRatioContainer/ColorRect /CenterContainer/Options/WindowScaleFactor/Value" .text = "%d%% " % (scale_factor * 100 )
129- get_tree ().set_screen_stretch ( stretch_mode , stretch_aspect , base_window_size , scale_factor )
127+ scale_factor = $ "Panel/AspectRatioContainer/Panel /CenterContainer/Options/WindowScaleFactor/HSlider" .value
128+ $ "Panel/AspectRatioContainer/Panel /CenterContainer/Options/WindowScaleFactor/Value" .text = "%d%% " % (scale_factor * 100 )
129+ get_viewport ().content_scale_factor = scale_factor
0 commit comments