control.gd 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. extends Control
  2. var mouse_position = Vector2()
  3. @onready var observer = $"../Observer"
  4. func _ready():
  5. if not check_wm_api():
  6. set_physics_process(false)
  7. set_process_input(false)
  8. # See godotengine/godot#73563, fetching the refresh rate on every frame may be slow on some platforms.
  9. $Labels/Label_Screen0_RefreshRate.text = "Screen0 Refresh Rate: %.2f Hz" % DisplayServer.screen_get_refresh_rate()
  10. if DisplayServer.get_screen_count() > 1:
  11. $Labels/Label_Screen1_RefreshRate.text = "Screen1 Refresh Rate: %.2f Hz" % DisplayServer.screen_get_refresh_rate(1)
  12. func _physics_process(_delta):
  13. var modetext = "Mode: "
  14. if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
  15. modetext += "Fullscreen\n"
  16. else:
  17. modetext += "Windowed\n"
  18. if DisplayServer.window_get_flag(DisplayServer.WINDOW_FLAG_RESIZE_DISABLED):
  19. modetext += "Fixed Size\n"
  20. if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_MINIMIZED:
  21. modetext += "Minimized\n"
  22. if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_MAXIMIZED:
  23. modetext += "Maximized\n"
  24. if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
  25. modetext += "Mouse Captured\n"
  26. $Buttons/Label_MouseModeCaptured_KeyInfo.show()
  27. else:
  28. $Buttons/Label_MouseModeCaptured_KeyInfo.hide()
  29. $Labels/Label_Mode.text = modetext
  30. $Labels/Label_Position.text = str("Position: ", DisplayServer.window_get_position())
  31. $Labels/Label_Size.text = str("Size: ", DisplayServer.window_get_size())
  32. $Labels/Label_MousePosition.text = str("Mouse Position: ", mouse_position)
  33. $Labels/Label_Screen_Count.text = str("Screen_Count: ", DisplayServer.get_screen_count())
  34. $Labels/Label_Screen_Current.text = str("Screen: ", DisplayServer.window_get_current_screen())
  35. $Labels/Label_Screen0_Resolution.text = str("Screen0 Resolution:\n", DisplayServer.screen_get_size())
  36. $Labels/Label_Screen0_Position.text = str("Screen0 Position:\n", DisplayServer.screen_get_position())
  37. $Labels/Label_Screen0_DPI.text = str("Screen0 DPI: ", DisplayServer.screen_get_dpi())
  38. if DisplayServer.get_screen_count() > 1:
  39. $Buttons/Button_Screen0.show()
  40. $Buttons/Button_Screen1.show()
  41. $Labels/Label_Screen1_Resolution.show()
  42. $Labels/Label_Screen1_Position.show()
  43. $Labels/Label_Screen1_DPI.show()
  44. $Labels/Label_Screen1_Resolution.text = str("Screen1 Resolution:\n", DisplayServer.screen_get_size(1))
  45. $Labels/Label_Screen1_Position.text = str("Screen1 Position:\n", DisplayServer.screen_get_position(1))
  46. $Labels/Label_Screen1_DPI.text = str("Screen1 DPI: ", DisplayServer.screen_get_dpi(1))
  47. else:
  48. $Buttons/Button_Screen0.hide()
  49. $Buttons/Button_Screen1.hide()
  50. $Labels/Label_Screen1_Resolution.hide()
  51. $Labels/Label_Screen1_Position.hide()
  52. $Labels/Label_Screen1_DPI.hide()
  53. $Labels/Label_Screen1_RefreshRate.hide()
  54. $Buttons/Button_Fullscreen.set_pressed(DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN)
  55. $Buttons/Button_FixedSize.set_pressed(DisplayServer.window_get_flag(DisplayServer.WINDOW_FLAG_RESIZE_DISABLED))
  56. $Buttons/Button_Minimized.set_pressed(DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_MINIMIZED)
  57. $Buttons/Button_Maximized.set_pressed(DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_MAXIMIZED)
  58. $Buttons/Button_MouseModeVisible.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE)
  59. $Buttons/Button_MouseModeHidden.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_HIDDEN)
  60. $Buttons/Button_MouseModeCaptured.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED)
  61. func _input(event):
  62. if event is InputEventMouseMotion:
  63. mouse_position = event.position
  64. if event is InputEventKey:
  65. if Input.is_action_pressed(&"mouse_mode_visible"):
  66. observer.state = observer.STATE_MENU
  67. _on_Button_MouseModeVisible_pressed()
  68. if Input.is_action_pressed(&"mouse_mode_hidden"):
  69. observer.state = observer.STATE_MENU
  70. _on_Button_MouseModeHidden_pressed()
  71. if Input.is_action_pressed(&"mouse_mode_captured"):
  72. _on_Button_MouseModeCaptured_pressed()
  73. if Input.is_action_pressed(&"mouse_mode_confined"):
  74. observer.state = observer.STATE_MENU
  75. _on_Button_MouseModeConfined_pressed()
  76. if Input.is_action_pressed(&"mouse_mode_confined_hidden"):
  77. observer.state = observer.STATE_MENU
  78. _on_Button_MouseModeConfinedHidden_pressed()
  79. func check_wm_api():
  80. var s = ""
  81. if not DisplayServer.has_method("get_screen_count"):
  82. s += " - get_screen_count()\n"
  83. if not DisplayServer.has_method("window_get_current_screen"):
  84. s += " - window_get_current_screen()\n"
  85. if not DisplayServer.has_method("window_set_current_screen"):
  86. s += " - window_set_current_screen()\n"
  87. if not DisplayServer.has_method("screen_get_position"):
  88. s += " - screen_get_position()\n"
  89. if not DisplayServer.has_method("window_get_size"):
  90. s += " - window_get_size()\n"
  91. if not DisplayServer.has_method("window_get_position"):
  92. s += " - window_get_position()\n"
  93. if not DisplayServer.has_method("window_set_position"):
  94. s += " - window_set_position()\n"
  95. if not DisplayServer.has_method("window_get_size"):
  96. s += " - get_window_size()\n"
  97. if not DisplayServer.has_method("window_set_size"):
  98. s += " - window_set_size()\n"
  99. # These function are no longer and this is set through flags!
  100. # if not DisplayServer.has_method("set_window_fullscreen"):
  101. # s += " - set_window_fullscreen()\n"
  102. # if not DisplayServer.window_get_flag() OS.has_method("is_window_fullscreen"):
  103. # s += " - is_window_fullscreen()\n"
  104. # if not OS.has_method("set_window_resizable"):
  105. # s += " - set_window_resizable()\n"
  106. # if not OS.has_method("is_window_resizable"):
  107. # s += " - is_window_resizable()\n"
  108. # if not OS.has_method("set_window_minimized"):
  109. # s += " - set_window_minimized()\n"
  110. # if not OS.has_method("is_window_minimized"):
  111. # s += " - is_window_minimized()\n"
  112. # if not OS.has_method("set_window_maximized"):
  113. # s += " - set_window_maximized()\n"
  114. # if not OS.has_method("is_window_maximized"):
  115. # s += " - is_window_maximized()\n"
  116. if s.length() == 0:
  117. return true
  118. else:
  119. $"ImplementationDialog/Text".text += s
  120. $ImplementationDialog.show()
  121. return false
  122. func _on_Button_MoveTo_pressed():
  123. DisplayServer.window_set_position(Vector2(100, 100))
  124. func _on_Button_Resize_pressed():
  125. DisplayServer.window_set_size(Vector2(1280, 720))
  126. func _on_Button_Screen0_pressed():
  127. DisplayServer.window_set_current_screen(0)
  128. func _on_Button_Screen1_pressed():
  129. DisplayServer.window_set_current_screen(1)
  130. func _on_Button_Fullscreen_pressed():
  131. if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN:
  132. DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
  133. else:
  134. DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
  135. func _on_Button_FixedSize_pressed():
  136. if DisplayServer.window_get_flag(DisplayServer.WINDOW_FLAG_RESIZE_DISABLED):
  137. DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_RESIZE_DISABLED, false)
  138. else:
  139. DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_RESIZE_DISABLED, true)
  140. func _on_Button_Minimized_pressed():
  141. if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_MINIMIZED:
  142. DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
  143. else:
  144. DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)
  145. func _on_Button_Maximized_pressed():
  146. if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_MAXIMIZED:
  147. DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)
  148. else:
  149. DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MAXIMIZED)
  150. func _on_Button_MouseModeVisible_pressed():
  151. Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
  152. func _on_Button_MouseModeHidden_pressed():
  153. Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
  154. func _on_Button_MouseModeCaptured_pressed():
  155. Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
  156. observer.state = observer.STATE_GRAB
  157. func _on_Button_MouseModeConfined_pressed():
  158. Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED)
  159. func _on_Button_MouseModeConfinedHidden_pressed():
  160. Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED_HIDDEN)