fix(input): move and resize the on-screen D-pad as one control, per-control button size and sizes above 100% (#2996)

* fix(input): move and resize the D-pad as one control, per-control button size and sizes above 100%

* fix(input): controller art for copied layouts, keep the minimum size when shrinking the D-pad

Copies and per-game versions of the on-screen gamepad now draw the same controller art and placement as the original, and resizing the D-pad from a corner or the per-control slider keeps every arrow at a usable size.

* Keep other controls' moves when undoing a repeated resize
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-21 23:47:35 -05:00
1 parent a2587f4f20
commit 3577073ab9
12 files changed
+279 -44

No files matched your search

@@ -13,11 +13,13 @@ internal class ControllerOverlayGeometry(
private val density = metrics.density
private val dpi = metrics.ydpi.takeIf { it in metrics.densityDpi * .6f..metrics.densityDpi * 1.6f }
?: metrics.densityDpi.toFloat()
private val unit = minOf(
min(w / 1600f, h / 900f) * min(1f, 80f / max(h / dpi * 25.4f, 1f)) * scale,
private val fit = minOf(
min(w / 1600f, h / 900f) * min(1f, 80f / max(h / dpi * 25.4f, 1f)),
(w - safe.left - safe.right).coerceAtLeast(1f) / 1200f,
(h - safe.top - safe.bottom).coerceAtLeast(1f) / 900f,
)
private val unit = fit * min(scale, 1f)
private val size = fit * scale
private fun anchor(value: Float, reference: Float, extent: Float, start: Int, end: Int): Float {
val low = start + value * unit
@@ -37,18 +39,18 @@ internal class ControllerOverlayGeometry(
if (!kit.steam) return placeStandardPad(elements, kit)
val leftEdge = safe.left + 52f * density
val middle = (w + safe.left - safe.right) / 2f
val keyboard = Box(max(x(136f), leftEdge + 46f * unit), y(848f), 46f).takeIf { elements.any { it.id == KEYBOARD } }
val keyboard = Box(max(x(136f), leftEdge + 46f * size), y(848f), 46f).takeIf { elements.any { it.id == KEYBOARD } }
val row = fitRow(listOfNotNull(keyboard,
Box(max(x(370f), leftEdge + 66f * unit), y(852f), 66f, 30f),
Box(max(x(370f), leftEdge + 66f * size), y(852f), 66f, 30f),
Box(middle - 140f * unit, y(850f), 46f, 26f),
Box(middle + 140f * unit, y(850f), 46f, 26f),
Box(x(1230f), y(852f), 66f, 30f)), leftEdge)
val (guide, select, start, qam) = row.takeLast(4)
val positions = shoulders() + face(1375f, 345f, 96f) + mapOf(
InputControl.UP to Box(x(220f), y(345f) - 102.5f * unit, 55.5f, 47.5f),
InputControl.RIGHT to Box(x(220f) + 102.5f * unit, y(345f), 47.5f, 55.5f),
InputControl.DOWN to Box(x(220f), y(345f) + 102.5f * unit, 55.5f, 47.5f),
InputControl.LEFT to Box(x(220f) - 102.5f * unit, y(345f), 47.5f, 55.5f),
InputControl.UP to Box(x(220f), y(345f) - 102.5f * size, 55.5f, 47.5f),
InputControl.RIGHT to Box(x(220f) + 102.5f * size, y(345f), 47.5f, 55.5f),
InputControl.DOWN to Box(x(220f), y(345f) + 102.5f * size, 55.5f, 47.5f),
InputControl.LEFT to Box(x(220f) - 102.5f * size, y(345f), 47.5f, 55.5f),
InputControl.LS to Box(x(290f), y(640f), 96f),
InputControl.RS to Box(x(1310f), y(640f), 96f),
InputControl.SELECT to select,
@@ -85,7 +87,7 @@ internal class ControllerOverlayGeometry(
private fun placeStandardPad(elements: List<InputSurfaceElement>, kit: PadKit): List<InputSurfaceElement> {
val leftEdge = safe.left + 52f * density
val middle = (w + safe.left - safe.right) / 2f
val keyboard = Box(max(x(136f), leftEdge + 46f * unit), y(848f), 46f).takeIf { elements.any { it.id == KEYBOARD } }
val keyboard = Box(max(x(136f), leftEdge + 46f * size), y(848f), 46f).takeIf { elements.any { it.id == KEYBOARD } }
val controls = if (kit.playStation) listOf(
InputControl.QAM to Box(x(220f), y(848f), 46f),
InputControl.SELECT to Box(middle - 160f * unit, y(850f), 50f, 30f),
@@ -103,15 +105,15 @@ internal class ControllerOverlayGeometry(
face(1350f, 395f, 96f) + dpad(250f, 395f, 125f, kit.dpad) + mapOf(
InputControl.LS to Box(x(565f), y(690f), 100f),
InputControl.RS to Box(x(1035f), y(690f), 100f),
InputControl.L3 to Box(x(565f) - 135f * unit, y(690f) - 100f * unit, 42f),
InputControl.R3 to Box(x(1035f) + 135f * unit, y(690f) - 100f * unit, 42f),
InputControl.L3 to Box(x(565f) - 135f * size, y(690f) - 100f * size, 42f),
InputControl.R3 to Box(x(1035f) + 135f * size, y(690f) - 100f * size, 42f),
)
} else {
face(1375f, 400f, 94f) + dpad(470f, 675f, 118f, kit.dpad) + mapOf(
InputControl.LS to Box(x(235f), y(400f), 104f),
InputControl.RS to Box(x(1130f), y(690f), 104f),
InputControl.L3 to Box(x(235f) + 150f * unit, y(400f) - 110f * unit, 42f),
InputControl.R3 to Box(x(1130f) + 160f * unit, y(690f) + 100f * unit, 42f),
InputControl.L3 to Box(x(235f) + 150f * size, y(400f) - 110f * size, 42f),
InputControl.R3 to Box(x(1130f) + 160f * size, y(690f) + 100f * size, 42f),
)
}
return elements.map { element ->
@@ -131,16 +133,16 @@ internal class ControllerOverlayGeometry(
)
private fun face(cx: Float, cy: Float, offset: Float) = mapOf(
InputControl.Y to Box(x(cx), y(cy) - offset * unit, 58f),
InputControl.X to Box(x(cx) - offset * unit, y(cy), 58f),
InputControl.B to Box(x(cx) + offset * unit, y(cy), 58f),
InputControl.A to Box(x(cx), y(cy) + offset * unit, 58f),
InputControl.Y to Box(x(cx), y(cy) - offset * size, 58f),
InputControl.X to Box(x(cx) - offset * size, y(cy), 58f),
InputControl.B to Box(x(cx) + offset * size, y(cy), 58f),
InputControl.A to Box(x(cx), y(cy) + offset * size, 58f),
)
private fun dpad(cx: Float, cy: Float, radius: Float, style: DpadStyle): Map<InputControl, Box> {
val inner = radius * if (style == DpadStyle.DISC) .25f else .14f
val depth = (radius - inner) / 2f
val offset = (radius - depth) * unit
val offset = (radius - depth) * size
val side = radius * .25f
return mapOf(
InputControl.UP to Box(x(cx), y(cy) - offset, side, depth),
@@ -160,12 +162,12 @@ internal class ControllerOverlayGeometry(
}
private inner class Box(val cx: Float, val cy: Float, val hw: Float, val hh: Float = hw) {
val width get() = max(hw * 2f * unit, w * .03f)
val width get() = max(hw * 2f * size, w * .03f)
fun at(cx: Float) = Box(cx, cy, hw, hh)
fun place(element: InputSurfaceElement): InputSurfaceElement {
val height = max(hh * 2f * unit, h * .03f)
val height = max(hh * 2f * size, h * .03f)
return element.copy(
x = (cx - width / 2f).coerceIn(safe.left.toFloat(), max(safe.left.toFloat(), w - safe.right - width)) / w,
y = (cy - height / 2f).coerceIn(safe.top.toFloat(), max(safe.top.toFloat(), h - safe.bottom - height)) / h,
@@ -27,6 +27,7 @@ data class SavedInputLayout(
val rotatedScale: Float = 1f,
) {
val editable get() = template == InputLayoutTemplate.CUSTOM
val overlay get() = (origin ?: id).let { it == InputLibraries.OVERLAY || it.startsWith("migrated.layout.") }
val quickButtons get() = QUICK_BUTTONS.filter { button -> elements.any { it.quickButton == button } }
fun withQuickButton(button: InputCommand, shown: Boolean) =
copy(style = style.copy(hidden = if (shown) style.hidden - button else style.hidden + button))
@@ -3,6 +3,8 @@ package com.droiddeck.launcher.input
import android.content.Context
import org.json.JSONArray
import org.json.JSONObject
import kotlin.math.max
import kotlin.math.min
enum class InputElementKind(val control: InputControl) {
BUTTON(InputControl.A), STICK(InputControl.LS), TRACKPAD(InputControl.LEFT_PAD),
@@ -63,6 +65,27 @@ internal fun List<InputSurfaceElement>.scaled(factor: Float): List<InputSurfaceE
width = w, height = h).bounded()
}
internal val DPAD = setOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
internal val InputSurfaceElement.dpadPiece get() = id == "legacy:${control.id}" && control in DPAD
internal fun List<InputSurfaceElement>.groupOf(e: InputSurfaceElement) = if (e.dpadPiece) filter { it.dpadPiece } else listOf(e)
internal fun List<InputSurfaceElement>.frame(): InputSurfaceElement {
val left = minOf { it.x }; val top = minOf { it.y }
return first().copy(x = left, y = top, width = maxOf { it.x + it.width } - left, height = maxOf { it.y + it.height } - top)
}
internal fun List<InputSurfaceElement>.resizedAroundCentre(factor: Float): List<InputSurfaceElement> {
if (isEmpty()) return this
val f = frame()
val k = factor.coerceIn(.03f / minOf { min(it.width, it.height) }, 1f / max(f.width, f.height))
val w = f.width * k; val h = f.height * k
val left = (f.x + f.width / 2 - w / 2).coerceIn(0f, 1f - w)
val top = (f.y + f.height / 2 - h / 2).coerceIn(0f, 1f - h)
return map { it.copy(x = left + (it.x - f.x) * k, y = top + (it.y - f.y) * k, width = it.width * k, height = it.height * k).bounded() }
}
internal fun List<InputSurfaceElement>.withPositionsOf(defaults: List<InputSurfaceElement>): List<InputSurfaceElement> {
val byId = defaults.associateBy { it.id }
return map { e -> byId[e.id]?.let { d -> e.copy(x = d.x, y = d.y, width = d.width, height = d.height).bounded() } ?: e }
@@ -334,7 +334,6 @@ internal class LegacyGamepadLayout(private val context: Context, private val wid
const val STICK_REACH = 1.25f
const val LEGACY_DPAD_RADIUS_DP = 26f
const val LEGACY_DPAD_OFFSET_DP = 52f
val DPAD = setOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
const val KEYBOARD_ID = "builtin:keyboard"
const val KEYBOARD_RADIUS_DP = 18f
const val KEYBOARD_X_DP = 90f
@@ -12,7 +12,7 @@ import kotlin.math.roundToInt
object OnScreenLayout {
internal fun supportsFloatingSteamControls(controller: String, layout: SavedInputLayout?) =
layout?.id == InputLibraries.OVERLAY &&
layout?.overlay == true &&
(controller == SessionPrefs.CONTROLLER_DECK || controller == SessionPrefs.CONTROLLER_STEAM)
data class Dock(val portrait: Boolean, val grips: Boolean, val left: InputControl = InputControl.LS, val right: InputControl = InputControl.RS) {
@@ -156,7 +156,7 @@ object OnScreenLayout {
if (gamepad.any { it.id.startsWith("legacy:") }) {
val named = layout.id.removePrefix("migrated.layout.").takeIf { it != layout.id }?.split('x')?.mapNotNull { it.toIntOrNull() }
?.takeIf { it.size == 2 && it.all { size -> size > 0 } }?.let { it[0] to it[1] }
val aspectSize = layout.aspect.takeIf { layout.id == InputLibraries.OVERLAY && it > 0f }
val aspectSize = layout.aspect.takeIf { layout.overlay && it > 0f }
?.let { (it * height).roundToInt().coerceAtLeast(1) to height }
for ((w, h) in listOfNotNull(named, width to height, aspectSize, long to short, short to long).distinct()) {
val generator = LegacyGamepadLayout(display, w, h, scale = layout.scale)
@@ -42,7 +42,7 @@ internal enum class PadKit(val face: FaceGlyphs, val dpad: DpadStyle, val stick:
companion object {
fun forOverlay(context: Context, layout: SavedInputLayout?): PadKit? =
if (layout?.id != InputLibraries.OVERLAY) null else when (SessionPrefs.steamController(context)) {
if (layout?.overlay != true) null else when (SessionPrefs.steamController(context)) {
SessionPrefs.CONTROLLER_DECK -> STEAM_DECK
SessionPrefs.CONTROLLER_STEAM -> STEAM_CONTROLLER
SessionPrefs.CONTROLLER_XBOX360 -> XBOX
@@ -97,8 +97,13 @@ private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputB
var aspect by mutableFloatStateOf(layout.aspect)
private var scaleBase by mutableStateOf<Triple<List<InputSurfaceElement>, List<InputSurfaceElement>, Float>?>(null)
private var scaleValue by mutableIntStateOf(100)
private var pieceBase by mutableStateOf<Triple<List<InputSurfaceElement>, List<InputSurfaceElement>, Int>?>(null)
private var pieceLayout: List<InputSurfaceElement>? = null
private val piece get() = element?.let { e -> (if (elements.any { it.id == e.id }) elements else shown).groupOf(e) }.orEmpty()
val scaleRange get() = if (piece.isEmpty()) 80..125 else 50..200
private val rescales get() = gamepad?.let { pad -> elements.any { it.id in pad.ids } } == true
val scale get() = when {
piece.isNotEmpty() -> pieceBase?.takeIf { it.second == piece && pieceLayout == elements }?.third ?: 100
scaleBase?.second == elements -> scaleValue
rescales -> ((if (canvas.width > 0 && canvas.height > 0 && aspect > 0f && (aspect < 1f) != (canvasAspect < 1f))
OnScreenLayout.oriented(layout, canvas.width, canvas.height).scale else layoutScale) * 100).roundToInt()
@@ -143,6 +148,24 @@ private class SurfaceDraft(val layout: SavedInputLayout, val preset: SavedInputB
} else base.first.scaled(factor)
scaleValue = percent; scaleBase = Triple(base.first, elements, base.third)
}
fun scaleSelected(context: android.content.Context, percent: Int) {
val id = selected ?: return
val adopted = adoptDisplayedFrame(context)
val base = pieceBase?.takeIf { it.second == piece && pieceLayout == elements } ?: run {
if (!adopted && canvas.width > 0 && canvas.height > 0 && shown.isNotEmpty()) {
val open = toolsExpanded
beginEdit(shown, canvasAspect)
toolsExpanded = open
} else if (!adopted) checkpoint()
val start = elements.firstOrNull { it.id == id }?.let { elements.groupOf(it) } ?: return
Triple(start, start, 100)
}
val resized = base.first.resizedAroundCentre(percent / 100f)
val byId = resized.associateBy { it.id }
elements = elements.map { byId[it.id] ?: it }
pieceBase = Triple(base.first, resized, percent)
pieceLayout = elements
}
var shown by mutableStateOf<List<InputSurfaceElement>>(emptyList())
private val canvasAspect get() = canvas.width.toFloat() / canvas.height.coerceAtLeast(1)
@@ -337,7 +360,7 @@ private fun SurfaceCanvas(draft: SurfaceDraft, transparent: Boolean = false) {
view.onBeginEdit = { e, w, h -> draft.beginEdit(e, w.toFloat() / h, if (draft.hasGamepad) GamepadScaler(view.context, w, h, draft.layout) else null) }
view.onResize = { w, h -> draft.canvas = IntSize(w, h) }
view.onDisplayed = { draft.shown = it }
view.onChange = { e -> if (!draft.properties) draft.elements = draft.elements.map { if (it.id == e.id) e else it } }
view.onChange = { changed -> if (!draft.properties) changed.associateBy { it.id }.let { byId -> draft.elements = draft.elements.map { byId[it.id] ?: it } } }
})
}
@@ -407,8 +430,8 @@ private fun SurfaceToolbar(draft: SurfaceDraft, onSave: () -> Unit, onLeave: ()
}
PrimaryButton(stringResource(R.string.input_editor_done), compact = true, onClick = onSave)
}
if (draft.elements.isNotEmpty()) SliderRow(stringResource(R.string.ctrl_size), null, draft.scale, 80..125, step = 5,
format = { "$it%" }, modifier = Modifier.testTag("input-editor-scale")) { draft.scaleAll(context, it) }
if (draft.elements.isNotEmpty()) SliderRow(stringResource(R.string.ctrl_size), null, draft.scale, draft.scaleRange, step = 5,
format = { "$it%" }, modifier = Modifier.testTag("input-editor-scale")) { if (draft.element != null) draft.scaleSelected(context, it) else draft.scaleAll(context, it) }
}
@OptIn(ExperimentalLayoutApi::class)
@@ -16,6 +16,9 @@ import com.droiddeck.launcher.input.PadKit
import com.droiddeck.launcher.input.SavedInputLayout
import com.droiddeck.launcher.input.InputSurfaceElement
import com.droiddeck.launcher.input.InputSurfaceStyle
import com.droiddeck.launcher.input.dpadPiece
import com.droiddeck.launcher.input.frame
import com.droiddeck.launcher.input.groupOf
import com.droiddeck.launcher.input.snapSurfaceElement
import kotlin.math.abs
@@ -41,13 +44,13 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
set(value) { field = value; invalidate() }
var onSelect: (String?) -> Unit = {}
var onBeginEdit: (List<InputSurfaceElement>, Int, Int) -> Unit = { _, _, _ -> }
var onChange: (InputSurfaceElement) -> Unit = {}
var onChange: (List<InputSurfaceElement>) -> Unit = {}
var onResize: (Int, Int) -> Unit = { _, _ -> }
var onDisplayed: (List<InputSurfaceElement>) -> Unit = {}
private val preview = InputSurfaceView(context)
private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = Color.rgb(26, 159, 255); strokeWidth = 2 * resources.displayMetrics.density }
private val radius = 14 * resources.displayMetrics.density
private var original: InputSurfaceElement? = null
private var original: List<InputSurfaceElement> = emptyList()
private var downX = 0f
private var downY = 0f
private var corner = 0
@@ -100,13 +103,15 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
paint.style = Paint.Style.STROKE
guideX?.let { canvas.drawLine(width * it, 0f, width * it, height.toFloat(), paint) }
guideY?.let { canvas.drawLine(0f, height * it, width.toFloat(), height * it, paint) }
val e = visibleElements.firstOrNull { it.id == selected } ?: return
val e = visibleElements.firstOrNull { it.id == selected }?.let { visibleElements.groupOf(it).frame() } ?: return
val l = width * e.x; val t = height * e.y; val r = l + width * e.width; val b = t + height * e.height
paint.style = Paint.Style.STROKE; canvas.drawRect(l, t, r, b, paint)
paint.style = Paint.Style.FILL
for (x in listOf(l, r)) for (y in listOf(t, b)) canvas.drawCircle(x, y, radius / 3, paint)
}
private fun contains(e: InputSurfaceElement, x: Float, y: Float) = x / width in e.x..(e.x + e.width) && y / height in e.y..(e.y + e.height)
private fun clearGuides() { guideX = null; guideY = null; invalidate() }
override fun onInterceptTouchEvent(event: MotionEvent) = true
@@ -118,7 +123,7 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
MotionEvent.ACTION_DOWN -> {
clearGuides()
downX = event.x; downY = event.y; dragging = false; corner = 0
val current = visibleElements.firstOrNull { it.id == selected }
val current = visibleElements.firstOrNull { it.id == selected }?.let { visibleElements.groupOf(it).frame() }
if (current != null) {
val left = width * current.x; val top = height * current.y
val right = left + width * current.width; val bottom = top + height * current.height
@@ -126,13 +131,16 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
val vertical = if (abs(downY - top) < radius) 4 else if (abs(downY - bottom) < radius) 8 else 0
if (horizontal != 0 && vertical != 0) corner = horizontal or vertical
}
original = if (corner != 0) current else visibleElements.asReversed().firstOrNull {
downX / width in it.x..(it.x + it.width) && downY / height in it.y..(it.y + it.height)
}
selected = original?.id; onSelect(selected)
val touched = if (corner != 0) visibleElements.firstOrNull { it.id == selected }
else visibleElements.asReversed().firstOrNull { contains(it, downX, downY) }
?: visibleElements.filter { it.dpadPiece }.takeIf { it.isNotEmpty() && contains(it.frame(), downX, downY) }
?.let { pad -> pad.firstOrNull { it.id == selected } ?: pad.first() }
original = touched?.let { visibleElements.groupOf(it) }.orEmpty()
selected = touched?.id; onSelect(selected)
}
MotionEvent.ACTION_MOVE -> {
val e = original ?: return true
if (original.isEmpty()) return true
val e = original.frame()
if (!dragging && abs(event.x - downX) + abs(event.y - downY) > ViewConfiguration.get(context).scaledTouchSlop) {
dragging = true; onBeginEdit(visibleElements, width, height)
}
@@ -140,20 +148,24 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
val dx = (event.x - downX) / width; val dy = (event.y - downY) / height
val next = if (corner == 0) e.copy(x = (e.x + dx).coerceIn(0f, 1f - e.width), y = (e.y + dy).coerceIn(0f, 1f - e.height))
else {
val left = if (corner and 1 != 0) (e.x + dx).coerceIn(0f, e.x + e.width - .03f) else e.x
val top = if (corner and 4 != 0) (e.y + dy).coerceIn(0f, e.y + e.height - .03f) else e.y
val right = if (corner and 2 != 0) (e.x + e.width + dx).coerceIn(left + .03f, 1f) else e.x + e.width
val bottom = if (corner and 8 != 0) (e.y + e.height + dy).coerceIn(top + .03f, 1f) else e.y + e.height
val minW = (.03f * e.width / original.minOf { it.width }).coerceIn(.03f, e.width.coerceAtLeast(.03f))
val minH = (.03f * e.height / original.minOf { it.height }).coerceIn(.03f, e.height.coerceAtLeast(.03f))
val left = if (corner and 1 != 0) (e.x + dx).coerceIn(0f, (e.x + e.width - minW).coerceAtLeast(0f)) else e.x
val top = if (corner and 4 != 0) (e.y + dy).coerceIn(0f, (e.y + e.height - minH).coerceAtLeast(0f)) else e.y
val right = if (corner and 2 != 0) (e.x + e.width + dx).coerceIn((left + minW).coerceAtMost(1f), 1f) else e.x + e.width
val bottom = if (corner and 8 != 0) (e.y + e.height + dy).coerceIn((top + minH).coerceAtMost(1f), 1f) else e.y + e.height
e.copy(x = left, y = top, width = right - left, height = bottom - top).bounded()
}
val aligned = if (snap) snapSurfaceElement(next, visibleElements.filter { it.id != e.id }, 9 * resources.displayMetrics.density / width,
val aligned = if (snap) snapSurfaceElement(next, visibleElements.filter { v -> original.none { it.id == v.id } }, 9 * resources.displayMetrics.density / width,
9 * resources.displayMetrics.density / height, corner) else null
if (aligned != null && (aligned.x != null && aligned.x != guideX || aligned.y != null && aligned.y != guideY)) performHapticFeedback(HapticFeedbackConstants.CLOCK_TICK)
guideX = aligned?.x; guideY = aligned?.y
onChange(aligned?.element ?: next)
val f = aligned?.element ?: next
val sx = f.width / e.width; val sy = f.height / e.height
onChange(original.map { it.copy(x = f.x + (it.x - e.x) * sx, y = f.y + (it.y - e.y) * sy, width = it.width * sx, height = it.height * sy) })
invalidate()
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { original = null; dragging = false; clearGuides() }
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> { original = emptyList(); dragging = false; clearGuides() }
}
return true
}
@@ -50,6 +50,7 @@ internal class PadArt(context: Context) {
InputControl.LB, InputControl.RB, InputControl.LT, InputControl.RT -> shoulder(canvas, w, h, control, kit, pressed)
InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5 -> grip(canvas, w, h, control.label, pressed)
InputControl.L3, InputControl.R3 -> small(canvas, w, h, control.label, pressed)
InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT -> arrow(canvas, w, h, control, pressed)
InputControl.SELECT, InputControl.START, InputControl.GUIDE, InputControl.QAM -> {
val (shape, icon) = systemLook(kit, control)
system(canvas, w, h, shape, icon, pressed)
@@ -238,6 +239,19 @@ internal class PadArt(context: Context) {
op(bar, Path.Op.UNION)
}
fun arrow(canvas: Canvas, w: Float, h: Float, control: InputControl, pressed: Boolean) {
val cx = w / 2f; val cy = h / 2f
val s = min(w, h) / 2f - dp(2f)
val (dx, dy) = when (control) {
InputControl.UP -> 0f to -1f
InputControl.RIGHT -> 1f to 0f
InputControl.DOWN -> 0f to 1f
else -> -1f to 0f
}
glass(canvas, roundRect(cx - s, cy - s, cx + s, cy + s, s * .32f), pressed)
chevron(canvas, cx, cy, dx, dy, s * .3f, if (pressed) ON_ACCENT else INK, s * .14f)
}
/** [held] bits: up 1, right 2, down 4, left 8. */
fun dpad(canvas: Canvas, w: Float, h: Float, kit: PadKit, held: Int, chevrons: Boolean = true, ink: Int = INK) {
val cx = w / 2f; val cy = h / 2f