mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
feat(input): restore controller-specific overlay designs
This commit is contained in:
1 parent
e06ca23f66
commit
66a4d28044
12 files changed
+564
-345
No files matched your search
+76
-13
@@ -5,7 +5,7 @@ import android.util.DisplayMetrics
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
internal class SteamDeckOverlayGeometry(
|
||||
internal class ControllerOverlayGeometry(
|
||||
width: Int, height: Int, private val safe: Rect, metrics: DisplayMetrics, scale: Float,
|
||||
) {
|
||||
private val w = width.toFloat()
|
||||
@@ -29,9 +29,12 @@ internal class SteamDeckOverlayGeometry(
|
||||
}
|
||||
}
|
||||
|
||||
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) }
|
||||
private fun x(ref: Float) = anchor(ref, 1600f, w, safe.left, safe.right)
|
||||
|
||||
private fun y(ref: Float) = anchor(ref, 900f, h, safe.top, safe.bottom)
|
||||
|
||||
fun place(elements: List<InputSurfaceElement>, kit: PadKit, rearButtons: Boolean, trackpads: Boolean): List<InputSurfaceElement> {
|
||||
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 } }
|
||||
@@ -41,15 +44,7 @@ internal class SteamDeckOverlayGeometry(
|
||||
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),
|
||||
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),
|
||||
@@ -86,6 +81,74 @@ internal class SteamDeckOverlayGeometry(
|
||||
}
|
||||
}
|
||||
|
||||
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 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),
|
||||
InputControl.GUIDE to Box(middle, y(850f), 46f),
|
||||
InputControl.START to Box(middle + 160f * unit, y(850f), 50f, 30f),
|
||||
) else listOf(
|
||||
InputControl.QAM to Box(x(220f), y(848f), 46f),
|
||||
InputControl.SELECT to Box(middle - 110f * unit, y(850f), 38f),
|
||||
InputControl.GUIDE to Box(middle, y(850f), 46f),
|
||||
InputControl.START to Box(middle + 110f * unit, y(850f), 38f),
|
||||
)
|
||||
val row = fitRow(listOfNotNull(keyboard) + controls.map { it.second }, leftEdge)
|
||||
val positions = controls.map { it.first }.zip(row.takeLast(controls.size)).toMap() + shoulders() +
|
||||
if (kit.playStation) {
|
||||
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),
|
||||
)
|
||||
} 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),
|
||||
)
|
||||
}
|
||||
return elements.map { element ->
|
||||
when (element.id) {
|
||||
KEYBOARD -> row.first().place(element)
|
||||
"legacy:${element.control.id}" -> positions[element.control]?.place(element) ?: element
|
||||
else -> element
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun shoulders() = 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),
|
||||
)
|
||||
|
||||
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),
|
||||
)
|
||||
|
||||
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 side = radius * .25f
|
||||
return mapOf(
|
||||
InputControl.UP to Box(x(cx), y(cy) - offset, side, depth),
|
||||
InputControl.RIGHT to Box(x(cx) + offset, y(cy), depth, side),
|
||||
InputControl.DOWN to Box(x(cx), y(cy) + offset, side, depth),
|
||||
InputControl.LEFT to Box(x(cx) - offset, y(cy), depth, side),
|
||||
)
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -100,9 +100,9 @@ class OnScreenControls(context: Context, pad: PadBridge?, val dock: OnScreenLayo
|
||||
|
||||
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 }
|
||||
val artwork = if (dock == null) PadKit.forOverlay(context, layout) else null
|
||||
surface.updateStyle(style, artwork)
|
||||
quickToggle.tint = style.tint.takeUnless { artwork != null }
|
||||
quickToggle.alpha = style.opacity / 100f
|
||||
quickToggle.invalidate()
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@ 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)
|
||||
@@ -49,13 +46,15 @@ object OnScreenLayout {
|
||||
}
|
||||
val byId = (placed + others).associateBy { it.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) &&
|
||||
if (dock != null) return ordered
|
||||
val kit = PadKit.forOverlay(context, layout) ?: return ordered
|
||||
if (generated && width >= height &&
|
||||
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 ControllerOverlayGeometry(width, height, safe, context.resources.displayMetrics, layout.scale)
|
||||
.place(ordered, kit, rearButtons == true, trackpads == true)
|
||||
}
|
||||
if (!kit.steam) return ordered
|
||||
return FloatingSteamOverlay(width, height, safe, context.resources.displayMetrics.density)
|
||||
.place(ordered, lowerShortcuts = generated, rearButtons = rearButtons, trackpads = trackpads)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.droiddeck.launcher.input
|
||||
|
||||
import android.content.Context
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
internal enum class FaceGlyphs { MONO_LETTERS, COLOR_LETTERS, COLOR_SYMBOLS, MONO_SYMBOLS }
|
||||
internal enum class DpadStyle { CROSS, DISC, ARROWS }
|
||||
internal enum class StickCap { RINGED, DISHED, KNURLED }
|
||||
|
||||
internal enum class PadKit(val face: FaceGlyphs, val dpad: DpadStyle, val stick: StickCap, private val xbox: Boolean = false) {
|
||||
STEAM_DECK(FaceGlyphs.MONO_LETTERS, DpadStyle.CROSS, StickCap.RINGED),
|
||||
STEAM_CONTROLLER(FaceGlyphs.MONO_LETTERS, DpadStyle.CROSS, StickCap.RINGED),
|
||||
XBOX(FaceGlyphs.COLOR_LETTERS, DpadStyle.DISC, StickCap.DISHED, xbox = true),
|
||||
DUALSHOCK(FaceGlyphs.COLOR_SYMBOLS, DpadStyle.ARROWS, StickCap.KNURLED),
|
||||
DUALSENSE(FaceGlyphs.MONO_SYMBOLS, DpadStyle.ARROWS, StickCap.KNURLED);
|
||||
|
||||
val steam get() = this == STEAM_DECK || this == STEAM_CONTROLLER
|
||||
val playStation get() = this == DUALSHOCK || this == DUALSENSE
|
||||
|
||||
fun label(control: InputControl): String = when (control) {
|
||||
InputControl.LB -> if (xbox) "LB" else "L1"
|
||||
InputControl.RB -> if (xbox) "RB" else "R1"
|
||||
InputControl.LT -> if (xbox) "LT" else "L2"
|
||||
InputControl.RT -> if (xbox) "RT" else "R2"
|
||||
else -> control.label
|
||||
}
|
||||
|
||||
/** What the player calls [control] on this controller. */
|
||||
fun name(control: InputControl): String = if (!playStation) label(control) else when (control) {
|
||||
InputControl.A -> "Cross"
|
||||
InputControl.B -> "Circle"
|
||||
InputControl.X -> "Square"
|
||||
InputControl.Y -> "Triangle"
|
||||
else -> label(control)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun forOverlay(context: Context, layout: SavedInputLayout?): PadKit? =
|
||||
if (layout?.id != InputLibraries.OVERLAY) null else when (SessionPrefs.steamController(context)) {
|
||||
SessionPrefs.CONTROLLER_DECK -> STEAM_DECK
|
||||
SessionPrefs.CONTROLLER_STEAM -> STEAM_CONTROLLER
|
||||
SessionPrefs.CONTROLLER_XBOX360 -> XBOX
|
||||
SessionPrefs.CONTROLLER_DS4 -> DUALSHOCK
|
||||
SessionPrefs.CONTROLLER_DUALSENSE -> DUALSENSE
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ 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) {
|
||||
@@ -48,11 +47,10 @@ internal class InputLayoutPreviewView(context: Context) : View(context) {
|
||||
fun update(layout: SavedInputLayout, role: InputRole) {
|
||||
sourceHeight = if (role == InputRole.PRIMARY) 563 else 870
|
||||
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
|
||||
val artwork = if (primary) PadKit.forOverlay(context, layout) else null
|
||||
val elements = if (artwork != null) 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.updateStyle(layout.style.copy(opacity = 100), artwork)
|
||||
renderer.measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(sourceHeight, MeasureSpec.EXACTLY))
|
||||
renderer.layout(0, 0, 1000, sourceHeight)
|
||||
contentDescription = layout.name
|
||||
|
||||
@@ -278,7 +278,7 @@ 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) {
|
||||
if (!OnScreenLayout.usesSteamDeckButtons(context, layout)) {
|
||||
if (role != InputRole.PRIMARY || PadKit.forOverlay(context, layout) == null) {
|
||||
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,
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.view.MotionEvent
|
||||
import android.view.ViewConfiguration
|
||||
import android.widget.FrameLayout
|
||||
import com.droiddeck.launcher.input.OnScreenLayout
|
||||
import com.droiddeck.launcher.input.PadKit
|
||||
import com.droiddeck.launcher.input.SavedInputLayout
|
||||
import com.droiddeck.launcher.input.InputSurfaceElement
|
||||
import com.droiddeck.launcher.input.InputSurfaceStyle
|
||||
@@ -56,7 +57,7 @@ internal class InputSurfaceEditorView(context: Context) : FrameLayout(context) {
|
||||
}
|
||||
|
||||
private fun updatePreviewStyle() {
|
||||
preview.updateStyle(style, steamDeckButtons = OnScreenLayout.usesSteamDeckButtons(context, sourceLayout))
|
||||
preview.updateStyle(style, PadKit.forOverlay(context, sourceLayout))
|
||||
}
|
||||
|
||||
private fun refreshElements() {
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.droiddeck.launcher.input.InputButtonIcons
|
||||
import com.droiddeck.launcher.input.InputButtonShape
|
||||
import com.droiddeck.launcher.input.InputButtonImages
|
||||
import com.droiddeck.launcher.input.PadBridge
|
||||
import com.droiddeck.launcher.input.PadKit
|
||||
import com.droiddeck.launcher.input.pcKeyLabel
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import kotlin.math.atan2
|
||||
@@ -56,10 +57,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 artwork: PadKit? = null
|
||||
private val art by lazy(LazyThreadSafetyMode.NONE) { PadArt(context) }
|
||||
private var artworkDpad = emptyList<HoldButton>()
|
||||
private val artworkDpadBounds = RectF()
|
||||
private var requestedLayout = customLayout
|
||||
init { customLayout = surfaceStyle.shown(customLayout); addView(content, LayoutParams(-1, -1)); renderCustom(pad) }
|
||||
|
||||
@@ -138,11 +139,11 @@ class InputSurfaceView(
|
||||
}
|
||||
}
|
||||
|
||||
fun updateStyle(style: InputSurfaceStyle, steamDeckButtons: Boolean = false) {
|
||||
if (surfaceStyle == style && this.steamDeckButtons == steamDeckButtons) return
|
||||
internal fun updateStyle(style: InputSurfaceStyle, artwork: PadKit? = null) {
|
||||
if (surfaceStyle == style && this.artwork == artwork) return
|
||||
val relayout = surfaceStyle.hidden != style.hidden
|
||||
surfaceStyle = style
|
||||
this.steamDeckButtons = steamDeckButtons
|
||||
this.artwork = artwork
|
||||
if (relayout) updateCustomLayout(requestedLayout)
|
||||
customCanvas?.let { canvas ->
|
||||
for (i in 0 until canvas.childCount) styleElement(canvas.getChildAt(i))
|
||||
@@ -181,7 +182,7 @@ class InputSurfaceView(
|
||||
}
|
||||
|
||||
private fun renderCustom(pad: PadBridge?) {
|
||||
deckDpad = emptyList()
|
||||
artworkDpad = emptyList()
|
||||
val canvas = object : ViewGroup(context) {
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
val layout = customLayout
|
||||
@@ -199,17 +200,18 @@ 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)
|
||||
updateArtworkDpad(this)
|
||||
}
|
||||
|
||||
override fun dispatchDraw(canvas: Canvas) {
|
||||
if (steamDeckButtons && deckDpad.isNotEmpty()) {
|
||||
val alpha = (deckDpad.first().alpha * 255f).toInt()
|
||||
val kit = artwork
|
||||
if (kit != null && artworkDpad.isNotEmpty()) {
|
||||
val alpha = (artworkDpad.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)
|
||||
else canvas.saveLayerAlpha(artworkDpadBounds, alpha)
|
||||
canvas.translate(artworkDpadBounds.left, artworkDpadBounds.top)
|
||||
val held = artworkDpad.foldIndexed(0) { i, bits, button -> if (button.highlighted) bits or (1 shl i) else bits }
|
||||
art.dpad(canvas, artworkDpadBounds.width(), artworkDpadBounds.height(), kit, held)
|
||||
canvas.restoreToCount(saved)
|
||||
}
|
||||
super.dispatchDraw(canvas)
|
||||
@@ -229,7 +231,7 @@ class InputSurfaceView(
|
||||
customCanvas = canvas
|
||||
}
|
||||
|
||||
private fun updateDeckDpad(canvas: ViewGroup) {
|
||||
private fun updateArtworkDpad(canvas: ViewGroup) {
|
||||
val buttons = DIRECTIONS.mapNotNull { direction ->
|
||||
val index = customLayout.indexOfFirst { element ->
|
||||
element.control == direction && classic(element) && element.buttonShape == InputButtonShape.CIRCLE &&
|
||||
@@ -238,7 +240,7 @@ class InputSurfaceView(
|
||||
}
|
||||
canvas.getChildAt(index) as? HoldButton
|
||||
}
|
||||
deckDpad = emptyList()
|
||||
artworkDpad = emptyList()
|
||||
if (buttons.size != DIRECTIONS.size) return
|
||||
val (up, right, down, left) = buttons
|
||||
val centerX = (left.left + right.right) / 2f
|
||||
@@ -248,8 +250,8 @@ class InputSurfaceView(
|
||||
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
|
||||
artworkDpadBounds.set(left.left.toFloat(), up.top.toFloat(), right.right.toFloat(), down.bottom.toFloat())
|
||||
artworkDpad = buttons
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
@@ -395,14 +397,17 @@ class InputSurfaceView(
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
val lit = highlighted
|
||||
val classic = classic(element)
|
||||
if (steamDeckButtons && element.image.isEmpty() && element.showLabel) {
|
||||
if (this in deckDpad) return
|
||||
val kit = artwork
|
||||
if (kit != null && element.image.isEmpty() && element.showLabel) {
|
||||
if (this in artworkDpad) return
|
||||
if (element.id == "builtin:keyboard" && element.icon == InputButtonIcons.KEYBOARD) {
|
||||
deckArt.keyboard(canvas, width, height, lit)
|
||||
art.system(canvas, width.toFloat(), height.toFloat(), PadArt.Shape.ROUND, PadArt.Icon.KEYBOARD, 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
|
||||
val control = element.control
|
||||
val native = element.id == "legacy:${control.id}" && element.icon == 0 &&
|
||||
(element.name == control.label || element.name == kit.name(control))
|
||||
if (native && art.button(canvas, width, height, control, kit, lit)) return
|
||||
}
|
||||
drawSurface(canvas, lit, element.buttonShape, classic)
|
||||
val cx = width / 2f
|
||||
@@ -452,7 +457,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()
|
||||
if (artwork != null && this in artworkDpad) customCanvas?.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -480,7 +485,7 @@ class InputSurfaceView(
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
if (!captioned) {
|
||||
deckArt.trackpad(canvas, width.toFloat(), height.toFloat(), touching || clicked, fingerX, fingerY)
|
||||
art.trackpad(canvas, width.toFloat(), height.toFloat(), touching || clicked, fingerX, fingerY)
|
||||
return
|
||||
}
|
||||
drawSurface(canvas, clicked)
|
||||
@@ -596,10 +601,11 @@ 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 kit = artwork
|
||||
if (kit != null && classic(element)) {
|
||||
val radius = min(width, height) / 2f - 2f * density
|
||||
if (radius > 0f) {
|
||||
deckArt.stick(canvas, cx, cy, radius, knobX, knobY, touching || clicking)
|
||||
art.stick(canvas, cx, cy, radius, kit, knobX, knobY, touching || clicking)
|
||||
if (element.showLabel) {
|
||||
labelPaint.color = TEXT
|
||||
drawDirectionLabels(canvas, source, false, cx, cy, radius * .66f, radius * .34f, labelPaint)
|
||||
|
||||
@@ -0,0 +1,378 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.DashPathEffect
|
||||
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.DpadStyle
|
||||
import com.droiddeck.launcher.input.FaceGlyphs
|
||||
import com.droiddeck.launcher.input.InputControl
|
||||
import com.droiddeck.launcher.input.PadKit
|
||||
import com.droiddeck.launcher.input.StickCap
|
||||
import kotlin.math.atan2
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sin
|
||||
|
||||
/** The on-screen controls' shared drawing: one glass material, shaped per virtual controller. */
|
||||
internal class PadArt(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
|
||||
|
||||
fun button(canvas: Canvas, width: Int, height: Int, control: InputControl, kit: PadKit, 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 ->
|
||||
face(canvas, w / 2f, h / 2f, min(w, h) / 2f - dp(2f), control, kit, pressed)
|
||||
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.SELECT, InputControl.START, InputControl.GUIDE, InputControl.QAM -> {
|
||||
val (shape, icon) = systemLook(kit, control)
|
||||
system(canvas, w, h, shape, icon, pressed)
|
||||
}
|
||||
else -> return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun systemLook(kit: PadKit, control: InputControl): Pair<Shape, Icon> = when {
|
||||
kit.steam -> when (control) {
|
||||
InputControl.SELECT -> Shape.CHIP to Icon.VIEW
|
||||
InputControl.START -> Shape.CHIP to Icon.MENU
|
||||
InputControl.GUIDE -> Shape.PILL to Icon.STEAM
|
||||
else -> Shape.PILL to Icon.QAM
|
||||
}
|
||||
kit.playStation -> when (control) {
|
||||
InputControl.SELECT -> Shape.PILL to if (kit == PadKit.DUALSHOCK) Icon.SHARE else Icon.CREATE
|
||||
InputControl.START -> Shape.PILL to if (kit == PadKit.DUALSHOCK) Icon.OPTIONS else Icon.MENU
|
||||
InputControl.GUIDE -> Shape.ROUND to Icon.HOME
|
||||
else -> Shape.ROUND to Icon.QAM
|
||||
}
|
||||
else -> Shape.ROUND to when (control) {
|
||||
InputControl.SELECT -> Icon.BACK
|
||||
InputControl.START -> Icon.START
|
||||
InputControl.GUIDE -> Icon.HOME
|
||||
else -> Icon.QAM
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
fun circle(cx: Float, cy: Float, r: Float): Path = path.apply { reset(); addCircle(cx, cy, r, Path.Direction.CW) }
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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 face(canvas: Canvas, cx: Float, cy: Float, r: Float, control: InputControl, kit: PadKit, pressed: Boolean) {
|
||||
glass(canvas, circle(cx, cy, r), pressed)
|
||||
when (kit.face) {
|
||||
FaceGlyphs.COLOR_SYMBOLS -> symbol(canvas, cx, cy, r, control, if (pressed) ON_ACCENT else SYMBOL_COLORS[control] ?: INK)
|
||||
FaceGlyphs.MONO_SYMBOLS -> symbol(canvas, cx, cy, r, control, if (pressed) ON_ACCENT else INK_SOFT)
|
||||
FaceGlyphs.COLOR_LETTERS -> text(canvas, control.label, cx, cy, r * .95f, if (pressed) ON_ACCENT else LETTER_COLORS[control] ?: INK)
|
||||
FaceGlyphs.MONO_LETTERS -> text(canvas, control.label, cx, cy, r * .95f, if (pressed) ON_ACCENT else INK)
|
||||
}
|
||||
}
|
||||
|
||||
private fun symbol(canvas: Canvas, cx: Float, cy: Float, r: Float, control: InputControl, color: Int) {
|
||||
val s = r * .4f
|
||||
line.color = color; line.strokeWidth = r * .12f
|
||||
when (control) {
|
||||
InputControl.A -> { canvas.drawLine(cx - s, cy - s, cx + s, cy + s, line); canvas.drawLine(cx + s, cy - s, cx - s, cy + s, line) }
|
||||
InputControl.B -> canvas.drawCircle(cx, cy, s * 1.05f, line)
|
||||
InputControl.X -> canvas.drawRoundRect(RectF(cx - s * .95f, cy - s * .95f, cx + s * .95f, cy + s * .95f), s * .18f, s * .18f, line)
|
||||
else -> canvas.drawPath(path.apply { reset(); moveTo(cx, cy - s * 1.1f); lineTo(cx + s * 1.1f, cy + s * .85f); lineTo(cx - s * 1.1f, cy + s * .85f); close() }, line)
|
||||
}
|
||||
}
|
||||
|
||||
fun shoulder(canvas: Canvas, w: Float, h: Float, control: InputControl, kit: PadKit, 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, kit.label(control), 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. */
|
||||
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)
|
||||
}
|
||||
|
||||
fun small(canvas: Canvas, w: Float, h: Float, label: String, pressed: Boolean) {
|
||||
val r = min(w, h) / 2f * VISUAL
|
||||
glass(canvas, circle(w / 2f, h / 2f, r), pressed)
|
||||
text(canvas, label, w / 2f, h / 2f, r * .62f, if (pressed) ON_ACCENT else INK)
|
||||
}
|
||||
|
||||
enum class Shape { ROUND, PILL, CHIP }
|
||||
enum class Icon { VIEW, MENU, QAM, KEYBOARD, BACK, START, CREATE, HOME, STEAM, SHARE, OPTIONS }
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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.BACK, Icon.START -> {
|
||||
val f = if (icon == Icon.START) 1f else -1f
|
||||
line.strokeWidth = 2.6f * u
|
||||
canvas.drawPath(path.apply { reset(); moveTo(cx - 6 * f * u, cy - 8 * u); lineTo(cx + 7 * f * u, cy); lineTo(cx - 6 * f * u, cy + 8 * u); close() }, line)
|
||||
}
|
||||
Icon.CREATE -> {
|
||||
line.strokeWidth = 2.8f * u
|
||||
canvas.drawLine(cx - 8 * u, cy + 8 * u, cx - 2 * u, cy - 8 * u, line)
|
||||
canvas.drawLine(cx + u, cy + 8 * u, cx + 4 * u, cy - 2 * u, line)
|
||||
canvas.drawLine(cx + 8 * u, cy + 8 * u, cx + 9 * u, cy + 3 * u, line)
|
||||
}
|
||||
Icon.HOME -> canvas.drawPath(path.apply {
|
||||
reset(); moveTo(cx - 13 * u, cy - u); lineTo(cx, cy - 13 * u); lineTo(cx + 13 * u, cy - u)
|
||||
moveTo(cx - 9 * u, cy - 4 * u); lineTo(cx - 9 * u, cy + 11 * u); lineTo(cx + 9 * u, cy + 11 * u); lineTo(cx + 9 * u, cy - 4 * u)
|
||||
}, line)
|
||||
Icon.STEAM, Icon.SHARE, Icon.OPTIONS -> {
|
||||
ink.letterSpacing = .12f
|
||||
text(canvas, when (icon) { Icon.STEAM -> "STEAM"; Icon.SHARE -> "SHARE"; else -> "OPTIONS" }, 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)
|
||||
}
|
||||
|
||||
/** [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
|
||||
val s = min(w, h) / 2f - dp(3f)
|
||||
if (s <= 0f) return
|
||||
val dirs = arrayOf(floatArrayOf(0f, -1f), floatArrayOf(1f, 0f), floatArrayOf(0f, 1f), floatArrayOf(-1f, 0f))
|
||||
when (kit.dpad) {
|
||||
DpadStyle.CROSS, DpadStyle.DISC -> {
|
||||
val disc = kit.dpad == DpadStyle.DISC
|
||||
val arms = if (disc) s * .78f else s
|
||||
val half = if (disc) s * .25f else s * .37f
|
||||
if (disc) {
|
||||
glass(canvas, circle(cx, cy, s), false)
|
||||
fill.shader = null; fill.color = Color.argb(18, 255, 255, 255)
|
||||
canvas.drawPath(cross(arm, cx, cy, arms, half, half * .5f), fill)
|
||||
edge.color = Color.argb(56, 255, 255, 255); edge.strokeWidth = dp(1f)
|
||||
canvas.drawPath(arm, edge)
|
||||
} else glass(canvas, cross(arm, cx, cy, arms, half, half * .43f), false)
|
||||
for (i in 0..3) {
|
||||
val dx = dirs[i][0]; val dy = dirs[i][1]
|
||||
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
|
||||
if (chevrons) chevron(canvas, cx + dx * m, cy + dy * m, dx, dy, half * .32f, if (on) ON_ACCENT else ink, half * .17f)
|
||||
}
|
||||
if (!disc) { fill.shader = null; fill.color = Color.argb(18, 255, 255, 255); canvas.drawCircle(cx, cy, half * .36f, fill) }
|
||||
}
|
||||
DpadStyle.ARROWS -> {
|
||||
fill.shader = null; fill.color = Color.argb(56, 0, 0, 0)
|
||||
canvas.drawCircle(cx, cy, s, fill)
|
||||
edge.color = Color.argb(36, 255, 255, 255); edge.strokeWidth = dp(1f)
|
||||
canvas.drawCircle(cx, cy, s, edge)
|
||||
val bw = s * .5f; val tip = s * .14f; val base = s * .38f; val top = s * .9f; val rc = s * .11f
|
||||
for (i in 0..3) {
|
||||
canvas.save()
|
||||
canvas.rotate(i * 90f, cx, cy)
|
||||
arm.reset()
|
||||
arm.moveTo(cx, cy - tip); arm.lineTo(cx - bw / 2, cy - base); arm.lineTo(cx - bw / 2, cy - top + rc)
|
||||
arm.quadTo(cx - bw / 2, cy - top, cx - bw / 2 + rc, cy - top); arm.lineTo(cx + bw / 2 - rc, cy - top)
|
||||
arm.quadTo(cx + bw / 2, cy - top, cx + bw / 2, cy - top + rc); arm.lineTo(cx + bw / 2, cy - base); arm.close()
|
||||
val on = held and (1 shl i) != 0
|
||||
glass(canvas, arm, on)
|
||||
val ty = cy - (base + top) / 2f; val ts = s * .07f
|
||||
fill.shader = null; fill.color = if (on) ON_ACCENT else INK_SOFT
|
||||
if (chevrons) canvas.drawPath(path.apply { reset(); moveTo(cx, ty - ts); lineTo(cx + ts, ty + ts * .7f); lineTo(cx - ts, ty + ts * .7f); close() }, fill)
|
||||
canvas.restore()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun stick(canvas: Canvas, cx: Float, cy: Float, radius: Float, kit: PadKit, 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
|
||||
if (kit.stick == StickCap.RINGED) {
|
||||
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)
|
||||
when (kit.stick) {
|
||||
StickCap.DISHED -> {
|
||||
fill.shader = RadialGradient(x, y - k * .1f, k * .74f, Color.argb(107, 0, 0, 0), Color.TRANSPARENT, Shader.TileMode.CLAMP)
|
||||
canvas.drawCircle(x, y, k * .74f, fill); fill.shader = null
|
||||
edge.color = if (active) ACCENT else Color.argb(51, 255, 255, 255); edge.strokeWidth = dp(1f)
|
||||
canvas.drawCircle(x, y, k * .74f, edge)
|
||||
}
|
||||
StickCap.KNURLED -> {
|
||||
line.color = if (active) ACCENT else Color.argb(66, 255, 255, 255); line.strokeWidth = dp(2.3f)
|
||||
line.pathEffect = DashPathEffect(floatArrayOf(dp(1.2f), dp(1.9f)), 0f)
|
||||
canvas.drawCircle(x, y, k * .9f, line); line.pathEffect = null
|
||||
fill.color = Color.argb(56, 0, 0, 0); canvas.drawCircle(x, y, k * .6f, fill)
|
||||
}
|
||||
StickCap.RINGED -> { 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) {
|
||||
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 {
|
||||
const val VISUAL = .72f
|
||||
val ACCENT = Color.rgb(0x1A, 0x9F, 0xFF)
|
||||
val ON_ACCENT = Color.rgb(0x03, 0x11, 0x1F)
|
||||
val INK = Color.rgb(0xF4, 0xF7, 0xFB)
|
||||
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)
|
||||
private val LETTER_COLORS = mapOf(InputControl.A to Color.rgb(0x5C, 0xCB, 0x5F), InputControl.B to Color.rgb(0xF0, 0x50, 0x4A),
|
||||
InputControl.X to Color.rgb(0x4C, 0x9B, 0xF0), InputControl.Y to Color.rgb(0xF5, 0xC0, 0x2E))
|
||||
private val SYMBOL_COLORS = mapOf(InputControl.A to Color.rgb(0x8D, 0xB4, 0xF2), InputControl.B to Color.rgb(0xF2, 0x61, 0x6B),
|
||||
InputControl.X to Color.rgb(0xEE, 0x93, 0xD6), InputControl.Y to Color.rgb(0x45, 0xCB, 0xAA))
|
||||
}
|
||||
}
|
||||
@@ -1,277 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,8 @@ class OnScreenLayoutTest {
|
||||
assertEquals(base, both.filter { it.control in standard })
|
||||
}
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_XBOX360)
|
||||
assertEquals(original, placed(true, true))
|
||||
assertEquals(original.map { it.id }, placed(true, true).map { it.id })
|
||||
assertEquals(placed(false, false), placed(true, true))
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_DECK)
|
||||
val edited = layout.copy(elements = layout.elements.map { e -> if (e.control == InputControl.START) e.copy(y = .3f) else e })
|
||||
val fitted = OnScreenLayout.elements(context, edited, w, h, safe)
|
||||
@@ -84,12 +85,12 @@ class OnScreenLayoutTest {
|
||||
}
|
||||
|
||||
@Test fun theBuiltInGamepadIsRegeneratedForEverySizeWithoutStretching() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_STEAM)
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_NONE)
|
||||
val layout = gamepad()
|
||||
for ((w, h) in listOf(1200 to 540, 540 to 1200, 900 to 850)) {
|
||||
val placed = OnScreenLayout.elements(context, layout, w, h, Rect())
|
||||
assertEquals(layout.elements.map { it.id }, placed.map { it.id })
|
||||
assertOnlyShortcutPositionsChanged(LegacyGamepadLayout(context, w, h).regenerate(layout.elements), placed)
|
||||
assertEquals(LegacyGamepadLayout(context, w, h).regenerate(layout.elements), placed)
|
||||
for (id in listOf("legacy:a", "legacy:up", "legacy:guide")) assertSquare(placed.first { it.id == id }, w, h)
|
||||
assertInside(placed, w, h)
|
||||
}
|
||||
@@ -97,10 +98,10 @@ class OnScreenLayoutTest {
|
||||
|
||||
@Test @Config(qualifiers = "w745dp-h343dp-land-420dpi")
|
||||
fun aBuiltInGamepadSavedAtTheDisplaySizeRegeneratesForTheMeasuredSurface() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_STEAM)
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_NONE)
|
||||
val saved = gamepad().copy(elements = LegacyGamepadLayout(context, 2608, 1200).elements(), aspect = 2608f / 1200)
|
||||
val placed = OnScreenLayout.elements(context, saved, 2048, 1200, Rect())
|
||||
assertOnlyShortcutPositionsChanged(LegacyGamepadLayout(context, 2048, 1200).regenerate(saved.elements), placed)
|
||||
assertEquals(LegacyGamepadLayout(context, 2048, 1200).regenerate(saved.elements), placed)
|
||||
}
|
||||
|
||||
@Test @Config(qualifiers = "w745dp-h343dp-land-420dpi")
|
||||
@@ -175,7 +176,7 @@ class OnScreenLayoutTest {
|
||||
}
|
||||
|
||||
@Test fun regenerationKeepsTheUsersButtonStylesAndRemovedButtons() {
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_STEAM)
|
||||
SessionPrefs.setSteamController(context, SessionPrefs.CONTROLLER_NONE)
|
||||
val layout = gamepad().let { g -> g.copy(elements = g.elements.filterNot { it.id == "legacy:y" }.map { if (it.id == "legacy:a") it.copy(opacity = .4f, icon = 0, name = "Jump") else it }) }
|
||||
val placed = OnScreenLayout.elements(context, layout, 2000, 1000, Rect())
|
||||
assertNull(placed.firstOrNull { it.id == "legacy:y" })
|
||||
|
||||
@@ -85,10 +85,12 @@ class InputSurfaceTouchTest {
|
||||
|
||||
touch(MotionEvent.ACTION_DOWN, 1 to (800f to 240f))
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
surface.updateStyle(InputSurfaceStyle(), steamDeckButtons = true)
|
||||
assertEquals(shown, surface.shownElements)
|
||||
assertTrue(surface.takesTouchAt(800f, 240f))
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
for (artwork in PadKit.entries) {
|
||||
surface.updateStyle(InputSurfaceStyle(), artwork)
|
||||
assertEquals(shown, surface.shownElements)
|
||||
assertTrue(surface.takesTouchAt(800f, 240f))
|
||||
assertTrue(state().isDown(PadState.A))
|
||||
}
|
||||
|
||||
touch(MotionEvent.ACTION_UP, 1 to (800f to 240f))
|
||||
assertFalse(state().isDown(PadState.A))
|
||||
|
||||
Reference in new issue
Block a user