Make screen work again with screen-layout

pull/1/head
cpsdqs 7 years ago
parent 3851cd6aa6
commit 73b390d7de
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 12
      js/term/debug.js
  2. 23
      js/term/screen.js
  3. 29
      js/term/screen_layout.js
  4. 9
      js/term/screen_renderer.js

@ -18,16 +18,16 @@ module.exports = function attachDebugger (screen, connection) {
let addCanvas = function () { let addCanvas = function () {
if (!debugCanvas.parentNode) { if (!debugCanvas.parentNode) {
screen.canvas.parentNode.appendChild(debugCanvas) screen.layout.canvas.parentNode.appendChild(debugCanvas)
screen.canvas.addEventListener('mousemove', onMouseMove) screen.layout.canvas.addEventListener('mousemove', onMouseMove)
screen.canvas.addEventListener('mouseout', onMouseOut) screen.layout.canvas.addEventListener('mouseout', onMouseOut)
} }
} }
let removeCanvas = function () { let removeCanvas = function () {
if (debugCanvas.parentNode) { if (debugCanvas.parentNode) {
debugCanvas.parentNode.removeChild(debugCanvas) debugCanvas.parentNode.removeChild(debugCanvas)
screen.canvas.removeEventListener('mousemove', onMouseMove) screen.layout.canvas.removeEventListener('mousemove', onMouseMove)
screen.canvas.removeEventListener('mouseout', onMouseOut) screen.layout.canvas.removeEventListener('mouseout', onMouseOut)
onMouseOut() onMouseOut()
} }
} }
@ -261,7 +261,7 @@ module.exports = function attachDebugger (screen, connection) {
} }
const attachToolbar = function () { const attachToolbar = function () {
screen.canvas.parentNode.appendChild(toolbar) screen.layout.canvas.parentNode.appendChild(toolbar)
} }
const detachToolbar = function () { const detachToolbar = function () {
toolbar.parentNode.removeChild(toolbar) toolbar.parentNode.removeChild(toolbar)

@ -92,20 +92,20 @@ module.exports = class TermScreen extends EventEmitter {
if (selecting) return if (selecting) return
selecting = true selecting = true
this.selection.start = this.selection.end = this.layout.screenToGrid(x, y, true) this.selection.start = this.selection.end = this.layout.screenToGrid(x, y, true)
this.layout.scheduleDraw('select-start') this.renderScreen('select-start')
} }
let selectMove = (x, y) => { let selectMove = (x, y) => {
if (!selecting) return if (!selecting) return
this.selection.end = this.layout.screenToGrid(x, y, true) this.selection.end = this.layout.screenToGrid(x, y, true)
this.layout.scheduleDraw('select-move') this.renderScreen('select-move')
} }
let selectEnd = (x, y) => { let selectEnd = (x, y) => {
if (!selecting) return if (!selecting) return
selecting = false selecting = false
this.selection.end = this.layout.screenToGrid(x, y, true) this.selection.end = this.layout.screenToGrid(x, y, true)
this.layout.scheduleDraw('select-end') this.renderScreen('select-end')
Object.assign(this.selection, this.getNormalizedSelection()) Object.assign(this.selection, this.getNormalizedSelection())
} }
@ -197,7 +197,7 @@ module.exports = class TermScreen extends EventEmitter {
// reset selection // reset selection
this.selection.start = this.selection.end = [0, 0] this.selection.start = this.selection.end = [0, 0]
this.emit('hide-touch-select-menu') this.emit('hide-touch-select-menu')
this.layout.scheduleDraw('select-reset') this.renderScreen('select-reset')
} else { } else {
e.preventDefault() e.preventDefault()
this.emit('open-soft-keyboard') this.emit('open-soft-keyboard')
@ -260,13 +260,20 @@ module.exports = class TermScreen extends EventEmitter {
this.layout.window.height = this.window.height this.layout.window.height = this.window.height
} }
renderScreen () { renderScreen (reason) {
this.layout.render({ let selection = []
for (let cell = 0; cell < this.screen.length; cell++) {
selection.push(this.isInSelection(cell % this.window.width, Math.floor(cell / this.window.width)))
}
this.layout.render(reason, {
width: this.window.width, width: this.window.width,
height: this.window.height, height: this.window.height,
screen: this.screen, screen: this.screen,
screenFG: this.screenFG, screenFG: this.screenFG,
screenBG: this.screenBG, screenBG: this.screenBG,
screenSelection: selection,
screenAttrs: this.screenAttrs, screenAttrs: this.screenAttrs,
cursor: this.cursor, cursor: this.cursor,
statusScreen: this.window.statusScreen statusScreen: this.window.statusScreen
@ -468,7 +475,7 @@ module.exports = class TermScreen extends EventEmitter {
this.cursor.hanging = update.hanging this.cursor.hanging = update.hanging
this.layout.renderer.resetCursorBlink() this.layout.renderer.resetCursorBlink()
this.emit('cursor-moved') this.emit('cursor-moved')
this.layout.renderer.scheduleDraw('cursor-moved') this.renderScreen('cursor-moved')
} }
break break
@ -519,7 +526,7 @@ module.exports = class TermScreen extends EventEmitter {
if (this.window.debug) console.log(`Blinking cells: ${this.blinkingCellCount}`) if (this.window.debug) console.log(`Blinking cells: ${this.blinkingCellCount}`)
this.layout.renderer.scheduleDraw('load', 16) this.renderScreen('load')
this.emit('load') this.emit('load')
break break

@ -171,6 +171,8 @@ module.exports = class ScreenLayout extends EventEmitter {
* @returns {Object} the cell size with `width` and `height` in pixels * @returns {Object} the cell size with `width` and `height` in pixels
*/ */
getCellSize () { getCellSize () {
if (!this.charSize.height && this.window.fontSize) this.updateCharSize()
return { return {
width: Math.ceil(this.charSize.width * this.window.gridScaleX), width: Math.ceil(this.charSize.width * this.window.gridScaleX),
height: Math.ceil(this.charSize.height * this.window.gridScaleY) height: Math.ceil(this.charSize.height * this.window.gridScaleY)
@ -244,12 +246,31 @@ module.exports = class ScreenLayout extends EventEmitter {
// the screen has been cleared (by changing canvas width) // the screen has been cleared (by changing canvas width)
this.renderer.resetDrawn() this.renderer.resetDrawn()
// draw immediately; the canvas shouldn't flash this.renderer.render('update-size', this.serializeRenderData())
this.renderer.draw('update-size') }
} }
serializeRenderData () {
return {
padding: Math.round(this._padding),
devicePixelRatio: this.window.devicePixelRatio,
charSize: this.charSize,
cellSize: this.getCellSize(),
fonts: [
this.getFont(),
this.getFont({ weight: 'bold' }),
this.getFont({ style: 'italic' }),
this.getFont({ weight: 'bold', style: 'italic' })
]
} }
}
render (reason, data) {
this.window.width = data.width
this.window.height = data.height
Object.assign(data, this.serializeRenderData())
render (...args) { this.renderer.render(reason, data)
this.renderer.render(...args)
} }
} }

@ -59,6 +59,7 @@ module.exports = class CanvasRenderer extends EventEmitter {
this.screenFG = [] this.screenFG = []
this.screenBG = [] this.screenBG = []
this.screenAttrs = [] this.screenAttrs = []
this.screenSelection = []
this.cursor = {} this.cursor = {}
this.resetDrawn() this.resetDrawn()
@ -73,6 +74,11 @@ module.exports = class CanvasRenderer extends EventEmitter {
this.resetCursorBlink() this.resetCursorBlink()
} }
render (reason, data) {
Object.assign(this, data)
this.scheduleDraw(reason)
}
resetDrawn () { resetDrawn () {
// used to determine if a cell should be redrawn; storing the current state // used to determine if a cell should be redrawn; storing the current state
// as it is on screen // as it is on screen
@ -511,12 +517,11 @@ module.exports = class CanvasRenderer extends EventEmitter {
let wasCursor = x === this.drawnCursor[0] && y === this.drawnCursor[1] let wasCursor = x === this.drawnCursor[0] && y === this.drawnCursor[1]
let inSelection = this.screen.isInSelection(x, y)
let text = this.screen[cell] let text = this.screen[cell]
let fg = this.screenFG[cell] | 0 let fg = this.screenFG[cell] | 0
let bg = this.screenBG[cell] | 0 let bg = this.screenBG[cell] | 0
let attrs = this.screenAttrs[cell] | 0 let attrs = this.screenAttrs[cell] | 0
let inSelection = this.screenSelection[cell]
let isDefaultBG = false let isDefaultBG = false

Loading…
Cancel
Save