Skip to content

Commit

Permalink
Fix mobile touch events (#233)
Browse files Browse the repository at this point in the history
Ported from #229

---------

Co-authored-by: Johnathon Selstad <makeshifted@gmail.com>
  • Loading branch information
mkeeter and zalo authored Jan 11, 2025
1 parent c8afb0d commit 94335a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
2 changes: 2 additions & 0 deletions demos/web-editor/web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
max-height: 512px;
outline: 1px solid #bbb;
margin-bottom: 12px;
user-select: none;
touch-action: none;
}
span#status {
display: block;
Expand Down
45 changes: 30 additions & 15 deletions demos/web-editor/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,36 @@ class App {
scene.canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
scene.canvas.addEventListener("mousedown", (event) => {
if (event.button === 0) {
scene.beginTranslate(event);
} else if (event.button === 2) {
scene.beginRotate(event);
}
});
window.addEventListener("mouseup", (event) => {
scene.endDrag();
});
window.addEventListener("mousemove", (event) => {
if (scene.drag(event)) {
requestRedraw();
}
});
scene.canvas.addEventListener(
"pointerdown",
(event) => {
event.preventDefault();
if (event.button === 0) {
scene.beginTranslate(event);
} else if (event.button === 2) {
scene.beginRotate(event);
}
},
{ passive: false },
);
window.addEventListener(
"pointerup",
(event) => {
event.preventDefault();
scene.endDrag();
},
{ passive: false },
);
window.addEventListener(
"pointermove",
(event) => {
event.preventDefault();
if (scene.drag(event)) {
requestRedraw();
}
},
{ passive: false },
);
this.scene = scene;

// Hot-patch the gyroid script to be eval (instead of exec) flavored
Expand Down

0 comments on commit 94335a9

Please sign in to comment.