Animate scrolling in menus

This commit is contained in:
James Babcock committed 2026-09-24 11:04:10 -07:00
1 parent 915f155819
commit c801bd5185
23 files changed
+514 -91

No files matched your search

@@ -1,6 +1,6 @@
package com.faceclaw.app
/** Revision 28 wire grammar, shared by scene planning and the local renderer. */
/** Revision 29 wire grammar, shared by scene planning and the local renderer. */
object DrawProtocol {
/** Mirrors g2flash/patches/zlib_glue.c. */
const val DRAW = CFW_MSG_DRAW_CALLS
@@ -97,14 +97,21 @@ object DrawProtocol {
fun rectCopy(
source: Int, x: Int, y: Int, width: Int, height: Int, dx: Int, dy: Int,
target: Int? = null, depth: Int? = null,
): ByteArray = rectCopy(source, DrawValue.Integer(x), DrawValue.Integer(y), width, height,
DrawValue.Integer(dx), DrawValue.Integer(dy), target, depth)
/** Revision 29: source and destination coordinates may be expressions; the source rect must stay in bounds. */
fun rectCopy(
source: Int, x: DrawValue, y: DrawValue, width: Int, height: Int, dx: DrawValue, dy: DrawValue,
target: Int? = null, depth: Int? = null,
): ByteArray = call(DRAW_OP_RECT_COPY, target, depth) {
writeU16(source)
writeU16(x)
writeU16(y)
writeExtended(x)
writeExtended(y)
writeU16(width)
writeU16(height)
writeS16(dx)
writeS16(dy)
writeExtended(dx)
writeExtended(dy)
}
/** Fill the whole target, ignoring depth. */
@@ -256,13 +256,14 @@ class DisplayListRenderer(
private fun drawRectCopy(reader: DrawReader, target: Target, walk: Walk) {
val id = reader.readU16()
val x = reader.readU16()
val y = reader.readU16()
val x = ExtendedVarint.evaluate(reader, walk.frame)
val y = ExtendedVarint.evaluate(reader, walk.frame)
val width = reader.readU16()
val height = reader.readU16()
val dx = reader.readS16()
val dy = reader.readS16()
val dx = ExtendedVarint.evaluate(reader, walk.frame)
val dy = ExtendedVarint.evaluate(reader, walk.frame)
reader.requireDone()
require(x >= 0 && y >= 0)
val source = when (id) {
DrawProtocol.SCREEN -> walk.screen
DrawProtocol.CURRENT -> target
@@ -272,7 +273,8 @@ class DisplayListRenderer(
}
}
require(width > 0 && height > 0 && x + width <= source.width && y + height <= source.height)
if (walk.apply) {
// Mirrors the firmware's overflow guard before the depth shift.
if (walk.apply && dx in -65536..65536) {
// Snapshot the rectangle so overlapping copies have memmove semantics.
val copy = IntArray(width * height) { source.get(x + it % width, y + it / width) }
for (i in copy.indices) target.put(dx + i % width, dy + i / width, copy[i])
@@ -21,7 +21,8 @@ class FrameDisplayList private constructor(
override fun translated(dx: Int, dy: Int) = FrameDisplayList(x + dx, y + dy, depth, resources, commands, startedAt, identity)
private class Command(val op: Int, val depth: Int, val values: IntArray,
val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0))
val x: DrawValue = DrawValue.Integer(0), val y: DrawValue = DrawValue.Integer(0),
val dx: DrawValue = DrawValue.Integer(0), val dy: DrawValue = DrawValue.Integer(0))
override fun calls(ids: IntArray, nowMs: Long): List<ByteArray> {
require(ids.size == resources.size)
@@ -34,9 +35,9 @@ class FrameDisplayList private constructor(
v[0], v[1], v[2], v[3], v[4], depth + c.depth)
DRAW_OP_IMAGE -> DrawProtocol.image(resource(v[0]), x + v[1], y + v[2], v[3], depth = depth + c.depth)
DRAW_OP_RECT_COPY -> DrawProtocol.rectCopy(resource(v[0]),
v[1] + if (v[0] == DrawProtocol.SCREEN) x else 0,
v[2] + if (v[0] == DrawProtocol.SCREEN) y else 0,
v[3], v[4], x + v[5], y + v[6], depth = depth + c.depth)
bind(c.x, elapsed, if (v[0] == DrawProtocol.SCREEN) x else 0),
bind(c.y, elapsed, if (v[0] == DrawProtocol.SCREEN) y else 0),
v[1], v[2], bind(c.dx, elapsed, x), bind(c.dy, elapsed, y), depth = depth + c.depth)
else -> error("Unsupported frame display-list opcode")
}
}
@@ -115,11 +116,12 @@ class FrameDisplayList private constructor(
Command(op, d, intArrayOf(id, xx, yy, options))
}
DRAW_OP_RECT_COPY -> {
val id = resource(); val sx = r.readS16(); val sy = r.readS16()
val w = r.readU16(); val h = r.readU16(); val dx = r.readS16(); val dy = r.readS16()
val id = resource(); val sx = value(); val sy = value()
val w = r.readU16(); val h = r.readU16(); val dx = value(); val dy = value()
require(w in 1..640 && h in 1..480)
require(id == DrawProtocol.SCREEN || sx >= 0 && sy >= 0)
Command(op, d, intArrayOf(id, sx, sy, w, h, dx, dy))
// Relative SCREEN sources may be negative until placement is added.
require(id == DrawProtocol.SCREEN || listOf(sx, sy).all { it !is DrawValue.Integer || it.value >= 0 })
Command(op, d, intArrayOf(id, w, h), sx, sy, dx, dy)
}
else -> error("Unsupported frame display-list opcode")
}