extends RefCounted ## Fingers for the phone tests (game/tests/mobile/), sent the way a phone sends them: through ## Input.parse_input_event, so Godot's touch-to-click emulation runs too (finger 0 is also the ## left mouse button), and delivered at once (Input.flush_buffered_events), so a check right ## after a call sees its effect on the GUI and on _unhandled_input. ## Points are canvas coordinates of the root viewport (what a full-rect HUD Control sees, at any ## interface scale); they're turned into window pixels through the root's final transform, as ## a phone's touches arrive. ## const Touch := preload("res://game/tests/mobile/touch.gd") ## Touch.touch(0, at, true) # finger 0 down at `at` ## Touch.drag(0, at, at + Vector2(150, 0)) # it moves (one drag event; the finger stays down) ## Touch.touch(0, at + Vector2(150, 0), false) # and lifts ## Touch.tap(1, at) # finger 1 down and up at once ## Finger i goes down (pressed) or lifts at this canvas point. static func touch(i: int, canvas_pos: Vector2, pressed: bool) -> void: var e := InputEventScreenTouch.new() e.index = i e.pressed = pressed e.position = window_pos(canvas_pos) _send(e) ## Finger i, already down, moves from one canvas point to another (one drag event). static func drag(i: int, from: Vector2, to: Vector2) -> void: var e := InputEventScreenDrag.new() e.index = i e.position = window_pos(to) e.relative = window_pos(to) - window_pos(from) e.screen_relative = e.relative _send(e) ## Finger i taps this canvas point: down, then up. static func tap(i: int, canvas_pos: Vector2) -> void: touch(i, canvas_pos, true) touch(i, canvas_pos, false) ## A canvas point of the root viewport in window pixels (where a phone reports a touch there). static func window_pos(canvas_pos: Vector2) -> Vector2: var tree := Engine.get_main_loop() as SceneTree return tree.root.get_final_transform() * canvas_pos static func _send(e: InputEvent) -> void: Input.parse_input_event(e) Input.flush_buffered_events()