@awayjs/scene 0.13.264 → 0.13.266

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