fix(input): D-pad middle measures the distance to each arm itself

This commit is contained in:
maxjivi05 committed 2026-12-01 21:41:01 -05:00
1 parent f7820da1c6
commit 50be439943
2 files changed
+7 -2

No files matched your search

@@ -278,8 +278,9 @@ class InputSurfaceView(
if (!crossDpadHole.contains(x - originX, y - originY)) return null
val hx = x - originX
val hy = y - originY
return listOf(up to hy - crossDpadHole.top, right to crossDpadHole.right - hx, down to crossDpadHole.bottom - hy, left to hx - crossDpadHole.left)
.minBy { it.second }.first
return listOf(up, right, down, left).minBy { arm ->
hypot(max(max(arm.left - hx, hx - arm.right), 0f), max(max(arm.top - hy, hy - arm.bottom), 0f))
}
}
private fun crossed(buttons: List<HoldButton>, bounds: RectF): Boolean {
@@ -270,6 +270,10 @@ class InputSurfaceTouchTest {
assertEquals(1, state().hatX())
assertEquals(0, state().hatY())
touch(MotionEvent.ACTION_UP, 1 to (530f to 290f))
touch(MotionEvent.ACTION_DOWN, 1 to (530f to 180f))
assertEquals(-1, state().hatY())
assertEquals(0, state().hatX())
touch(MotionEvent.ACTION_UP, 1 to (530f to 180f))
show(InputSurfaceElement(InputControl.UP, .2f, .1f, .1f, .15f),
InputSurfaceElement(InputControl.DOWN, .7f, .6f, .1f, .15f),
InputSurfaceElement(InputControl.LEFT, .1f, .35f, .15f, .2f),