Files
godot-demo-projects/viewport/3d_scaling/hud.gd
Hugo Locurcio bac1e69164 Use static typing in all demos (#1063)
This leads to code that is easier to understand and runs
faster thanks to GDScript's typed instructions.

The untyped declaration warning is now enabled on all projects
where type hints were added. All projects currently run without
any untyped declration warnings.

Dodge the Creeps and Squash the Creeps demos intentionally don't
use type hints to match the documentation, where type hints haven't
been adopted yet (given its beginner focus).
2024-06-01 12:12:18 +02:00

35 lines
1.2 KiB
GDScript

extends Control
## The 3D viewport's shrink factor. For instance, 1 is full resolution,
## 2 is half resolution and 4 is quarter resolution. Lower values look
## sharper but are slower to render.
var scale_factor := 1
var filter_mode := Viewport.SCALING_3D_MODE_BILINEAR
@onready var viewport: Window = get_tree().root
@onready var scale_label: Label = $VBoxContainer/Scale
@onready var filter_label: Label = $VBoxContainer/Filter
func _ready() -> void:
viewport.scaling_3d_mode = filter_mode
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed(&"cycle_viewport_resolution"):
scale_factor = wrapi(scale_factor + 1, 1, 5)
viewport.scaling_3d_scale = 1.0 / scale_factor
scale_label.text = "Scale: %3.0f%%" % (100.0 / scale_factor)
if event.is_action_pressed(&"toggle_filtering"):
filter_mode = wrapi(filter_mode + 1, Viewport.SCALING_3D_MODE_BILINEAR, Viewport.SCALING_3D_MODE_MAX) as Viewport.Scaling3DMode
viewport.scaling_3d_mode = filter_mode
filter_label.text = (
ClassDB.class_get_enum_constants("Viewport", "Scaling3DMode")[filter_mode]
.capitalize()
.replace("3d", "3D")
.replace("Mode", "Mode:")
.replace("Fsr", "FSR")
)