blob: 17884d11348630bd8856d4304914c5f57d757056 (
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
|
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 = " "
}
Lex.prototype.build = function(){
this.span.className = this.css()
this.span.innerHTML = this.html()
}
Lex.prototype.css = function(){
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.irc = function(){
var char = this.char == "%" ? '%%' : this.char || " "
if (this.bg == 1 && this.fg == 0) {
return 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.build()
}
Lex.prototype.erase = function (lex){
if (lex.opacity == 0) return
this.fg = colors.white
this.bg = colors.black
this.char = " "
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.fg && this.char == lex.char
}
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
}
Lex.prototype.demolish = function(){
this.span.parentNode.removeChild(this.span)
this.span = null
}
Lex.prototype.key = function(char, keyCode) {
if (! char) { return }
this.char = char
this.fg = brush.bg
this.build()
}
|