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