mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
feat(input): restyle Steam Deck buttons (#2966)
* feat(input): restyle Steam Deck buttons * feat(input): add Steam overlay options * fix(input): align floating overlay previews * fix(input): polish floating Steam trackpads * fix(input): restore overlay options on startup * fix(input): restore original Steam Deck artwork * fix(input): restore Steam Deck overlay geometry * fix(input): keep the Steam Deck shortcut row apart on small screens The Steam pill sits right of the keyboard by a density-based margin while Select and Start sit at unit-scaled offsets from the middle, so on a small, dense surface (800x450 at xxxhdpi) the Steam pill covered Select. Lay out Steam, Select, Start and Quick Access left to right with an 8 dp gap. * fix(input): fit the Steam Deck shortcut row inside the safe area Clamping each pill on its own after spacing could move Quick Access back onto Start when a cutout inset narrows the right side. Fit the keyboard, Steam, Select, Start and Quick Access as one row: push each right past its neighbour, pull the row back inside the right edge, and shrink the 8 dp gap only when the row would not fit otherwise. --------- Co-authored-by: K11MCH1 <81425424+K11MCH1@users.noreply.github.com>
This commit is contained in:
1 parent
4349563fd1
commit
64b7339da9
15 files changed
+785
-25
No files matched your search
@@ -77,6 +77,7 @@ import com.droiddeck.launcher.input.KeyboardHost
|
||||
import com.droiddeck.launcher.input.ControllerPrefs
|
||||
import com.droiddeck.launcher.input.SessionClipboard
|
||||
import com.droiddeck.launcher.input.OnScreenControls
|
||||
import com.droiddeck.launcher.input.OnScreenLayout
|
||||
import com.droiddeck.launcher.input.InputRouter
|
||||
import com.droiddeck.launcher.input.InputOutput
|
||||
import com.droiddeck.launcher.input.InputCommand
|
||||
@@ -246,7 +247,16 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var handCamera: com.droiddeck.launcher.handtracking.HandCamera? = null
|
||||
private var padMotion: com.droiddeck.launcher.input.PadMotion? = null
|
||||
private var resumed by mutableStateOf(false)
|
||||
private val deckPadListener: () -> Unit = { uiHandler.post { updatePadMotion(); openDeckRing("deck pad changed"); applyUnfoldedControls(); leaveDeckPanel() } }
|
||||
private val deckPadListener: () -> Unit = {
|
||||
uiHandler.post {
|
||||
updatePadMotion()
|
||||
openDeckRing("deck pad changed")
|
||||
onScreenControls?.reload()
|
||||
bottomInputControls?.reload()
|
||||
applyUnfoldedControls()
|
||||
leaveDeckPanel()
|
||||
}
|
||||
}
|
||||
|
||||
private fun openDeckRing(why: String) {
|
||||
val deck = SessionState.deckPad
|
||||
@@ -659,6 +669,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
private var suspendPolicy by mutableStateOf(SessionPrefs.SUSPEND_MANUAL)
|
||||
private var steamDownloadsInBackground by mutableStateOf(false)
|
||||
private var oscMode by mutableStateOf(SessionPrefs.OSC_AUTO)
|
||||
private var oscRearButtons by mutableStateOf(false)
|
||||
private var oscTrackpads by mutableStateOf(false)
|
||||
private var onScreenButtonsVisible by mutableStateOf(false)
|
||||
private var secondScreenMode by mutableStateOf(SessionState.secondScreenMode)
|
||||
private var secondScreenDisplays by mutableStateOf<List<SecondScreenDisplay>>(emptyList())
|
||||
@@ -1703,6 +1715,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
com.droiddeck.launcher.input.FakeInputWriter.setPadType(SessionPrefs.padType(id))
|
||||
com.droiddeck.launcher.session.InputSysfsComponent.padTypeChanged(SessionPrefs.padType(id))
|
||||
padType = id
|
||||
onScreenControls?.reload()
|
||||
bottomInputControls?.reload()
|
||||
},
|
||||
backHold = backHold,
|
||||
onBackHold = { on ->
|
||||
@@ -1814,6 +1828,23 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
primaryInputLayout?.let { com.droiddeck.launcher.input.InputLibraries.setAdaptiveSticks(this@SessionActivity, it.id, on) }
|
||||
refreshInputProfile()
|
||||
},
|
||||
showFloatingSteamControls = SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad && unfoldedPanel == null &&
|
||||
oscMode != SessionPrefs.OSC_NEVER && oscMode != SessionPrefs.OSC_STEAM_QAM &&
|
||||
!steamTouchInUse && OnScreenLayout.supportsFloatingSteamControls(padType, primaryInputLayout),
|
||||
oscRearButtons = oscRearButtons,
|
||||
oscTrackpads = oscTrackpads,
|
||||
onOscRearButtons = { shown ->
|
||||
SessionPrefs.setOscRearButtons(this@SessionActivity, shown)
|
||||
oscRearButtons = shown
|
||||
onScreenControls?.reload()
|
||||
bottomInputControls?.reload()
|
||||
},
|
||||
onOscTrackpads = { shown ->
|
||||
SessionPrefs.setOscTrackpads(this@SessionActivity, shown)
|
||||
oscTrackpads = shown
|
||||
onScreenControls?.reload()
|
||||
bottomInputControls?.reload()
|
||||
},
|
||||
quickButtons = quickButtons.takeIf {
|
||||
unfoldedPanel != null || oscMode != SessionPrefs.OSC_NEVER && !steamTouchInUse
|
||||
}.orEmpty(),
|
||||
@@ -2555,6 +2586,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
suspendPolicy = SessionPrefs.suspendPolicy(this, SessionState.mode)
|
||||
steamDownloadsInBackground = SessionPrefs.steamDownloadsInBackground(this)
|
||||
oscMode = SessionPrefs.oscMode(this, SessionState.mode == SessionService.MODE_STEAM)
|
||||
oscRearButtons = SessionPrefs.oscRearButtons(this)
|
||||
oscTrackpads = SessionPrefs.oscTrackpads(this)
|
||||
backHold = SessionPrefs.backHold(this)
|
||||
backActionsInverted = SessionPrefs.backActionsInverted(this)
|
||||
physicalShortcuts.bindings = PhysicalShortcuts.read(this)
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Rect
|
||||
import kotlin.math.min
|
||||
|
||||
internal class FloatingSteamOverlay(width: Int, height: Int, safe: Rect, density: Float) {
|
||||
private val w = width.toFloat()
|
||||
private val h = height.toFloat()
|
||||
private val left = safe.left / w
|
||||
private val top = safe.top / h
|
||||
private val right = 1f - safe.right / w
|
||||
private val bottom = 1f - safe.bottom / h
|
||||
private val gap = 3f * density
|
||||
private val bottomPadding = 14f * density
|
||||
private val dp = min(density, min(width, height) / 250f)
|
||||
|
||||
fun place(elements: List<InputSurfaceElement>, lowerShortcuts: Boolean,
|
||||
rearButtons: Boolean?, trackpads: Boolean?): List<InputSurfaceElement> {
|
||||
val visible = elements.filter { element ->
|
||||
when {
|
||||
!isStock(element) -> true
|
||||
element.control in rear -> rearButtons != false
|
||||
element.control.isTrackpad -> trackpads != false
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
val lowered = if (lowerShortcuts) lower(visible) else visible
|
||||
if (rearButtons != true && trackpads != true) return lowered
|
||||
val placed = lowered.toMutableList()
|
||||
fun add(control: InputControl, x: Float, y: List<Float>, widthDp: Int, heightDp: Int, shape: InputButtonShape) {
|
||||
if (placed.any { it.id == "legacy:${control.id}" }) return
|
||||
val element = InputSurfaceElement(control, 0f, 0f, (widthDp * dp / w).coerceAtLeast(.03f),
|
||||
(heightDp * dp / h).coerceAtLeast(.03f), floating = false, buttonShape = shape, showLabel = !control.isTrackpad)
|
||||
findSpace(element, x, y, placed)?.let(placed::add)
|
||||
}
|
||||
if (rearButtons == true) {
|
||||
add(InputControl.L4, .045f, listOf(.48f, .38f, .58f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.L5, .045f, listOf(.62f, .72f, .53f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.R4, .955f, listOf(.48f, .38f, .58f), 28, 46, InputButtonShape.PILL)
|
||||
add(InputControl.R5, .955f, listOf(.62f, .72f, .53f), 28, 46, InputButtonShape.PILL)
|
||||
}
|
||||
if (trackpads == true) {
|
||||
val rows = listOf(.45f, .36f, .54f, .27f, .63f)
|
||||
add(InputControl.LEFT_PAD, .34f, rows, 68, 63, InputButtonShape.ROUNDED)
|
||||
add(InputControl.RIGHT_PAD, .66f, rows, 68, 63, InputButtonShape.ROUNDED)
|
||||
}
|
||||
return placed
|
||||
}
|
||||
|
||||
private fun lower(elements: List<InputSurfaceElement>): List<InputSurfaceElement> {
|
||||
val row = elements.filter { isStock(it) && it.control in shortcuts }
|
||||
val occupied = (elements - row.toSet()).toMutableList()
|
||||
val moved = mutableMapOf<String, InputSurfaceElement>()
|
||||
for (element in row.sortedBy { shortcuts.getValue(it.control) }) {
|
||||
val y = bottom - bottomPadding / h - element.height / 2f
|
||||
val position = findSpace(element, shortcuts.getValue(element.control), listOf(y, y - .07f), occupied)
|
||||
?: return elements
|
||||
occupied += position
|
||||
moved[element.id] = position
|
||||
}
|
||||
return elements.map { moved[it.id] ?: it }
|
||||
}
|
||||
|
||||
private fun findSpace(element: InputSurfaceElement, x: Float, rows: List<Float>,
|
||||
occupied: List<InputSurfaceElement>): InputSurfaceElement? {
|
||||
val maxX = right - element.width
|
||||
val maxY = bottom - element.height
|
||||
if (maxX < left || maxY < top) return null
|
||||
for (y in rows) {
|
||||
for (dx in horizontalOffsets) {
|
||||
val candidate = element.copy(
|
||||
x = (x + dx - element.width / 2f).coerceIn(left, maxX),
|
||||
y = (y - element.height / 2f).coerceIn(top, maxY),
|
||||
)
|
||||
if (occupied.none { overlaps(candidate, it) }) return candidate
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun overlaps(a: InputSurfaceElement, b: InputSurfaceElement): Boolean =
|
||||
a.x < b.x + b.width + gap / w && b.x < a.x + a.width + gap / w &&
|
||||
a.y < b.y + b.height + gap / h && b.y < a.y + a.height + gap / h
|
||||
|
||||
private fun isStock(element: InputSurfaceElement) = element.id == "legacy:${element.control.id}"
|
||||
|
||||
private companion object {
|
||||
val rear = setOf(InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5)
|
||||
val shortcuts = mapOf(InputControl.GUIDE to .23f, InputControl.SELECT to .41f, InputControl.START to .59f, InputControl.QAM to .77f)
|
||||
val horizontalOffsets = listOf(0f, -.035f, .035f, -.07f, .07f, -.105f, .105f)
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,9 @@ import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.widget.FrameLayout
|
||||
import com.droiddeck.launcher.ui.InputSurfaceView
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionService
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
|
||||
class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayout.Dock? = null) : FrameLayout(context) {
|
||||
private val surface = InputSurfaceView(context, pad, inputRole = InputRole.PRIMARY, haptics = dock != null)
|
||||
@@ -77,7 +80,10 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
private fun placed(): List<InputSurfaceElement> {
|
||||
val key = Placement(layout, viewWidth, viewHeight, Rect(safe), isButtonsOnly)
|
||||
return placements.getOrPut(key) {
|
||||
OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, isButtonsOnly, dock)
|
||||
val steam = SessionState.mode == SessionService.MODE_STEAM && SessionState.deckPad
|
||||
OnScreenLayout.elements(context, layout, viewWidth, viewHeight, safe, isButtonsOnly, dock,
|
||||
rearButtons = SessionPrefs.oscRearButtons(context).takeIf { steam },
|
||||
trackpads = SessionPrefs.oscTrackpads(context).takeIf { steam })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,11 +94,16 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
isQuickHidden -> elements.filter { it.id == "builtin:keyboard" || it.alwaysShown }
|
||||
else -> elements
|
||||
})
|
||||
val style = layout?.style ?: InputSurfaceStyle()
|
||||
surface.updateStyle(style)
|
||||
quickToggle.tint = style.tint
|
||||
quickToggle.alpha = style.opacity / 100f
|
||||
quickToggle.visibility = if (isButtonsOnly || isPinnedOnly || layout == null || dock != null) GONE else VISIBLE
|
||||
refreshAppearance()
|
||||
}
|
||||
|
||||
private fun refreshAppearance() {
|
||||
val style = layout?.style ?: InputSurfaceStyle()
|
||||
val deck = dock == null && OnScreenLayout.usesSteamDeckButtons(context, layout)
|
||||
surface.updateStyle(style, steamDeckButtons = deck)
|
||||
quickToggle.tint = style.tint.takeUnless { deck }
|
||||
quickToggle.alpha = style.opacity / 100f
|
||||
quickToggle.invalidate()
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,20 @@ package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object OnScreenLayout {
|
||||
internal fun usesSteamDeckButtons(context: Context, layout: SavedInputLayout?) =
|
||||
layout?.id == InputLibraries.OVERLAY && SessionPrefs.steamController(context) == SessionPrefs.CONTROLLER_DECK
|
||||
|
||||
internal fun supportsFloatingSteamControls(controller: String, layout: SavedInputLayout?) =
|
||||
layout?.id == InputLibraries.OVERLAY &&
|
||||
(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) {
|
||||
companion object {
|
||||
fun deck(portrait: Boolean, gamepad: SavedInputLayout?): Dock {
|
||||
@@ -25,7 +33,8 @@ object OnScreenLayout {
|
||||
private const val KEYBOARD_ID = "builtin:keyboard"
|
||||
|
||||
fun elements(context: Context, layout: SavedInputLayout?, width: Int, height: Int, safe: Rect,
|
||||
buttonsOnly: Boolean = false, dock: Dock? = null): List<InputSurfaceElement> {
|
||||
buttonsOnly: Boolean = false, dock: Dock? = null, rearButtons: Boolean? = null,
|
||||
trackpads: Boolean? = null): List<InputSurfaceElement> {
|
||||
val stored = layout?.elements ?: return emptyList()
|
||||
if (width <= 0 || height <= 0) return stored
|
||||
val generator = LegacyGamepadLayout(context, width, height, safe, layout.scale)
|
||||
@@ -39,7 +48,16 @@ object OnScreenLayout {
|
||||
else -> generator.regenerate(gamepad)
|
||||
}
|
||||
val byId = (placed + others).associateBy { it.id }
|
||||
return stored.mapNotNull { byId[it.id] } + placed.filter { p -> stored.none { it.id == p.id } }
|
||||
val ordered = stored.mapNotNull { byId[it.id] } + placed.filter { p -> stored.none { it.id == p.id } }
|
||||
if (dock != null || !supportsFloatingSteamControls(SessionPrefs.steamController(context), layout)) return ordered
|
||||
if (generated && width >= height && usesSteamDeckButtons(context, layout) &&
|
||||
ControllerPrefs.layout(context, reference.first.toInt(), reference.second.toInt()).isEmpty() &&
|
||||
ControllerPrefs.layout(context, width, height).isEmpty()) {
|
||||
return SteamDeckOverlayGeometry(width, height, safe, context.resources.displayMetrics, layout.scale)
|
||||
.place(ordered, rearButtons == true, trackpads == true)
|
||||
}
|
||||
return FloatingSteamOverlay(width, height, safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, lowerShortcuts = generated, rearButtons = rearButtons, trackpads = trackpads)
|
||||
}
|
||||
|
||||
fun editorElements(context: Context, layout: SavedInputLayout, width: Int, height: Int, edited: Boolean = false): List<InputSurfaceElement> =
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.graphics.Rect
|
||||
import android.util.DisplayMetrics
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
internal class SteamDeckOverlayGeometry(
|
||||
width: Int, height: Int, private val safe: Rect, metrics: DisplayMetrics, scale: Float,
|
||||
) {
|
||||
private val w = width.toFloat()
|
||||
private val h = height.toFloat()
|
||||
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,
|
||||
(w - safe.left - safe.right).coerceAtLeast(1f) / 1200f,
|
||||
(h - safe.top - safe.bottom).coerceAtLeast(1f) / 900f,
|
||||
)
|
||||
|
||||
private fun anchor(value: Float, reference: Float, extent: Float, start: Int, end: Int): Float {
|
||||
val low = start + value * unit
|
||||
val high = extent - end - (reference - value) * unit
|
||||
return when {
|
||||
value < reference / 3f -> low
|
||||
value > reference * 2f / 3f -> high
|
||||
else -> (extent / 2f + (value - reference / 2f) * unit).coerceIn(low, max(low, high))
|
||||
}
|
||||
}
|
||||
|
||||
fun place(elements: List<InputSurfaceElement>, rearButtons: Boolean, trackpads: Boolean): List<InputSurfaceElement> {
|
||||
val x = { ref: Float -> anchor(ref, 1600f, w, safe.left, safe.right) }
|
||||
val y = { ref: Float -> anchor(ref, 900f, h, safe.top, safe.bottom) }
|
||||
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 row = fitRow(listOfNotNull(keyboard,
|
||||
Box(max(x(370f), leftEdge + 66f * unit), 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 = mapOf(
|
||||
InputControl.LT to Box(x(140f), y(66f), 88f, 34f),
|
||||
InputControl.LB to Box(x(140f), y(148f), 88f, 30f),
|
||||
InputControl.RT to Box(x(1460f), y(66f), 88f, 34f),
|
||||
InputControl.RB to Box(x(1460f), y(148f), 88f, 30f),
|
||||
InputControl.Y to Box(x(1375f), y(345f) - 96f * unit, 58f),
|
||||
InputControl.X to Box(x(1375f) - 96f * unit, y(345f), 58f),
|
||||
InputControl.B to Box(x(1375f) + 96f * unit, y(345f), 58f),
|
||||
InputControl.A to Box(x(1375f), y(345f) + 96f * unit, 58f),
|
||||
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.LS to Box(x(290f), y(640f), 96f),
|
||||
InputControl.RS to Box(x(1310f), y(640f), 96f),
|
||||
InputControl.SELECT to select,
|
||||
InputControl.START to start,
|
||||
InputControl.GUIDE to guide,
|
||||
InputControl.QAM to qam,
|
||||
)
|
||||
val rear = mapOf(
|
||||
InputControl.L4 to Box(x(30f), y(470f), 30f, 58f),
|
||||
InputControl.L5 to Box(x(30f), y(590f), 30f, 58f),
|
||||
InputControl.R4 to Box(x(1570f), y(470f), 30f, 58f),
|
||||
InputControl.R5 to Box(x(1570f), y(590f), 30f, 58f),
|
||||
)
|
||||
val pads = mapOf(
|
||||
InputControl.LEFT_PAD to Box(x(470f), y(360f), 88f),
|
||||
InputControl.RIGHT_PAD to Box(x(1130f), y(360f), 88f),
|
||||
)
|
||||
val optional = rear.filterKeys { rearButtons } + pads.filterKeys { trackpads }
|
||||
val placed = elements.mapNotNull { element ->
|
||||
when {
|
||||
element.id == KEYBOARD -> row.first().place(element)
|
||||
element.id != "legacy:${element.control.id}" -> element
|
||||
element.control in rear || element.control in pads -> optional[element.control]?.place(element)
|
||||
else -> positions[element.control]?.place(element) ?: element
|
||||
}
|
||||
}
|
||||
return placed + optional.mapNotNull { (control, box) ->
|
||||
if (placed.any { it.id == "legacy:${control.id}" }) null else box.place(InputSurfaceElement(control,
|
||||
0f, 0f, 0f, 0f, floating = false, buttonShape = InputButtonShape.PILL, showLabel = !control.isTrackpad))
|
||||
}
|
||||
}
|
||||
|
||||
private fun fitRow(row: List<Box>, start: Float): List<Box> {
|
||||
val end = w - safe.right
|
||||
val gap = ((end - start - row.fold(0f) { sum, box -> sum + box.width }) / (row.size - 1)).coerceIn(0f, 8f * density)
|
||||
var edge = start - gap
|
||||
val pushed = row.map { box -> box.at(max(box.cx, edge + gap + box.width / 2f)).also { edge = it.cx + it.width / 2f } }
|
||||
edge = end + gap
|
||||
return pushed.asReversed().map { box -> box.at(min(box.cx, edge - gap - box.width / 2f)).also { edge = it.cx - it.width / 2f } }.asReversed()
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
fun at(cx: Float) = Box(cx, cy, hw, hh)
|
||||
|
||||
fun place(element: InputSurfaceElement): InputSurfaceElement {
|
||||
val height = max(hh * 2f * unit, 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,
|
||||
width = width / w, height = height / h,
|
||||
).bounded()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val KEYBOARD = "builtin:keyboard"
|
||||
}
|
||||
}
|
||||
@@ -673,6 +673,12 @@ object SessionPrefs {
|
||||
prefs(context).edit().putString("osc", mode).apply()
|
||||
}
|
||||
|
||||
fun oscRearButtons(context: Context): Boolean = prefs(context).getBoolean("oscRearButtons", false)
|
||||
fun setOscRearButtons(context: Context, shown: Boolean) { prefs(context).edit().putBoolean("oscRearButtons", shown).apply() }
|
||||
|
||||
fun oscTrackpads(context: Context): Boolean = prefs(context).getBoolean("oscTrackpads", false)
|
||||
fun setOscTrackpads(context: Context, shown: Boolean) { prefs(context).edit().putBoolean("oscTrackpads", shown).apply() }
|
||||
|
||||
fun linuxDriver(context: Context): String =
|
||||
prefs(context).getString("linuxDriver", null)
|
||||
?: prefs(context).getString("linuxDriver.steam", null)
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.*
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
@Composable
|
||||
internal fun InputLayoutRow(layout: SavedInputLayout, role: InputRole, detail: String?, onManage: () -> Unit, onPick: () -> Unit) {
|
||||
@@ -46,8 +47,12 @@ internal class InputLayoutPreviewView(context: Context) : View(context) {
|
||||
private var sourceHeight = 563
|
||||
fun update(layout: SavedInputLayout, role: InputRole) {
|
||||
sourceHeight = if (role == InputRole.PRIMARY) 563 else 870
|
||||
renderer.updateCustomLayout(layout.elements)
|
||||
renderer.updateStyle(layout.style.copy(opacity = 100))
|
||||
val primary = role == InputRole.PRIMARY
|
||||
val steamOverlay = primary && OnScreenLayout.supportsFloatingSteamControls(SessionPrefs.steamController(context), layout)
|
||||
val elements = if (steamOverlay) OnScreenLayout.editorElements(context, layout, 1000, sourceHeight) else layout.elements
|
||||
renderer.updateCustomLayout(elements)
|
||||
renderer.updateStyle(layout.style.copy(opacity = 100),
|
||||
steamDeckButtons = primary && OnScreenLayout.usesSteamDeckButtons(context, layout))
|
||||
renderer.measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(sourceHeight, MeasureSpec.EXACTLY))
|
||||
renderer.layout(0, 0, 1000, sourceHeight)
|
||||
contentDescription = layout.name
|
||||
|
||||
@@ -278,7 +278,9 @@ private fun InputSettingsContent(onBack: () -> Unit, onChanged: () -> Unit, embe
|
||||
else InputHint(layout.name)
|
||||
InputNavigationRow(stringResource(R.string.input_saved_layouts), stringResource(R.string.input_saved_layouts_hint)) { go(InputPage.LAYOUTS) }
|
||||
if (layout.editable) {
|
||||
InputColorRow(host, layout.style.tint) { color -> update { it.withLayout(layout.copy(style = layout.style.copy(tint = color))) } }
|
||||
if (!OnScreenLayout.usesSteamDeckButtons(context, layout)) {
|
||||
InputColorRow(host, layout.style.tint) { color -> update { it.withLayout(layout.copy(style = layout.style.copy(tint = color))) } }
|
||||
}
|
||||
SliderRow(stringResource(R.string.ctrl_opacity), null, layout.style.opacity, 1..100, step = 1,
|
||||
format = { "$it%" }) { opacity -> update { it.withLayout(layout.copy(style = layout.style.copy(opacity = opacity))) } }
|
||||
for (button in layout.quickButtons) ToggleRow(host, "quick-${button.name.lowercase()}", stringResource(quickButtonLabel(button)), null,
|
||||
|
||||
@@ -22,9 +22,14 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
|
||||
var aspect = 1f
|
||||
set(value) { field = value; refreshElements(); invalidate() }
|
||||
var sourceLayout: SavedInputLayout? = null
|
||||
set(value) { field = value; refreshElements(); invalidate() }
|
||||
set(value) {
|
||||
field = value
|
||||
updatePreviewStyle()
|
||||
refreshElements()
|
||||
invalidate()
|
||||
}
|
||||
var style = InputSurfaceStyle()
|
||||
set(value) { field = value; preview.updateStyle(value) }
|
||||
set(value) { field = value; updatePreviewStyle() }
|
||||
var snap = true
|
||||
set(value) { field = value; if (!value) clearGuides() }
|
||||
private var guideX: Float? = null
|
||||
@@ -50,6 +55,10 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
|
||||
addView(preview, LayoutParams(-1, -1))
|
||||
}
|
||||
|
||||
private fun updatePreviewStyle() {
|
||||
preview.updateStyle(style, steamDeckButtons = OnScreenLayout.usesSteamDeckButtons(context, sourceLayout))
|
||||
}
|
||||
|
||||
private fun refreshElements() {
|
||||
visibleElements = sourceLayout?.let { layout ->
|
||||
OnScreenLayout.editorElements(context, layout.copy(elements = elements, aspect = aspect), width, height)
|
||||
|
||||
@@ -56,6 +56,10 @@ class InputSurfaceView(
|
||||
private val elementSources = ArrayList<InputSurfaceSource>()
|
||||
private var customCanvas: ViewGroup? = null
|
||||
private val owners = HashMap<Int, View>()
|
||||
private var steamDeckButtons = false
|
||||
private val deckArt by lazy(LazyThreadSafetyMode.NONE) { SteamDeckButtonArt(context) }
|
||||
private var deckDpad = emptyList<HoldButton>()
|
||||
private val deckDpadBounds = RectF()
|
||||
private var requestedLayout = customLayout
|
||||
init { customLayout = surfaceStyle.shown(customLayout); addView(content, LayoutParams(-1, -1)); renderCustom(pad) }
|
||||
|
||||
@@ -134,12 +138,16 @@ class InputSurfaceView(
|
||||
}
|
||||
}
|
||||
|
||||
fun updateStyle(style: InputSurfaceStyle) {
|
||||
if (surfaceStyle == style) return
|
||||
fun updateStyle(style: InputSurfaceStyle, steamDeckButtons: Boolean = false) {
|
||||
if (surfaceStyle == style && this.steamDeckButtons == steamDeckButtons) return
|
||||
val relayout = surfaceStyle.hidden != style.hidden
|
||||
surfaceStyle = style
|
||||
this.steamDeckButtons = steamDeckButtons
|
||||
if (relayout) updateCustomLayout(requestedLayout)
|
||||
customCanvas?.let { canvas -> for (i in 0 until canvas.childCount) styleElement(canvas.getChildAt(i)) }
|
||||
customCanvas?.let { canvas ->
|
||||
for (i in 0 until canvas.childCount) styleElement(canvas.getChildAt(i))
|
||||
canvas.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
private fun styleElement(view: View) {
|
||||
@@ -173,6 +181,7 @@ class InputSurfaceView(
|
||||
}
|
||||
|
||||
private fun renderCustom(pad: PadBridge?) {
|
||||
deckDpad = emptyList()
|
||||
val canvas = object : ViewGroup(context) {
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val layout = customLayout
|
||||
@@ -190,6 +199,20 @@ class InputSurfaceView(
|
||||
val x = (width * e.x).toInt(); val y = (height * e.y).toInt()
|
||||
child.layout(x, y, x + child.measuredWidth, y + child.measuredHeight)
|
||||
}
|
||||
updateDeckDpad(this)
|
||||
}
|
||||
|
||||
override fun dispatchDraw(canvas: Canvas) {
|
||||
if (steamDeckButtons && deckDpad.isNotEmpty()) {
|
||||
val alpha = (deckDpad.first().alpha * 255f).toInt()
|
||||
val saved = if (alpha == 255) canvas.save()
|
||||
else canvas.saveLayerAlpha(deckDpadBounds, alpha)
|
||||
canvas.translate(deckDpadBounds.left, deckDpadBounds.top)
|
||||
val held = deckDpad.foldIndexed(0) { i, bits, button -> if (button.highlighted) bits or (1 shl i) else bits }
|
||||
deckArt.dpad(canvas, deckDpadBounds.width(), deckDpadBounds.height(), held)
|
||||
canvas.restoreToCount(saved)
|
||||
}
|
||||
super.dispatchDraw(canvas)
|
||||
}
|
||||
}
|
||||
canvas.clipChildren = customLayout.none { it.kind == InputElementKind.STICK && (classic(it) || adaptive(it)) }
|
||||
@@ -197,7 +220,7 @@ class InputSurfaceView(
|
||||
val source = pad?.let { InputSurfaceSource(it, inputRole, element).also { s -> elementSources += s } }
|
||||
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, source = source)
|
||||
InputElementKind.TRACKPAD -> TrackpadView(context, element.control == InputControl.RIGHT_PAD, captioned = element.showLabel, source = source)
|
||||
InputElementKind.DPAD -> DirectionPad(context, element, source)
|
||||
else -> HoldButton(context, element, source)
|
||||
}.apply { tag = element; contentDescription = element.name; styleElement(this); source?.onStateChanged = { postInvalidate() } })
|
||||
@@ -206,6 +229,29 @@ class InputSurfaceView(
|
||||
customCanvas = canvas
|
||||
}
|
||||
|
||||
private fun updateDeckDpad(canvas: ViewGroup) {
|
||||
val buttons = DIRECTIONS.mapNotNull { direction ->
|
||||
val index = customLayout.indexOfFirst { element ->
|
||||
element.control == direction && classic(element) && element.buttonShape == InputButtonShape.CIRCLE &&
|
||||
element.name == direction.label && element.icon == 0 && element.image.isEmpty() &&
|
||||
element.showLabel && !element.toggle && element.opacity == 1f
|
||||
}
|
||||
canvas.getChildAt(index) as? HoldButton
|
||||
}
|
||||
deckDpad = emptyList()
|
||||
if (buttons.size != DIRECTIONS.size) return
|
||||
val (up, right, down, left) = buttons
|
||||
val centerX = (left.left + right.right) / 2f
|
||||
val centerY = (up.top + down.bottom) / 2f
|
||||
if (kotlin.math.abs((up.left + up.right) / 2f - centerX) > 2f ||
|
||||
kotlin.math.abs((down.left + down.right) / 2f - centerX) > 2f ||
|
||||
kotlin.math.abs((left.top + left.bottom) / 2f - centerY) > 2f ||
|
||||
kotlin.math.abs((right.top + right.bottom) / 2f - centerY) > 2f ||
|
||||
up.bottom >= down.top || left.right >= right.left) return
|
||||
deckDpadBounds.set(left.left.toFloat(), up.top.toFloat(), right.right.toFloat(), down.bottom.toFloat())
|
||||
deckDpad = buttons
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
if (pad != null && elementSources.isEmpty()) {
|
||||
@@ -344,9 +390,20 @@ class InputSurfaceView(
|
||||
}
|
||||
private val imageRect = RectF()
|
||||
|
||||
val highlighted get() = if (element.toggle) source?.latched == true else down
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val lit = if (element.toggle) source?.latched == true else down
|
||||
val lit = highlighted
|
||||
val classic = classic(element)
|
||||
if (steamDeckButtons && element.image.isEmpty() && element.showLabel) {
|
||||
if (this in deckDpad) return
|
||||
if (element.id == "builtin:keyboard" && element.icon == InputButtonIcons.KEYBOARD) {
|
||||
deckArt.keyboard(canvas, width, height, lit)
|
||||
return
|
||||
}
|
||||
val native = element.id == "legacy:${element.control.id}" && element.name == element.control.label && element.icon == 0
|
||||
if (native && deckArt.button(canvas, width, height, element.control, lit)) return
|
||||
}
|
||||
drawSurface(canvas, lit, element.buttonShape, classic)
|
||||
val cx = width / 2f
|
||||
labelPaint.color = if (classic && tint != null) textColor(lit) else if (lit) ACCENT else TEXT
|
||||
@@ -364,7 +421,7 @@ class InputSurfaceView(
|
||||
if (classic && element.name == element.control.label) {
|
||||
val radius = min(width, height) / 2f
|
||||
val direction = DIRECTIONS.indexOf(element.control)
|
||||
if (direction >= 0) { drawArrow(canvas, cx, height / 2f, radius * 0.34f, direction, labelPaint); return }
|
||||
if (direction >= 0) { drawArrow(canvas, cx, height / 2f, radius * .34f, direction, labelPaint); return }
|
||||
val glyph = glyph(element.control)
|
||||
labelPaint.textSize = when {
|
||||
element.buttonShape == InputButtonShape.PILL -> height / 2f * 0.8f
|
||||
@@ -395,6 +452,7 @@ class InputSurfaceView(
|
||||
if (pressed) feedback(this, HapticFeedbackConstants.VIRTUAL_KEY)
|
||||
if (!pressed && cancelled) source?.cancel() else source?.update(if (pressed) 1f else 0f)
|
||||
invalidate()
|
||||
if (steamDeckButtons && this in deckDpad) customCanvas?.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,18 +479,22 @@ class InputSurfaceView(
|
||||
private val glow = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
if (!captioned) {
|
||||
deckArt.trackpad(canvas, width.toFloat(), height.toFloat(), touching || clicked, fingerX, fingerY)
|
||||
return
|
||||
}
|
||||
drawSurface(canvas, clicked)
|
||||
val cx = width / 2f
|
||||
val cy = height / 2f
|
||||
guide.strokeWidth = density
|
||||
val reach = min(width, height) / 2f - 24 * density
|
||||
val reach = (min(width, height) / 2f - 24 * density).coerceAtLeast(0f)
|
||||
canvas.drawCircle(cx, cy, reach, guide)
|
||||
canvas.drawCircle(cx, cy, reach / 2f, guide)
|
||||
canvas.drawLine(cx - reach, cy, cx + reach, cy, guide)
|
||||
canvas.drawLine(cx, cy - reach, cx, cy + reach, guide)
|
||||
captionPaint.textSize = 12 * density
|
||||
captionPaint.color = if (touching) ACCENT else TEXT_DIM
|
||||
if (captioned) canvas.drawText((contentDescription?.toString() ?: if (right) context.getString(R.string.deck_right_trackpad) else context.getString(R.string.deck_left_trackpad)).uppercase(), cx, 28 * density, captionPaint)
|
||||
canvas.drawText((contentDescription?.toString() ?: if (right) context.getString(R.string.deck_right_trackpad) else context.getString(R.string.deck_left_trackpad)).uppercase(), cx, 28 * density, captionPaint)
|
||||
if (touching) {
|
||||
val radius = 56 * density
|
||||
glow.shader = RadialGradient(fingerX, fingerY, radius, ACCENT_GLOW, Color.TRANSPARENT, Shader.TileMode.CLAMP)
|
||||
@@ -534,6 +596,17 @@ class InputSurfaceView(
|
||||
if (hideWhenIdle && !touching) return
|
||||
val cx = if (touching) originX else centreX()
|
||||
val cy = if (touching) originY else height / 2f
|
||||
if (steamDeckButtons && classic(element)) {
|
||||
val radius = min(width, height) / 2f - 2f * density
|
||||
if (radius > 0f) {
|
||||
deckArt.stick(canvas, cx, cy, radius, knobX, knobY, touching || clicking)
|
||||
if (element.showLabel) {
|
||||
labelPaint.color = TEXT
|
||||
drawDirectionLabels(canvas, source, false, cx, cy, radius * .66f, radius * .34f, labelPaint)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
val color = tint
|
||||
if (classic(element) && color != null) {
|
||||
val radius = min(width, height) / 2f - 0.75f * density
|
||||
|
||||
@@ -343,6 +343,11 @@ class DrawerActions(
|
||||
val unfoldedControls: Boolean? = null,
|
||||
val adaptiveSticks: Boolean? = null,
|
||||
val onAdaptiveSticks: (Boolean) -> Unit = {},
|
||||
val showFloatingSteamControls: Boolean = false,
|
||||
val oscRearButtons: Boolean = false,
|
||||
val oscTrackpads: Boolean = false,
|
||||
val onOscRearButtons: (Boolean) -> Unit = {},
|
||||
val onOscTrackpads: (Boolean) -> Unit = {},
|
||||
val quickButtons: Map<com.droiddeck.launcher.input.InputCommand, Boolean> = emptyMap(),
|
||||
val onQuickButton: (com.droiddeck.launcher.input.InputCommand, Boolean) -> Unit = { _, _ -> },
|
||||
val onUnfoldedControls: (Boolean) -> Unit = {},
|
||||
@@ -721,6 +726,12 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
ToggleRow(host, "adaptive-sticks", stringResource(R.string.ctrl_adaptive), null, on,
|
||||
chipModifier = focus.track(page, "adaptive-sticks"), onChange = a.onAdaptiveSticks)
|
||||
}
|
||||
if (a.showFloatingSteamControls) {
|
||||
ToggleRow(host, "rear-buttons", stringResource(R.string.osc_rear_buttons), null, a.oscRearButtons,
|
||||
chipModifier = focus.track(page, "rear-buttons"), onChange = a.onOscRearButtons)
|
||||
ToggleRow(host, "trackpads", stringResource(R.string.osc_trackpads), null, a.oscTrackpads,
|
||||
chipModifier = focus.track(page, "trackpads"), onChange = a.onOscTrackpads)
|
||||
}
|
||||
for ((button, shown) in a.quickButtons) {
|
||||
val key = "quick-${button.name.lowercase()}"
|
||||
ToggleRow(host, key, stringResource(quickButtonLabel(button)), null, shown,
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.LinearGradient
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Path
|
||||
import android.graphics.RadialGradient
|
||||
import android.graphics.RectF
|
||||
import android.graphics.Shader
|
||||
import android.graphics.Typeface
|
||||
import com.droiddeck.launcher.input.InputControl
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sin
|
||||
|
||||
internal class SteamDeckButtonArt(context: Context) {
|
||||
private val density = context.resources.displayMetrics.density
|
||||
private val body = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val shine = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val edge = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE }
|
||||
private val ink = Paint(Paint.ANTI_ALIAS_FLAG).apply { textAlign = Paint.Align.CENTER; typeface = Typeface.create("sans-serif-medium", Typeface.BOLD) }
|
||||
private val line = Paint(Paint.ANTI_ALIAS_FLAG).apply { style = Paint.Style.STROKE; strokeCap = Paint.Cap.ROUND; strokeJoin = Paint.Join.ROUND }
|
||||
private val fill = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val path = Path()
|
||||
private val arm = Path()
|
||||
private val bar = Path()
|
||||
private val rect = RectF()
|
||||
private var shineTop = Float.NaN
|
||||
private var shineHeight = Float.NaN
|
||||
|
||||
private fun dp(value: Float) = value * density
|
||||
|
||||
private fun glass(canvas: Canvas, shape: Path, pressed: Boolean, tint: Int = BODY) {
|
||||
shape.computeBounds(rect, false)
|
||||
body.color = if (pressed) PRESSED else tint
|
||||
body.setShadowLayer(dp(2.5f), 0f, dp(1.5f), SHADOW)
|
||||
canvas.drawPath(shape, body)
|
||||
body.clearShadowLayer()
|
||||
if (!pressed) {
|
||||
if (rect.top != shineTop || rect.height() != shineHeight) {
|
||||
shineTop = rect.top; shineHeight = rect.height()
|
||||
shine.shader = LinearGradient(0f, rect.top, 0f, rect.top + rect.height() * .55f, SHINE, Color.TRANSPARENT, Shader.TileMode.CLAMP)
|
||||
}
|
||||
canvas.drawPath(shape, shine)
|
||||
}
|
||||
edge.color = if (pressed) EDGE_PRESSED else EDGE
|
||||
edge.strokeWidth = dp(1.25f)
|
||||
canvas.drawPath(shape, edge)
|
||||
}
|
||||
|
||||
private fun circle(cx: Float, cy: Float, r: Float): Path = path.apply { reset(); addCircle(cx, cy, r, Path.Direction.CW) }
|
||||
|
||||
private fun roundRect(l: Float, t: Float, r: Float, b: Float, radius: Float): Path = path.apply {
|
||||
reset(); addRoundRect(RectF(l, t, r, b), radius, radius, Path.Direction.CW)
|
||||
}
|
||||
|
||||
private fun corners(l: Float, t: Float, r: Float, b: Float, tl: Float, tr: Float, br: Float, bl: Float): Path = path.apply {
|
||||
reset(); addRoundRect(RectF(l, t, r, b), floatArrayOf(tl, tl, tr, tr, br, br, bl, bl), Path.Direction.CW)
|
||||
}
|
||||
|
||||
private fun text(canvas: Canvas, value: String, cx: Float, cy: Float, size: Float, color: Int, maxWidth: Float = Float.MAX_VALUE) {
|
||||
ink.textSize = size
|
||||
val measured = ink.measureText(value)
|
||||
if (measured > maxWidth) ink.textSize = size * maxWidth / measured
|
||||
ink.color = color
|
||||
canvas.drawText(value, cx, cy - (ink.ascent() + ink.descent()) / 2f, ink)
|
||||
}
|
||||
|
||||
fun button(canvas: Canvas, width: Int, height: Int, control: InputControl, pressed: Boolean): Boolean {
|
||||
val w = width.toFloat()
|
||||
val h = height.toFloat()
|
||||
if (min(w, h) <= dp(4f)) return false
|
||||
when (control) {
|
||||
InputControl.A, InputControl.B, InputControl.X, InputControl.Y -> {
|
||||
val radius = min(w, h) / 2f - dp(2f)
|
||||
glass(canvas, circle(w / 2f, h / 2f, radius), pressed)
|
||||
text(canvas, control.label, w / 2f, h / 2f, radius * .95f, if (pressed) ON_ACCENT else INK)
|
||||
}
|
||||
InputControl.LB, InputControl.RB, InputControl.LT, InputControl.RT -> shoulder(canvas, w, h, control, pressed)
|
||||
InputControl.L4, InputControl.L5, InputControl.R4, InputControl.R5 -> grip(canvas, w, h, control.label, pressed)
|
||||
InputControl.SELECT -> system(canvas, w, h, Shape.CHIP, Icon.VIEW, pressed)
|
||||
InputControl.START -> system(canvas, w, h, Shape.CHIP, Icon.MENU, pressed)
|
||||
InputControl.GUIDE -> system(canvas, w, h, Shape.PILL, Icon.STEAM, pressed)
|
||||
InputControl.QAM -> system(canvas, w, h, Shape.PILL, Icon.QAM, pressed)
|
||||
else -> return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun keyboard(canvas: Canvas, w: Int, h: Int, pressed: Boolean) =
|
||||
system(canvas, w.toFloat(), h.toFloat(), Shape.ROUND, Icon.KEYBOARD, pressed)
|
||||
|
||||
private fun shoulder(canvas: Canvas, w: Float, h: Float, control: InputControl, pressed: Boolean) {
|
||||
val inset = dp(2f)
|
||||
val l = inset; val t = inset; val r = w - inset; val b = h - inset
|
||||
val trigger = control == InputControl.LT || control == InputControl.RT
|
||||
val big = (b - t) * if (trigger) .9f else .62f
|
||||
val small = dp(5f)
|
||||
val left = control == InputControl.LT || control == InputControl.LB
|
||||
glass(canvas, if (left) corners(l, t, r, b, big, small, small, small) else corners(l, t, r, b, small, big, small, small), pressed)
|
||||
text(canvas, when (control) {
|
||||
InputControl.LB -> "L1"
|
||||
InputControl.RB -> "R1"
|
||||
InputControl.LT -> "L2"
|
||||
else -> "R2"
|
||||
}, w / 2f, h / 2f, (b - t) * .46f, if (pressed) ON_ACCENT else INK, (r - l) * .8f)
|
||||
}
|
||||
|
||||
/** A back grip: a capsule along the long side of its box, at most 2.2 times as long as it is thick. */
|
||||
private fun grip(canvas: Canvas, w: Float, h: Float, label: String, pressed: Boolean) {
|
||||
val inset = dp(3f)
|
||||
val thick = (min(w, h) - 2 * inset).coerceAtLeast(1f)
|
||||
val long = (max(w, h) - 2 * inset).coerceAtMost(thick * 2.2f)
|
||||
val bw = if (w >= h) long else thick; val bh = if (w >= h) thick else long
|
||||
val cx = w / 2f; val cy = h / 2f
|
||||
glass(canvas, roundRect(cx - bw / 2, cy - bh / 2, cx + bw / 2, cy + bh / 2, thick / 2), pressed)
|
||||
text(canvas, label, cx, cy, thick * .42f, if (pressed) ON_ACCENT else INK_SOFT)
|
||||
}
|
||||
|
||||
private enum class Shape { ROUND, PILL, CHIP }
|
||||
private enum class Icon { VIEW, MENU, QAM, KEYBOARD, STEAM }
|
||||
|
||||
private fun system(canvas: Canvas, w: Float, h: Float, shape: Shape, icon: Icon, pressed: Boolean, ink: Int = INK) {
|
||||
val cx = w / 2f; val cy = h / 2f
|
||||
val size = when (shape) {
|
||||
Shape.ROUND -> { val r = min(w, h) / 2f * VISUAL; glass(canvas, circle(cx, cy, r), pressed); r * 1.2f }
|
||||
Shape.PILL -> { val vh = min(h * VISUAL, w * VISUAL / 2.3f); val vw = vh * 2.3f
|
||||
glass(canvas, roundRect(cx - vw / 2, cy - vh / 2, cx + vw / 2, cy + vh / 2, vh / 2), pressed); vh * 1.1f }
|
||||
Shape.CHIP -> { val vh = min(h * VISUAL, w * VISUAL / 1.9f); val vw = vh * 1.9f
|
||||
glass(canvas, roundRect(cx - vw / 2, cy - vh / 2, cx + vw / 2, cy + vh / 2, vh * .32f), pressed); vh * 1.05f }
|
||||
}
|
||||
icon(canvas, cx, cy, size, icon, if (pressed) ON_ACCENT else ink)
|
||||
}
|
||||
|
||||
private fun icon(canvas: Canvas, cx: Float, cy: Float, size: Float, icon: Icon, color: Int) {
|
||||
val u = size / 28f
|
||||
line.color = color; line.strokeWidth = 3.2f * u
|
||||
fill.color = color; fill.shader = null
|
||||
when (icon) {
|
||||
Icon.VIEW -> {
|
||||
canvas.drawRoundRect(RectF(cx - 12 * u, cy - 9 * u, cx + 3 * u, cy + 3 * u), 3 * u, 3 * u, line)
|
||||
fill.color = Color.argb(230, 14, 16, 20)
|
||||
canvas.drawRoundRect(RectF(cx - 4 * u, cy - 3 * u, cx + 11 * u, cy + 9 * u), 3 * u, 3 * u, fill)
|
||||
canvas.drawRoundRect(RectF(cx - 4 * u, cy - 3 * u, cx + 11 * u, cy + 9 * u), 3 * u, 3 * u, line)
|
||||
}
|
||||
Icon.MENU -> for (dy in intArrayOf(-7, 0, 7)) canvas.drawLine(cx - 11 * u, cy + dy * u, cx + 11 * u, cy + dy * u, line)
|
||||
Icon.QAM -> for (dx in intArrayOf(-10, 0, 10)) canvas.drawCircle(cx + dx * u, cy, 3.4f * u, fill)
|
||||
Icon.KEYBOARD -> {
|
||||
canvas.drawRoundRect(RectF(cx - 16 * u, cy - 11 * u, cx + 16 * u, cy + 11 * u), 4.5f * u, 4.5f * u, line)
|
||||
for (row in 0..1) for (col in 0..3) canvas.drawCircle(cx + (-9 + col * 6) * u, cy + (-4 + row * 5) * u, 1.7f * u, fill)
|
||||
line.strokeWidth = 2.6f * u; canvas.drawLine(cx - 6 * u, cy + 6 * u, cx + 6 * u, cy + 6 * u, line)
|
||||
}
|
||||
Icon.STEAM -> {
|
||||
ink.letterSpacing = .12f
|
||||
text(canvas, "STEAM", cx, cy, 14 * u, color, size * 1.9f)
|
||||
ink.letterSpacing = 0f
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun chevron(canvas: Canvas, ax: Float, ay: Float, dx: Float, dy: Float, k: Float, color: Int, width: Float) {
|
||||
val px = -dy; val py = dx
|
||||
line.color = color; line.strokeWidth = width
|
||||
canvas.drawPath(path.apply {
|
||||
reset(); moveTo(ax - dx * k * .5f + px * k, ay - dy * k * .5f + py * k); lineTo(ax + dx * k * .6f, ay + dy * k * .6f)
|
||||
lineTo(ax - dx * k * .5f - px * k, ay - dy * k * .5f - py * k)
|
||||
}, line)
|
||||
}
|
||||
|
||||
private fun cross(target: Path, cx: Float, cy: Float, s: Float, h: Float, rc: Float) = target.apply {
|
||||
reset()
|
||||
addRoundRect(RectF(cx - h, cy - s, cx + h, cy + s), rc, rc, Path.Direction.CW)
|
||||
bar.reset()
|
||||
bar.addRoundRect(RectF(cx - s, cy - h, cx + s, cy + h), rc, rc, Path.Direction.CW)
|
||||
op(bar, Path.Op.UNION)
|
||||
}
|
||||
|
||||
fun dpad(canvas: Canvas, w: Float, h: Float, held: Int) {
|
||||
val cx = w / 2f
|
||||
val cy = h / 2f
|
||||
val arms = min(w, h) / 2f - dp(3f)
|
||||
if (arms <= 0f) return
|
||||
val half = arms * .37f
|
||||
glass(canvas, cross(arm, cx, cy, arms, half, half * .43f), false)
|
||||
for (i in 0..3) {
|
||||
val dx = when (i) { 1 -> 1f; 3 -> -1f; else -> 0f }
|
||||
val dy = when (i) { 0 -> -1f; 2 -> 1f; else -> 0f }
|
||||
val on = held and (1 shl i) != 0
|
||||
if (on && half > dp(2f)) {
|
||||
fill.shader = null
|
||||
fill.color = PRESSED
|
||||
val near = half + dp(1f)
|
||||
val far = arms - dp(2f)
|
||||
val side = half - dp(2f)
|
||||
rect.set(if (dx == 0f) cx - side else if (dx > 0) cx + near else cx - far,
|
||||
if (dy == 0f) cy - side else if (dy > 0) cy + near else cy - far,
|
||||
if (dx == 0f) cx + side else if (dx > 0) cx + far else cx - near,
|
||||
if (dy == 0f) cy + side else if (dy > 0) cy + far else cy - near)
|
||||
canvas.drawRoundRect(rect, half * .4f, half * .4f, fill)
|
||||
}
|
||||
val m = (arms + half) / 2f
|
||||
chevron(canvas, cx + dx * m, cy + dy * m, dx, dy, half * .32f, if (on) ON_ACCENT else INK, half * .17f)
|
||||
}
|
||||
fill.shader = null
|
||||
fill.color = Color.argb(18, 255, 255, 255)
|
||||
canvas.drawCircle(cx, cy, half * .36f, fill)
|
||||
}
|
||||
|
||||
fun stick(canvas: Canvas, cx: Float, cy: Float, radius: Float, kx: Float, ky: Float, active: Boolean) {
|
||||
fill.alpha = 255
|
||||
fill.shader = RadialGradient(cx, cy, radius, WELL_IN, WELL_OUT, Shader.TileMode.CLAMP)
|
||||
fill.setShadowLayer(dp(2.5f), 0f, dp(1.5f), SHADOW)
|
||||
canvas.drawCircle(cx, cy, radius, fill)
|
||||
fill.clearShadowLayer(); fill.shader = null
|
||||
edge.color = Color.argb(61, 255, 255, 255); edge.strokeWidth = dp(1.25f)
|
||||
canvas.drawCircle(cx, cy, radius, edge)
|
||||
line.color = Color.argb(71, 255, 255, 255); line.strokeWidth = dp(1.4f)
|
||||
for (i in 0 until 8) {
|
||||
val a = i * Math.PI / 4
|
||||
val c = cos(a).toFloat(); val n = sin(a).toFloat()
|
||||
canvas.drawLine(cx + c * (radius - dp(7f)), cy + n * (radius - dp(7f)), cx + c * (radius - dp(3.5f)), cy + n * (radius - dp(3.5f)), line)
|
||||
}
|
||||
if (active && (kx != 0f || ky != 0f)) {
|
||||
val angle = Math.toDegrees(atan2(ky, kx).toDouble()).toFloat()
|
||||
line.color = ACCENT; line.strokeWidth = dp(3f)
|
||||
val r = radius - dp(2f)
|
||||
canvas.drawArc(RectF(cx - r, cy - r, cx + r, cy + r), angle - 35f, 70f, false, line)
|
||||
}
|
||||
val k = radius * .46f
|
||||
val x = cx + kx; val y = cy + ky
|
||||
line.color = if (active) ACCENT else Color.argb(140, 226, 232, 240)
|
||||
line.strokeWidth = dp(2.8f)
|
||||
canvas.drawCircle(x, y, k * 1.14f, line)
|
||||
glass(canvas, circle(x, y, k), false)
|
||||
edge.color = Color.argb(36, 255, 255, 255)
|
||||
edge.strokeWidth = dp(1f)
|
||||
canvas.drawCircle(x, y, k * .66f, edge)
|
||||
}
|
||||
|
||||
fun trackpad(canvas: Canvas, w: Float, h: Float, touching: Boolean, fx: Float, fy: Float) {
|
||||
if (w <= 0f || h <= 0f) return
|
||||
val inset = dp(1.5f)
|
||||
val radius = min(w, h) * .14f
|
||||
fill.shader = null; fill.color = Color.argb(51, 14, 16, 20)
|
||||
rect.set(inset, inset, w - inset, h - inset)
|
||||
canvas.drawRoundRect(rect, radius, radius, fill)
|
||||
edge.color = if (touching) Color.argb(191, 0x1A, 0x9F, 0xFF) else Color.argb(51, 255, 255, 255)
|
||||
edge.strokeWidth = dp(if (touching) 1.5f else 1f)
|
||||
canvas.drawRoundRect(rect, radius, radius, edge)
|
||||
if (!touching) return
|
||||
val glow = min(w, h) * .3f
|
||||
fill.shader = RadialGradient(fx, fy, glow, GLOW, Color.TRANSPARENT, Shader.TileMode.CLAMP)
|
||||
canvas.drawCircle(fx, fy, glow, fill); fill.shader = null
|
||||
fill.color = ACCENT; canvas.drawCircle(fx, fy, dp(5f), fill)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val VISUAL = .72f
|
||||
private val ACCENT = Color.rgb(0x1A, 0x9F, 0xFF)
|
||||
private val ON_ACCENT = Color.rgb(0x03, 0x11, 0x1F)
|
||||
val INK = Color.rgb(0xF4, 0xF7, 0xFB)
|
||||
private val INK_SOFT = Color.argb(209, 0xF4, 0xF7, 0xFB)
|
||||
private val BODY = Color.argb(133, 14, 16, 20)
|
||||
private val PRESSED = Color.argb(235, 0x1A, 0x9F, 0xFF)
|
||||
private val SHINE = Color.argb(43, 255, 255, 255)
|
||||
private val EDGE = Color.argb(77, 255, 255, 255)
|
||||
private val EDGE_PRESSED = Color.argb(140, 255, 255, 255)
|
||||
private val SHADOW = Color.argb(97, 0, 0, 0)
|
||||
private val WELL_IN = Color.argb(140, 5, 7, 10)
|
||||
private val WELL_OUT = Color.argb(71, 14, 16, 20)
|
||||
private val GLOW = Color.argb(140, 0x1A, 0x9F, 0xFF)
|
||||
}
|
||||
}
|
||||
@@ -323,6 +323,8 @@
|
||||
<string name="mode_pen_button">Side button</string>
|
||||
<string name="mode_osc">On-screen controls</string>
|
||||
<string name="mode_osc_qam">Steam + QAM</string>
|
||||
<string name="osc_rear_buttons">Rear buttons</string>
|
||||
<string name="osc_trackpads">Trackpads</string>
|
||||
<string name="mode_osc_note">Auto shows the controls when no controller is connected.</string>
|
||||
<string name="osc_steam_touch">Steam touch (beta)</string>
|
||||
<string name="osc_style_next_session">Steam\'s touch controls start with the next Steam session</string>
|
||||
|
||||
Reference in new issue
Block a user