11extends Control
22
3- # Member variables
43var mousepos
54
65onready var observer = $ "../Observer"
76
7+ func _ready ():
8+ if not check_wm_api ():
9+ set_physics_process (false )
10+ set_process_input (false )
11+
12+
813func _physics_process (_delta ):
914 var modetext = "Mode:\n "
10-
1115 if OS .is_window_fullscreen ():
1216 modetext += "Fullscreen\n "
1317 else :
1418 modetext += "Windowed\n "
15-
1619 if ! OS .is_window_resizable ():
1720 modetext += "FixedSize\n "
18-
1921 if OS .is_window_minimized ():
2022 modetext += "Minimized\n "
21-
2223 if OS .is_window_maximized ():
2324 modetext += "Maximized\n "
24-
2525 if Input .get_mouse_mode () == Input .MOUSE_MODE_CAPTURED :
2626 modetext += "MouseGrab\n "
2727 $ Label_MouseModeCaptured_KeyInfo .show ()
@@ -63,56 +63,57 @@ func _physics_process(_delta):
6363 $ Button_MouseModeCaptured .set_pressed (Input .get_mouse_mode () == Input .MOUSE_MODE_CAPTURED )
6464
6565
66+ func _input (event ):
67+ if event is InputEventMouseMotion :
68+ mousepos = event .position
69+
70+ if event is InputEventKey :
71+ if Input .is_action_pressed ("mouse_mode_visible" ):
72+ observer .state = observer .STATE_MENU
73+ _on_Button_MouseModeVisible_pressed ()
74+
75+ if Input .is_action_pressed ("mouse_mode_hidden" ):
76+ observer .state = observer .STATE_MENU
77+ _on_Button_MouseModeHidden_pressed ()
78+
79+ if Input .is_action_pressed ("mouse_mode_captured" ):
80+ _on_Button_MouseModeCaptured_pressed ()
81+
82+
6683func check_wm_api ():
6784 var s = ""
6885 if ! OS .has_method ("get_screen_count" ):
6986 s += " - get_screen_count()\n "
70-
7187 if ! OS .has_method ("get_current_screen" ):
7288 s += " - get_current_screen()\n "
73-
7489 if ! OS .has_method ("set_current_screen" ):
7590 s += " - set_current_screen()\n "
76-
7791 if ! OS .has_method ("get_screen_position" ):
7892 s += " - get_screen_position()\n "
79-
8093 if ! OS .has_method ("get_screen_size" ):
8194 s += " - get_screen_size()\n "
82-
8395 if ! OS .has_method ("get_window_position" ):
8496 s += " - get_window_position()\n "
85-
8697 if ! OS .has_method ("set_window_position" ):
8798 s += " - set_window_position()\n "
88-
8999 if ! OS .has_method ("get_window_size" ):
90100 s += " - get_window_size()\n "
91-
92101 if ! OS .has_method ("set_window_size" ):
93102 s += " - set_window_size()\n "
94-
95103 if ! OS .has_method ("set_window_fullscreen" ):
96104 s += " - set_window_fullscreen()\n "
97-
98105 if ! OS .has_method ("is_window_fullscreen" ):
99106 s += " - is_window_fullscreen()\n "
100-
101107 if ! OS .has_method ("set_window_resizable" ):
102108 s += " - set_window_resizable()\n "
103-
104109 if ! OS .has_method ("is_window_resizable" ):
105110 s += " - is_window_resizable()\n "
106-
107111 if ! OS .has_method ("set_window_minimized" ):
108112 s += " - set_window_minimized()\n "
109-
110113 if ! OS .has_method ("is_window_minimized" ):
111114 s += " - is_window_minimized()\n "
112-
113115 if ! OS .has_method ("set_window_maximized" ):
114116 s += " - set_window_maximized()\n "
115-
116117 if ! OS .has_method ("is_window_maximized" ):
117118 s += " - is_window_maximized()\n "
118119
@@ -124,29 +125,6 @@ func check_wm_api():
124125 return false
125126
126127
127- func _ready ():
128- if not check_wm_api ():
129- set_physics_process (false )
130- set_process_input (false )
131-
132-
133- func _input (event ):
134- if event is InputEventMouseMotion :
135- mousepos = event .position
136-
137- if event is InputEventKey :
138- if Input .is_action_pressed ("mouse_mode_visible" ):
139- observer .state = observer .STATE_MENU
140- _on_Button_MouseModeVisible_pressed ()
141-
142- if Input .is_action_pressed ("mouse_mode_hidden" ):
143- observer .state = observer .STATE_MENU
144- _on_Button_MouseModeHidden_pressed ()
145-
146- if Input .is_action_pressed ("mouse_mode_captured" ):
147- _on_Button_MouseModeCaptured_pressed ()
148-
149-
150128func _on_Button_MoveTo_pressed ():
151129 OS .set_window_position (Vector2 (100 , 100 ))
152130
@@ -200,4 +178,5 @@ func _on_Button_MouseModeHidden_pressed():
200178
201179
202180func _on_Button_MouseModeCaptured_pressed ():
181+ Input .set_mouse_mode (Input .MOUSE_MODE_CAPTURED )
203182 observer .state = observer .STATE_GRAB
0 commit comments