fix(input): preserve customized controller artwork

This commit is contained in:
Kurt Himebauch committed 2026-11-21 12:20:56 -05:00
1 parent 97e84184ed
commit 5f3b885ee0
2 files changed
+14 -5

No files matched your search

@@ -223,7 +223,7 @@ class InputSurfaceView(
canvas.addView(when (element.kind) {
InputElementKind.STICK -> StickView(context, element, source, element.floating, element.hideWhenIdle && pad != null)
InputElementKind.TRACKPAD -> TrackpadView(context, element.control == InputControl.RIGHT_PAD, captioned = element.showLabel,
stock = element.id == "legacy:${element.control.id}", source = source)
stock = element.id == "legacy:${element.control.id}" && element.name == element.control.label, source = source)
InputElementKind.DPAD -> DirectionPad(context, element, source)
else -> HoldButton(context, element, source)
}.apply { tag = element; contentDescription = element.name; styleElement(this); source?.onStateChanged = { postInvalidate() } })
@@ -407,7 +407,8 @@ class InputSurfaceView(
}
val control = element.control
val native = element.id == "legacy:${control.id}" && element.icon == 0 &&
(element.name == control.label || element.name == kit.name(control))
(element.name == control.label || element.name == kit.name(control)) &&
usesStockShape(control, element.buttonShape)
if (native && art.button(canvas, width, height, control, kit, lit)) return
}
drawSurface(canvas, lit, element.buttonShape, classic)
@@ -604,7 +605,7 @@ class InputSurfaceView(
val cx = if (touching) originX else centreX()
val cy = if (touching) originY else height / 2f
val kit = artwork
if (kit != null && classic(element)) {
if (kit != null && classic(element) && element.name == element.control.label) {
val radius = min(width, height) / 2f - 2f * density
if (radius > 0f) {
art.stick(canvas, cx, cy, radius, kit, knobX, knobY, touching || clicking)
@@ -789,6 +790,12 @@ class InputSurfaceView(
private fun classic(element: InputSurfaceElement) = (element.id == "legacy:${element.control.id}" || element.id == "builtin:keyboard") &&
(element.buttonShape == InputButtonShape.CIRCLE || element.buttonShape == InputButtonShape.PILL)
private fun usesStockShape(control: InputControl, shape: InputButtonShape): Boolean = when (control) {
InputControl.LT, InputControl.LB, InputControl.RB, InputControl.RT -> shape == InputButtonShape.PILL
InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5 -> shape == InputButtonShape.PILL || shape == InputButtonShape.ROUNDED
else -> shape == InputButtonShape.CIRCLE
}
private val DIRECTIONS = listOf(InputControl.UP, InputControl.RIGHT, InputControl.DOWN, InputControl.LEFT)
internal fun shade(tint: Int, alpha: Int, f: Float) =
@@ -14,7 +14,7 @@ import org.robolectric.annotation.Config
class InputLayoutToolsTest {
private val context: Context get() = RuntimeEnvironment.getApplication()
@Before fun reset() {
for (name in listOf("input-profiles", "input-surfaces", "controller")) context.getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().commit()
for (name in listOf("input-profiles", "input-surfaces", "controller", "session")) context.getSharedPreferences(name, Context.MODE_PRIVATE).edit().clear().commit()
}
@Test fun scaleAllResizesEveryElementAroundItsCentreInsideTheScreen() {
@@ -139,7 +139,9 @@ class InputLayoutToolsTest {
val scaled = gamepad.copy(scale = 1.25f, elements = LegacyGamepadLayout(display, long, short, scale = 1.25f).regenerate(gamepad.elements))
assertEquals(long to short, OnScreenLayout.generatedSize(context, scaled, long, short))
val rotated = OnScreenLayout.elements(context, scaled, short, long, android.graphics.Rect())
assertEquals(LegacyGamepadLayout(context, short, long, scale = 1.25f).regenerate(scaled.elements), rotated)
val stock = OnScreenLayout.elements(context, gamepad, short, long, android.graphics.Rect())
assertEquals(stock.map { it.id }, rotated.map { it.id })
assertTrue(rotated.first { it.control == InputControl.LS }.width > stock.first { it.control == InputControl.LS }.width)
assertNull(OnScreenLayout.generatedSize(context, scaled.copy(scale = 1f), long, short))
InputLibraries.update(context) { it.withLayout(scaled) }
assertEquals(1.25f, InputLibraries.read(context).layouts.first { it.id == gamepad.id }.scale)