feat(input): both sticks and both trackpads for Steam kits in portrait

This commit is contained in:
Kurt Himebauch committed 2026-11-18 20:19:02 -05:00
1 parent 0364792111
commit b29a5ef8aa
5 files changed
+50 -13

No files matched your search

@@ -9,6 +9,7 @@ object GamepadGeometry {
VIEW, STEAM, QAM, MENU,
PANELS,
L4, L5, R5, R4,
LEFT_TOUCH, RIGHT_TOUCH,
}
data class Box(val cx: Float, val cy: Float, val width: Float, val height: Float) {
@@ -26,10 +27,11 @@ object GamepadGeometry {
fun tall(w: Float, h: Float): Boolean = h >= w * 0.45f
fun layout(w: Float, h: Float, density: Float, portraitDock: Boolean = false, grips: Boolean = true, upright: Boolean = false): Map<Slot, Box> {
fun layout(w: Float, h: Float, density: Float, portraitDock: Boolean = false, grips: Boolean = true, upright: Boolean = false,
trackpads: Boolean = false): Map<Slot, Box> {
if (w <= 0f || h <= 0f) return emptyMap()
if (upright || portraitDock && h >= w * 0.6f && w >= 300 * density && h >= 300 * density) {
return portraitLayout(w, h, density, grips)
return portraitLayout(w, h, density, grips, trackpads)
}
val pad = 8 * density
val buttonH = 40 * density
@@ -96,7 +98,7 @@ object GamepadGeometry {
* The panel under a portrait game: shoulders with View and Menu across the top, the back grips under them when the kit has
* them, then the d-pad and face buttons and, along the bottom edge, the sticks or trackpads, each as large as the panel allows.
*/
private fun portraitLayout(w: Float, h: Float, density: Float, grips: Boolean): Map<Slot, Box> {
private fun portraitLayout(w: Float, h: Float, density: Float, grips: Boolean, trackpads: Boolean): Map<Slot, Box> {
val pad = 8 * density
val gap = 8 * density
val buttonH = 44 * density
@@ -114,6 +116,21 @@ object GamepadGeometry {
areaTop += gripH + gap
}
val area = h - pad - areaTop - gap
if (trackpads) {
val second = min(w * 0.42f, area * 0.5f)
val rowH = area - second
val col = (w - 2 * pad - 3 * gap) / 4f
val stick = min(col, rowH)
val rowY = h - pad - rowH / 2f
val secondY = areaTop + second / 2f
boxes[Slot.LEFT_SECOND] = Box(w * 0.25f, secondY, second, second)
boxes[Slot.RIGHT_SECOND] = Box(w * 0.75f, secondY, second, second)
boxes[Slot.LEFT_TOUCH] = Box(pad + col / 2f, rowY, col, rowH)
boxes[Slot.LEFT_MAIN] = Box(pad + col * 1.5f + gap, rowY, stick, stick)
boxes[Slot.RIGHT_MAIN] = Box(w - pad - col * 1.5f - gap, rowY, stick, stick)
boxes[Slot.RIGHT_TOUCH] = Box(w - pad - col / 2f, rowY, col, rowH)
return boxes
}
val main = min(w * 0.46f, area * 0.53f)
val second = min(w * 0.42f, area - main)
val secondY = areaTop + second / 2f
@@ -118,7 +118,7 @@ object KitLayout {
val inner = (w - safe.left - safe.right).coerceAtLeast(1f)
val area = (min(h * .6f, inner * 1.15f) * scale).coerceAtMost(h - safe.top - safe.bottom - row).coerceAtLeast(1f)
val top = h - safe.bottom - row - area
val pad = dock(context, kit, inner.toInt(), area.toInt(), true, InputControl.LS, if (kit.steam) InputControl.RIGHT_PAD else InputControl.RS, upright = true).map { e ->
val pad = dock(context, kit, inner.toInt(), area.toInt(), true, InputControl.LS, InputControl.RS, upright = true).map { e ->
e.copy(x = (safe.left + e.x * inner) / w, y = (top + e.y * area) / h, width = e.width * inner / w, height = e.height * area / h,
floating = e.kind == InputElementKind.STICK)
}
@@ -154,7 +154,8 @@ object KitLayout {
fun dock(context: Context, kit: PadKit, width: Int, height: Int, portrait: Boolean, left: InputControl, right: InputControl,
upright: Boolean = false): List<InputSurfaceElement> {
val w = width.toFloat(); val h = height.toFloat()
val boxes = GamepadGeometry.layout(w, h, context.resources.displayMetrics.density, portrait, grips = kit.steam, upright = upright)
val boxes = GamepadGeometry.layout(w, h, context.resources.displayMetrics.density, portrait, grips = kit.steam, upright = upright,
trackpads = kit.steam)
val placed = mutableListOf<InputSurfaceElement>()
fun put(control: InputControl, box: GamepadGeometry.Box?, shape: InputButtonShape, id: String = "legacy:${control.id}",
kind: InputElementKind = InputElementKind.from(control), name: String = kit.name(control)) {
@@ -162,8 +163,13 @@ object KitLayout {
placed += InputSurfaceElement(control, b.left / w, b.top / h, b.width / w, b.height / h, id, kind, name, floating = false, buttonShape = shape).bounded()
}
fun square(box: GamepadGeometry.Box?) = box?.let { val side = min(it.width, it.height); GamepadGeometry.Box(it.cx, it.cy, side, side) }
val leftMain = if (kit.steam || left != InputControl.LEFT_PAD) left else InputControl.LS
val rightMain = if (kit.steam || right != InputControl.RIGHT_PAD) right else InputControl.RS
val four = GamepadGeometry.Slot.LEFT_TOUCH in boxes
val leftMain = if (four || !kit.steam && left == InputControl.LEFT_PAD) InputControl.LS else left
val rightMain = if (four || !kit.steam && right == InputControl.RIGHT_PAD) InputControl.RS else right
if (four) {
put(InputControl.LEFT_PAD, boxes[GamepadGeometry.Slot.LEFT_TOUCH], InputButtonShape.ROUNDED)
put(InputControl.RIGHT_PAD, boxes[GamepadGeometry.Slot.RIGHT_TOUCH], InputButtonShape.ROUNDED)
}
put(leftMain, square(boxes[GamepadGeometry.Slot.LEFT_MAIN]), InputButtonShape.CIRCLE)
put(InputControl.LS, square(boxes[GamepadGeometry.Slot.LEFT_SECOND]), InputButtonShape.ROUNDED, DPAD_ID, InputElementKind.DPAD, "D-pad")
put(rightMain, square(boxes[GamepadGeometry.Slot.RIGHT_MAIN]), InputButtonShape.CIRCLE)