function Lex (x,y) { if (typeof x == "number") { this.y = y this.x = x this.span = document.createElement("span") } else { this.span = x } this.fg = colors.white this.bg = colors.black this.char = " " this.opacity = 1 } Lex.prototype.build = function(){ this.span.className = this.css() this.span.innerHTML = this.html() } Lex.prototype.css = function(){ if (this.opacity == 0 && ! this.char) return "fabb" return "f" + letters[mod(this.fg,16)] + "b" + letters[mod(this.bg,16)] } Lex.prototype.html = function(){ return this.char == " " ? " " : this.char || " " } Lex.prototype.read = function(){ this.char = this.span.innerHTML return this.char } Lex.prototype.ascii = function(){ return this.char || " " } Lex.prototype.sanitize = function(){ switch (this.char) { case "%": return "%%" case undefined: case "": return " " default: return this.char } } var fgOnly = false Lex.prototype.mirc = function(){ var char = this.char || " " if (fgOnly) { return "\x03" + (this.fg&15) + char } if ((this.bg&15) < 10 && parseInt(char)) { return "\x03" + (this.fg&15) + ",0" + (this.bg&15) + char } else { return "\x03" + (this.fg&15) + "," + (this.bg&15) + char } } Lex.prototype.clone = function (lex){ if (lex.opacity == 0) return this.fg = lex.fg this.bg = lex.bg this.char = lex.char this.opacity = lex.opacity this.build() } Lex.prototype.paint = function (lex){ if (lex.opacity == 0) return if (brush.draw_fg) this.fg = lex.fg if (brush.draw_bg) this.bg = lex.bg if (brush.draw_char) this.char = lex.char this.opacity = 1 this.build() } Lex.prototype.copy = function () { var lex = new Lex (0,0) lex.clone(this) return lex } Lex.prototype.erase = function (){ this.fg = colors.white this.bg = colors.black this.char = " " this.opacity = 0 this.build() } Lex.prototype.fill = function(fg, bg){ this.fg = fg this.bg = bg this.opacity = 1 this.build() } Lex.prototype.eq = function(lex){ return lex && this.fg == lex.fg && this.bg == lex.bg && this.char == lex.char } Lex.prototype.ne = function(lex){ return ! this.eq(lex) } Lex.prototype.clear = function(){ this.bg = 1 this.fg = 0 this.char = " " this.opacity = 0 this.build() } Lex.prototype.isClear = function(){ return this.bg == 1 && this.fg == 0 && this.char == " " } Lex.prototype.focus = function(){ if (focused) focused.blur() this.span.classList.add('focused') focused = this } Lex.prototype.blur = function(){ this.span.classList.remove('focused') focused = null this.onBlur && this.onBlur() } Lex.prototype.demolish = function(){ if (this.span.parentNode) { this.span.parentNode.removeChild(this.span) } this.span = null } Lex.prototype.key = function(char, keyCode) { if (! char) { return } this.char = char this.fg = brush.fg this.build() }