diff --git a/mobile/multitouch_view/Main.gd b/mobile/multitouch_view/Main.gd index d31d612d..14a89e33 100644 --- a/mobile/multitouch_view/Main.gd +++ b/mobile/multitouch_view/Main.gd @@ -9,14 +9,14 @@ func _draw(): # Get the touch helper singleton. var touch_helper = get_node("/root/TouchHelper") # Draw every pointer as a circle. - for ptr_id in touch_helper.state.keys(): - var pos = touch_helper.state[ptr_id] - var color = _get_color_for_ptr_id(ptr_id) + for ptr_index in touch_helper.state.keys(): + var pos = touch_helper.state[ptr_index] + var color = _get_color_for_ptr_index(ptr_index) color.a = 0.75 draw_circle(pos, 40.0, color) # Just a way of getting different colors. -func _get_color_for_ptr_id(id): - var x = (id % 7) + 1 +func _get_color_for_ptr_index(index): + var x = (index % 7) + 1 return Color(float(bool(x & 1)), float(bool(x & 2)), float(bool(x & 4))) diff --git a/mobile/multitouch_view/README.md b/mobile/multitouch_view/README.md index bf1378e5..33068e11 100644 --- a/mobile/multitouch_view/README.md +++ b/mobile/multitouch_view/README.md @@ -1,6 +1,6 @@ # Multitouch View with GDScript -Simple debugger for multitouch input. Shows red dots everywhere you press. +Simple debugger for multitouch input. Shows colored dots everywhere you press. Language: GDScript diff --git a/mobile/multitouch_view/TouchHelper.gd b/mobile/multitouch_view/TouchHelper.gd index 13aeb541..ab14b298 100644 --- a/mobile/multitouch_view/TouchHelper.gd +++ b/mobile/multitouch_view/TouchHelper.gd @@ -1,29 +1,20 @@ extends Node # This will track the position of every pointer in its public `state` property, which is a -# Dictionary, in which each key is a pointer id (integer) and each value its position (Vector2). +# Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2). # It works by listening to input events not handled by other means. # It also remaps the pointer indices coming from the OS to the lowest available to be friendlier. # It can be conveniently setup as a singleton. var state = {} -var _os2own = {} func _unhandled_input(event): if event is InputEventScreenTouch: if event.pressed: # Down. - if !_os2own.has(event.index): # Defensively discard index if already known. - var ptr_id = state.size() - state[ptr_id] = event.position - _os2own[event.index] = ptr_id + state[event.index] = event.position else: # Up. - if _os2own.has(event.index): # Defensively discard index if not known. - var ptr_id = _os2own[event.index] - state.erase(ptr_id) - _os2own.erase(event.index) + state.erase(event.index) get_tree().set_input_as_handled() elif event is InputEventScreenDrag: # Movement. - if _os2own.has(event.index): # Defensively discard index if not known. - var ptr_id = _os2own[event.index] - state[ptr_id] = event.position + state[event.index] = event.position get_tree().set_input_as_handled() diff --git a/mobile/multitouch_view/screenshots/multitouch.png b/mobile/multitouch_view/screenshots/multitouch.png index 5010f3e4..0161035e 100644 Binary files a/mobile/multitouch_view/screenshots/multitouch.png and b/mobile/multitouch_view/screenshots/multitouch.png differ diff --git a/visual_script/multitouch_view/TouchHelper.gd b/visual_script/multitouch_view/TouchHelper.gd index 13aeb541..ab14b298 100644 --- a/visual_script/multitouch_view/TouchHelper.gd +++ b/visual_script/multitouch_view/TouchHelper.gd @@ -1,29 +1,20 @@ extends Node # This will track the position of every pointer in its public `state` property, which is a -# Dictionary, in which each key is a pointer id (integer) and each value its position (Vector2). +# Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2). # It works by listening to input events not handled by other means. # It also remaps the pointer indices coming from the OS to the lowest available to be friendlier. # It can be conveniently setup as a singleton. var state = {} -var _os2own = {} func _unhandled_input(event): if event is InputEventScreenTouch: if event.pressed: # Down. - if !_os2own.has(event.index): # Defensively discard index if already known. - var ptr_id = state.size() - state[ptr_id] = event.position - _os2own[event.index] = ptr_id + state[event.index] = event.position else: # Up. - if _os2own.has(event.index): # Defensively discard index if not known. - var ptr_id = _os2own[event.index] - state.erase(ptr_id) - _os2own.erase(event.index) + state.erase(event.index) get_tree().set_input_as_handled() elif event is InputEventScreenDrag: # Movement. - if _os2own.has(event.index): # Defensively discard index if not known. - var ptr_id = _os2own[event.index] - state[ptr_id] = event.position + state[event.index] = event.position get_tree().set_input_as_handled()