-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.js
41 lines (30 loc) · 1005 Bytes
/
controls.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
let isPointerDown = false;
let lastX, lastY;
addEventListener("pointerdown", (e) => {
if (!e.isPrimary || document.getElementById("settings").contains(e.target)) return;
isPointerDown = true;
lastX = e.clientX;
lastY = e.clientY;
});
addEventListener("pointerup", () => {
isPointerDown = false;
document.body.style.userSelect = null;
});
addEventListener("pointermove", (e) => {
if (!isPointerDown) return;
const deltaX = e.clientX - lastX;
const deltaY = e.clientY - lastY;
settings.posX -= deltaX / settings.zoomFunction(settings.zoom);
settings.posY -= deltaY / settings.zoomFunction(settings.zoom);
// Prevent user from selecting text in the settings section when moving around with the mouse
document.body.style.userSelect = "none";
lastX = e.clientX;
lastY = e.clientY;
update();
});
addEventListener("wheel", (e) => {
let zoomDelta = e.deltaY < 0 ? 1 : -1;
if (e.shiftKey) zoomDelta *= 10;
settings.zoom = settings.zoom + zoomDelta;
update();
});