Skip to content

Commit

Permalink
fix(inputsystem): capture pointer on pointerdown (Orillusion#432)
Browse files Browse the repository at this point in the history
remove pointerleave pointerout
  • Loading branch information
lslzl3000 authored Jul 27, 2024
1 parent 1922f18 commit cc90b82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
10 changes: 4 additions & 6 deletions src/components/controller/OrbitController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ export class OrbitController extends ComponentBase {
this._isPanning = false;
}
}
private onPointerLeave() {
this._isMouseDown = false;
this._isPanning = false;
}
// private onPointerLeave() {
// this._isMouseDown = false;
// this._isPanning = false;
// }
/**
* @internal
*/
Expand All @@ -285,7 +285,6 @@ export class OrbitController extends ComponentBase {
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_DOWN, this.onPointerDown, this);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_MOVE, this.onPointerMove, this);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_UP, this.onPointerUp, this);
Engine3D.inputSystem.addEventListener(PointerEvent3D.POINTER_OUT, this.onPointerLeave, this);
}
/**
* @internal
Expand All @@ -295,7 +294,6 @@ export class OrbitController extends ComponentBase {
Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_DOWN, this.onPointerDown, this);
Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_MOVE, this.onPointerMove, this);
Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_UP, this.onPointerUp, this);
Engine3D.inputSystem.removeEventListener(PointerEvent3D.POINTER_OUT, this.onPointerLeave, this);
}
}

Expand Down
23 changes: 13 additions & 10 deletions src/io/InputSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export class InputSystem extends CEventDispatcher {
protected _windowsEvent3d: CEvent;
mouseLock: boolean = false;



/**
* init the input system
* @param canvas the reference of canvas
Expand All @@ -111,6 +109,7 @@ export class InputSystem extends CEventDispatcher {
this.isRightMouseDown = true
this.mouseStart(ev);
}
canvas.setPointerCapture(ev.pointerId)
}
canvas.onpointerup = (ev: PointerEvent) => {
if (ev.button == 0) {
Expand All @@ -124,6 +123,7 @@ export class InputSystem extends CEventDispatcher {
if(ev.button === _button && performance.now() - _t < 300 && Math.abs(_x - ev.clientX) < 20 && Math.abs(_y - ev.clientY) < 20){
ev.button === 0 ? this.mouseClick(ev) : this.rightClick(ev);
}
canvas.releasePointerCapture(ev.pointerId)
}
canvas.onpointerenter = (ev: PointerEvent) => {
this.mouseOver(ev);
Expand All @@ -132,14 +132,18 @@ export class InputSystem extends CEventDispatcher {
this.mouseMove(ev);
}
canvas.onpointercancel = (ev: PointerEvent) => {
this.mouseEnd(ev);
}
canvas.onpointerleave = (ev: PointerEvent) => {
this.mouseEnd(ev);
}
canvas.onpointerout = (ev: PointerEvent) => {
this.mouseEnd(ev);
canvas.releasePointerCapture(ev.pointerId)
if (ev.button == 1)
this.middleUp(ev);
else
this.mouseEnd(ev);
}
// canvas.onpointerleave = (ev: PointerEvent) => {
// this.mouseEnd(ev);
// }
// canvas.onpointerout = (ev: PointerEvent) => {
// this.mouseEnd(ev);
// }

// let input = document.createElement(`input`);
// input.setSelectionRange(-1000, 1000);
Expand Down Expand Up @@ -332,7 +336,6 @@ export class InputSystem extends CEventDispatcher {
this.dispatchEvent(this._pointerEvent3D);
}


private mouseStart(e: PointerEvent | MouseEvent) {

this.isMouseDown = true;
Expand Down

0 comments on commit cc90b82

Please sign in to comment.