summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
Diffstat (limited to 'demos')
-rw-r--r--demos/misc/window_management/control.gd186
-rw-r--r--demos/misc/window_management/engine.cfg19
-rw-r--r--demos/misc/window_management/icon.pngbin0 -> 3639 bytes
-rw-r--r--demos/misc/window_management/icon.png.flags1
-rw-r--r--demos/misc/window_management/observer/observer.gd79
-rw-r--r--demos/misc/window_management/observer/observer.scnbin0 -> 1786 bytes
-rw-r--r--demos/misc/window_management/window_management.scnbin0 -> 4850 bytes
7 files changed, 285 insertions, 0 deletions
diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd
new file mode 100644
index 0000000000..50fc3a3765
--- /dev/null
+++ b/demos/misc/window_management/control.gd
@@ -0,0 +1,186 @@
+
+extends Control
+
+func _fixed_process(delta):
+
+ var modetext = "Mode:\n"
+
+ if(OS.is_fullscreen()):
+ modetext += "Fullscreen\n"
+ else:
+ modetext += "Windowed\n"
+
+ if(!OS.is_resizable()):
+ modetext += "FixedSize\n"
+
+ if(OS.is_minimized()):
+ modetext += "Minimized\n"
+
+ if(OS.is_maximized()):
+ modetext += "Maximized\n"
+
+ if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED):
+ modetext += "MouseGrab\n"
+
+ get_node("Label_Mode").set_text(modetext)
+
+ get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) )
+
+ get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) )
+
+ get_node("Label_MousePosition").set_text(str("Mouse Position:\n", Input.get_mouse_pos() ) )
+
+ get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) )
+
+ get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_screen() ) )
+
+ get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) )
+
+ get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position() ) )
+
+ if(OS.get_screen_count() > 1):
+ get_node("Button_Screen0").show()
+ get_node("Button_Screen1").show()
+ get_node("Label_Screen1_Resolution").show()
+ get_node("Label_Screen1_Position").show()
+ get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) )
+ get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) )
+ else:
+ get_node("Button_Screen0").hide()
+ get_node("Button_Screen1").hide()
+ get_node("Label_Screen1_Resolution").hide()
+ get_node("Label_Screen1_Position").hide()
+
+ if( Input.is_action_pressed("ui_right")):
+ OS.set_screen(1)
+
+ if( Input.is_action_pressed("ui_left")):
+ OS.set_screen(0)
+
+ if( Input.is_action_pressed("ui_up")):
+ OS.set_fullscreen(true)
+
+ if( Input.is_action_pressed("ui_down")):
+ OS.set_fullscreen(false)
+
+ get_node("Button_Fullscreen").set_pressed( OS.is_fullscreen() )
+ get_node("Button_FixedSize").set_pressed( !OS.is_resizable() )
+ get_node("Button_Minimized").set_pressed( OS.is_minimized() )
+ get_node("Button_Maximized").set_pressed( OS.is_maximized() )
+ get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED )
+
+
+func check_wm_api():
+ var s = ""
+ if( !OS.has_method("get_screen_count") ):
+ s += " - get_screen_count()\n"
+
+ if( !OS.has_method("get_screen") ):
+ s += " - get_screen()\n"
+
+ if( !OS.has_method("set_screen") ):
+ s += " - set_screen()\n"
+
+ if( !OS.has_method("get_screen_position") ):
+ s += " - get_screen_position()\n"
+
+ if( !OS.has_method("get_screen_size") ):
+ s += " - get_screen_size()\n"
+
+ if( !OS.has_method("get_window_position") ):
+ s += " - get_window_position()\n"
+
+ if( !OS.has_method("set_window_position") ):
+ s += " - set_window_position()\n"
+
+ if( !OS.has_method("get_window_size") ):
+ s += " - get_window_size()\n"
+
+ if( !OS.has_method("set_window_size") ):
+ s += " - set_window_size()\n"
+
+ if( !OS.has_method("set_fullscreen") ):
+ s += " - set_fullscreen()\n"
+
+ if( !OS.has_method("is_fullscreen") ):
+ s += " - is_fullscreen()\n"
+
+ if( !OS.has_method("set_resizable") ):
+ s += " - set_resizable()\n"
+
+ if( !OS.has_method("is_resizable") ):
+ s += " - is_resizable()\n"
+
+ if( !OS.has_method("set_minimized") ):
+ s += " - set_minimized()\n"
+
+ if( !OS.has_method("is_minimized") ):
+ s += " - is_minimized()\n"
+
+ if( !OS.has_method("set_maximized") ):
+ s += " - set_maximized()\n"
+
+ if( !OS.has_method("is_maximized") ):
+ s += " - is_maximized()\n"
+
+ if( s.length() == 0 ):
+ return true
+ else:
+ var text = get_node("ImplementationDialog/Text").get_text()
+ get_node("ImplementationDialog/Text").set_text( text + s )
+ get_node("ImplementationDialog").show()
+ return false
+
+
+func _ready():
+ if( check_wm_api() ):
+ set_fixed_process(true)
+
+
+func _on_Button_MoveTo_pressed():
+ OS.set_window_position( Vector2(100,100) )
+
+
+func _on_Button_Resize_pressed():
+ OS.set_window_size( Vector2(1024,768) )
+
+
+func _on_Button_Screen0_pressed():
+ OS.set_screen(0)
+
+
+func _on_Button_Screen1_pressed():
+ OS.set_screen(1)
+
+
+func _on_Button_Fullscreen_pressed():
+ if(OS.is_fullscreen()):
+ OS.set_fullscreen(false)
+ else:
+ OS.set_fullscreen(true)
+
+
+func _on_Button_FixedSize_pressed():
+ if(OS.is_resizable()):
+ OS.set_resizable(false)
+ else:
+ OS.set_resizable(true)
+
+
+func _on_Button_Minimized_pressed():
+ if(OS.is_minimized()):
+ OS.set_minimized(false)
+ else:
+ OS.set_minimized(true)
+
+
+func _on_Button_Maximized_pressed():
+ if(OS.is_maximized()):
+ OS.set_maximized(false)
+ else:
+ OS.set_maximized(true)
+
+
+func _on_Button_Mouse_Grab_pressed():
+ var observer = get_node("../Observer")
+ observer.state = observer.STATE_GRAB
diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg
new file mode 100644
index 0000000000..c53bd45fb7
--- /dev/null
+++ b/demos/misc/window_management/engine.cfg
@@ -0,0 +1,19 @@
+[application]
+
+name="window_management"
+main_scene="res://window_management.scn"
+icon="icon.png"
+
+[display]
+
+fullscreen=false
+resizable=true
+width=800
+height=600
+
+[input]
+
+move_forward=[key(W)]
+move_backwards=[key(S)]
+move_left=[key(A)]
+move_right=[key(D)]
diff --git a/demos/misc/window_management/icon.png b/demos/misc/window_management/icon.png
new file mode 100644
index 0000000000..0c422e37b0
--- /dev/null
+++ b/demos/misc/window_management/icon.png
Binary files differ
diff --git a/demos/misc/window_management/icon.png.flags b/demos/misc/window_management/icon.png.flags
new file mode 100644
index 0000000000..5130fd1aab
--- /dev/null
+++ b/demos/misc/window_management/icon.png.flags
@@ -0,0 +1 @@
+gen_mipmaps=false
diff --git a/demos/misc/window_management/observer/observer.gd b/demos/misc/window_management/observer/observer.gd
new file mode 100644
index 0000000000..d27912a670
--- /dev/null
+++ b/demos/misc/window_management/observer/observer.gd
@@ -0,0 +1,79 @@
+
+extends Spatial
+
+var r_pos = Vector2()
+var state
+
+const STATE_MENU=0
+const STATE_GRAB=1
+
+func direction(vector):
+ var v = get_node("Camera").get_global_transform().basis * vector
+ v = v.normalized()
+
+ return v
+
+
+func impulse(event, action):
+ if(event.is_action(action) && event.is_pressed() && !event.is_echo()):
+ return true
+ else:
+ return false
+
+
+func _fixed_process(delta):
+
+ if(state != STATE_GRAB):
+ return
+
+ if(Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED):
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+
+ var dir = Vector3()
+ var cam = get_global_transform()
+ var org = get_translation()
+
+ if (Input.is_action_pressed("move_forward")):
+ dir += direction(Vector3(0,0,-1))
+ if (Input.is_action_pressed("move_backwards")):
+ dir += direction(Vector3(0,0,1))
+ if (Input.is_action_pressed("move_left")):
+ dir += direction(Vector3(-1,0,0))
+ if (Input.is_action_pressed("move_right")):
+ dir += direction(Vector3(1,0,0))
+
+ dir = dir.normalized()
+
+ move(dir * 10 * delta)
+ var d = delta * 0.1
+
+ var yaw = get_transform().rotated(Vector3(0,1,0), d * r_pos.x)
+ set_transform(yaw)
+
+ var cam = get_node("Camera")
+ var pitch = cam.get_transform().rotated(Vector3(1,0,0), d * r_pos.y)
+ cam.set_transform(pitch)
+
+ r_pos.x = 0.0
+ r_pos.y = 0.0
+
+
+func _input( event ):
+ if(event.type == InputEvent.MOUSE_MOTION):
+ r_pos = event.relative_pos
+
+ if(impulse(event, "ui_cancel")):
+ if(state == STATE_GRAB):
+ Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
+ state = STATE_MENU
+ else:
+ Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
+ state = STATE_GRAB
+
+
+func _ready():
+ set_fixed_process(true)
+ set_process_input(true)
+
+ state = STATE_MENU
+
diff --git a/demos/misc/window_management/observer/observer.scn b/demos/misc/window_management/observer/observer.scn
new file mode 100644
index 0000000000..da29ad62b8
--- /dev/null
+++ b/demos/misc/window_management/observer/observer.scn
Binary files differ
diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn
new file mode 100644
index 0000000000..14d0da0415
--- /dev/null
+++ b/demos/misc/window_management/window_management.scn
Binary files differ