control.gd 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. extends Control
  2. var mousepos
  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. func _physics_process(_delta):
  9. var modetext = "Mode:\n"
  10. if OS.is_window_fullscreen():
  11. modetext += "Fullscreen\n"
  12. else:
  13. modetext += "Windowed\n"
  14. if not OS.is_window_resizable():
  15. modetext += "FixedSize\n"
  16. if OS.is_window_minimized():
  17. modetext += "Minimized\n"
  18. if OS.is_window_maximized():
  19. modetext += "Maximized\n"
  20. if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
  21. modetext += "MouseGrab\n"
  22. $Label_MouseModeCaptured_KeyInfo.show()
  23. else:
  24. $Label_MouseModeCaptured_KeyInfo.hide()
  25. $Label_Mode.text = modetext
  26. $Label_Position.text = str("Position:\n", OS.get_window_position())
  27. $Label_Size.text = str("Size:\n", OS.get_window_size())
  28. $Label_MousePosition.text = str("Mouse Position:\n", mousepos)
  29. $Label_Screen_Count.text = str("Screen_Count:\n", OS.get_screen_count())
  30. $Label_Screen_Current.text = str("Screen:\n", OS.get_current_screen())
  31. $Label_Screen0_Resolution.text = str("Screen0 Resolution:\n", OS.get_screen_size())
  32. $Label_Screen0_Position.text = str("Screen0 Position:\n", OS.get_screen_position())
  33. $Label_Screen0_DPI.text = str("Screen0 DPI:\n", OS.get_screen_dpi())
  34. if OS.get_screen_count() > 1:
  35. $Button_Screen0.show()
  36. $Button_Screen1.show()
  37. $Label_Screen1_Resolution.show()
  38. $Label_Screen1_Position.show()
  39. $Label_Screen1_DPI.show()
  40. $Label_Screen1_Resolution.text = str("Screen1 Resolution:\n", OS.get_screen_size(1))
  41. $Label_Screen1_Position.text = str("Screen1 Position:\n", OS.get_screen_position(1))
  42. $Label_Screen1_DPI.text = str("Screen1 DPI:\n", OS.get_screen_dpi(1))
  43. else:
  44. $Button_Screen0.hide()
  45. $Button_Screen1.hide()
  46. $Label_Screen1_Resolution.hide()
  47. $Label_Screen1_Position.hide()
  48. $Label_Screen1_DPI.hide()
  49. $Button_Fullscreen.set_pressed(OS.is_window_fullscreen())
  50. $Button_FixedSize.set_pressed(not OS.is_window_resizable())
  51. $Button_Minimized.set_pressed(OS.is_window_minimized())
  52. $Button_Maximized.set_pressed(OS.is_window_maximized())
  53. $Button_MouseModeVisible.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE)
  54. $Button_MouseModeHidden.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_HIDDEN)
  55. $Button_MouseModeCaptured.set_pressed(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED)
  56. func _unhandled_input(event):
  57. if event is InputEventMouseMotion:
  58. mousepos = event.position
  59. if event is InputEventKey:
  60. if Input.is_action_pressed("mouse_mode_visible"):
  61. observer.state = observer.STATE_MENU
  62. _on_Button_MouseModeVisible_pressed()
  63. if Input.is_action_pressed("mouse_mode_hidden"):
  64. observer.state = observer.STATE_MENU
  65. _on_Button_MouseModeHidden_pressed()
  66. if Input.is_action_pressed("mouse_mode_captured"):
  67. _on_Button_MouseModeCaptured_pressed()
  68. func check_wm_api():
  69. var s = ""
  70. if not OS.has_method("get_screen_count"):
  71. s += " - get_screen_count()\n"
  72. if not OS.has_method("get_current_screen"):
  73. s += " - get_current_screen()\n"
  74. if not OS.has_method("set_current_screen"):
  75. s += " - set_current_screen()\n"
  76. if not OS.has_method("get_screen_position"):
  77. s += " - get_screen_position()\n"
  78. if not OS.has_method("get_screen_size"):
  79. s += " - get_screen_size()\n"
  80. if not OS.has_method("get_window_position"):
  81. s += " - get_window_position()\n"
  82. if not OS.has_method("set_window_position"):
  83. s += " - set_window_position()\n"
  84. if not OS.has_method("get_window_size"):
  85. s += " - get_window_size()\n"
  86. if not OS.has_method("set_window_size"):
  87. s += " - set_window_size()\n"
  88. if not OS.has_method("set_window_fullscreen"):
  89. s += " - set_window_fullscreen()\n"
  90. if not OS.has_method("is_window_fullscreen"):
  91. s += " - is_window_fullscreen()\n"
  92. if not OS.has_method("set_window_resizable"):
  93. s += " - set_window_resizable()\n"
  94. if not OS.has_method("is_window_resizable"):
  95. s += " - is_window_resizable()\n"
  96. if not OS.has_method("set_window_minimized"):
  97. s += " - set_window_minimized()\n"
  98. if not OS.has_method("is_window_minimized"):
  99. s += " - is_window_minimized()\n"
  100. if not OS.has_method("set_window_maximized"):
  101. s += " - set_window_maximized()\n"
  102. if not OS.has_method("is_window_maximized"):
  103. s += " - is_window_maximized()\n"
  104. if s.length() == 0:
  105. return true
  106. else:
  107. $"ImplementationDialog/Text".text += s
  108. $ImplementationDialog.show()
  109. return false
  110. func _on_Button_MoveTo_pressed():
  111. OS.set_window_position(Vector2(100, 100))
  112. func _on_Button_Resize_pressed():
  113. OS.set_window_size(Vector2(1024, 768))
  114. func _on_Button_Screen0_pressed():
  115. OS.set_current_screen(0)
  116. func _on_Button_Screen1_pressed():
  117. OS.set_current_screen(1)
  118. func _on_Button_Fullscreen_pressed():
  119. if OS.is_window_fullscreen():
  120. OS.set_window_fullscreen(false)
  121. else:
  122. OS.set_window_fullscreen(true)
  123. func _on_Button_FixedSize_pressed():
  124. if OS.is_window_resizable():
  125. OS.set_window_resizable(false)
  126. else:
  127. OS.set_window_resizable(true)
  128. func _on_Button_Minimized_pressed():
  129. if OS.is_window_minimized():
  130. OS.set_window_minimized(false)
  131. else:
  132. OS.set_window_minimized(true)
  133. func _on_Button_Maximized_pressed():
  134. if OS.is_window_maximized():
  135. OS.set_window_maximized(false)
  136. else:
  137. OS.set_window_maximized(true)
  138. func _on_Button_MouseModeVisible_pressed():
  139. Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
  140. func _on_Button_MouseModeHidden_pressed():
  141. Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
  142. func _on_Button_MouseModeCaptured_pressed():
  143. Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
  144. observer.state = observer.STATE_GRAB