MobilePort: ui_scale() (clampf(4.3 / the screen's shorter side in inches, 1, 1.8) times the
Interface size; 1 on desktop), a size-class fallback (below 500 pt = phone, 1.6) when the
density is 0 or implausible, safe_rect(ci) (the display's safe area mapped into ci's canvas
through the final transform), minimum_target() (44 pt in canvas pixels), and the `forced`
override for tests. The desktop preview (-- --mobile) plays the phone in the window:
--safe-area=l,t,r,b insets it, --dpi=N sets its density, and without --dpi a 16:9-or-wider
window is a 2.7 in phone (about 1.6x) and a squarer one a 6 in iPad (1x).
GameSettings: interface_size (0.8-1.3, saved under [touch]) and apply_scale(), which sets the
window's content_scale_factor (always 1 on desktop). PerfTest shows the screen, density, safe
area, and resulting scale, to check the density on a device.
Test kit: test_mobile (last in SUITES) runs game/tests/mobile/*_test.gd in name order and puts
the root window back between files; mobile/touch.gd sends touches through
Input.parse_input_event; scale_test covers phones, iPads, desktop, the safe rect, and the target;
sticks_test is the 8c81d81 driver's 24 checks. game/tools/capture_mobile.gd takes the phone
screenshots.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2 KiB
GDScript
49 lines
2 KiB
GDScript
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()
|