-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.js
31 lines (31 loc) · 894 Bytes
/
events.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
var initializeEvents = (gl, methodName, method2, zoom) => {
var canvas = gl.canvas;
var isDown = false;
var startX, startY, endX, endY;
canvas.addEventListener('mouseup', (e) => {
isDown = false;
endX = e.offsetX; endY = e.offsetY;
if (method2) {
method2(startX, startY, endX, endY);
}
});
canvas.addEventListener('mousedown', (e) => {
startX = e.offsetX; startY = e.offsetY;
isDown = true;
});
canvas.addEventListener('mousemove', (e) => {
if (isDown) {
//dragging
endX = e.offsetX; endY = e.offsetY;
if (methodName) {
methodName(startX, startY, endX, endY);
}
}
});
canvas.addEventListener('mousewheel', (e) => {
console.log(e.deltaY);
if (zoom) {
zoom(e.deltaY);
}
});
};