-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtouch.js
53 lines (42 loc) · 1.1 KB
/
touch.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function touchEvents(){
C().addEventListener('mousedown', touchHandler);
C().addEventListener('mousemove', touchHandler);
C().addEventListener('touchstart', touchHandler);
C().addEventListener('touchmove', touchHandler);
window.addEventListener('mousedown', startTouching);
window.addEventListener('mouseup', stopTouching);
window.addEventListener('touchstart', startTouching);
window.addEventListener('touchend', stopTouching);
}
function startTouching(){
S().dragging = true;
}
function stopTouching(){
S().draggingDelay = false;
}
function touchHandler(e){
if(e.type == 'mousemove' && !S().dragging){
return;
}
let pos;
if(e.type == 'mousedown' || e.type == 'mousemove'){
pos = [ e.x, e.y ];
}else{
const touch = e.changedTouches[0];
pos = [ touch.clientX, touch.clientY ];
}
const rect = C().getBoundingClientRect();
pos = [ pos[0] - rect.left, pos[1] - rect.top ];
pos[0] = Math.round(pos[0] / S().zoom);
pos[1] = Math.round(pos[1] / S().zoom);
MPos.X = pos[0];
MPos.Y = pos[1];
}
const dots = [];
function addDot(x, y){
dots.push([x, y]);
}
const MPos = {
X: 0,
Y: 0,
};