Skip to content

Commit 83f7ded

Browse files
authored
Merge pull request #430 from littleboarx/master
fix #422
2 parents b1199bb + 772fed9 commit 83f7ded

File tree

4 files changed

+6691
-4479
lines changed

4 files changed

+6691
-4479
lines changed

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@
4848
"url": "https://github.com/davidfig/pixi-viewport/issues"
4949
},
5050
"homepage": "https://github.com/davidfig/pixi-viewport#readme",
51-
"peerDependencies": {},
5251
"devDependencies": {
53-
"@pixi/core": "^7.0.4",
54-
"@pixi/display": "^7.0.4",
52+
"@pixi/core": "^7.1.1",
53+
"@pixi/display": "^7.1.1",
5554
"@pixi/eslint-config": "^4.0.1",
56-
"@pixi/events": "^7.0.4",
57-
"@pixi/math": "^7.0.4",
58-
"@pixi/ticker": "^7.0.4",
55+
"@pixi/events": "^7.1.1",
56+
"@pixi/math": "^7.1.1",
57+
"@pixi/ticker": "^7.1.1",
5958
"@typescript-eslint/parser": "^5.5.0",
6059
"chai": "^4.3.4",
6160
"clicked": "^4.0.3",
@@ -68,7 +67,7 @@
6867
"jsdoc": "^3.6.3",
6968
"lint-staged": "^13.1.0",
7069
"pixi-ease": "^3.0.7",
71-
"pixi.js": "^7.0.5",
70+
"pixi.js": "^7.1.1",
7271
"raf": "^3.4.1",
7372
"typescript": "^4.5.2",
7473
"vite": "^3.2.4",

src/InputManager.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,24 @@ export class InputManager
4545
this.viewport.hitArea = new Rectangle(0, 0, this.viewport.worldWidth, this.viewport.worldHeight);
4646
}
4747
this.viewport.on('pointerdown', this.down, this);
48-
this.viewport.on('pointermove', this.move, this);
48+
if (this.viewport.options.allowPreserveDragOutside)
49+
50+
{
51+
this.viewport.on('globalpointermove', this.move, this);
52+
}
53+
else
54+
{
55+
this.viewport.on('pointermove', this.move, this);
56+
}
57+
4958
this.viewport.on('pointerup', this.up, this);
5059
this.viewport.on('pointerupoutside', this.up, this);
5160
this.viewport.on('pointercancel', this.up, this);
52-
this.viewport.on('pointerout', this.up, this);
61+
if (!this.viewport.options.allowPreserveDragOutside)
62+
{
63+
this.viewport.on('pointerleave', this.up, this);
64+
}
65+
5366
this.wheelFunction = (e) => this.handleWheel(e);
5467
this.viewport.options.events.domElement.addEventListener(
5568
'wheel',

src/Viewport.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export interface IViewportOptions
5656
*/
5757
stopPropagation?: boolean;
5858

59+
/**
60+
* Whether to stop drag when the pointer is out of the viewport
61+
*/
62+
63+
allowPreserveDragOutside?:boolean;
64+
5965
/**
6066
* Change the default hitArea from world size to a new value
6167
*/
@@ -117,6 +123,7 @@ const DEFAULT_VIEWPORT_OPTIONS: Partial<ICompleteViewportOptions> = {
117123
noTicker: false,
118124
disableOnContextMenu: false,
119125
ticker: Ticker.shared,
126+
allowPreserveDragOutside: false,
120127
};
121128

122129
/**
@@ -226,6 +233,7 @@ export class Viewport extends Container
226233
{
227234
this.options.events.domElement.addEventListener('contextmenu', this._disableOnContextMenu);
228235
}
236+
229237
if (!this.options.noTicker)
230238
{
231239
this.tickerFunction = () => this.update(this.options.ticker.elapsedMS);

0 commit comments

Comments
 (0)