generated from rnentjes/kotlin-server-web-undertow
Refactor rewind functionality with circular buffer, update BufferedImageData handling in DisplayView, enhance ConsoleView rendering updates, and integrate SnakeCode data.
This commit is contained in:
@@ -3,13 +3,13 @@ package mtmc.view
|
||||
import kotlinx.html.canvas
|
||||
import kotlinx.html.div
|
||||
import mtmc.display
|
||||
import mtmc.emulator.BufferedImageData
|
||||
import mtmc.emulator.MonTanaMiniComputer
|
||||
import nl.astraeus.komp.HtmlBuilder
|
||||
import nl.astraeus.komp.Komponent
|
||||
import nl.astraeus.komp.currentElement
|
||||
import org.w3c.dom.CanvasRenderingContext2D
|
||||
import org.w3c.dom.HTMLCanvasElement
|
||||
import org.w3c.dom.ImageData
|
||||
|
||||
class DiplayControlView(
|
||||
val computer: MonTanaMiniComputer
|
||||
@@ -26,7 +26,6 @@ class DisplayView(
|
||||
val computer: MonTanaMiniComputer
|
||||
) : Komponent() {
|
||||
var ctx: CanvasRenderingContext2D? = null
|
||||
var imageData: ImageData? = null
|
||||
|
||||
override fun HtmlBuilder.render() {
|
||||
canvas("display-canvas") {
|
||||
@@ -37,16 +36,16 @@ class DisplayView(
|
||||
|
||||
ctx = cv?.getContext("2d")?.unsafeCast<CanvasRenderingContext2D>()
|
||||
|
||||
ctx?.fillStyle = "#404040"
|
||||
ctx?.fillStyle = "#400040"
|
||||
ctx?.fillRect(0.0, 0.0, 160.0, 144.0)
|
||||
imageData = ctx?.getImageData(0.0, 0.0, 160.0, 144.0)
|
||||
}
|
||||
}
|
||||
|
||||
override fun renderUpdate() {
|
||||
// move data to canvas
|
||||
imageData?.let { id ->
|
||||
ctx?.putImageData(id, 0.0, 0.0)
|
||||
val buffer = computer.display.buffer
|
||||
if (buffer is BufferedImageData) {
|
||||
ctx?.putImageData(buffer.imageData, 0.0, 0.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user