summaryrefslogtreecommitdiff
path: root/demos/viewport/gui_in_3d
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2015-12-09 08:38:23 +0100
committerRémi Verschelde <rverschelde@gmail.com>2015-12-09 08:38:23 +0100
commit8639cecf4cedd56452b47503be19c44b304cd02f (patch)
treee2a795da15e40c7d9d5b82e33378f8dbf0eaf67a /demos/viewport/gui_in_3d
parentefbb834936fdc9da9789ad37c9cc61e0b90cda95 (diff)
Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions: - space after a comma in lists of arguments - space around weak operators (+, -), no space around strong operators (*, /) - space after a comment start (#) - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now) - function blocks separate by two newlines The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
Diffstat (limited to 'demos/viewport/gui_in_3d')
-rw-r--r--demos/viewport/gui_in_3d/gui.scnbin3267 -> 2579 bytes
-rw-r--r--demos/viewport/gui_in_3d/gui_3d.gd69
-rw-r--r--demos/viewport/gui_in_3d/gui_3d.scnbin4668 -> 6137 bytes
3 files changed, 31 insertions, 38 deletions
diff --git a/demos/viewport/gui_in_3d/gui.scn b/demos/viewport/gui_in_3d/gui.scn
index 5e8c04754e..d7daa30340 100644
--- a/demos/viewport/gui_in_3d/gui.scn
+++ b/demos/viewport/gui_in_3d/gui.scn
Binary files differ
diff --git a/demos/viewport/gui_in_3d/gui_3d.gd b/demos/viewport/gui_in_3d/gui_3d.gd
index c2a9df0069..8b9e352682 100644
--- a/demos/viewport/gui_in_3d/gui_3d.gd
+++ b/demos/viewport/gui_in_3d/gui_3d.gd
@@ -1,45 +1,38 @@
extends Spatial
-# member variables here, example:
-# var a=2
-# var b="textvar"
-
-var prev_pos=null
-
-
-func _input( ev ):
- #all other (non-mouse) events
- if (not ev.type in [InputEvent.MOUSE_BUTTON,InputEvent.MOUSE_MOTION,InputEvent.SCREEN_DRAG,InputEvent.SCREEN_TOUCH]):
- get_node("viewport").input(ev)
-
-
-#mouse events for area
-func _on_area_input_event( camera, ev, click_pos, click_normal, shape_idx ):
-
- #use click pos (click in 3d space, convert to area space
- var pos = get_node("area").get_global_transform().affine_inverse() * click_pos
- #convert to 2D
- pos = Vector2(pos.x,pos.y)
- #convert to viewport coordinate system
- pos.x=(pos.x+1.5)*100
- pos.y=(-pos.y+0.75)*100
- #set to event
- ev.pos=pos
- ev.global_pos=pos
- if (prev_pos==null):
- prev_pos=pos
- if (ev.type==InputEvent.MOUSE_MOTION):
- ev.relative_pos=pos-prev_pos
- prev_pos=pos
-
- get_node("viewport").input(ev)
-
-
+# member variables
+var prev_pos = null
+
+
+func _input(event):
+ # all other (non-mouse) events
+ if (not event.type in [InputEvent.MOUSE_BUTTON, InputEvent.MOUSE_MOTION, InputEvent.SCREEN_DRAG, InputEvent.SCREEN_TOUCH]):
+ get_node("viewport").input(event)
+
+
+# mouse events for area
+func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
+ # use click pos (click in 3d space, convert to area space)
+ var pos = get_node("area").get_global_transform().affine_inverse()*click_pos
+ # convert to 2D
+ pos = Vector2(pos.x, pos.y)
+ # convert to viewport coordinate system
+ pos.x = (pos.x + 1.5)*100
+ pos.y = (-pos.y + 0.75)*100
+ # set to event
+ event.pos = pos
+ event.global_pos = pos
+ if (prev_pos == null):
+ prev_pos = pos
+ if (event.type == InputEvent.MOUSE_MOTION):
+ event.relative_pos = pos - prev_pos
+ prev_pos = pos
+ # sned the event to the viewport
+ get_node("viewport").input(event)
+
func _ready():
# Initalization here
- get_node("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture() )
+ get_node("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture())
set_process_input(true)
- pass
-
diff --git a/demos/viewport/gui_in_3d/gui_3d.scn b/demos/viewport/gui_in_3d/gui_3d.scn
index c69d4dc73f..0541e7b142 100644
--- a/demos/viewport/gui_in_3d/gui_3d.scn
+++ b/demos/viewport/gui_in_3d/gui_3d.scn
Binary files differ