Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add support for global point move
  • Loading branch information
littleboarx committed Mar 3, 2023
1 parent b1199bb commit 014a04f
Show file tree
Hide file tree
Showing 3 changed files with 6,749 additions and 4,472 deletions.
22 changes: 20 additions & 2 deletions src/InputManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@ export class InputManager
this.viewport.hitArea = new Rectangle(0, 0, this.viewport.worldWidth, this.viewport.worldHeight);
}
this.viewport.on('pointerdown', this.down, this);
this.viewport.on('pointermove', this.move, this);
if (this.viewport.options.globalMoveEventObject)
{
this.viewport.options.globalMoveEventObject.interactive = true;
this.viewport.options.globalMoveEventObject.on('pointermove', this.move, this);
}
else
{
this.viewport.on('pointermove', this.move, this);
}

this.viewport.on('pointerup', this.up, this);
this.viewport.on('pointerupoutside', this.up, this);
this.viewport.on('pointercancel', this.up, this);
this.viewport.on('pointerout', this.up, this);
this.viewport.on('pointerleave', this.upPointerLeave, this);
this.wheelFunction = (e) => this.handleWheel(e);
this.viewport.options.events.domElement.addEventListener(
'wheel',
Expand All @@ -65,6 +74,7 @@ export class InputManager
public destroy(): void
{
this.viewport.options.events.domElement.removeEventListener('wheel', this.wheelFunction as any);
this.viewport.options.globalMoveEventObject?.off('pointermove', this.move);
}

/**
Expand Down Expand Up @@ -202,6 +212,14 @@ export class InputManager
}
}

public upPointerLeave(event: FederatedPointerEvent)
{
if (!this.viewport.options.allowPreserveDragOutside)
{
this.up(event);
}
}

/** Gets pointer position if this.interaction is set */
public getPointerPosition(event: WheelEvent): Point
{
Expand Down
13 changes: 13 additions & 0 deletions src/Viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ export interface IViewportOptions
*/
stopPropagation?: boolean;

/**
* Whether to stop drag when the pointer is out of the viewport
*/

allowPreserveDragOutside?:boolean;

/**
* use if you wish keep drag out of viewport
*/

globalMoveEventObject?: DisplayObject;

/**
* Change the default hitArea from world size to a new value
*/
Expand Down Expand Up @@ -117,6 +129,7 @@ const DEFAULT_VIEWPORT_OPTIONS: Partial<ICompleteViewportOptions> = {
noTicker: false,
disableOnContextMenu: false,
ticker: Ticker.shared,
allowPreserveDragOutside: false,
};

/**
Expand Down
Loading

0 comments on commit 014a04f

Please sign in to comment.