control.gd 5.3 KB

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