blob: b0d6007ea839cf4d18ec153bfc34bb9f5f89be87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
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
this.focused = false
}
Lex.prototype.build = function(){
this.span.className = this.css()
this.span.innerHTML = this.html()
}
Lex.prototype.css = function(){
return (
this.focused ?
"focused " : ""
) + (
this.opacity === 0 ?
"transparent f" + color_alphabet[mod(this.fg,16)] :
"f" + color_alphabet[mod(this.fg,16)] + " b" + color_alphabet[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 && ! isNaN(parseInt(char))) {
return "\x03" + (this.fg&15) + ",0" + (this.bg&15) + char
}
else {
return "\x03" + (this.fg&15) + "," + (this.bg&15) + char
}
}
Lex.prototype.assign = function (lex){
this.fg = lex.fg
this.bg = lex.bg
this.char = lex.char
this.opacity = lex.opacity
this.build()
}
Lex.prototype.stamp = function (lex, brush){
if (brush.draw_fg) this.fg = lex.fg
if (brush.draw_bg && lex.opacity > 0) this.bg = lex.bg
if (brush.draw_char) this.char = lex.char
this.opacity = 1
this.build()
}
Lex.prototype.clone = function () {
var lex = new Lex (0,0)
lex.assign(this)
return lex
}
Lex.prototype.erase = function (){
this.fg = fillColor
this.bg = fillColor
this.char = " "
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.eqColor = function(lex){
return lex && this.fg == lex.fg && this.bg == lex.bg
}
Lex.prototype.ne = function(lex){
return ! this.eq(lex)
}
Lex.prototype.clear = function(){
this.bg = colors.black
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')
this.focused = true
focused = this
}
Lex.prototype.blur = function(){
focused = null
this.span && this.span.classList.remove('focused')
this.focused = false
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()
return true
}
|