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
|
var canvas = (function(){
var cols = 80
var rows = 24
var exports = new Matrix (cols, rows, function(x,y){
var lex = new Lex (x,y)
lex.build()
return lex
})
exports.bind = function(){
var last_point = [0,0]
exports.forEach(function(lex, x, y){
if (lex.bound) return
lex.bound = true
var point = [x,y]
lex.span.addEventListener('contextmenu', function(e){
e.preventDefault()
})
lex.span.addEventListener('mousedown', function(e){
e.preventDefault()
dragging = true
current_canvas = canvas
if (drawing) {
erasing = (e.which == "3" || e.ctrlKey)
draw(lex, x, y, erasing)
last_point[0] = x
last_point[1] = y
}
lex.focus()
})
lex.span.addEventListener("mousemove", function(){
if (! dragging) return
if (drawing) {
line(lex, last_point, point, erasing)
last_point[0] = x
last_point[1] = y
}
lex.focus()
})
})
}
return exports
})()
|