-
Notifications
You must be signed in to change notification settings - Fork 45
/
FullScreenHandler.gd
39 lines (33 loc) · 1.14 KB
/
FullScreenHandler.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
extends Node
var _previous_mouse_mode: Input.MouseMode = Input.mouse_mode
func _init() -> void:
process_mode = Node.PROCESS_MODE_ALWAYS
func _input(event: InputEvent) -> void:
if OS.has_feature("HTML5"):
if event is InputEventMouseButton and Input.mouse_mode != Input.MOUSE_MODE_CAPTURED:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
else:
if event is InputEventKey \
and event.is_pressed():
# Fullscreen
if (
event.keycode == KEY_F11 \
or (
event.keycode == KEY_ENTER \
and event.is_alt_pressed()
)
):
get_tree().root.mode = Window.MODE_WINDOWED \
if get_tree().root.mode == Window.MODE_FULLSCREEN \
else Window.MODE_FULLSCREEN
# Decapture Mouse
elif event.keycode == KEY_ESCAPE \
and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
_previous_mouse_mode = Input.mouse_mode
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
# Recapture mouse
elif event is InputEventMouseButton \
and event.button_index == MOUSE_BUTTON_LEFT \
and _previous_mouse_mode == Input.MOUSE_MODE_CAPTURED \
and Input.mouse_mode != Input.MOUSE_MODE_CAPTURED:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED