Add fancy graphics

cpsdqs/unified-input
cpsdqs 7 years ago
parent 16f37aafd5
commit de897f013c
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 5
      jssrc/debug_screen.js
  2. 46
      jssrc/term_screen.js

@ -6,6 +6,7 @@ if (Screen) {
// hackity hack should probably set this in CSS // hackity hack should probably set this in CSS
debugCanvas.style.top = '6px' debugCanvas.style.top = '6px'
debugCanvas.style.left = '6px' debugCanvas.style.left = '6px'
debugCanvas.style.pointerEvents = 'none'
let addCanvas = function () { let addCanvas = function () {
if (!debugCanvas.parentNode) qs('#screen').appendChild(debugCanvas) if (!debugCanvas.parentNode) qs('#screen').appendChild(debugCanvas)
@ -22,17 +23,19 @@ if (Screen) {
debugCanvas.style.height = `${height * cellSize.height}px` debugCanvas.style.height = `${height * cellSize.height}px`
} }
let startTime, endTime let startTime, endTime, lastReason
let cells = new Map() let cells = new Map()
let startDrawing let startDrawing
Screen._debug = { Screen._debug = {
drawStart (reason) { drawStart (reason) {
lastReason = reason
startTime = Date.now() startTime = Date.now()
}, },
drawEnd () { drawEnd () {
endTime = Date.now() endTime = Date.now()
console.log(`Draw: ${lastReason} (${(endTime - startTime)} ms) with fancy graphics: ${Screen.window.graphics}`)
startDrawing() startDrawing()
}, },
setCell (cell, flags) { setCell (cell, flags) {

@ -108,7 +108,8 @@ class TermScreen {
blinkInterval: null, blinkInterval: null,
fitIntoWidth: 0, fitIntoWidth: 0,
fitIntoHeight: 0, fitIntoHeight: 0,
debug: false debug: false,
graphics: 0
} }
// properties of this.window that require updating size and redrawing // properties of this.window that require updating size and redrawing
@ -791,35 +792,32 @@ class TermScreen {
if (adjacentDidUpdate) shouldUpdate = true if (adjacentDidUpdate) shouldUpdate = true
} }
if (shouldUpdate) { redrawMap.set(cell, shouldUpdate)
if (isWideCell) {
// set redraw for adjacent cells
for (let adjacentCell of this.getAdjacentCells(cell)) {
redrawMap.set(adjacentCell, true)
} }
// update previous wide cells as well for (let cell of updateMap.keys()) updateRedrawMapAt(cell)
let index = cell - 1
while (index > 0) {
let text = this.screen[index]
let isWide = isTextWide(text)
if (redrawMap.get(index - 1)) break
// might be out of bounds but that doesn't matter
redrawMap.set(index - width, true)
redrawMap.set(index + width, true)
redrawMap.set(index--, true)
if (!isWide) break // mask to redrawing regions only
if (this.window.graphics > 1) {
ctx.save()
ctx.beginPath()
for (let y = 0; y < height; y++) {
let regionStart = null
for (let x = 0; x < width; x++) {
let cell = y * width + x
let redrawing = redrawMap.get(cell)
if (redrawing && regionStart === null) regionStart = x
if (!redrawing && regionStart !== null) {
ctx.rect(regionStart * cellWidth, y * cellHeight, (x - regionStart) * cellWidth, cellHeight)
regionStart = null
} }
} }
if (regionStart !== null) {
ctx.rect(regionStart * cellWidth, y * cellHeight, (width - regionStart) * cellWidth, cellHeight)
} }
redrawMap.set(cell, shouldUpdate)
} }
ctx.clip()
for (let cell of updateMap.keys()) updateRedrawMapAt(cell) }
// pass 1: backgrounds // pass 1: backgrounds
for (let font of fontGroups.keys()) { for (let font of fontGroups.keys()) {
@ -893,6 +891,8 @@ class TermScreen {
} }
} }
if (this.window.graphics > 1) ctx.restore()
if (this.window.debug && this._debug) this._debug.drawEnd() if (this.window.debug && this._debug) this._debug.drawEnd()
} }

Loading…
Cancel
Save