@awayjs/scene 0.13.322 → 0.13.323
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +100 -100
- package/README.md +61 -61
- package/bundle/awayjs-scene.umd.js +2 -2
- package/bundle/awayjs-scene.umd.js.map +1 -1
- package/copyVersionToIndex.js +23 -23
- package/dist/index.d.ts +76 -76
- package/dist/index.js +67 -67
- package/dist/lib/Scene.d.ts +85 -85
- package/dist/lib/Scene.js +285 -285
- package/dist/lib/Settings.d.ts +16 -16
- package/dist/lib/Settings.js +60 -60
- package/dist/lib/adapters/IDisplayObjectAdapter.d.ts +13 -13
- package/dist/lib/adapters/IDisplayObjectAdapter.js +1 -1
- package/dist/lib/adapters/IFilter.d.ts +24 -24
- package/dist/lib/adapters/IFilter.js +1 -1
- package/dist/lib/adapters/IMovieClipAdapter.d.ts +15 -14
- package/dist/lib/adapters/IMovieClipAdapter.d.ts.map +1 -1
- package/dist/lib/adapters/IMovieClipAdapter.js +1 -1
- package/dist/lib/adapters/ITextfieldAdapter.d.ts +4 -4
- package/dist/lib/adapters/ITextfieldAdapter.js +1 -1
- package/dist/lib/base/IBitmapDrawable.d.ts +11 -11
- package/dist/lib/base/IBitmapDrawable.js +1 -1
- package/dist/lib/base/IFrameLabel.d.ts +4 -4
- package/dist/lib/base/IFrameLabel.js +1 -1
- package/dist/lib/base/IFrameScript.d.ts +5 -5
- package/dist/lib/base/IFrameScript.js +1 -1
- package/dist/lib/base/MouseButtons.d.ts +26 -26
- package/dist/lib/base/MouseButtons.js +1 -1
- package/dist/lib/base/Timeline.d.ts +147 -147
- package/dist/lib/base/Timeline.js +525 -525
- package/dist/lib/base/TimelineActionType.d.ts +18 -18
- package/dist/lib/base/TimelineActionType.js +1 -1
- package/dist/lib/controllers/ControllerBase.d.ts +14 -14
- package/dist/lib/controllers/ControllerBase.js +60 -60
- package/dist/lib/controllers/FirstPersonController.d.ts +78 -78
- package/dist/lib/controllers/FirstPersonController.js +228 -228
- package/dist/lib/controllers/FollowController.d.ts +12 -12
- package/dist/lib/controllers/FollowController.js +27 -27
- package/dist/lib/controllers/HoverController.d.ts +105 -105
- package/dist/lib/controllers/HoverController.js +302 -302
- package/dist/lib/controllers/LookAtController.d.ts +14 -14
- package/dist/lib/controllers/LookAtController.js +68 -68
- package/dist/lib/controllers/SpringController.d.ts +38 -38
- package/dist/lib/controllers/SpringController.js +59 -59
- package/dist/lib/display/Billboard.d.ts +132 -132
- package/dist/lib/display/Billboard.js +397 -397
- package/dist/lib/display/Camera.d.ts +31 -31
- package/dist/lib/display/Camera.js +72 -72
- package/dist/lib/display/DisplayObject.d.ts +921 -921
- package/dist/lib/display/DisplayObject.js +1595 -1595
- package/dist/lib/display/DisplayObjectContainer.d.ts +325 -325
- package/dist/lib/display/DisplayObjectContainer.js +486 -486
- package/dist/lib/display/LineSegment.d.ts +69 -69
- package/dist/lib/display/LineSegment.js +203 -203
- package/dist/lib/display/LoaderContainer.d.ts +504 -504
- package/dist/lib/display/LoaderContainer.js +603 -603
- package/dist/lib/display/MorphSprite.d.ts +20 -20
- package/dist/lib/display/MorphSprite.js +246 -246
- package/dist/lib/display/MovieClip.d.ts +149 -149
- package/dist/lib/display/MovieClip.js +733 -733
- package/dist/lib/display/SimpleButton.d.ts +158 -158
- package/dist/lib/display/SimpleButton.js +228 -228
- package/dist/lib/display/Skybox.d.ts +144 -144
- package/dist/lib/display/Skybox.js +288 -288
- package/dist/lib/display/Sprite.d.ts +65 -65
- package/dist/lib/display/Sprite.d.ts.map +1 -1
- package/dist/lib/display/Sprite.js +134 -132
- package/dist/lib/display/TextField.d.ts +1104 -1104
- package/dist/lib/display/TextField.js +3018 -3018
- package/dist/lib/display/TextSprite.d.ts +16 -16
- package/dist/lib/display/TextSprite.js +36 -36
- package/dist/lib/elements/SkyboxElements.d.ts +29 -29
- package/dist/lib/elements/SkyboxElements.js +127 -127
- package/dist/lib/errors/CastError.d.ts +4 -4
- package/dist/lib/errors/CastError.js +10 -10
- package/dist/lib/events/CameraEvent.d.ts +16 -16
- package/dist/lib/events/CameraEvent.js +30 -30
- package/dist/lib/events/FocusEvent.d.ts +42 -42
- package/dist/lib/events/FocusEvent.js +43 -43
- package/dist/lib/events/KeyboardEvent.d.ts +21 -21
- package/dist/lib/events/KeyboardEvent.js +43 -43
- package/dist/lib/events/MouseEvent.d.ts +91 -91
- package/dist/lib/events/MouseEvent.js +122 -122
- package/dist/lib/events/PointerEvent.d.ts +93 -93
- package/dist/lib/events/PointerEvent.js +73 -73
- package/dist/lib/events/ResizeEvent.d.ts +15 -15
- package/dist/lib/events/ResizeEvent.js +38 -38
- package/dist/lib/events/TextfieldEvent.d.ts +19 -19
- package/dist/lib/events/TextfieldEvent.js +28 -28
- package/dist/lib/events/TouchEvent.d.ts +54 -54
- package/dist/lib/events/TouchEvent.js +89 -89
- package/dist/lib/factories/DefaultSceneGraphFactory.d.ts +27 -27
- package/dist/lib/factories/DefaultSceneGraphFactory.js +55 -55
- package/dist/lib/factories/ISceneGraphFactory.d.ts +20 -20
- package/dist/lib/factories/ISceneGraphFactory.js +1 -1
- package/dist/lib/image/SceneImage2D.d.ts +219 -219
- package/dist/lib/image/SceneImage2D.js +606 -606
- package/dist/lib/managers/DefaultFontManager.d.ts +14 -14
- package/dist/lib/managers/DefaultFontManager.js +101 -101
- package/dist/lib/managers/DeviceFontManager.d.ts +8 -8
- package/dist/lib/managers/DeviceFontManager.js +44 -44
- package/dist/lib/managers/FrameScriptManager.d.ts +37 -37
- package/dist/lib/managers/FrameScriptManager.js +386 -386
- package/dist/lib/managers/IInputRecorder.d.ts +3 -3
- package/dist/lib/managers/IInputRecorder.js +1 -1
- package/dist/lib/managers/MouseManager.d.ts +74 -74
- package/dist/lib/managers/MouseManager.js +803 -803
- package/dist/lib/prefabs/PrefabBase.d.ts +19 -19
- package/dist/lib/prefabs/PrefabBase.js +42 -42
- package/dist/lib/prefabs/PrimitiveCapsulePrefab.d.ts +56 -56
- package/dist/lib/prefabs/PrimitiveCapsulePrefab.js +269 -269
- package/dist/lib/prefabs/PrimitiveConePrefab.d.ts +21 -21
- package/dist/lib/prefabs/PrimitiveConePrefab.js +43 -43
- package/dist/lib/prefabs/PrimitiveCubePrefab.d.ts +74 -74
- package/dist/lib/prefabs/PrimitiveCubePrefab.js +545 -545
- package/dist/lib/prefabs/PrimitiveCylinderPrefab.d.ts +79 -79
- package/dist/lib/prefabs/PrimitiveCylinderPrefab.js +584 -584
- package/dist/lib/prefabs/PrimitivePlanePrefab.d.ts +65 -65
- package/dist/lib/prefabs/PrimitivePlanePrefab.js +300 -300
- package/dist/lib/prefabs/PrimitivePolygonPrefab.d.ts +29 -29
- package/dist/lib/prefabs/PrimitivePolygonPrefab.js +64 -64
- package/dist/lib/prefabs/PrimitivePrefabBase.d.ts +67 -67
- package/dist/lib/prefabs/PrimitivePrefabBase.js +158 -158
- package/dist/lib/prefabs/PrimitiveSpherePrefab.d.ts +48 -48
- package/dist/lib/prefabs/PrimitiveSpherePrefab.js +294 -294
- package/dist/lib/prefabs/PrimitiveTorusPrefab.d.ts +55 -55
- package/dist/lib/prefabs/PrimitiveTorusPrefab.js +260 -260
- package/dist/lib/text/AntiAliasType.d.ts +24 -24
- package/dist/lib/text/AntiAliasType.js +28 -28
- package/dist/lib/text/BitmapFontChar.d.ts +39 -39
- package/dist/lib/text/BitmapFontChar.js +42 -42
- package/dist/lib/text/BitmapFontTable.d.ts +73 -73
- package/dist/lib/text/BitmapFontTable.js +183 -183
- package/dist/lib/text/FNTGenerator.d.ts +10 -10
- package/dist/lib/text/FNTGenerator.js +74 -74
- package/dist/lib/text/FNTGeneratorCanvas.d.ts +22 -22
- package/dist/lib/text/FNTGeneratorCanvas.js +202 -202
- package/dist/lib/text/FNTGeneratrorBase.d.ts +7 -7
- package/dist/lib/text/FNTGeneratrorBase.js +7 -7
- package/dist/lib/text/Font.d.ts +38 -38
- package/dist/lib/text/Font.js +109 -109
- package/dist/lib/text/FontLookUpMode.d.ts +5 -5
- package/dist/lib/text/FontLookUpMode.js +7 -7
- package/dist/lib/text/FontStyleName.d.ts +6 -6
- package/dist/lib/text/FontStyleName.js +7 -7
- package/dist/lib/text/GridFitType.d.ts +31 -31
- package/dist/lib/text/GridFitType.js +35 -35
- package/dist/lib/text/HTMLTextProcessor.d.ts +8 -8
- package/dist/lib/text/HTMLTextProcessor.js +426 -426
- package/dist/lib/text/IFontTable.d.ts +16 -16
- package/dist/lib/text/IFontTable.js +1 -1
- package/dist/lib/text/TesselatedFontChar.d.ts +58 -58
- package/dist/lib/text/TesselatedFontChar.js +66 -66
- package/dist/lib/text/TesselatedFontTable.d.ts +88 -88
- package/dist/lib/text/TesselatedFontTable.js +963 -963
- package/dist/lib/text/TextFieldAutoSize.d.ts +28 -28
- package/dist/lib/text/TextFieldAutoSize.js +32 -32
- package/dist/lib/text/TextFieldType.d.ts +20 -20
- package/dist/lib/text/TextFieldType.js +24 -24
- package/dist/lib/text/TextFormat.d.ts +273 -273
- package/dist/lib/text/TextFormat.d.ts.map +1 -1
- package/dist/lib/text/TextFormat.js +449 -442
- package/dist/lib/text/TextFormatAlign.d.ts +26 -26
- package/dist/lib/text/TextFormatAlign.js +30 -30
- package/dist/lib/text/TextInteractionMode.d.ts +21 -21
- package/dist/lib/text/TextInteractionMode.js +25 -25
- package/dist/lib/text/TextLineMetrics.d.ts +61 -61
- package/dist/lib/text/TextLineMetrics.js +42 -42
- package/dist/lib/text/TextShape.d.ts +22 -22
- package/dist/lib/text/TextShape.js +75 -75
- package/dist/lib/tools/Merge.d.ts +81 -81
- package/dist/lib/tools/Merge.js +266 -266
- package/dist/lib/utils/Cast.d.ts +20 -20
- package/dist/lib/utils/Cast.js +271 -271
- package/index.ts +92 -92
- package/lib/Scene.ts +339 -339
- package/lib/Settings.ts +83 -83
- package/lib/adapters/IDisplayObjectAdapter.ts +23 -23
- package/lib/adapters/IFilter.ts +25 -25
- package/lib/adapters/IMovieClipAdapter.ts +26 -24
- package/lib/adapters/ITextfieldAdapter.ts +6 -6
- package/lib/base/IBitmapDrawable.ts +13 -13
- package/lib/base/IFrameLabel.ts +3 -3
- package/lib/base/IFrameScript.ts +4 -4
- package/lib/base/MouseButtons.ts +31 -31
- package/lib/base/Timeline.ts +715 -715
- package/lib/base/TimelineActionType.ts +18 -18
- package/lib/controllers/ControllerBase.ts +66 -66
- package/lib/controllers/FirstPersonController.ts +241 -241
- package/lib/controllers/FollowController.ts +22 -22
- package/lib/controllers/HoverController.ts +304 -304
- package/lib/controllers/LookAtController.ts +75 -75
- package/lib/controllers/SpringController.ts +91 -91
- package/lib/display/Billboard.ts +468 -468
- package/lib/display/Camera.ts +75 -75
- package/lib/display/DisplayObject.ts +1829 -1829
- package/lib/display/DisplayObjectContainer.ts +546 -546
- package/lib/display/LineSegment.ts +229 -229
- package/lib/display/LoaderContainer.ts +651 -651
- package/lib/display/MorphSprite.ts +339 -339
- package/lib/display/MovieClip.ts +870 -870
- package/lib/display/SimpleButton.ts +224 -224
- package/lib/display/Skybox.ts +352 -352
- package/lib/display/Sprite.ts +154 -150
- package/lib/display/TextField.ts +3875 -3875
- package/lib/display/TextSprite.ts +34 -34
- package/lib/elements/SkyboxElements.ts +141 -141
- package/lib/errors/CastError.ts +6 -6
- package/lib/events/CameraEvent.ts +29 -29
- package/lib/events/FocusEvent.ts +69 -69
- package/lib/events/KeyboardEvent.ts +40 -40
- package/lib/events/MouseEvent.ts +144 -144
- package/lib/events/PointerEvent.ts +145 -145
- package/lib/events/ResizeEvent.ts +31 -31
- package/lib/events/TextfieldEvent.ts +28 -28
- package/lib/events/TouchEvent.ts +103 -103
- package/lib/factories/DefaultSceneGraphFactory.ts +58 -58
- package/lib/factories/ISceneGraphFactory.ts +28 -28
- package/lib/image/SceneImage2D.ts +907 -907
- package/lib/managers/DefaultFontManager.ts +124 -124
- package/lib/managers/DeviceFontManager.ts +55 -55
- package/lib/managers/FrameScriptManager.ts +440 -440
- package/lib/managers/IInputRecorder.ts +2 -2
- package/lib/managers/MouseManager.ts +942 -942
- package/lib/prefabs/PrefabBase.ts +47 -47
- package/lib/prefabs/PrimitiveCapsulePrefab.ts +286 -286
- package/lib/prefabs/PrimitiveConePrefab.ts +37 -37
- package/lib/prefabs/PrimitiveCubePrefab.ts +630 -630
- package/lib/prefabs/PrimitiveCylinderPrefab.ts +657 -657
- package/lib/prefabs/PrimitivePlanePrefab.ts +352 -352
- package/lib/prefabs/PrimitivePolygonPrefab.ts +53 -53
- package/lib/prefabs/PrimitivePrefabBase.ts +177 -177
- package/lib/prefabs/PrimitiveSpherePrefab.ts +336 -336
- package/lib/prefabs/PrimitiveTorusPrefab.ts +282 -282
- package/lib/text/AntiAliasType.ts +24 -24
- package/lib/text/BitmapFontChar.ts +53 -53
- package/lib/text/BitmapFontTable.ts +213 -213
- package/lib/text/FNTGenerator.ts +100 -100
- package/lib/text/FNTGeneratorCanvas.ts +283 -283
- package/lib/text/FNTGeneratrorBase.ts +10 -10
- package/lib/text/Font.ts +114 -114
- package/lib/text/FontLookUpMode.ts +5 -5
- package/lib/text/FontStyleName.ts +6 -6
- package/lib/text/GridFitType.ts +32 -32
- package/lib/text/HTMLTextProcessor.ts +421 -421
- package/lib/text/IFontTable.ts +17 -17
- package/lib/text/TesselatedFontChar.ts +80 -80
- package/lib/text/TesselatedFontTable.ts +1181 -1181
- package/lib/text/TextFieldAutoSize.ts +30 -30
- package/lib/text/TextFieldType.ts +21 -21
- package/lib/text/TextFormat.ts +603 -603
- package/lib/text/TextFormatAlign.ts +28 -28
- package/lib/text/TextInteractionMode.ts +21 -21
- package/lib/text/TextLineMetrics.ts +74 -74
- package/lib/text/TextShape.ts +91 -91
- package/lib/tools/Merge.ts +311 -311
- package/lib/utils/Cast.ts +304 -304
- package/package.json +74 -74
- package/rollup.config.js +33 -33
- package/scripts/build.sh +2 -2
- package/scripts/gendocs.sh +14 -14
- package/scripts/genexamples.sh +14 -14
- package/scripts/genfull.sh +14 -14
- package/system.config.js +51 -51
- package/tsconfig.json +18 -18
|
@@ -1,803 +1,803 @@
|
|
|
1
|
-
import { Vector3D } from '@awayjs/core';
|
|
2
|
-
import { FocusEvent } from '../events/FocusEvent';
|
|
3
|
-
import { KeyboardEvent } from '../events/KeyboardEvent';
|
|
4
|
-
import { MouseEvent as AwayMouseEvent } from '../events/MouseEvent';
|
|
5
|
-
import { TouchEvent as AwayTouchEvent } from '../events/TouchEvent';
|
|
6
|
-
/**
|
|
7
|
-
* MouseManager enforces a singleton pattern and is not intended to be instanced.
|
|
8
|
-
* it provides a manager class for detecting mouse hits on scene objects and sending out mouse events.
|
|
9
|
-
*/
|
|
10
|
-
var MouseManager = /** @class */ (function () {
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new <code>MouseManager</code> object.
|
|
13
|
-
*/
|
|
14
|
-
function MouseManager(stage) {
|
|
15
|
-
this._pickerLookup = new Array();
|
|
16
|
-
this._pointerDataArray = {};
|
|
17
|
-
this.allowKeyInput = true;
|
|
18
|
-
this._eventBubbling = true; // should events bubble up
|
|
19
|
-
this._allowFocusOnUnfocusable = true; // should unfocus-able object steal focus ?
|
|
20
|
-
this._cursorType = 'auto';
|
|
21
|
-
this._nullVector = new Vector3D();
|
|
22
|
-
this._dragOut = new AwayMouseEvent(AwayMouseEvent.DRAG_OUT);
|
|
23
|
-
this._dragOver = new AwayMouseEvent(AwayMouseEvent.DRAG_OVER);
|
|
24
|
-
this._dragMove = new AwayMouseEvent(AwayMouseEvent.DRAG_MOVE);
|
|
25
|
-
this._dragStart = new AwayMouseEvent(AwayMouseEvent.DRAG_START);
|
|
26
|
-
this._dragStop = new AwayMouseEvent(AwayMouseEvent.DRAG_STOP);
|
|
27
|
-
this._focusIn = new FocusEvent(FocusEvent.FOCUS_IN);
|
|
28
|
-
this._focusOut = new FocusEvent(FocusEvent.FOCUS_OUT);
|
|
29
|
-
this._useSoftkeyboard = false;
|
|
30
|
-
this._isAVM1Dragging = false;
|
|
31
|
-
this._stage = stage;
|
|
32
|
-
this.onDoubleClick = this.onDoubleClick.bind(this);
|
|
33
|
-
this.onMouseDown = this.onMouseDown.bind(this);
|
|
34
|
-
this.onMouseMove = this.onMouseMove.bind(this);
|
|
35
|
-
this.onMouseUp = this.onMouseUp.bind(this);
|
|
36
|
-
this.onMouseWheel = this.onMouseWheel.bind(this);
|
|
37
|
-
this.onMouseOver = this.onMouseOver.bind(this);
|
|
38
|
-
this.onMouseOut = this.onMouseOut.bind(this);
|
|
39
|
-
this.onKeyDown = this.onKeyDown.bind(this);
|
|
40
|
-
this.onKeyUp = this.onKeyUp.bind(this);
|
|
41
|
-
this._showCursor = true;
|
|
42
|
-
//register stage
|
|
43
|
-
var container = this._stage.container;
|
|
44
|
-
container.addEventListener('touchstart', this.onMouseDown);
|
|
45
|
-
container.addEventListener('mousedown', this.onMouseDown);
|
|
46
|
-
window.addEventListener('touchmove', this.onMouseMove);
|
|
47
|
-
window.addEventListener('mousemove', this.onMouseMove);
|
|
48
|
-
window.addEventListener('mouseup', this.onMouseUp);
|
|
49
|
-
container.addEventListener('touchend', this.onMouseUp);
|
|
50
|
-
container.addEventListener('mousewheel', this.onMouseWheel);
|
|
51
|
-
container.addEventListener('mouseover', this.onMouseOver);
|
|
52
|
-
container.addEventListener('mouseout', this.onMouseOut);
|
|
53
|
-
window.addEventListener('keydown', this.onKeyDown);
|
|
54
|
-
window.addEventListener('keyup', this.onKeyUp);
|
|
55
|
-
// supress context menu
|
|
56
|
-
container.addEventListener('contextmenu', function (e) { return e.preventDefault(); });
|
|
57
|
-
}
|
|
58
|
-
MouseManager.prototype.startDragObject = function (collision, isAVM1Dragging) {
|
|
59
|
-
if (isAVM1Dragging === void 0) { isAVM1Dragging = false; }
|
|
60
|
-
this._isAVM1Dragging = isAVM1Dragging;
|
|
61
|
-
// we MUST overrider collision target if present, because draggable !== drag emitter
|
|
62
|
-
if (collision)
|
|
63
|
-
(this._pointerDataArray[0] || (this._pointerDataArray[0] = new PointerData(0, true))).dragCollision = collision;
|
|
64
|
-
};
|
|
65
|
-
MouseManager.prototype.stopDragObject = function () {
|
|
66
|
-
this._isAVM1Dragging = false;
|
|
67
|
-
};
|
|
68
|
-
Object.defineProperty(MouseManager.prototype, "showCursor", {
|
|
69
|
-
get: function () {
|
|
70
|
-
return this._showCursor;
|
|
71
|
-
},
|
|
72
|
-
set: function (value) {
|
|
73
|
-
this._showCursor = value;
|
|
74
|
-
this.cursorType = this._cursorType;
|
|
75
|
-
},
|
|
76
|
-
enumerable: false,
|
|
77
|
-
configurable: true
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(MouseManager.prototype, "cursorType", {
|
|
80
|
-
get: function () {
|
|
81
|
-
return this._cursorType;
|
|
82
|
-
},
|
|
83
|
-
set: function (t) {
|
|
84
|
-
this._cursorType = t;
|
|
85
|
-
this._stage.container.style.cursor = this._showCursor ? t : 'none';
|
|
86
|
-
},
|
|
87
|
-
enumerable: false,
|
|
88
|
-
configurable: true
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(MouseManager.prototype, "eventBubbling", {
|
|
91
|
-
get: function () {
|
|
92
|
-
return this._eventBubbling;
|
|
93
|
-
},
|
|
94
|
-
set: function (value) {
|
|
95
|
-
this._eventBubbling = value;
|
|
96
|
-
},
|
|
97
|
-
enumerable: false,
|
|
98
|
-
configurable: true
|
|
99
|
-
});
|
|
100
|
-
Object.defineProperty(MouseManager.prototype, "useSoftkeyboard", {
|
|
101
|
-
get: function () {
|
|
102
|
-
return this._useSoftkeyboard;
|
|
103
|
-
},
|
|
104
|
-
set: function (value) {
|
|
105
|
-
this._useSoftkeyboard = value;
|
|
106
|
-
// todo: improve this, so that we can
|
|
107
|
-
// - use device-softkeyboard on tablet / mobide
|
|
108
|
-
// - optionally use a custom softkeyboard
|
|
109
|
-
if (!value) {
|
|
110
|
-
window.addEventListener('keydown', this.onKeyDown);
|
|
111
|
-
window.addEventListener('keyup', this.onKeyUp);
|
|
112
|
-
}
|
|
113
|
-
else if (value) {
|
|
114
|
-
window.removeEventListener('keydown', this.onKeyDown);
|
|
115
|
-
window.removeEventListener('keyup', this.onKeyUp);
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
enumerable: false,
|
|
119
|
-
configurable: true
|
|
120
|
-
});
|
|
121
|
-
MouseManager.prototype.dispose = function () {
|
|
122
|
-
//unregister stage
|
|
123
|
-
var container = this._stage.container;
|
|
124
|
-
container.removeEventListener('dblclick', this.onDoubleClick);
|
|
125
|
-
container.removeEventListener('touchstart', this.onMouseDown);
|
|
126
|
-
container.removeEventListener('mousedown', this.onMouseDown);
|
|
127
|
-
window.removeEventListener('touchmove', this.onMouseMove);
|
|
128
|
-
window.removeEventListener('mousemove', this.onMouseMove);
|
|
129
|
-
window.removeEventListener('mouseup', this.onMouseUp);
|
|
130
|
-
container.removeEventListener('touchend', this.onMouseUp);
|
|
131
|
-
container.removeEventListener('wheel', this.onMouseWheel);
|
|
132
|
-
container.removeEventListener('mouseover', this.onMouseOver);
|
|
133
|
-
container.removeEventListener('mouseout', this.onMouseOut);
|
|
134
|
-
window.removeEventListener('keydown', this.onKeyDown);
|
|
135
|
-
window.removeEventListener('keyup', this.onKeyUp);
|
|
136
|
-
this._stage = null;
|
|
137
|
-
this._dragOut = null;
|
|
138
|
-
this._dragOver = null;
|
|
139
|
-
this._dragMove = null;
|
|
140
|
-
this._dragStart = null;
|
|
141
|
-
this._dragStop = null;
|
|
142
|
-
};
|
|
143
|
-
MouseManager.clearInstance = function (stage) {
|
|
144
|
-
if (this._instancePool[stage.id]) {
|
|
145
|
-
this._instancePool[stage.id].dispose();
|
|
146
|
-
delete this._instancePool[stage.id];
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
MouseManager.getInstance = function (stage) {
|
|
150
|
-
return this._instancePool[stage.id]
|
|
151
|
-
|| (this._instancePool[stage.id] = new MouseManager(stage));
|
|
152
|
-
};
|
|
153
|
-
MouseManager.prototype.setFocus = function (node) {
|
|
154
|
-
if (this._focusNode == node)
|
|
155
|
-
return;
|
|
156
|
-
// in FP6, a mouseclick on non focus-able object still steal the focus
|
|
157
|
-
// in newer FP they only steal the focus if the the new hit is focusable
|
|
158
|
-
if (this._allowFocusOnUnfocusable || this._focusNode.container.tabEnabled) {
|
|
159
|
-
if (this._focusNode && this._focusNode.container) {
|
|
160
|
-
this.dispatchEvent(this._focusOut, this._focusNode);
|
|
161
|
-
this._focusNode.container.setFocus(false, true);
|
|
162
|
-
}
|
|
163
|
-
this._focusNode = node;
|
|
164
|
-
if (this._focusNode) {
|
|
165
|
-
this.dispatchEvent(this._focusIn, this._focusNode);
|
|
166
|
-
this._focusNode.container.setFocus(true, true);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
MouseManager.prototype.getFocus = function () {
|
|
171
|
-
return this._focusNode;
|
|
172
|
-
};
|
|
173
|
-
MouseManager.prototype.dispatchEvent = function (event, dispatcher) {
|
|
174
|
-
if (!this._eventBubbling) {
|
|
175
|
-
if (dispatcher) {
|
|
176
|
-
event._dispatchEvent(dispatcher, dispatcher.container);
|
|
177
|
-
}
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
var target = dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.container;
|
|
181
|
-
while (dispatcher) {
|
|
182
|
-
if (event.commonAncestor && dispatcher == event.commonAncestor) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
event._dispatchEvent(dispatcher, target);
|
|
186
|
-
if (!event._iAllowedToPropagate) {
|
|
187
|
-
dispatcher = null;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
dispatcher = dispatcher.parent;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
MouseManager.prototype.setupAndDispatchEvent = function (event, pointerData, collision, commonAncestor) {
|
|
195
|
-
if (commonAncestor === void 0) { commonAncestor = null; }
|
|
196
|
-
var sourceEvent = pointerData.sourceEvent;
|
|
197
|
-
if (sourceEvent) {
|
|
198
|
-
if (event instanceof AwayMouseEvent) {
|
|
199
|
-
event.delta = sourceEvent.deltaY;
|
|
200
|
-
event.buttons = sourceEvent.buttons;
|
|
201
|
-
}
|
|
202
|
-
event.ctrlKey = sourceEvent.ctrlKey;
|
|
203
|
-
event.altKey = sourceEvent.altKey;
|
|
204
|
-
event.shiftKey = sourceEvent.shiftKey;
|
|
205
|
-
}
|
|
206
|
-
event = this.setUpEvent(event, pointerData, collision, commonAncestor);
|
|
207
|
-
this.dispatchEvent(event, event.rootNode);
|
|
208
|
-
};
|
|
209
|
-
MouseManager.prototype.fireMouseEvents = function (forcePicker) {
|
|
210
|
-
if (forcePicker === void 0) { forcePicker = null; }
|
|
211
|
-
//if theres nothing to update, return
|
|
212
|
-
if (!forcePicker && !this._updateDirty)
|
|
213
|
-
return;
|
|
214
|
-
for (var key in this._pointerDataArray) {
|
|
215
|
-
this._fireMouseEventsInternal(this._pointerDataArray[key], forcePicker);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
MouseManager.prototype._fireMouseEventsInternal = function (pointerData, forcePicker) {
|
|
219
|
-
var _a, _b, _c;
|
|
220
|
-
if (forcePicker === void 0) { forcePicker = null; }
|
|
221
|
-
var collision;
|
|
222
|
-
if (forcePicker) {
|
|
223
|
-
collision = forcePicker.getViewCollision(pointerData.screenX, pointerData.screenY);
|
|
224
|
-
}
|
|
225
|
-
else if (this._updateDirty) {
|
|
226
|
-
for (var i = 0; i < this._pickerLookup.length; i++)
|
|
227
|
-
if (!collision || this._pickerLookup[i].layeredView)
|
|
228
|
-
collision = this._pickerLookup[i].getViewCollision(pointerData.screenX, pointerData.screenY, false, collision);
|
|
229
|
-
}
|
|
230
|
-
var event;
|
|
231
|
-
var dispatcher;
|
|
232
|
-
var len = pointerData.queuedEvents.length;
|
|
233
|
-
for (var i = 0; i < len; ++i) {
|
|
234
|
-
event = pointerData.queuedEvents[i];
|
|
235
|
-
dispatcher = collision === null || collision === void 0 ? void 0 : collision.rootNode;
|
|
236
|
-
this.setUpEvent(event, pointerData, collision);
|
|
237
|
-
if (event.type == pointerData.down.type) {
|
|
238
|
-
// no event-bubbling. dispatch on stage first
|
|
239
|
-
if (!this._eventBubbling)
|
|
240
|
-
this._stage.dispatchEvent(event);
|
|
241
|
-
// @todo: at this point the object under the mouse might have been changed,
|
|
242
|
-
// so we need to recheck the collision ?
|
|
243
|
-
// on Touch dispatch mouseOver Command
|
|
244
|
-
if (!pointerData.isMouse)
|
|
245
|
-
this.setupAndDispatchEvent(pointerData.over, pointerData, collision);
|
|
246
|
-
if (pointerData.id == 0)
|
|
247
|
-
pointerData.dragCollision = collision;
|
|
248
|
-
if (dispatcher)
|
|
249
|
-
this.dispatchEvent(event, dispatcher);
|
|
250
|
-
else if (this._eventBubbling)
|
|
251
|
-
this._stage.dispatchEvent(event);
|
|
252
|
-
if (pointerData.dragCollision) {
|
|
253
|
-
this.setFocus(pointerData.dragCollision.rootNode);
|
|
254
|
-
this.setupAndDispatchEvent(this._dragStart, pointerData, pointerData.dragCollision);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
else if (event.type == pointerData.up.type) {
|
|
258
|
-
// no event-bubbling. dispatch on stage first
|
|
259
|
-
if (!this._eventBubbling)
|
|
260
|
-
this._stage.dispatchEvent(event);
|
|
261
|
-
// @todo: at this point the object under the mouse might have been changed,
|
|
262
|
-
// so we need to recheck the collision ?
|
|
263
|
-
var upContainerNode = null;
|
|
264
|
-
var upRootNode = null;
|
|
265
|
-
if (this._isAVM1Dragging && pointerData.dragCollision) {
|
|
266
|
-
// avm1dragging is in process, dispatch the mouse-up on this.
|
|
267
|
-
// mouseDragEntity instead of the current collision
|
|
268
|
-
upRootNode = pointerData.dragCollision.rootNode;
|
|
269
|
-
upContainerNode = pointerData.dragCollision.containerNode;
|
|
270
|
-
}
|
|
271
|
-
else if (pointerData.dragCollision && pointerData.dragCollision.rootNode != dispatcher) {
|
|
272
|
-
// no avm1dragging is in process, but current collision
|
|
273
|
-
// is not the same as collision that appeared on mouse-down,
|
|
274
|
-
// need to dispatch a MOUSE_UP_OUTSIDE after mouse up
|
|
275
|
-
}
|
|
276
|
-
else if (pointerData.dragCollision && pointerData.dragCollision.rootNode == dispatcher) {
|
|
277
|
-
// no avm1dragging is in process,
|
|
278
|
-
// current collision is the same as collision that appeared on
|
|
279
|
-
// mouse-down, need to dispatch a MOUSE_CLICK event after mouse up
|
|
280
|
-
upRootNode = pointerData.dragCollision.rootNode;
|
|
281
|
-
upContainerNode = pointerData.dragCollision.containerNode;
|
|
282
|
-
}
|
|
283
|
-
if (upRootNode)
|
|
284
|
-
this.dispatchEvent(event, upRootNode);
|
|
285
|
-
else if (dispatcher)
|
|
286
|
-
this.dispatchEvent(event, dispatcher);
|
|
287
|
-
else if (this._eventBubbling)
|
|
288
|
-
this._stage.dispatchEvent(event);
|
|
289
|
-
if (upContainerNode) {
|
|
290
|
-
if (!this._isAVM1Dragging)
|
|
291
|
-
this.setupAndDispatchEvent(pointerData.click, pointerData, pointerData.dragCollision);
|
|
292
|
-
this.setupAndDispatchEvent(this._dragStop, pointerData, pointerData.dragCollision);
|
|
293
|
-
}
|
|
294
|
-
else if (pointerData.dragCollision) {
|
|
295
|
-
this.setupAndDispatchEvent(pointerData.upOutside, pointerData, pointerData.dragCollision);
|
|
296
|
-
}
|
|
297
|
-
pointerData.dragCollision = null;
|
|
298
|
-
this._isAVM1Dragging = false;
|
|
299
|
-
//make sure to clear old touch references when no longer needed
|
|
300
|
-
if (pointerData.id != 0)
|
|
301
|
-
delete this._pointerDataArray[pointerData.id];
|
|
302
|
-
}
|
|
303
|
-
else if (event.type == pointerData.move.type) {
|
|
304
|
-
// no event-bubbling. dispatch on stage first
|
|
305
|
-
if (!this._eventBubbling)
|
|
306
|
-
this._stage.dispatchEvent(event);
|
|
307
|
-
// fire to picker
|
|
308
|
-
if (dispatcher)
|
|
309
|
-
this.dispatchEvent(event, dispatcher);
|
|
310
|
-
else if (this._eventBubbling)
|
|
311
|
-
this._stage.dispatchEvent(event);
|
|
312
|
-
if (pointerData.dragCollision)
|
|
313
|
-
this.setupAndDispatchEvent(this._dragMove, pointerData, pointerData.dragCollision);
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
// MouseEvent.MOUSE_OVER / MouseEvent.MOUSE_OUT / MouseEvent.DRAG_OVER / MouseEvent.DRAG_OUT
|
|
317
|
-
this.dispatchEvent(event, dispatcher);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
pointerData.queuedEvents.length = 0;
|
|
321
|
-
pointerData.rollOut.commonAncestor = null;
|
|
322
|
-
pointerData.rollOver.commonAncestor = null;
|
|
323
|
-
var collisionNode = collision === null || collision === void 0 ? void 0 : collision.rootNode;
|
|
324
|
-
var prevCollisionNode = (_a = pointerData.prevCollision) === null || _a === void 0 ? void 0 : _a.rootNode;
|
|
325
|
-
if (collisionNode != prevCollisionNode) {
|
|
326
|
-
// If colliding object has changed, queue OVER and OUT events.
|
|
327
|
-
// If the mouse is dragged (mouse-down is hold), use DRAG_OVER and DRAG_OUT as well as MOUSE_OVER MOUSE_OUT
|
|
328
|
-
// DRAG_OVER and DRAG_OUT are only dispatched on the object that was hit on the mouse-down
|
|
329
|
-
// (_mouseDragEntity)
|
|
330
|
-
// Store the info if the collision is a enabled Button (_collisionIsEnabledButton)
|
|
331
|
-
if (prevCollisionNode) {
|
|
332
|
-
this.setupAndDispatchEvent(pointerData.out, pointerData, pointerData.prevCollision);
|
|
333
|
-
if (((_b = pointerData.dragCollision) === null || _b === void 0 ? void 0 : _b.rootNode) == prevCollisionNode)
|
|
334
|
-
this.setupAndDispatchEvent(this._dragOut, pointerData, pointerData.prevCollision);
|
|
335
|
-
}
|
|
336
|
-
if (!prevCollisionNode && collisionNode) {
|
|
337
|
-
// rollout / rollover easy case, can just bubble up
|
|
338
|
-
this.setupAndDispatchEvent(pointerData.rollOut, pointerData, pointerData.prevCollision);
|
|
339
|
-
this.setupAndDispatchEvent(pointerData.rollOver, pointerData, collision);
|
|
340
|
-
}
|
|
341
|
-
if (prevCollisionNode && !collisionNode) {
|
|
342
|
-
// rollout / rollover easy case, can just bubble up
|
|
343
|
-
this.setupAndDispatchEvent(pointerData.rollOut, pointerData, pointerData.prevCollision);
|
|
344
|
-
this.setupAndDispatchEvent(pointerData.rollOver, pointerData, collision);
|
|
345
|
-
}
|
|
346
|
-
if (prevCollisionNode && collisionNode) {
|
|
347
|
-
// rollout / rollover find common ancester and only bubble up to that point
|
|
348
|
-
var parentsPrev = [];
|
|
349
|
-
var parent_1 = prevCollisionNode;
|
|
350
|
-
while (parent_1 && !parent_1.container.isAVMScene) {
|
|
351
|
-
parentsPrev.push(parent_1);
|
|
352
|
-
parent_1 = parent_1.parent;
|
|
353
|
-
}
|
|
354
|
-
var commonAncestor = null;
|
|
355
|
-
parent_1 = collisionNode;
|
|
356
|
-
while (parent_1 && !parent_1.container.isAVMScene) {
|
|
357
|
-
var oldParentIdx = parentsPrev.indexOf(parent_1);
|
|
358
|
-
if (oldParentIdx == -1) {
|
|
359
|
-
parent_1 = parent_1.parent;
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
commonAncestor = parent_1;
|
|
363
|
-
parent_1 = null;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
if (commonAncestor != prevCollisionNode)
|
|
367
|
-
this.setupAndDispatchEvent(pointerData.rollOut, pointerData, pointerData.prevCollision, commonAncestor);
|
|
368
|
-
if (commonAncestor != collisionNode)
|
|
369
|
-
this.setupAndDispatchEvent(pointerData.rollOver, pointerData, collision, commonAncestor);
|
|
370
|
-
}
|
|
371
|
-
pointerData.collisionIsEnabledButton = collisionNode ? collisionNode.buttonEnabled : false;
|
|
372
|
-
if (collisionNode) {
|
|
373
|
-
this.setupAndDispatchEvent(pointerData.over, pointerData, collision);
|
|
374
|
-
if (pointerData.dragCollision)
|
|
375
|
-
this.setupAndDispatchEvent(this._dragOver, pointerData, collision);
|
|
376
|
-
}
|
|
377
|
-
pointerData.prevCollision = collision;
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
// colliding object has not changed
|
|
381
|
-
// Check if we need to send any MOUSE_OVER/DRAG_OVER event to handle the case
|
|
382
|
-
// when a Button has become active while under the mouse.
|
|
383
|
-
var isActiveButton = collisionNode ? collisionNode.buttonEnabled : false;
|
|
384
|
-
if (pointerData.collisionIsEnabledButton != isActiveButton && isActiveButton) {
|
|
385
|
-
if (pointerData.isMouse)
|
|
386
|
-
this.setupAndDispatchEvent(pointerData.over, pointerData, collision);
|
|
387
|
-
else if (((_c = pointerData.dragCollision) === null || _c === void 0 ? void 0 : _c.rootNode) == collisionNode)
|
|
388
|
-
this.setupAndDispatchEvent(this._dragOver, pointerData, collision);
|
|
389
|
-
}
|
|
390
|
-
pointerData.collisionIsEnabledButton = isActiveButton;
|
|
391
|
-
}
|
|
392
|
-
// set cursor if not dragging mouse ???
|
|
393
|
-
if (!pointerData.dragCollision) {
|
|
394
|
-
this.cursorType = collisionNode ? collisionNode.container.getMouseCursor() : 'auto';
|
|
395
|
-
}
|
|
396
|
-
this._updateDirty = false;
|
|
397
|
-
};
|
|
398
|
-
MouseManager.prototype.registerPicker = function (picker) {
|
|
399
|
-
this._pickerLookup.push(picker);
|
|
400
|
-
};
|
|
401
|
-
MouseManager.prototype.unregisterPicker = function (picker) {
|
|
402
|
-
this._pickerLookup.splice(this._pickerLookup.indexOf(picker), 1);
|
|
403
|
-
};
|
|
404
|
-
MouseManager.prototype.addEventsForSceneBinary = function (touchMessage, sceneIdx) {
|
|
405
|
-
if (sceneIdx === void 0) { sceneIdx = 0; }
|
|
406
|
-
var newTouchEvent = {};
|
|
407
|
-
newTouchEvent.clientX = null; // we get the x position from the active touch
|
|
408
|
-
newTouchEvent.clientY = null; // we get the y position from the active touch
|
|
409
|
-
newTouchEvent.touches = [];
|
|
410
|
-
newTouchEvent.changedTouches = [];
|
|
411
|
-
newTouchEvent.preventDefault = function () { };
|
|
412
|
-
var messageScene = new Float32Array(touchMessage);
|
|
413
|
-
// transfer touches to event
|
|
414
|
-
var i = 0;
|
|
415
|
-
var cnt = 0;
|
|
416
|
-
var touchCnt = 0;
|
|
417
|
-
cnt++; //we temporary added 1 float to transfer fps from java to js. skip this
|
|
418
|
-
var numTouches = messageScene[cnt++];
|
|
419
|
-
var touchtype = messageScene[cnt++];
|
|
420
|
-
var activeTouchID = messageScene[cnt++];
|
|
421
|
-
if ((touchtype != 1) && (touchtype != 6) && (touchtype != 12) && (touchtype != 262) && (touchtype != 518)) {
|
|
422
|
-
// if this is not a UP command, we add all touches
|
|
423
|
-
for (i = 0; i < numTouches; i++) {
|
|
424
|
-
var newTouch = {};
|
|
425
|
-
newTouch.identifier = messageScene[cnt++];
|
|
426
|
-
newTouch.clientX = messageScene[cnt++];
|
|
427
|
-
newTouch.clientY = messageScene[cnt++];
|
|
428
|
-
newTouchEvent.touches[i] = newTouch;
|
|
429
|
-
//newTouchEvent.changedTouches[i] = newTouch;
|
|
430
|
-
}
|
|
431
|
-
newTouchEvent.changedTouches[0] = newTouchEvent.touches[activeTouchID];
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
// if this is a UP command, we add all touches, except the active one
|
|
435
|
-
if (numTouches == 1) {
|
|
436
|
-
var newTouch = {};
|
|
437
|
-
newTouch.identifier = messageScene[cnt++];
|
|
438
|
-
newTouch.clientX = messageScene[cnt++];
|
|
439
|
-
newTouch.clientY = messageScene[cnt++];
|
|
440
|
-
newTouchEvent.clientX = newTouch.clientX;
|
|
441
|
-
newTouchEvent.clientY = newTouch.clientY;
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
for (i = 0; i < numTouches; i++) {
|
|
445
|
-
var newTouch = {};
|
|
446
|
-
newTouch.identifier = messageScene[cnt++];
|
|
447
|
-
newTouch.clientX = messageScene[cnt++];
|
|
448
|
-
newTouch.clientY = messageScene[cnt++];
|
|
449
|
-
if (i != activeTouchID) {
|
|
450
|
-
newTouchEvent.touches[touchCnt] = newTouch;
|
|
451
|
-
//newTouchEvent.changedTouches[touchCnt++] = newTouch;
|
|
452
|
-
}
|
|
453
|
-
else {
|
|
454
|
-
newTouchEvent.clientX = newTouch.clientX;
|
|
455
|
-
newTouchEvent.clientY = newTouch.clientY;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
//console.log("Touch ID:"+touchtype+" activeTouchID "+activeTouchID+" numTouches "+numTouches+" x"+x+" y"+y);
|
|
461
|
-
/*
|
|
462
|
-
public static final int ACTION_DOWN = 0;
|
|
463
|
-
public static final int ACTION_POINTER_1_DOWN = 5;
|
|
464
|
-
public static final int ACTION_POINTER_DOWN = 5;
|
|
465
|
-
public static final int ACTION_BUTTON_PRESS = 11;
|
|
466
|
-
public static final int ACTION_POINTER_2_DOWN = 261;
|
|
467
|
-
public static final int ACTION_POINTER_3_DOWN = 517;
|
|
468
|
-
|
|
469
|
-
public static final int ACTION_UP = 1;
|
|
470
|
-
public static final int ACTION_POINTER_1_UP = 6;
|
|
471
|
-
public static final int ACTION_POINTER_UP = 6;
|
|
472
|
-
public static final int ACTION_BUTTON_RELEASE = 12;
|
|
473
|
-
public static final int ACTION_POINTER_2_UP = 262;
|
|
474
|
-
public static final int ACTION_POINTER_3_UP = 518;
|
|
475
|
-
|
|
476
|
-
public static final int ACTION_MOVE = 2;
|
|
477
|
-
|
|
478
|
-
*/
|
|
479
|
-
if ((touchtype == 0) || (touchtype == 5) || (touchtype == 11) || (touchtype == 261) || (touchtype == 517)) {
|
|
480
|
-
this.onMouseDown(newTouchEvent);
|
|
481
|
-
}
|
|
482
|
-
else if ((touchtype == 1) || (touchtype == 6)
|
|
483
|
-
|| (touchtype == 12) || (touchtype == 262) || (touchtype == 518)) {
|
|
484
|
-
this.onMouseUp(newTouchEvent);
|
|
485
|
-
}
|
|
486
|
-
else if (touchtype == 2) {
|
|
487
|
-
this.onMouseMove(newTouchEvent);
|
|
488
|
-
}
|
|
489
|
-
else {
|
|
490
|
-
console.log('recieved unknown touch event-type: ' + touchtype);
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
MouseManager.prototype.fireEventsForSceneFromString = function (touchMessage, _sceneIdx) {
|
|
494
|
-
if (_sceneIdx === void 0) { _sceneIdx = 0; }
|
|
495
|
-
var newTouchEvent = {};
|
|
496
|
-
newTouchEvent.clientX = null; // set the x position from the active touch
|
|
497
|
-
newTouchEvent.clientY = null; // set the y position from the active touch
|
|
498
|
-
newTouchEvent.preventDefault = function () { };
|
|
499
|
-
var touchesFromMessage = touchMessage.split(',');
|
|
500
|
-
// transfer touches to event
|
|
501
|
-
var i = 0;
|
|
502
|
-
var cnt = 0;
|
|
503
|
-
var numTouches = parseInt(touchesFromMessage[cnt++]);
|
|
504
|
-
var touchtype = parseInt(touchesFromMessage[cnt++]);
|
|
505
|
-
var activeTouch = parseInt(touchesFromMessage[cnt++]);
|
|
506
|
-
newTouchEvent.touches = [];
|
|
507
|
-
newTouchEvent.changedTouches = [];
|
|
508
|
-
if ((touchtype != 1) && (touchtype != 6)) {
|
|
509
|
-
for (i = 0; i < numTouches; i++) {
|
|
510
|
-
var newTouch = {};
|
|
511
|
-
newTouch.identifier = touchesFromMessage[cnt++];
|
|
512
|
-
newTouch.clientX = touchesFromMessage[cnt++];
|
|
513
|
-
newTouch.clientY = touchesFromMessage[cnt++];
|
|
514
|
-
newTouchEvent.touches[i] = newTouch;
|
|
515
|
-
newTouchEvent.changedTouches[i] = newTouch;
|
|
516
|
-
}
|
|
517
|
-
newTouchEvent.changedTouches[i] = newTouchEvent.touches[activeTouch];
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
for (i = 0; i < numTouches; i++) {
|
|
521
|
-
if (i != activeTouch) {
|
|
522
|
-
var newTouch = {};
|
|
523
|
-
newTouch.identifier = touchesFromMessage[cnt++];
|
|
524
|
-
newTouch.clientX = touchesFromMessage[cnt++];
|
|
525
|
-
newTouch.clientY = touchesFromMessage[cnt++];
|
|
526
|
-
newTouchEvent.touches[i] = newTouch;
|
|
527
|
-
newTouchEvent.changedTouches[i] = newTouch;
|
|
528
|
-
}
|
|
529
|
-
else {
|
|
530
|
-
newTouchEvent.clientX = touchesFromMessage[cnt++];
|
|
531
|
-
newTouchEvent.clientY = touchesFromMessage[cnt++];
|
|
532
|
-
cnt++;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
if (touchtype == 0) { //mousedown
|
|
537
|
-
this.onMouseDown(newTouchEvent);
|
|
538
|
-
}
|
|
539
|
-
else if (touchtype == 1) { //mouseup
|
|
540
|
-
this.onMouseUp(newTouchEvent);
|
|
541
|
-
}
|
|
542
|
-
else if (touchtype == 2) { //mousemove
|
|
543
|
-
this.onMouseMove(newTouchEvent);
|
|
544
|
-
}
|
|
545
|
-
else if (touchtype == 261) { //mousedownPointer
|
|
546
|
-
this.onMouseDown(newTouchEvent);
|
|
547
|
-
}
|
|
548
|
-
else if (touchtype == 6) { //mouseupPointer
|
|
549
|
-
this.onMouseUp(newTouchEvent);
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
// ---------------------------------------------------------------------
|
|
553
|
-
// Private.
|
|
554
|
-
// ---------------------------------------------------------------------
|
|
555
|
-
MouseManager.prototype.setUpEvent = function (event, pointerData, collision, commonAncestor) {
|
|
556
|
-
var _a, _b;
|
|
557
|
-
if (commonAncestor === void 0) { commonAncestor = null; }
|
|
558
|
-
event._iAllowedToImmediatlyPropagate = true;
|
|
559
|
-
event._iAllowedToPropagate = true;
|
|
560
|
-
// 2D properties.
|
|
561
|
-
event.screenX = pointerData.screenX;
|
|
562
|
-
event.screenY = pointerData.screenY;
|
|
563
|
-
if (event instanceof AwayTouchEvent)
|
|
564
|
-
event.touchPointID = pointerData.id;
|
|
565
|
-
//console.log("event", event, collisionNode, collisionNode);
|
|
566
|
-
// 3D properties.
|
|
567
|
-
if (collision) {
|
|
568
|
-
event.containerNode = collision.containerNode;
|
|
569
|
-
event.rootNode = collision.rootNode;
|
|
570
|
-
// Object.
|
|
571
|
-
event.pickable = collision.pickable;
|
|
572
|
-
// UV.
|
|
573
|
-
event.uv = collision.uv;
|
|
574
|
-
// Position.
|
|
575
|
-
event.position = (_a = collision.position) === null || _a === void 0 ? void 0 : _a.clone();
|
|
576
|
-
// Normal.
|
|
577
|
-
event.normal = (_b = collision.normal) === null || _b === void 0 ? void 0 : _b.clone();
|
|
578
|
-
// Face index.
|
|
579
|
-
event.elementIndex = collision.elementIndex;
|
|
580
|
-
}
|
|
581
|
-
else {
|
|
582
|
-
// Set all to null.
|
|
583
|
-
event.containerNode = null;
|
|
584
|
-
event.rootNode = null;
|
|
585
|
-
event.pickable = null;
|
|
586
|
-
event.uv = null;
|
|
587
|
-
event.position = this._nullVector;
|
|
588
|
-
event.normal = this._nullVector;
|
|
589
|
-
event.elementIndex = 0;
|
|
590
|
-
}
|
|
591
|
-
event.commonAncestor = commonAncestor;
|
|
592
|
-
return event;
|
|
593
|
-
};
|
|
594
|
-
MouseManager.prototype.queueDispatch = function (pointerData, event, sourceEvent) {
|
|
595
|
-
// Store event to be dispatched later.
|
|
596
|
-
if (event instanceof AwayMouseEvent) {
|
|
597
|
-
event.delta = (sourceEvent instanceof WheelEvent) ? -3 * sourceEvent.deltaY / 100 : 0;
|
|
598
|
-
event.buttons = (sourceEvent instanceof MouseEvent) ? sourceEvent.buttons : 0 /* MouseButtons.NO_BUTTON */;
|
|
599
|
-
}
|
|
600
|
-
event.ctrlKey = sourceEvent.ctrlKey;
|
|
601
|
-
event.altKey = sourceEvent.altKey;
|
|
602
|
-
event.shiftKey = sourceEvent.shiftKey;
|
|
603
|
-
//restrict events fired to one type every animation frame
|
|
604
|
-
var index = pointerData.queuedEvents.indexOf(event);
|
|
605
|
-
if (index != -1)
|
|
606
|
-
pointerData.queuedEvents.splice(index, 1);
|
|
607
|
-
pointerData.queuedEvents.push(event);
|
|
608
|
-
pointerData.sourceEvent = sourceEvent;
|
|
609
|
-
};
|
|
610
|
-
// ---------------------------------------------------------------------
|
|
611
|
-
// Listeners.
|
|
612
|
-
// ---------------------------------------------------------------------
|
|
613
|
-
MouseManager.prototype.onKeyDown = function (event) {
|
|
614
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
615
|
-
//console.log("Keydown", event);
|
|
616
|
-
if (this.allowKeyInput) {
|
|
617
|
-
switch (event.keyCode) {
|
|
618
|
-
case 32: // spacebar
|
|
619
|
-
case 37: // left
|
|
620
|
-
case 39: // right
|
|
621
|
-
case 38: // up
|
|
622
|
-
case 40: // down
|
|
623
|
-
event.preventDefault();
|
|
624
|
-
break;
|
|
625
|
-
default:
|
|
626
|
-
break;
|
|
627
|
-
}
|
|
628
|
-
if (this._focusNode || this._stage) {
|
|
629
|
-
//console.log("dispatch keydown on ", this._focusNode);
|
|
630
|
-
var newEvent = new KeyboardEvent(KeyboardEvent.KEYDOWN, event.key, event.code);
|
|
631
|
-
newEvent.isShift = event.shiftKey;
|
|
632
|
-
newEvent.isCTRL = event.ctrlKey;
|
|
633
|
-
newEvent.isAlt = event.altKey;
|
|
634
|
-
newEvent.keyCode = event.keyCode;
|
|
635
|
-
if (this._focusNode)
|
|
636
|
-
this._focusNode.container.dispatchEvent(newEvent);
|
|
637
|
-
if (this._stage)
|
|
638
|
-
this._stage.dispatchEvent(newEvent);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
MouseManager.prototype.onKeyUp = function (event) {
|
|
643
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
644
|
-
//console.log("Keyup", event);
|
|
645
|
-
if (this.allowKeyInput) {
|
|
646
|
-
switch (event.keyCode) {
|
|
647
|
-
case 32: // spacebar
|
|
648
|
-
case 37: // left
|
|
649
|
-
case 39: // right
|
|
650
|
-
case 38: // up
|
|
651
|
-
case 40: // down
|
|
652
|
-
event.preventDefault();
|
|
653
|
-
break;
|
|
654
|
-
default:
|
|
655
|
-
break;
|
|
656
|
-
}
|
|
657
|
-
if (this._focusNode || this._stage) {
|
|
658
|
-
//console.log("dispatch keydown on ", this._focusNode);
|
|
659
|
-
var newEvent = new KeyboardEvent(KeyboardEvent.KEYUP, event.key, event.code);
|
|
660
|
-
newEvent.isShift = event.shiftKey;
|
|
661
|
-
newEvent.isCTRL = event.ctrlKey;
|
|
662
|
-
newEvent.isAlt = event.altKey;
|
|
663
|
-
newEvent.keyCode = event.keyCode;
|
|
664
|
-
if (this._focusNode)
|
|
665
|
-
this._focusNode.container.dispatchEvent(newEvent);
|
|
666
|
-
if (this._stage)
|
|
667
|
-
this._stage.dispatchEvent(newEvent);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
MouseManager.prototype.onMouseMove = function (event) {
|
|
672
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
673
|
-
this.updateColliders(event);
|
|
674
|
-
};
|
|
675
|
-
MouseManager.prototype.onMouseOut = function (event) {
|
|
676
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
677
|
-
this.updateColliders(event);
|
|
678
|
-
};
|
|
679
|
-
MouseManager.prototype.onMouseOver = function (event) {
|
|
680
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
681
|
-
this.updateColliders(event);
|
|
682
|
-
};
|
|
683
|
-
MouseManager.prototype.onDoubleClick = function (event) {
|
|
684
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
685
|
-
this.updateColliders(event);
|
|
686
|
-
// prevent middle and second button
|
|
687
|
-
if (event instanceof MouseEvent && event.buttons & 6) {
|
|
688
|
-
event.preventDefault();
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
MouseManager.prototype.onMouseDown = function (event) {
|
|
692
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
693
|
-
this.updateColliders(event);
|
|
694
|
-
var prevent = (event.type !== 'mousedown');
|
|
695
|
-
// prevent middle and second button
|
|
696
|
-
if (event instanceof MouseEvent && event.buttons & 6) {
|
|
697
|
-
prevent = true;
|
|
698
|
-
}
|
|
699
|
-
if (prevent) {
|
|
700
|
-
event.preventDefault();
|
|
701
|
-
this._stage.container.focus();
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
MouseManager.prototype.onMouseUp = function (event) {
|
|
705
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
706
|
-
this.updateColliders(event);
|
|
707
|
-
var prevent = event.type !== 'mouseup';
|
|
708
|
-
// prevent middle and second button
|
|
709
|
-
if (event instanceof MouseEvent && event.button === 1) {
|
|
710
|
-
prevent = true;
|
|
711
|
-
}
|
|
712
|
-
if (prevent) {
|
|
713
|
-
event.preventDefault();
|
|
714
|
-
this._stage.container.focus();
|
|
715
|
-
}
|
|
716
|
-
};
|
|
717
|
-
MouseManager.prototype.onMouseWheel = function (event) {
|
|
718
|
-
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
719
|
-
this.updateColliders(event);
|
|
720
|
-
};
|
|
721
|
-
MouseManager.prototype.updateColliders = function (event) {
|
|
722
|
-
this._stage.interactionHandler(event);
|
|
723
|
-
this._updateDirty = true;
|
|
724
|
-
var mouseData = this._pointerDataArray[0] || (this._pointerDataArray[0] = new PointerData(0, true));
|
|
725
|
-
mouseData.isMouse = (event instanceof MouseEvent);
|
|
726
|
-
var type = (mouseData.isMouse) ? event.type : MouseManager._touchToMouseDict[event.type];
|
|
727
|
-
this.queueDispatch(mouseData, MouseManager._pointerDict[type], event);
|
|
728
|
-
mouseData.screenX = this._stage.screenX;
|
|
729
|
-
mouseData.screenY = this._stage.screenY;
|
|
730
|
-
if (event.changedTouches) {
|
|
731
|
-
for (var i = 0; i < event.changedTouches.length; i++) {
|
|
732
|
-
var touch = event.changedTouches[i];
|
|
733
|
-
var touchData = this._pointerDataArray[touch.identifier] || (this._pointerDataArray[touch.identifier] = new PointerData(touch.identifier));
|
|
734
|
-
var point = this._stage.mapWindowToStage(touch.clientX, touch.clientY);
|
|
735
|
-
touchData.screenX = point.x;
|
|
736
|
-
touchData.screenY = point.y;
|
|
737
|
-
this.queueDispatch(touchData, MouseManager._pointerDict[event.type], event);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
};
|
|
741
|
-
MouseManager._instancePool = {};
|
|
742
|
-
MouseManager._touchToMouseDict = {
|
|
743
|
-
touchstart: 'mousedown',
|
|
744
|
-
touchend: 'mouseup',
|
|
745
|
-
touchmove: 'mousemove',
|
|
746
|
-
};
|
|
747
|
-
MouseManager._pointerDict = {
|
|
748
|
-
mouseup: new AwayMouseEvent(AwayMouseEvent.MOUSE_UP),
|
|
749
|
-
mouseupoutside: new AwayMouseEvent(AwayMouseEvent.MOUSE_UP_OUTSIDE),
|
|
750
|
-
click: new AwayMouseEvent(AwayMouseEvent.CLICK),
|
|
751
|
-
mouseout: new AwayMouseEvent(AwayMouseEvent.MOUSE_OUT),
|
|
752
|
-
mousedown: new AwayMouseEvent(AwayMouseEvent.MOUSE_DOWN),
|
|
753
|
-
mousemove: new AwayMouseEvent(AwayMouseEvent.MOUSE_MOVE),
|
|
754
|
-
mouseover: new AwayMouseEvent(AwayMouseEvent.MOUSE_OVER),
|
|
755
|
-
mousewheel: new AwayMouseEvent(AwayMouseEvent.MOUSE_WHEEL),
|
|
756
|
-
dblclick: new AwayMouseEvent(AwayMouseEvent.DOUBLE_CLICK),
|
|
757
|
-
rollover: new AwayMouseEvent(AwayMouseEvent.ROLL_OVER),
|
|
758
|
-
rollout: new AwayMouseEvent(AwayMouseEvent.ROLL_OUT),
|
|
759
|
-
touchend: new AwayTouchEvent(AwayTouchEvent.TOUCH_END),
|
|
760
|
-
touchtap: new AwayTouchEvent(AwayTouchEvent.TOUCH_TAP),
|
|
761
|
-
touchout: new AwayTouchEvent(AwayTouchEvent.TOUCH_OUT),
|
|
762
|
-
touchstart: new AwayTouchEvent(AwayTouchEvent.TOUCH_BEGIN),
|
|
763
|
-
touchmove: new AwayTouchEvent(AwayTouchEvent.TOUCH_MOVE),
|
|
764
|
-
touchover: new AwayTouchEvent(AwayTouchEvent.TOUCH_OVER),
|
|
765
|
-
touchrollover: new AwayTouchEvent(AwayTouchEvent.TOUCH_ROLL_OVER),
|
|
766
|
-
touchrollout: new AwayTouchEvent(AwayTouchEvent.TOUCH_ROLL_OUT),
|
|
767
|
-
};
|
|
768
|
-
return MouseManager;
|
|
769
|
-
}());
|
|
770
|
-
export { MouseManager };
|
|
771
|
-
var PointerData = /** @class */ (function () {
|
|
772
|
-
function PointerData(id, isMouse) {
|
|
773
|
-
if (isMouse === void 0) { isMouse = false; }
|
|
774
|
-
this.id = id;
|
|
775
|
-
this.isMouse = isMouse;
|
|
776
|
-
this.collisionIsEnabledButton = false;
|
|
777
|
-
this.queuedEvents = new Array();
|
|
778
|
-
if (isMouse) {
|
|
779
|
-
this.up = MouseManager._pointerDict.mouseup;
|
|
780
|
-
this.upOutside = MouseManager._pointerDict.mouseupoutside;
|
|
781
|
-
this.click = MouseManager._pointerDict.click;
|
|
782
|
-
this.out = MouseManager._pointerDict.mouseout;
|
|
783
|
-
this.down = MouseManager._pointerDict.mousedown;
|
|
784
|
-
this.move = MouseManager._pointerDict.mousemove;
|
|
785
|
-
this.over = MouseManager._pointerDict.mouseover;
|
|
786
|
-
this.wheel = MouseManager._pointerDict.mousewheel;
|
|
787
|
-
this.doubleClick = MouseManager._pointerDict.dblclick;
|
|
788
|
-
this.rollOver = MouseManager._pointerDict.rollover;
|
|
789
|
-
this.rollOut = MouseManager._pointerDict.rollout;
|
|
790
|
-
}
|
|
791
|
-
else {
|
|
792
|
-
this.up = MouseManager._pointerDict.touchend;
|
|
793
|
-
this.click = MouseManager._pointerDict.touchtap;
|
|
794
|
-
this.out = MouseManager._pointerDict.touchout;
|
|
795
|
-
this.down = MouseManager._pointerDict.touchstart;
|
|
796
|
-
this.move = MouseManager._pointerDict.touchmove;
|
|
797
|
-
this.over = MouseManager._pointerDict.touchover;
|
|
798
|
-
this.rollOver = MouseManager._pointerDict.touchrollover;
|
|
799
|
-
this.rollOut = MouseManager._pointerDict.touchrollout;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
return PointerData;
|
|
803
|
-
}());
|
|
1
|
+
import { Vector3D } from '@awayjs/core';
|
|
2
|
+
import { FocusEvent } from '../events/FocusEvent';
|
|
3
|
+
import { KeyboardEvent } from '../events/KeyboardEvent';
|
|
4
|
+
import { MouseEvent as AwayMouseEvent } from '../events/MouseEvent';
|
|
5
|
+
import { TouchEvent as AwayTouchEvent } from '../events/TouchEvent';
|
|
6
|
+
/**
|
|
7
|
+
* MouseManager enforces a singleton pattern and is not intended to be instanced.
|
|
8
|
+
* it provides a manager class for detecting mouse hits on scene objects and sending out mouse events.
|
|
9
|
+
*/
|
|
10
|
+
var MouseManager = /** @class */ (function () {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new <code>MouseManager</code> object.
|
|
13
|
+
*/
|
|
14
|
+
function MouseManager(stage) {
|
|
15
|
+
this._pickerLookup = new Array();
|
|
16
|
+
this._pointerDataArray = {};
|
|
17
|
+
this.allowKeyInput = true;
|
|
18
|
+
this._eventBubbling = true; // should events bubble up
|
|
19
|
+
this._allowFocusOnUnfocusable = true; // should unfocus-able object steal focus ?
|
|
20
|
+
this._cursorType = 'auto';
|
|
21
|
+
this._nullVector = new Vector3D();
|
|
22
|
+
this._dragOut = new AwayMouseEvent(AwayMouseEvent.DRAG_OUT);
|
|
23
|
+
this._dragOver = new AwayMouseEvent(AwayMouseEvent.DRAG_OVER);
|
|
24
|
+
this._dragMove = new AwayMouseEvent(AwayMouseEvent.DRAG_MOVE);
|
|
25
|
+
this._dragStart = new AwayMouseEvent(AwayMouseEvent.DRAG_START);
|
|
26
|
+
this._dragStop = new AwayMouseEvent(AwayMouseEvent.DRAG_STOP);
|
|
27
|
+
this._focusIn = new FocusEvent(FocusEvent.FOCUS_IN);
|
|
28
|
+
this._focusOut = new FocusEvent(FocusEvent.FOCUS_OUT);
|
|
29
|
+
this._useSoftkeyboard = false;
|
|
30
|
+
this._isAVM1Dragging = false;
|
|
31
|
+
this._stage = stage;
|
|
32
|
+
this.onDoubleClick = this.onDoubleClick.bind(this);
|
|
33
|
+
this.onMouseDown = this.onMouseDown.bind(this);
|
|
34
|
+
this.onMouseMove = this.onMouseMove.bind(this);
|
|
35
|
+
this.onMouseUp = this.onMouseUp.bind(this);
|
|
36
|
+
this.onMouseWheel = this.onMouseWheel.bind(this);
|
|
37
|
+
this.onMouseOver = this.onMouseOver.bind(this);
|
|
38
|
+
this.onMouseOut = this.onMouseOut.bind(this);
|
|
39
|
+
this.onKeyDown = this.onKeyDown.bind(this);
|
|
40
|
+
this.onKeyUp = this.onKeyUp.bind(this);
|
|
41
|
+
this._showCursor = true;
|
|
42
|
+
//register stage
|
|
43
|
+
var container = this._stage.container;
|
|
44
|
+
container.addEventListener('touchstart', this.onMouseDown);
|
|
45
|
+
container.addEventListener('mousedown', this.onMouseDown);
|
|
46
|
+
window.addEventListener('touchmove', this.onMouseMove);
|
|
47
|
+
window.addEventListener('mousemove', this.onMouseMove);
|
|
48
|
+
window.addEventListener('mouseup', this.onMouseUp);
|
|
49
|
+
container.addEventListener('touchend', this.onMouseUp);
|
|
50
|
+
container.addEventListener('mousewheel', this.onMouseWheel);
|
|
51
|
+
container.addEventListener('mouseover', this.onMouseOver);
|
|
52
|
+
container.addEventListener('mouseout', this.onMouseOut);
|
|
53
|
+
window.addEventListener('keydown', this.onKeyDown);
|
|
54
|
+
window.addEventListener('keyup', this.onKeyUp);
|
|
55
|
+
// supress context menu
|
|
56
|
+
container.addEventListener('contextmenu', function (e) { return e.preventDefault(); });
|
|
57
|
+
}
|
|
58
|
+
MouseManager.prototype.startDragObject = function (collision, isAVM1Dragging) {
|
|
59
|
+
if (isAVM1Dragging === void 0) { isAVM1Dragging = false; }
|
|
60
|
+
this._isAVM1Dragging = isAVM1Dragging;
|
|
61
|
+
// we MUST overrider collision target if present, because draggable !== drag emitter
|
|
62
|
+
if (collision)
|
|
63
|
+
(this._pointerDataArray[0] || (this._pointerDataArray[0] = new PointerData(0, true))).dragCollision = collision;
|
|
64
|
+
};
|
|
65
|
+
MouseManager.prototype.stopDragObject = function () {
|
|
66
|
+
this._isAVM1Dragging = false;
|
|
67
|
+
};
|
|
68
|
+
Object.defineProperty(MouseManager.prototype, "showCursor", {
|
|
69
|
+
get: function () {
|
|
70
|
+
return this._showCursor;
|
|
71
|
+
},
|
|
72
|
+
set: function (value) {
|
|
73
|
+
this._showCursor = value;
|
|
74
|
+
this.cursorType = this._cursorType;
|
|
75
|
+
},
|
|
76
|
+
enumerable: false,
|
|
77
|
+
configurable: true
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(MouseManager.prototype, "cursorType", {
|
|
80
|
+
get: function () {
|
|
81
|
+
return this._cursorType;
|
|
82
|
+
},
|
|
83
|
+
set: function (t) {
|
|
84
|
+
this._cursorType = t;
|
|
85
|
+
this._stage.container.style.cursor = this._showCursor ? t : 'none';
|
|
86
|
+
},
|
|
87
|
+
enumerable: false,
|
|
88
|
+
configurable: true
|
|
89
|
+
});
|
|
90
|
+
Object.defineProperty(MouseManager.prototype, "eventBubbling", {
|
|
91
|
+
get: function () {
|
|
92
|
+
return this._eventBubbling;
|
|
93
|
+
},
|
|
94
|
+
set: function (value) {
|
|
95
|
+
this._eventBubbling = value;
|
|
96
|
+
},
|
|
97
|
+
enumerable: false,
|
|
98
|
+
configurable: true
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(MouseManager.prototype, "useSoftkeyboard", {
|
|
101
|
+
get: function () {
|
|
102
|
+
return this._useSoftkeyboard;
|
|
103
|
+
},
|
|
104
|
+
set: function (value) {
|
|
105
|
+
this._useSoftkeyboard = value;
|
|
106
|
+
// todo: improve this, so that we can
|
|
107
|
+
// - use device-softkeyboard on tablet / mobide
|
|
108
|
+
// - optionally use a custom softkeyboard
|
|
109
|
+
if (!value) {
|
|
110
|
+
window.addEventListener('keydown', this.onKeyDown);
|
|
111
|
+
window.addEventListener('keyup', this.onKeyUp);
|
|
112
|
+
}
|
|
113
|
+
else if (value) {
|
|
114
|
+
window.removeEventListener('keydown', this.onKeyDown);
|
|
115
|
+
window.removeEventListener('keyup', this.onKeyUp);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
enumerable: false,
|
|
119
|
+
configurable: true
|
|
120
|
+
});
|
|
121
|
+
MouseManager.prototype.dispose = function () {
|
|
122
|
+
//unregister stage
|
|
123
|
+
var container = this._stage.container;
|
|
124
|
+
container.removeEventListener('dblclick', this.onDoubleClick);
|
|
125
|
+
container.removeEventListener('touchstart', this.onMouseDown);
|
|
126
|
+
container.removeEventListener('mousedown', this.onMouseDown);
|
|
127
|
+
window.removeEventListener('touchmove', this.onMouseMove);
|
|
128
|
+
window.removeEventListener('mousemove', this.onMouseMove);
|
|
129
|
+
window.removeEventListener('mouseup', this.onMouseUp);
|
|
130
|
+
container.removeEventListener('touchend', this.onMouseUp);
|
|
131
|
+
container.removeEventListener('wheel', this.onMouseWheel);
|
|
132
|
+
container.removeEventListener('mouseover', this.onMouseOver);
|
|
133
|
+
container.removeEventListener('mouseout', this.onMouseOut);
|
|
134
|
+
window.removeEventListener('keydown', this.onKeyDown);
|
|
135
|
+
window.removeEventListener('keyup', this.onKeyUp);
|
|
136
|
+
this._stage = null;
|
|
137
|
+
this._dragOut = null;
|
|
138
|
+
this._dragOver = null;
|
|
139
|
+
this._dragMove = null;
|
|
140
|
+
this._dragStart = null;
|
|
141
|
+
this._dragStop = null;
|
|
142
|
+
};
|
|
143
|
+
MouseManager.clearInstance = function (stage) {
|
|
144
|
+
if (this._instancePool[stage.id]) {
|
|
145
|
+
this._instancePool[stage.id].dispose();
|
|
146
|
+
delete this._instancePool[stage.id];
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
MouseManager.getInstance = function (stage) {
|
|
150
|
+
return this._instancePool[stage.id]
|
|
151
|
+
|| (this._instancePool[stage.id] = new MouseManager(stage));
|
|
152
|
+
};
|
|
153
|
+
MouseManager.prototype.setFocus = function (node) {
|
|
154
|
+
if (this._focusNode == node)
|
|
155
|
+
return;
|
|
156
|
+
// in FP6, a mouseclick on non focus-able object still steal the focus
|
|
157
|
+
// in newer FP they only steal the focus if the the new hit is focusable
|
|
158
|
+
if (this._allowFocusOnUnfocusable || this._focusNode.container.tabEnabled) {
|
|
159
|
+
if (this._focusNode && this._focusNode.container) {
|
|
160
|
+
this.dispatchEvent(this._focusOut, this._focusNode);
|
|
161
|
+
this._focusNode.container.setFocus(false, true);
|
|
162
|
+
}
|
|
163
|
+
this._focusNode = node;
|
|
164
|
+
if (this._focusNode) {
|
|
165
|
+
this.dispatchEvent(this._focusIn, this._focusNode);
|
|
166
|
+
this._focusNode.container.setFocus(true, true);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
MouseManager.prototype.getFocus = function () {
|
|
171
|
+
return this._focusNode;
|
|
172
|
+
};
|
|
173
|
+
MouseManager.prototype.dispatchEvent = function (event, dispatcher) {
|
|
174
|
+
if (!this._eventBubbling) {
|
|
175
|
+
if (dispatcher) {
|
|
176
|
+
event._dispatchEvent(dispatcher, dispatcher.container);
|
|
177
|
+
}
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
var target = dispatcher === null || dispatcher === void 0 ? void 0 : dispatcher.container;
|
|
181
|
+
while (dispatcher) {
|
|
182
|
+
if (event.commonAncestor && dispatcher == event.commonAncestor) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
event._dispatchEvent(dispatcher, target);
|
|
186
|
+
if (!event._iAllowedToPropagate) {
|
|
187
|
+
dispatcher = null;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
dispatcher = dispatcher.parent;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
MouseManager.prototype.setupAndDispatchEvent = function (event, pointerData, collision, commonAncestor) {
|
|
195
|
+
if (commonAncestor === void 0) { commonAncestor = null; }
|
|
196
|
+
var sourceEvent = pointerData.sourceEvent;
|
|
197
|
+
if (sourceEvent) {
|
|
198
|
+
if (event instanceof AwayMouseEvent) {
|
|
199
|
+
event.delta = sourceEvent.deltaY;
|
|
200
|
+
event.buttons = sourceEvent.buttons;
|
|
201
|
+
}
|
|
202
|
+
event.ctrlKey = sourceEvent.ctrlKey;
|
|
203
|
+
event.altKey = sourceEvent.altKey;
|
|
204
|
+
event.shiftKey = sourceEvent.shiftKey;
|
|
205
|
+
}
|
|
206
|
+
event = this.setUpEvent(event, pointerData, collision, commonAncestor);
|
|
207
|
+
this.dispatchEvent(event, event.rootNode);
|
|
208
|
+
};
|
|
209
|
+
MouseManager.prototype.fireMouseEvents = function (forcePicker) {
|
|
210
|
+
if (forcePicker === void 0) { forcePicker = null; }
|
|
211
|
+
//if theres nothing to update, return
|
|
212
|
+
if (!forcePicker && !this._updateDirty)
|
|
213
|
+
return;
|
|
214
|
+
for (var key in this._pointerDataArray) {
|
|
215
|
+
this._fireMouseEventsInternal(this._pointerDataArray[key], forcePicker);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
MouseManager.prototype._fireMouseEventsInternal = function (pointerData, forcePicker) {
|
|
219
|
+
var _a, _b, _c;
|
|
220
|
+
if (forcePicker === void 0) { forcePicker = null; }
|
|
221
|
+
var collision;
|
|
222
|
+
if (forcePicker) {
|
|
223
|
+
collision = forcePicker.getViewCollision(pointerData.screenX, pointerData.screenY);
|
|
224
|
+
}
|
|
225
|
+
else if (this._updateDirty) {
|
|
226
|
+
for (var i = 0; i < this._pickerLookup.length; i++)
|
|
227
|
+
if (!collision || this._pickerLookup[i].layeredView)
|
|
228
|
+
collision = this._pickerLookup[i].getViewCollision(pointerData.screenX, pointerData.screenY, false, collision);
|
|
229
|
+
}
|
|
230
|
+
var event;
|
|
231
|
+
var dispatcher;
|
|
232
|
+
var len = pointerData.queuedEvents.length;
|
|
233
|
+
for (var i = 0; i < len; ++i) {
|
|
234
|
+
event = pointerData.queuedEvents[i];
|
|
235
|
+
dispatcher = collision === null || collision === void 0 ? void 0 : collision.rootNode;
|
|
236
|
+
this.setUpEvent(event, pointerData, collision);
|
|
237
|
+
if (event.type == pointerData.down.type) {
|
|
238
|
+
// no event-bubbling. dispatch on stage first
|
|
239
|
+
if (!this._eventBubbling)
|
|
240
|
+
this._stage.dispatchEvent(event);
|
|
241
|
+
// @todo: at this point the object under the mouse might have been changed,
|
|
242
|
+
// so we need to recheck the collision ?
|
|
243
|
+
// on Touch dispatch mouseOver Command
|
|
244
|
+
if (!pointerData.isMouse)
|
|
245
|
+
this.setupAndDispatchEvent(pointerData.over, pointerData, collision);
|
|
246
|
+
if (pointerData.id == 0)
|
|
247
|
+
pointerData.dragCollision = collision;
|
|
248
|
+
if (dispatcher)
|
|
249
|
+
this.dispatchEvent(event, dispatcher);
|
|
250
|
+
else if (this._eventBubbling)
|
|
251
|
+
this._stage.dispatchEvent(event);
|
|
252
|
+
if (pointerData.dragCollision) {
|
|
253
|
+
this.setFocus(pointerData.dragCollision.rootNode);
|
|
254
|
+
this.setupAndDispatchEvent(this._dragStart, pointerData, pointerData.dragCollision);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else if (event.type == pointerData.up.type) {
|
|
258
|
+
// no event-bubbling. dispatch on stage first
|
|
259
|
+
if (!this._eventBubbling)
|
|
260
|
+
this._stage.dispatchEvent(event);
|
|
261
|
+
// @todo: at this point the object under the mouse might have been changed,
|
|
262
|
+
// so we need to recheck the collision ?
|
|
263
|
+
var upContainerNode = null;
|
|
264
|
+
var upRootNode = null;
|
|
265
|
+
if (this._isAVM1Dragging && pointerData.dragCollision) {
|
|
266
|
+
// avm1dragging is in process, dispatch the mouse-up on this.
|
|
267
|
+
// mouseDragEntity instead of the current collision
|
|
268
|
+
upRootNode = pointerData.dragCollision.rootNode;
|
|
269
|
+
upContainerNode = pointerData.dragCollision.containerNode;
|
|
270
|
+
}
|
|
271
|
+
else if (pointerData.dragCollision && pointerData.dragCollision.rootNode != dispatcher) {
|
|
272
|
+
// no avm1dragging is in process, but current collision
|
|
273
|
+
// is not the same as collision that appeared on mouse-down,
|
|
274
|
+
// need to dispatch a MOUSE_UP_OUTSIDE after mouse up
|
|
275
|
+
}
|
|
276
|
+
else if (pointerData.dragCollision && pointerData.dragCollision.rootNode == dispatcher) {
|
|
277
|
+
// no avm1dragging is in process,
|
|
278
|
+
// current collision is the same as collision that appeared on
|
|
279
|
+
// mouse-down, need to dispatch a MOUSE_CLICK event after mouse up
|
|
280
|
+
upRootNode = pointerData.dragCollision.rootNode;
|
|
281
|
+
upContainerNode = pointerData.dragCollision.containerNode;
|
|
282
|
+
}
|
|
283
|
+
if (upRootNode)
|
|
284
|
+
this.dispatchEvent(event, upRootNode);
|
|
285
|
+
else if (dispatcher)
|
|
286
|
+
this.dispatchEvent(event, dispatcher);
|
|
287
|
+
else if (this._eventBubbling)
|
|
288
|
+
this._stage.dispatchEvent(event);
|
|
289
|
+
if (upContainerNode) {
|
|
290
|
+
if (!this._isAVM1Dragging)
|
|
291
|
+
this.setupAndDispatchEvent(pointerData.click, pointerData, pointerData.dragCollision);
|
|
292
|
+
this.setupAndDispatchEvent(this._dragStop, pointerData, pointerData.dragCollision);
|
|
293
|
+
}
|
|
294
|
+
else if (pointerData.dragCollision) {
|
|
295
|
+
this.setupAndDispatchEvent(pointerData.upOutside, pointerData, pointerData.dragCollision);
|
|
296
|
+
}
|
|
297
|
+
pointerData.dragCollision = null;
|
|
298
|
+
this._isAVM1Dragging = false;
|
|
299
|
+
//make sure to clear old touch references when no longer needed
|
|
300
|
+
if (pointerData.id != 0)
|
|
301
|
+
delete this._pointerDataArray[pointerData.id];
|
|
302
|
+
}
|
|
303
|
+
else if (event.type == pointerData.move.type) {
|
|
304
|
+
// no event-bubbling. dispatch on stage first
|
|
305
|
+
if (!this._eventBubbling)
|
|
306
|
+
this._stage.dispatchEvent(event);
|
|
307
|
+
// fire to picker
|
|
308
|
+
if (dispatcher)
|
|
309
|
+
this.dispatchEvent(event, dispatcher);
|
|
310
|
+
else if (this._eventBubbling)
|
|
311
|
+
this._stage.dispatchEvent(event);
|
|
312
|
+
if (pointerData.dragCollision)
|
|
313
|
+
this.setupAndDispatchEvent(this._dragMove, pointerData, pointerData.dragCollision);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
// MouseEvent.MOUSE_OVER / MouseEvent.MOUSE_OUT / MouseEvent.DRAG_OVER / MouseEvent.DRAG_OUT
|
|
317
|
+
this.dispatchEvent(event, dispatcher);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
pointerData.queuedEvents.length = 0;
|
|
321
|
+
pointerData.rollOut.commonAncestor = null;
|
|
322
|
+
pointerData.rollOver.commonAncestor = null;
|
|
323
|
+
var collisionNode = collision === null || collision === void 0 ? void 0 : collision.rootNode;
|
|
324
|
+
var prevCollisionNode = (_a = pointerData.prevCollision) === null || _a === void 0 ? void 0 : _a.rootNode;
|
|
325
|
+
if (collisionNode != prevCollisionNode) {
|
|
326
|
+
// If colliding object has changed, queue OVER and OUT events.
|
|
327
|
+
// If the mouse is dragged (mouse-down is hold), use DRAG_OVER and DRAG_OUT as well as MOUSE_OVER MOUSE_OUT
|
|
328
|
+
// DRAG_OVER and DRAG_OUT are only dispatched on the object that was hit on the mouse-down
|
|
329
|
+
// (_mouseDragEntity)
|
|
330
|
+
// Store the info if the collision is a enabled Button (_collisionIsEnabledButton)
|
|
331
|
+
if (prevCollisionNode) {
|
|
332
|
+
this.setupAndDispatchEvent(pointerData.out, pointerData, pointerData.prevCollision);
|
|
333
|
+
if (((_b = pointerData.dragCollision) === null || _b === void 0 ? void 0 : _b.rootNode) == prevCollisionNode)
|
|
334
|
+
this.setupAndDispatchEvent(this._dragOut, pointerData, pointerData.prevCollision);
|
|
335
|
+
}
|
|
336
|
+
if (!prevCollisionNode && collisionNode) {
|
|
337
|
+
// rollout / rollover easy case, can just bubble up
|
|
338
|
+
this.setupAndDispatchEvent(pointerData.rollOut, pointerData, pointerData.prevCollision);
|
|
339
|
+
this.setupAndDispatchEvent(pointerData.rollOver, pointerData, collision);
|
|
340
|
+
}
|
|
341
|
+
if (prevCollisionNode && !collisionNode) {
|
|
342
|
+
// rollout / rollover easy case, can just bubble up
|
|
343
|
+
this.setupAndDispatchEvent(pointerData.rollOut, pointerData, pointerData.prevCollision);
|
|
344
|
+
this.setupAndDispatchEvent(pointerData.rollOver, pointerData, collision);
|
|
345
|
+
}
|
|
346
|
+
if (prevCollisionNode && collisionNode) {
|
|
347
|
+
// rollout / rollover find common ancester and only bubble up to that point
|
|
348
|
+
var parentsPrev = [];
|
|
349
|
+
var parent_1 = prevCollisionNode;
|
|
350
|
+
while (parent_1 && !parent_1.container.isAVMScene) {
|
|
351
|
+
parentsPrev.push(parent_1);
|
|
352
|
+
parent_1 = parent_1.parent;
|
|
353
|
+
}
|
|
354
|
+
var commonAncestor = null;
|
|
355
|
+
parent_1 = collisionNode;
|
|
356
|
+
while (parent_1 && !parent_1.container.isAVMScene) {
|
|
357
|
+
var oldParentIdx = parentsPrev.indexOf(parent_1);
|
|
358
|
+
if (oldParentIdx == -1) {
|
|
359
|
+
parent_1 = parent_1.parent;
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
commonAncestor = parent_1;
|
|
363
|
+
parent_1 = null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if (commonAncestor != prevCollisionNode)
|
|
367
|
+
this.setupAndDispatchEvent(pointerData.rollOut, pointerData, pointerData.prevCollision, commonAncestor);
|
|
368
|
+
if (commonAncestor != collisionNode)
|
|
369
|
+
this.setupAndDispatchEvent(pointerData.rollOver, pointerData, collision, commonAncestor);
|
|
370
|
+
}
|
|
371
|
+
pointerData.collisionIsEnabledButton = collisionNode ? collisionNode.buttonEnabled : false;
|
|
372
|
+
if (collisionNode) {
|
|
373
|
+
this.setupAndDispatchEvent(pointerData.over, pointerData, collision);
|
|
374
|
+
if (pointerData.dragCollision)
|
|
375
|
+
this.setupAndDispatchEvent(this._dragOver, pointerData, collision);
|
|
376
|
+
}
|
|
377
|
+
pointerData.prevCollision = collision;
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
// colliding object has not changed
|
|
381
|
+
// Check if we need to send any MOUSE_OVER/DRAG_OVER event to handle the case
|
|
382
|
+
// when a Button has become active while under the mouse.
|
|
383
|
+
var isActiveButton = collisionNode ? collisionNode.buttonEnabled : false;
|
|
384
|
+
if (pointerData.collisionIsEnabledButton != isActiveButton && isActiveButton) {
|
|
385
|
+
if (pointerData.isMouse)
|
|
386
|
+
this.setupAndDispatchEvent(pointerData.over, pointerData, collision);
|
|
387
|
+
else if (((_c = pointerData.dragCollision) === null || _c === void 0 ? void 0 : _c.rootNode) == collisionNode)
|
|
388
|
+
this.setupAndDispatchEvent(this._dragOver, pointerData, collision);
|
|
389
|
+
}
|
|
390
|
+
pointerData.collisionIsEnabledButton = isActiveButton;
|
|
391
|
+
}
|
|
392
|
+
// set cursor if not dragging mouse ???
|
|
393
|
+
if (!pointerData.dragCollision) {
|
|
394
|
+
this.cursorType = collisionNode ? collisionNode.container.getMouseCursor() : 'auto';
|
|
395
|
+
}
|
|
396
|
+
this._updateDirty = false;
|
|
397
|
+
};
|
|
398
|
+
MouseManager.prototype.registerPicker = function (picker) {
|
|
399
|
+
this._pickerLookup.push(picker);
|
|
400
|
+
};
|
|
401
|
+
MouseManager.prototype.unregisterPicker = function (picker) {
|
|
402
|
+
this._pickerLookup.splice(this._pickerLookup.indexOf(picker), 1);
|
|
403
|
+
};
|
|
404
|
+
MouseManager.prototype.addEventsForSceneBinary = function (touchMessage, sceneIdx) {
|
|
405
|
+
if (sceneIdx === void 0) { sceneIdx = 0; }
|
|
406
|
+
var newTouchEvent = {};
|
|
407
|
+
newTouchEvent.clientX = null; // we get the x position from the active touch
|
|
408
|
+
newTouchEvent.clientY = null; // we get the y position from the active touch
|
|
409
|
+
newTouchEvent.touches = [];
|
|
410
|
+
newTouchEvent.changedTouches = [];
|
|
411
|
+
newTouchEvent.preventDefault = function () { };
|
|
412
|
+
var messageScene = new Float32Array(touchMessage);
|
|
413
|
+
// transfer touches to event
|
|
414
|
+
var i = 0;
|
|
415
|
+
var cnt = 0;
|
|
416
|
+
var touchCnt = 0;
|
|
417
|
+
cnt++; //we temporary added 1 float to transfer fps from java to js. skip this
|
|
418
|
+
var numTouches = messageScene[cnt++];
|
|
419
|
+
var touchtype = messageScene[cnt++];
|
|
420
|
+
var activeTouchID = messageScene[cnt++];
|
|
421
|
+
if ((touchtype != 1) && (touchtype != 6) && (touchtype != 12) && (touchtype != 262) && (touchtype != 518)) {
|
|
422
|
+
// if this is not a UP command, we add all touches
|
|
423
|
+
for (i = 0; i < numTouches; i++) {
|
|
424
|
+
var newTouch = {};
|
|
425
|
+
newTouch.identifier = messageScene[cnt++];
|
|
426
|
+
newTouch.clientX = messageScene[cnt++];
|
|
427
|
+
newTouch.clientY = messageScene[cnt++];
|
|
428
|
+
newTouchEvent.touches[i] = newTouch;
|
|
429
|
+
//newTouchEvent.changedTouches[i] = newTouch;
|
|
430
|
+
}
|
|
431
|
+
newTouchEvent.changedTouches[0] = newTouchEvent.touches[activeTouchID];
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
// if this is a UP command, we add all touches, except the active one
|
|
435
|
+
if (numTouches == 1) {
|
|
436
|
+
var newTouch = {};
|
|
437
|
+
newTouch.identifier = messageScene[cnt++];
|
|
438
|
+
newTouch.clientX = messageScene[cnt++];
|
|
439
|
+
newTouch.clientY = messageScene[cnt++];
|
|
440
|
+
newTouchEvent.clientX = newTouch.clientX;
|
|
441
|
+
newTouchEvent.clientY = newTouch.clientY;
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
for (i = 0; i < numTouches; i++) {
|
|
445
|
+
var newTouch = {};
|
|
446
|
+
newTouch.identifier = messageScene[cnt++];
|
|
447
|
+
newTouch.clientX = messageScene[cnt++];
|
|
448
|
+
newTouch.clientY = messageScene[cnt++];
|
|
449
|
+
if (i != activeTouchID) {
|
|
450
|
+
newTouchEvent.touches[touchCnt] = newTouch;
|
|
451
|
+
//newTouchEvent.changedTouches[touchCnt++] = newTouch;
|
|
452
|
+
}
|
|
453
|
+
else {
|
|
454
|
+
newTouchEvent.clientX = newTouch.clientX;
|
|
455
|
+
newTouchEvent.clientY = newTouch.clientY;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
//console.log("Touch ID:"+touchtype+" activeTouchID "+activeTouchID+" numTouches "+numTouches+" x"+x+" y"+y);
|
|
461
|
+
/*
|
|
462
|
+
public static final int ACTION_DOWN = 0;
|
|
463
|
+
public static final int ACTION_POINTER_1_DOWN = 5;
|
|
464
|
+
public static final int ACTION_POINTER_DOWN = 5;
|
|
465
|
+
public static final int ACTION_BUTTON_PRESS = 11;
|
|
466
|
+
public static final int ACTION_POINTER_2_DOWN = 261;
|
|
467
|
+
public static final int ACTION_POINTER_3_DOWN = 517;
|
|
468
|
+
|
|
469
|
+
public static final int ACTION_UP = 1;
|
|
470
|
+
public static final int ACTION_POINTER_1_UP = 6;
|
|
471
|
+
public static final int ACTION_POINTER_UP = 6;
|
|
472
|
+
public static final int ACTION_BUTTON_RELEASE = 12;
|
|
473
|
+
public static final int ACTION_POINTER_2_UP = 262;
|
|
474
|
+
public static final int ACTION_POINTER_3_UP = 518;
|
|
475
|
+
|
|
476
|
+
public static final int ACTION_MOVE = 2;
|
|
477
|
+
|
|
478
|
+
*/
|
|
479
|
+
if ((touchtype == 0) || (touchtype == 5) || (touchtype == 11) || (touchtype == 261) || (touchtype == 517)) {
|
|
480
|
+
this.onMouseDown(newTouchEvent);
|
|
481
|
+
}
|
|
482
|
+
else if ((touchtype == 1) || (touchtype == 6)
|
|
483
|
+
|| (touchtype == 12) || (touchtype == 262) || (touchtype == 518)) {
|
|
484
|
+
this.onMouseUp(newTouchEvent);
|
|
485
|
+
}
|
|
486
|
+
else if (touchtype == 2) {
|
|
487
|
+
this.onMouseMove(newTouchEvent);
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
console.log('recieved unknown touch event-type: ' + touchtype);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
MouseManager.prototype.fireEventsForSceneFromString = function (touchMessage, _sceneIdx) {
|
|
494
|
+
if (_sceneIdx === void 0) { _sceneIdx = 0; }
|
|
495
|
+
var newTouchEvent = {};
|
|
496
|
+
newTouchEvent.clientX = null; // set the x position from the active touch
|
|
497
|
+
newTouchEvent.clientY = null; // set the y position from the active touch
|
|
498
|
+
newTouchEvent.preventDefault = function () { };
|
|
499
|
+
var touchesFromMessage = touchMessage.split(',');
|
|
500
|
+
// transfer touches to event
|
|
501
|
+
var i = 0;
|
|
502
|
+
var cnt = 0;
|
|
503
|
+
var numTouches = parseInt(touchesFromMessage[cnt++]);
|
|
504
|
+
var touchtype = parseInt(touchesFromMessage[cnt++]);
|
|
505
|
+
var activeTouch = parseInt(touchesFromMessage[cnt++]);
|
|
506
|
+
newTouchEvent.touches = [];
|
|
507
|
+
newTouchEvent.changedTouches = [];
|
|
508
|
+
if ((touchtype != 1) && (touchtype != 6)) {
|
|
509
|
+
for (i = 0; i < numTouches; i++) {
|
|
510
|
+
var newTouch = {};
|
|
511
|
+
newTouch.identifier = touchesFromMessage[cnt++];
|
|
512
|
+
newTouch.clientX = touchesFromMessage[cnt++];
|
|
513
|
+
newTouch.clientY = touchesFromMessage[cnt++];
|
|
514
|
+
newTouchEvent.touches[i] = newTouch;
|
|
515
|
+
newTouchEvent.changedTouches[i] = newTouch;
|
|
516
|
+
}
|
|
517
|
+
newTouchEvent.changedTouches[i] = newTouchEvent.touches[activeTouch];
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
for (i = 0; i < numTouches; i++) {
|
|
521
|
+
if (i != activeTouch) {
|
|
522
|
+
var newTouch = {};
|
|
523
|
+
newTouch.identifier = touchesFromMessage[cnt++];
|
|
524
|
+
newTouch.clientX = touchesFromMessage[cnt++];
|
|
525
|
+
newTouch.clientY = touchesFromMessage[cnt++];
|
|
526
|
+
newTouchEvent.touches[i] = newTouch;
|
|
527
|
+
newTouchEvent.changedTouches[i] = newTouch;
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
newTouchEvent.clientX = touchesFromMessage[cnt++];
|
|
531
|
+
newTouchEvent.clientY = touchesFromMessage[cnt++];
|
|
532
|
+
cnt++;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
if (touchtype == 0) { //mousedown
|
|
537
|
+
this.onMouseDown(newTouchEvent);
|
|
538
|
+
}
|
|
539
|
+
else if (touchtype == 1) { //mouseup
|
|
540
|
+
this.onMouseUp(newTouchEvent);
|
|
541
|
+
}
|
|
542
|
+
else if (touchtype == 2) { //mousemove
|
|
543
|
+
this.onMouseMove(newTouchEvent);
|
|
544
|
+
}
|
|
545
|
+
else if (touchtype == 261) { //mousedownPointer
|
|
546
|
+
this.onMouseDown(newTouchEvent);
|
|
547
|
+
}
|
|
548
|
+
else if (touchtype == 6) { //mouseupPointer
|
|
549
|
+
this.onMouseUp(newTouchEvent);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
// ---------------------------------------------------------------------
|
|
553
|
+
// Private.
|
|
554
|
+
// ---------------------------------------------------------------------
|
|
555
|
+
MouseManager.prototype.setUpEvent = function (event, pointerData, collision, commonAncestor) {
|
|
556
|
+
var _a, _b;
|
|
557
|
+
if (commonAncestor === void 0) { commonAncestor = null; }
|
|
558
|
+
event._iAllowedToImmediatlyPropagate = true;
|
|
559
|
+
event._iAllowedToPropagate = true;
|
|
560
|
+
// 2D properties.
|
|
561
|
+
event.screenX = pointerData.screenX;
|
|
562
|
+
event.screenY = pointerData.screenY;
|
|
563
|
+
if (event instanceof AwayTouchEvent)
|
|
564
|
+
event.touchPointID = pointerData.id;
|
|
565
|
+
//console.log("event", event, collisionNode, collisionNode);
|
|
566
|
+
// 3D properties.
|
|
567
|
+
if (collision) {
|
|
568
|
+
event.containerNode = collision.containerNode;
|
|
569
|
+
event.rootNode = collision.rootNode;
|
|
570
|
+
// Object.
|
|
571
|
+
event.pickable = collision.pickable;
|
|
572
|
+
// UV.
|
|
573
|
+
event.uv = collision.uv;
|
|
574
|
+
// Position.
|
|
575
|
+
event.position = (_a = collision.position) === null || _a === void 0 ? void 0 : _a.clone();
|
|
576
|
+
// Normal.
|
|
577
|
+
event.normal = (_b = collision.normal) === null || _b === void 0 ? void 0 : _b.clone();
|
|
578
|
+
// Face index.
|
|
579
|
+
event.elementIndex = collision.elementIndex;
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
// Set all to null.
|
|
583
|
+
event.containerNode = null;
|
|
584
|
+
event.rootNode = null;
|
|
585
|
+
event.pickable = null;
|
|
586
|
+
event.uv = null;
|
|
587
|
+
event.position = this._nullVector;
|
|
588
|
+
event.normal = this._nullVector;
|
|
589
|
+
event.elementIndex = 0;
|
|
590
|
+
}
|
|
591
|
+
event.commonAncestor = commonAncestor;
|
|
592
|
+
return event;
|
|
593
|
+
};
|
|
594
|
+
MouseManager.prototype.queueDispatch = function (pointerData, event, sourceEvent) {
|
|
595
|
+
// Store event to be dispatched later.
|
|
596
|
+
if (event instanceof AwayMouseEvent) {
|
|
597
|
+
event.delta = (sourceEvent instanceof WheelEvent) ? -3 * sourceEvent.deltaY / 100 : 0;
|
|
598
|
+
event.buttons = (sourceEvent instanceof MouseEvent) ? sourceEvent.buttons : 0 /* MouseButtons.NO_BUTTON */;
|
|
599
|
+
}
|
|
600
|
+
event.ctrlKey = sourceEvent.ctrlKey;
|
|
601
|
+
event.altKey = sourceEvent.altKey;
|
|
602
|
+
event.shiftKey = sourceEvent.shiftKey;
|
|
603
|
+
//restrict events fired to one type every animation frame
|
|
604
|
+
var index = pointerData.queuedEvents.indexOf(event);
|
|
605
|
+
if (index != -1)
|
|
606
|
+
pointerData.queuedEvents.splice(index, 1);
|
|
607
|
+
pointerData.queuedEvents.push(event);
|
|
608
|
+
pointerData.sourceEvent = sourceEvent;
|
|
609
|
+
};
|
|
610
|
+
// ---------------------------------------------------------------------
|
|
611
|
+
// Listeners.
|
|
612
|
+
// ---------------------------------------------------------------------
|
|
613
|
+
MouseManager.prototype.onKeyDown = function (event) {
|
|
614
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
615
|
+
//console.log("Keydown", event);
|
|
616
|
+
if (this.allowKeyInput) {
|
|
617
|
+
switch (event.keyCode) {
|
|
618
|
+
case 32: // spacebar
|
|
619
|
+
case 37: // left
|
|
620
|
+
case 39: // right
|
|
621
|
+
case 38: // up
|
|
622
|
+
case 40: // down
|
|
623
|
+
event.preventDefault();
|
|
624
|
+
break;
|
|
625
|
+
default:
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
if (this._focusNode || this._stage) {
|
|
629
|
+
//console.log("dispatch keydown on ", this._focusNode);
|
|
630
|
+
var newEvent = new KeyboardEvent(KeyboardEvent.KEYDOWN, event.key, event.code);
|
|
631
|
+
newEvent.isShift = event.shiftKey;
|
|
632
|
+
newEvent.isCTRL = event.ctrlKey;
|
|
633
|
+
newEvent.isAlt = event.altKey;
|
|
634
|
+
newEvent.keyCode = event.keyCode;
|
|
635
|
+
if (this._focusNode)
|
|
636
|
+
this._focusNode.container.dispatchEvent(newEvent);
|
|
637
|
+
if (this._stage)
|
|
638
|
+
this._stage.dispatchEvent(newEvent);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
MouseManager.prototype.onKeyUp = function (event) {
|
|
643
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
644
|
+
//console.log("Keyup", event);
|
|
645
|
+
if (this.allowKeyInput) {
|
|
646
|
+
switch (event.keyCode) {
|
|
647
|
+
case 32: // spacebar
|
|
648
|
+
case 37: // left
|
|
649
|
+
case 39: // right
|
|
650
|
+
case 38: // up
|
|
651
|
+
case 40: // down
|
|
652
|
+
event.preventDefault();
|
|
653
|
+
break;
|
|
654
|
+
default:
|
|
655
|
+
break;
|
|
656
|
+
}
|
|
657
|
+
if (this._focusNode || this._stage) {
|
|
658
|
+
//console.log("dispatch keydown on ", this._focusNode);
|
|
659
|
+
var newEvent = new KeyboardEvent(KeyboardEvent.KEYUP, event.key, event.code);
|
|
660
|
+
newEvent.isShift = event.shiftKey;
|
|
661
|
+
newEvent.isCTRL = event.ctrlKey;
|
|
662
|
+
newEvent.isAlt = event.altKey;
|
|
663
|
+
newEvent.keyCode = event.keyCode;
|
|
664
|
+
if (this._focusNode)
|
|
665
|
+
this._focusNode.container.dispatchEvent(newEvent);
|
|
666
|
+
if (this._stage)
|
|
667
|
+
this._stage.dispatchEvent(newEvent);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
MouseManager.prototype.onMouseMove = function (event) {
|
|
672
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
673
|
+
this.updateColliders(event);
|
|
674
|
+
};
|
|
675
|
+
MouseManager.prototype.onMouseOut = function (event) {
|
|
676
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
677
|
+
this.updateColliders(event);
|
|
678
|
+
};
|
|
679
|
+
MouseManager.prototype.onMouseOver = function (event) {
|
|
680
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
681
|
+
this.updateColliders(event);
|
|
682
|
+
};
|
|
683
|
+
MouseManager.prototype.onDoubleClick = function (event) {
|
|
684
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
685
|
+
this.updateColliders(event);
|
|
686
|
+
// prevent middle and second button
|
|
687
|
+
if (event instanceof MouseEvent && event.buttons & 6) {
|
|
688
|
+
event.preventDefault();
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
MouseManager.prototype.onMouseDown = function (event) {
|
|
692
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
693
|
+
this.updateColliders(event);
|
|
694
|
+
var prevent = (event.type !== 'mousedown');
|
|
695
|
+
// prevent middle and second button
|
|
696
|
+
if (event instanceof MouseEvent && event.buttons & 6) {
|
|
697
|
+
prevent = true;
|
|
698
|
+
}
|
|
699
|
+
if (prevent) {
|
|
700
|
+
event.preventDefault();
|
|
701
|
+
this._stage.container.focus();
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
MouseManager.prototype.onMouseUp = function (event) {
|
|
705
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
706
|
+
this.updateColliders(event);
|
|
707
|
+
var prevent = event.type !== 'mouseup';
|
|
708
|
+
// prevent middle and second button
|
|
709
|
+
if (event instanceof MouseEvent && event.button === 1) {
|
|
710
|
+
prevent = true;
|
|
711
|
+
}
|
|
712
|
+
if (prevent) {
|
|
713
|
+
event.preventDefault();
|
|
714
|
+
this._stage.container.focus();
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
MouseManager.prototype.onMouseWheel = function (event) {
|
|
718
|
+
!MouseManager.inputRecorder || MouseManager.inputRecorder.recordEvent(event);
|
|
719
|
+
this.updateColliders(event);
|
|
720
|
+
};
|
|
721
|
+
MouseManager.prototype.updateColliders = function (event) {
|
|
722
|
+
this._stage.interactionHandler(event);
|
|
723
|
+
this._updateDirty = true;
|
|
724
|
+
var mouseData = this._pointerDataArray[0] || (this._pointerDataArray[0] = new PointerData(0, true));
|
|
725
|
+
mouseData.isMouse = (event instanceof MouseEvent);
|
|
726
|
+
var type = (mouseData.isMouse) ? event.type : MouseManager._touchToMouseDict[event.type];
|
|
727
|
+
this.queueDispatch(mouseData, MouseManager._pointerDict[type], event);
|
|
728
|
+
mouseData.screenX = this._stage.screenX;
|
|
729
|
+
mouseData.screenY = this._stage.screenY;
|
|
730
|
+
if (event.changedTouches) {
|
|
731
|
+
for (var i = 0; i < event.changedTouches.length; i++) {
|
|
732
|
+
var touch = event.changedTouches[i];
|
|
733
|
+
var touchData = this._pointerDataArray[touch.identifier] || (this._pointerDataArray[touch.identifier] = new PointerData(touch.identifier));
|
|
734
|
+
var point = this._stage.mapWindowToStage(touch.clientX, touch.clientY);
|
|
735
|
+
touchData.screenX = point.x;
|
|
736
|
+
touchData.screenY = point.y;
|
|
737
|
+
this.queueDispatch(touchData, MouseManager._pointerDict[event.type], event);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
MouseManager._instancePool = {};
|
|
742
|
+
MouseManager._touchToMouseDict = {
|
|
743
|
+
touchstart: 'mousedown',
|
|
744
|
+
touchend: 'mouseup',
|
|
745
|
+
touchmove: 'mousemove',
|
|
746
|
+
};
|
|
747
|
+
MouseManager._pointerDict = {
|
|
748
|
+
mouseup: new AwayMouseEvent(AwayMouseEvent.MOUSE_UP),
|
|
749
|
+
mouseupoutside: new AwayMouseEvent(AwayMouseEvent.MOUSE_UP_OUTSIDE),
|
|
750
|
+
click: new AwayMouseEvent(AwayMouseEvent.CLICK),
|
|
751
|
+
mouseout: new AwayMouseEvent(AwayMouseEvent.MOUSE_OUT),
|
|
752
|
+
mousedown: new AwayMouseEvent(AwayMouseEvent.MOUSE_DOWN),
|
|
753
|
+
mousemove: new AwayMouseEvent(AwayMouseEvent.MOUSE_MOVE),
|
|
754
|
+
mouseover: new AwayMouseEvent(AwayMouseEvent.MOUSE_OVER),
|
|
755
|
+
mousewheel: new AwayMouseEvent(AwayMouseEvent.MOUSE_WHEEL),
|
|
756
|
+
dblclick: new AwayMouseEvent(AwayMouseEvent.DOUBLE_CLICK),
|
|
757
|
+
rollover: new AwayMouseEvent(AwayMouseEvent.ROLL_OVER),
|
|
758
|
+
rollout: new AwayMouseEvent(AwayMouseEvent.ROLL_OUT),
|
|
759
|
+
touchend: new AwayTouchEvent(AwayTouchEvent.TOUCH_END),
|
|
760
|
+
touchtap: new AwayTouchEvent(AwayTouchEvent.TOUCH_TAP),
|
|
761
|
+
touchout: new AwayTouchEvent(AwayTouchEvent.TOUCH_OUT),
|
|
762
|
+
touchstart: new AwayTouchEvent(AwayTouchEvent.TOUCH_BEGIN),
|
|
763
|
+
touchmove: new AwayTouchEvent(AwayTouchEvent.TOUCH_MOVE),
|
|
764
|
+
touchover: new AwayTouchEvent(AwayTouchEvent.TOUCH_OVER),
|
|
765
|
+
touchrollover: new AwayTouchEvent(AwayTouchEvent.TOUCH_ROLL_OVER),
|
|
766
|
+
touchrollout: new AwayTouchEvent(AwayTouchEvent.TOUCH_ROLL_OUT),
|
|
767
|
+
};
|
|
768
|
+
return MouseManager;
|
|
769
|
+
}());
|
|
770
|
+
export { MouseManager };
|
|
771
|
+
var PointerData = /** @class */ (function () {
|
|
772
|
+
function PointerData(id, isMouse) {
|
|
773
|
+
if (isMouse === void 0) { isMouse = false; }
|
|
774
|
+
this.id = id;
|
|
775
|
+
this.isMouse = isMouse;
|
|
776
|
+
this.collisionIsEnabledButton = false;
|
|
777
|
+
this.queuedEvents = new Array();
|
|
778
|
+
if (isMouse) {
|
|
779
|
+
this.up = MouseManager._pointerDict.mouseup;
|
|
780
|
+
this.upOutside = MouseManager._pointerDict.mouseupoutside;
|
|
781
|
+
this.click = MouseManager._pointerDict.click;
|
|
782
|
+
this.out = MouseManager._pointerDict.mouseout;
|
|
783
|
+
this.down = MouseManager._pointerDict.mousedown;
|
|
784
|
+
this.move = MouseManager._pointerDict.mousemove;
|
|
785
|
+
this.over = MouseManager._pointerDict.mouseover;
|
|
786
|
+
this.wheel = MouseManager._pointerDict.mousewheel;
|
|
787
|
+
this.doubleClick = MouseManager._pointerDict.dblclick;
|
|
788
|
+
this.rollOver = MouseManager._pointerDict.rollover;
|
|
789
|
+
this.rollOut = MouseManager._pointerDict.rollout;
|
|
790
|
+
}
|
|
791
|
+
else {
|
|
792
|
+
this.up = MouseManager._pointerDict.touchend;
|
|
793
|
+
this.click = MouseManager._pointerDict.touchtap;
|
|
794
|
+
this.out = MouseManager._pointerDict.touchout;
|
|
795
|
+
this.down = MouseManager._pointerDict.touchstart;
|
|
796
|
+
this.move = MouseManager._pointerDict.touchmove;
|
|
797
|
+
this.over = MouseManager._pointerDict.touchover;
|
|
798
|
+
this.rollOver = MouseManager._pointerDict.touchrollover;
|
|
799
|
+
this.rollOut = MouseManager._pointerDict.touchrollout;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return PointerData;
|
|
803
|
+
}());
|