-
Notifications
You must be signed in to change notification settings - Fork 171
/
line-handler.js
39 lines (31 loc) · 937 Bytes
/
line-handler.js
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
var lineHandler = {
ismousedown: false,
prevX: 0,
prevY: 0,
mousedown: function(e) {
var x = e.pageX - canvas.offsetLeft,
y = e.pageY - canvas.offsetTop;
var t = this;
t.prevX = x;
t.prevY = y;
t.ismousedown = true;
},
mouseup: function(e) {
var x = e.pageX - canvas.offsetLeft,
y = e.pageY - canvas.offsetTop;
var t = this;
if (t.ismousedown) {
points[points.length] = ['line', [t.prevX, t.prevY, x, y], drawHelper.getOptions()];
t.ismousedown = false;
}
},
mousemove: function(e) {
var x = e.pageX - canvas.offsetLeft,
y = e.pageY - canvas.offsetTop;
var t = this;
if (t.ismousedown) {
tempContext.clearRect(0, 0, innerWidth, innerHeight);
drawHelper.line(tempContext, [t.prevX, t.prevY, x, y]);
}
}
};