@babylonjs/gui 5.0.0-beta.9 → 5.0.0-rc.10

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 (305) hide show
  1. package/2D/adtInstrumentation.d.ts +52 -52
  2. package/2D/adtInstrumentation.js +126 -126
  3. package/2D/adtInstrumentation.js.map +1 -1
  4. package/2D/advancedDynamicTexture.d.ts +449 -412
  5. package/2D/advancedDynamicTexture.js +1318 -1239
  6. package/2D/advancedDynamicTexture.js.map +1 -1
  7. package/2D/controls/button.d.ts +135 -97
  8. package/2D/controls/button.js +276 -238
  9. package/2D/controls/button.js.map +1 -1
  10. package/2D/controls/checkbox.d.ts +59 -51
  11. package/2D/controls/checkbox.js +188 -178
  12. package/2D/controls/checkbox.js.map +1 -1
  13. package/2D/controls/colorpicker.d.ts +103 -90
  14. package/2D/controls/colorpicker.js +1417 -1400
  15. package/2D/controls/colorpicker.js.map +1 -1
  16. package/2D/controls/container.d.ts +175 -130
  17. package/2D/controls/container.js +570 -525
  18. package/2D/controls/container.js.map +1 -1
  19. package/2D/controls/control.d.ts +866 -743
  20. package/2D/controls/control.js +2433 -2308
  21. package/2D/controls/control.js.map +1 -1
  22. package/2D/controls/displayGrid.d.ts +53 -55
  23. package/2D/controls/displayGrid.js +245 -245
  24. package/2D/controls/displayGrid.js.map +1 -1
  25. package/2D/controls/ellipse.d.ts +21 -21
  26. package/2D/controls/ellipse.js +85 -85
  27. package/2D/controls/ellipse.js.map +1 -1
  28. package/2D/controls/focusableButton.d.ts +59 -52
  29. package/2D/controls/focusableButton.js +99 -92
  30. package/2D/controls/focusableButton.js.map +1 -1
  31. package/2D/controls/focusableControl.d.ts +34 -34
  32. package/2D/controls/focusableControl.js +1 -1
  33. package/2D/controls/focusableControl.js.map +1 -1
  34. package/2D/controls/grid.d.ts +139 -135
  35. package/2D/controls/grid.js +529 -525
  36. package/2D/controls/grid.js.map +1 -1
  37. package/2D/controls/image.d.ts +204 -197
  38. package/2D/controls/image.js +887 -879
  39. package/2D/controls/image.js.map +1 -1
  40. package/2D/controls/index.d.ts +29 -29
  41. package/2D/controls/index.js +29 -29
  42. package/2D/controls/index.js.map +1 -1
  43. package/2D/controls/inputPassword.d.ts +9 -8
  44. package/2D/controls/inputPassword.js +28 -25
  45. package/2D/controls/inputPassword.js.map +1 -1
  46. package/2D/controls/inputText.d.ts +201 -180
  47. package/2D/controls/inputText.js +1119 -1095
  48. package/2D/controls/inputText.js.map +1 -1
  49. package/2D/controls/line.d.ts +66 -66
  50. package/2D/controls/line.js +271 -271
  51. package/2D/controls/line.js.map +1 -1
  52. package/2D/controls/multiLine.d.ts +75 -77
  53. package/2D/controls/multiLine.js +262 -262
  54. package/2D/controls/multiLine.js.map +1 -1
  55. package/2D/controls/radioButton.d.ts +49 -49
  56. package/2D/controls/radioButton.js +205 -205
  57. package/2D/controls/radioButton.js.map +1 -1
  58. package/2D/controls/rectangle.d.ts +29 -29
  59. package/2D/controls/rectangle.js +150 -150
  60. package/2D/controls/rectangle.js.map +1 -1
  61. package/2D/controls/scrollViewers/scrollViewer.d.ts +182 -175
  62. package/2D/controls/scrollViewers/scrollViewer.js +677 -676
  63. package/2D/controls/scrollViewers/scrollViewer.js.map +1 -1
  64. package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +57 -45
  65. package/2D/controls/scrollViewers/scrollViewerWindow.js +278 -263
  66. package/2D/controls/scrollViewers/scrollViewerWindow.js.map +1 -1
  67. package/2D/controls/selector.d.ts +263 -209
  68. package/2D/controls/selector.js +692 -629
  69. package/2D/controls/selector.js.map +1 -1
  70. package/2D/controls/sliders/baseSlider.d.ts +82 -78
  71. package/2D/controls/sliders/baseSlider.js +347 -343
  72. package/2D/controls/sliders/baseSlider.js.map +1 -1
  73. package/2D/controls/sliders/imageBasedSlider.d.ts +49 -47
  74. package/2D/controls/sliders/imageBasedSlider.js +192 -188
  75. package/2D/controls/sliders/imageBasedSlider.js.map +1 -1
  76. package/2D/controls/sliders/imageScrollBar.d.ts +65 -61
  77. package/2D/controls/sliders/imageScrollBar.js +263 -256
  78. package/2D/controls/sliders/imageScrollBar.js.map +1 -1
  79. package/2D/controls/sliders/scrollBar.d.ts +38 -34
  80. package/2D/controls/sliders/scrollBar.js +143 -136
  81. package/2D/controls/sliders/scrollBar.js.map +1 -1
  82. package/2D/controls/sliders/slider.d.ts +35 -37
  83. package/2D/controls/sliders/slider.js +271 -271
  84. package/2D/controls/sliders/slider.js.map +1 -1
  85. package/2D/controls/stackPanel.d.ts +64 -56
  86. package/2D/controls/stackPanel.js +246 -236
  87. package/2D/controls/stackPanel.js.map +1 -1
  88. package/2D/controls/statics.d.ts +6 -6
  89. package/2D/controls/statics.js +49 -47
  90. package/2D/controls/statics.js.map +1 -1
  91. package/2D/controls/textBlock.d.ts +175 -171
  92. package/2D/controls/textBlock.js +603 -588
  93. package/2D/controls/textBlock.js.map +1 -1
  94. package/2D/controls/textWrapper.d.ts +13 -13
  95. package/2D/controls/textWrapper.js +101 -101
  96. package/2D/controls/textWrapper.js.map +1 -1
  97. package/2D/controls/toggleButton.d.ts +117 -83
  98. package/2D/controls/toggleButton.js +268 -234
  99. package/2D/controls/toggleButton.js.map +1 -1
  100. package/2D/controls/virtualKeyboard.d.ts +96 -96
  101. package/2D/controls/virtualKeyboard.js +256 -256
  102. package/2D/controls/virtualKeyboard.js.map +1 -1
  103. package/2D/index.d.ts +9 -9
  104. package/2D/index.js +10 -9
  105. package/2D/index.js.map +1 -1
  106. package/2D/math2D.d.ts +117 -117
  107. package/2D/math2D.js +221 -221
  108. package/2D/math2D.js.map +1 -1
  109. package/2D/measure.d.ts +77 -77
  110. package/2D/measure.js +139 -149
  111. package/2D/measure.js.map +1 -1
  112. package/2D/multiLinePoint.d.ts +47 -47
  113. package/2D/multiLinePoint.js +127 -127
  114. package/2D/multiLinePoint.js.map +1 -1
  115. package/2D/style.d.ts +46 -46
  116. package/2D/style.js +97 -97
  117. package/2D/style.js.map +1 -1
  118. package/2D/valueAndUnit.d.ts +89 -89
  119. package/2D/valueAndUnit.js +226 -222
  120. package/2D/valueAndUnit.js.map +1 -1
  121. package/2D/xmlLoader.d.ts +60 -60
  122. package/2D/xmlLoader.js +348 -341
  123. package/2D/xmlLoader.js.map +1 -1
  124. package/3D/behaviors/defaultBehavior.d.ts +73 -73
  125. package/3D/behaviors/defaultBehavior.js +121 -121
  126. package/3D/behaviors/defaultBehavior.js.map +1 -1
  127. package/3D/controls/abstractButton3D.d.ts +15 -15
  128. package/3D/controls/abstractButton3D.js +25 -25
  129. package/3D/controls/abstractButton3D.js.map +1 -1
  130. package/3D/controls/button3D.d.ts +30 -30
  131. package/3D/controls/button3D.js +93 -93
  132. package/3D/controls/button3D.js.map +1 -1
  133. package/3D/controls/container3D.d.ts +72 -72
  134. package/3D/controls/container3D.js +139 -140
  135. package/3D/controls/container3D.js.map +1 -1
  136. package/3D/controls/contentDisplay3D.d.ts +30 -30
  137. package/3D/controls/contentDisplay3D.js +79 -78
  138. package/3D/controls/contentDisplay3D.js.map +1 -1
  139. package/3D/controls/control3D.d.ts +201 -165
  140. package/3D/controls/control3D.js +445 -408
  141. package/3D/controls/control3D.js.map +1 -1
  142. package/3D/controls/cylinderPanel.d.ts +17 -17
  143. package/3D/controls/cylinderPanel.js +66 -66
  144. package/3D/controls/cylinderPanel.js.map +1 -1
  145. package/3D/controls/handMenu.d.ts +28 -28
  146. package/3D/controls/handMenu.js +47 -47
  147. package/3D/controls/handMenu.js.map +1 -1
  148. package/3D/controls/holographicBackplate.d.ts +49 -48
  149. package/3D/controls/holographicBackplate.js +120 -120
  150. package/3D/controls/holographicBackplate.js.map +1 -1
  151. package/3D/controls/holographicButton.d.ts +84 -83
  152. package/3D/controls/holographicButton.js +339 -338
  153. package/3D/controls/holographicButton.js.map +1 -1
  154. package/3D/controls/holographicSlate.d.ts +131 -118
  155. package/3D/controls/holographicSlate.js +431 -369
  156. package/3D/controls/holographicSlate.js.map +1 -1
  157. package/3D/controls/index.d.ts +21 -21
  158. package/3D/controls/index.js +21 -21
  159. package/3D/controls/index.js.map +1 -1
  160. package/3D/controls/meshButton3D.d.ts +21 -21
  161. package/3D/controls/meshButton3D.js +62 -61
  162. package/3D/controls/meshButton3D.js.map +1 -1
  163. package/3D/controls/nearMenu.d.ts +44 -44
  164. package/3D/controls/nearMenu.js +114 -112
  165. package/3D/controls/nearMenu.js.map +1 -1
  166. package/3D/controls/planePanel.d.ts +9 -9
  167. package/3D/controls/planePanel.js +36 -36
  168. package/3D/controls/planePanel.js.map +1 -1
  169. package/3D/controls/scatterPanel.d.ts +18 -18
  170. package/3D/controls/scatterPanel.js +108 -108
  171. package/3D/controls/scatterPanel.js.map +1 -1
  172. package/3D/controls/slider3D.d.ts +81 -80
  173. package/3D/controls/slider3D.js +268 -267
  174. package/3D/controls/slider3D.js.map +1 -1
  175. package/3D/controls/spherePanel.d.ts +17 -17
  176. package/3D/controls/spherePanel.js +67 -67
  177. package/3D/controls/spherePanel.js.map +1 -1
  178. package/3D/controls/stackPanel3D.d.ts +22 -22
  179. package/3D/controls/stackPanel3D.js +107 -107
  180. package/3D/controls/stackPanel3D.js.map +1 -1
  181. package/3D/controls/touchButton3D.d.ts +80 -64
  182. package/3D/controls/touchButton3D.js +233 -188
  183. package/3D/controls/touchButton3D.js.map +1 -1
  184. package/3D/controls/touchHolographicButton.d.ts +110 -104
  185. package/3D/controls/touchHolographicButton.js +445 -432
  186. package/3D/controls/touchHolographicButton.js.map +1 -1
  187. package/3D/controls/touchHolographicMenu.d.ts +61 -61
  188. package/3D/controls/touchHolographicMenu.js +149 -148
  189. package/3D/controls/touchHolographicMenu.js.map +1 -1
  190. package/3D/controls/touchMeshButton3D.d.ts +21 -22
  191. package/3D/controls/touchMeshButton3D.js +62 -62
  192. package/3D/controls/touchMeshButton3D.js.map +1 -1
  193. package/3D/controls/volumeBasedPanel.d.ts +53 -52
  194. package/3D/controls/volumeBasedPanel.js +174 -174
  195. package/3D/controls/volumeBasedPanel.js.map +1 -1
  196. package/3D/gizmos/gizmoHandle.d.ts +108 -108
  197. package/3D/gizmos/gizmoHandle.js +209 -209
  198. package/3D/gizmos/gizmoHandle.js.map +1 -1
  199. package/3D/gizmos/index.d.ts +2 -2
  200. package/3D/gizmos/index.js +2 -2
  201. package/3D/gizmos/index.js.map +1 -1
  202. package/3D/gizmos/slateGizmo.d.ts +57 -59
  203. package/3D/gizmos/slateGizmo.js +369 -363
  204. package/3D/gizmos/slateGizmo.js.map +1 -1
  205. package/3D/gui3DManager.d.ts +94 -94
  206. package/3D/gui3DManager.js +257 -257
  207. package/3D/gui3DManager.js.map +1 -1
  208. package/3D/index.d.ts +5 -5
  209. package/3D/index.js +6 -5
  210. package/3D/index.js.map +1 -1
  211. package/3D/materials/fluent/fluentMaterial.d.ts +91 -90
  212. package/3D/materials/fluent/fluentMaterial.js +292 -281
  213. package/3D/materials/fluent/fluentMaterial.js.map +1 -1
  214. package/3D/materials/fluent/index.d.ts +1 -1
  215. package/3D/materials/fluent/index.js +1 -1
  216. package/3D/materials/fluent/index.js.map +1 -1
  217. package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -5
  218. package/3D/materials/fluent/shaders/fluent.fragment.js +8 -6
  219. package/3D/materials/fluent/shaders/fluent.fragment.js.map +1 -1
  220. package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -5
  221. package/3D/materials/fluent/shaders/fluent.vertex.js +8 -6
  222. package/3D/materials/fluent/shaders/fluent.vertex.js.map +1 -1
  223. package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +155 -154
  224. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +469 -434
  225. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js.map +1 -1
  226. package/3D/materials/fluentBackplate/index.d.ts +1 -1
  227. package/3D/materials/fluentBackplate/index.js +1 -1
  228. package/3D/materials/fluentBackplate/index.js.map +1 -1
  229. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -5
  230. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +8 -6
  231. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js.map +1 -1
  232. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -5
  233. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +8 -6
  234. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js.map +1 -1
  235. package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +190 -189
  236. package/3D/materials/fluentButton/fluentButtonMaterial.js +539 -537
  237. package/3D/materials/fluentButton/fluentButtonMaterial.js.map +1 -1
  238. package/3D/materials/fluentButton/index.d.ts +1 -1
  239. package/3D/materials/fluentButton/index.js +1 -1
  240. package/3D/materials/fluentButton/index.js.map +1 -1
  241. package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -5
  242. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +8 -6
  243. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js.map +1 -1
  244. package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -5
  245. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +8 -6
  246. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js.map +1 -1
  247. package/3D/materials/fluentMaterial.d.ts +4 -4
  248. package/3D/materials/fluentMaterial.js +4 -4
  249. package/3D/materials/fluentMaterial.js.map +1 -1
  250. package/3D/materials/handle/handleMaterial.d.ts +68 -68
  251. package/3D/materials/handle/handleMaterial.js +126 -126
  252. package/3D/materials/handle/handleMaterial.js.map +1 -1
  253. package/3D/materials/handle/index.d.ts +1 -1
  254. package/3D/materials/handle/index.js +1 -1
  255. package/3D/materials/handle/index.js.map +1 -1
  256. package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -5
  257. package/3D/materials/handle/shaders/handle.fragment.js +8 -6
  258. package/3D/materials/handle/shaders/handle.fragment.js.map +1 -1
  259. package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -5
  260. package/3D/materials/handle/shaders/handle.vertex.js +8 -6
  261. package/3D/materials/handle/shaders/handle.vertex.js.map +1 -1
  262. package/3D/materials/index.d.ts +5 -5
  263. package/3D/materials/index.js +6 -5
  264. package/3D/materials/index.js.map +1 -1
  265. package/3D/materials/mrdl/index.d.ts +3 -3
  266. package/3D/materials/mrdl/index.js +3 -3
  267. package/3D/materials/mrdl/index.js.map +1 -1
  268. package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +148 -147
  269. package/3D/materials/mrdl/mrdlBackplateMaterial.js +436 -409
  270. package/3D/materials/mrdl/mrdlBackplateMaterial.js.map +1 -1
  271. package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +334 -333
  272. package/3D/materials/mrdl/mrdlSliderBarMaterial.js +851 -786
  273. package/3D/materials/mrdl/mrdlSliderBarMaterial.js.map +1 -1
  274. package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +334 -333
  275. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +851 -786
  276. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js.map +1 -1
  277. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -5
  278. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +8 -6
  279. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js.map +1 -1
  280. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -5
  281. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +8 -6
  282. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js.map +1 -1
  283. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -5
  284. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +8 -6
  285. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js.map +1 -1
  286. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -5
  287. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +8 -6
  288. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js.map +1 -1
  289. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -5
  290. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +8 -6
  291. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js.map +1 -1
  292. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -5
  293. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +8 -6
  294. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js.map +1 -1
  295. package/3D/vector3WithInfo.d.ts +16 -16
  296. package/3D/vector3WithInfo.js +23 -23
  297. package/3D/vector3WithInfo.js.map +1 -1
  298. package/index.d.ts +2 -2
  299. package/index.js +3 -2
  300. package/index.js.map +1 -1
  301. package/legacy/legacy.d.ts +1 -1
  302. package/legacy/legacy.js +14 -13
  303. package/legacy/legacy.js.map +1 -1
  304. package/package.json +21 -328
  305. package/readme.md +2 -2
@@ -1,1240 +1,1319 @@
1
- import { __extends } from "tslib";
2
- import { Observable } from "@babylonjs/core/Misc/observable.js";
3
- import { Vector2, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
4
- import { Tools } from "@babylonjs/core/Misc/tools.js";
5
- import { PointerEventTypes } from "@babylonjs/core/Events/pointerEvents.js";
6
- import { ClipboardEventTypes, ClipboardInfo } from "@babylonjs/core/Events/clipboardEvents.js";
7
- import { KeyboardEventTypes } from "@babylonjs/core/Events/keyboardEvents.js";
8
- import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
9
- import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
10
- import { DynamicTexture } from "@babylonjs/core/Materials/Textures/dynamicTexture.js";
11
- import { Layer } from "@babylonjs/core/Layers/layer.js";
12
- import { Container } from "./controls/container.js";
13
- import { Control } from "./controls/control.js";
14
- import { Style } from "./style.js";
15
- import { Measure } from "./measure.js";
16
- import { Constants } from "@babylonjs/core/Engines/constants.js";
17
- import { Viewport } from "@babylonjs/core/Maths/math.viewport.js";
18
- import { Color3 } from "@babylonjs/core/Maths/math.color.js";
19
- import { WebRequest } from "@babylonjs/core/Misc/webRequest.js";
20
- import { RandomGUID } from "@babylonjs/core/Misc/guid.js";
21
- /**
22
- * Class used to create texture to support 2D GUI elements
23
- * @see https://doc.babylonjs.com/how_to/gui
24
- */
25
- var AdvancedDynamicTexture = /** @class */ (function (_super) {
26
- __extends(AdvancedDynamicTexture, _super);
27
- /**
28
- * Creates a new AdvancedDynamicTexture
29
- * @param name defines the name of the texture
30
- * @param width defines the width of the texture
31
- * @param height defines the height of the texture
32
- * @param scene defines the hosting scene
33
- * @param generateMipMaps defines a boolean indicating if mipmaps must be generated (false by default)
34
- * @param samplingMode defines the texture sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
35
- * @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
36
- */
37
- function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode, invertY) {
38
- if (width === void 0) { width = 0; }
39
- if (height === void 0) { height = 0; }
40
- if (generateMipMaps === void 0) { generateMipMaps = false; }
41
- if (samplingMode === void 0) { samplingMode = Texture.NEAREST_SAMPLINGMODE; }
42
- if (invertY === void 0) { invertY = true; }
43
- var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, Constants.TEXTUREFORMAT_RGBA, invertY) || this;
44
- _this._isDirty = false;
45
- /** @hidden */
46
- _this._rootContainer = new Container("root");
47
- /** @hidden */
48
- _this._lastControlOver = {};
49
- /** @hidden */
50
- _this._lastControlDown = {};
51
- /** @hidden */
52
- _this._capturingControl = {};
53
- /** @hidden */
54
- _this._linkedControls = new Array();
55
- _this._isFullscreen = false;
56
- _this._fullscreenViewport = new Viewport(0, 0, 1, 1);
57
- _this._idealWidth = 0;
58
- _this._idealHeight = 0;
59
- _this._useSmallestIdeal = false;
60
- _this._renderAtIdealSize = false;
61
- _this._blockNextFocusCheck = false;
62
- _this._renderScale = 1;
63
- _this._cursorChanged = false;
64
- _this._defaultMousePointerId = 0;
65
- /** @hidden */
66
- _this._numLayoutCalls = 0;
67
- /** @hidden */
68
- _this._numRenderCalls = 0;
69
- /**
70
- * Define type to string to ensure compatibility across browsers
71
- * Safari doesn't support DataTransfer constructor
72
- */
73
- _this._clipboardData = "";
74
- /**
75
- * Observable event triggered each time an clipboard event is received from the rendering canvas
76
- */
77
- _this.onClipboardObservable = new Observable();
78
- /**
79
- * Observable event triggered each time a pointer down is intercepted by a control
80
- */
81
- _this.onControlPickedObservable = new Observable();
82
- /**
83
- * Observable event triggered before layout is evaluated
84
- */
85
- _this.onBeginLayoutObservable = new Observable();
86
- /**
87
- * Observable event triggered after the layout was evaluated
88
- */
89
- _this.onEndLayoutObservable = new Observable();
90
- /**
91
- * Observable event triggered before the texture is rendered
92
- */
93
- _this.onBeginRenderObservable = new Observable();
94
- /**
95
- * Observable event triggered after the texture was rendered
96
- */
97
- _this.onEndRenderObservable = new Observable();
98
- /**
99
- * Gets or sets a boolean defining if alpha is stored as premultiplied
100
- */
101
- _this.premulAlpha = false;
102
- /**
103
- * Gets or sets a boolean indicating that the canvas must be reverted on Y when updating the texture
104
- */
105
- _this.applyYInversionOnUpdate = true;
106
- _this._useInvalidateRectOptimization = true;
107
- // Invalidated rectangle which is the combination of all invalidated controls after they have been rotated into absolute position
108
- _this._invalidatedRectangle = null;
109
- _this._clearMeasure = new Measure(0, 0, 0, 0);
110
- /** @hidden */
111
- _this.onClipboardCopy = function (rawEvt) {
112
- var evt = rawEvt;
113
- var ev = new ClipboardInfo(ClipboardEventTypes.COPY, evt);
114
- _this.onClipboardObservable.notifyObservers(ev);
115
- evt.preventDefault();
116
- };
117
- /** @hidden */
118
- _this.onClipboardCut = function (rawEvt) {
119
- var evt = rawEvt;
120
- var ev = new ClipboardInfo(ClipboardEventTypes.CUT, evt);
121
- _this.onClipboardObservable.notifyObservers(ev);
122
- evt.preventDefault();
123
- };
124
- /** @hidden */
125
- _this.onClipboardPaste = function (rawEvt) {
126
- var evt = rawEvt;
127
- var ev = new ClipboardInfo(ClipboardEventTypes.PASTE, evt);
128
- _this.onClipboardObservable.notifyObservers(ev);
129
- evt.preventDefault();
130
- };
131
- scene = _this.getScene();
132
- if (!scene || !_this._texture) {
133
- return _this;
134
- }
135
- _this.applyYInversionOnUpdate = invertY;
136
- _this._rootElement = scene.getEngine().getInputElement();
137
- _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
138
- _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
139
- if (!_this._focusedControl) {
140
- return;
141
- }
142
- if (info.type === KeyboardEventTypes.KEYDOWN) {
143
- _this._focusedControl.processKeyboard(info.event);
144
- }
145
- info.skipOnPointerObservable = true;
146
- });
147
- _this._rootContainer._link(_this);
148
- _this.hasAlpha = true;
149
- if (!width || !height) {
150
- _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
151
- _this._onResize();
152
- }
153
- _this._texture.isReady = true;
154
- return _this;
155
- }
156
- Object.defineProperty(AdvancedDynamicTexture.prototype, "numLayoutCalls", {
157
- /** Gets the number of layout calls made the last time the ADT has been rendered */
158
- get: function () {
159
- return this._numLayoutCalls;
160
- },
161
- enumerable: false,
162
- configurable: true
163
- });
164
- Object.defineProperty(AdvancedDynamicTexture.prototype, "numRenderCalls", {
165
- /** Gets the number of render calls made the last time the ADT has been rendered */
166
- get: function () {
167
- return this._numRenderCalls;
168
- },
169
- enumerable: false,
170
- configurable: true
171
- });
172
- Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
173
- /**
174
- * Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
175
- * Useful when you want more antialiasing
176
- */
177
- get: function () {
178
- return this._renderScale;
179
- },
180
- set: function (value) {
181
- if (value === this._renderScale) {
182
- return;
183
- }
184
- this._renderScale = value;
185
- this._onResize();
186
- },
187
- enumerable: false,
188
- configurable: true
189
- });
190
- Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
191
- /** Gets or sets the background color */
192
- get: function () {
193
- return this._background;
194
- },
195
- set: function (value) {
196
- if (this._background === value) {
197
- return;
198
- }
199
- this._background = value;
200
- this.markAsDirty();
201
- },
202
- enumerable: false,
203
- configurable: true
204
- });
205
- Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
206
- /**
207
- * Gets or sets the ideal width used to design controls.
208
- * The GUI will then rescale everything accordingly
209
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
210
- */
211
- get: function () {
212
- return this._idealWidth;
213
- },
214
- set: function (value) {
215
- if (this._idealWidth === value) {
216
- return;
217
- }
218
- this._idealWidth = value;
219
- this.markAsDirty();
220
- this._rootContainer._markAllAsDirty();
221
- },
222
- enumerable: false,
223
- configurable: true
224
- });
225
- Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
226
- /**
227
- * Gets or sets the ideal height used to design controls.
228
- * The GUI will then rescale everything accordingly
229
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
230
- */
231
- get: function () {
232
- return this._idealHeight;
233
- },
234
- set: function (value) {
235
- if (this._idealHeight === value) {
236
- return;
237
- }
238
- this._idealHeight = value;
239
- this.markAsDirty();
240
- this._rootContainer._markAllAsDirty();
241
- },
242
- enumerable: false,
243
- configurable: true
244
- });
245
- Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
246
- /**
247
- * Gets or sets a boolean indicating if the smallest ideal value must be used if idealWidth and idealHeight are both set
248
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
249
- */
250
- get: function () {
251
- return this._useSmallestIdeal;
252
- },
253
- set: function (value) {
254
- if (this._useSmallestIdeal === value) {
255
- return;
256
- }
257
- this._useSmallestIdeal = value;
258
- this.markAsDirty();
259
- this._rootContainer._markAllAsDirty();
260
- },
261
- enumerable: false,
262
- configurable: true
263
- });
264
- Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
265
- /**
266
- * Gets or sets a boolean indicating if adaptive scaling must be used
267
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
268
- */
269
- get: function () {
270
- return this._renderAtIdealSize;
271
- },
272
- set: function (value) {
273
- if (this._renderAtIdealSize === value) {
274
- return;
275
- }
276
- this._renderAtIdealSize = value;
277
- this._onResize();
278
- },
279
- enumerable: false,
280
- configurable: true
281
- });
282
- Object.defineProperty(AdvancedDynamicTexture.prototype, "idealRatio", {
283
- /**
284
- * Gets the ratio used when in "ideal mode"
285
- * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
286
- * */
287
- get: function () {
288
- var rwidth = 0;
289
- var rheight = 0;
290
- if (this._idealWidth) {
291
- rwidth = this.getSize().width / this._idealWidth;
292
- }
293
- if (this._idealHeight) {
294
- rheight = this.getSize().height / this._idealHeight;
295
- }
296
- if (this._useSmallestIdeal && this._idealWidth && this._idealHeight) {
297
- return window.innerWidth < window.innerHeight ? rwidth : rheight;
298
- }
299
- if (this._idealWidth) {
300
- // horizontal
301
- return rwidth;
302
- }
303
- if (this._idealHeight) {
304
- // vertical
305
- return rheight;
306
- }
307
- return 1;
308
- },
309
- enumerable: false,
310
- configurable: true
311
- });
312
- Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
313
- /**
314
- * Gets the underlying layer used to render the texture when in fullscreen mode
315
- */
316
- get: function () {
317
- return this._layerToDispose;
318
- },
319
- enumerable: false,
320
- configurable: true
321
- });
322
- Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
323
- /**
324
- * Gets the root container control
325
- */
326
- get: function () {
327
- return this._rootContainer;
328
- },
329
- enumerable: false,
330
- configurable: true
331
- });
332
- /**
333
- * Returns an array containing the root container.
334
- * This is mostly used to let the Inspector introspects the ADT
335
- * @returns an array containing the rootContainer
336
- */
337
- AdvancedDynamicTexture.prototype.getChildren = function () {
338
- return [this._rootContainer];
339
- };
340
- /**
341
- * Will return all controls that are inside this texture
342
- * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
343
- * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
344
- * @return all child controls
345
- */
346
- AdvancedDynamicTexture.prototype.getDescendants = function (directDescendantsOnly, predicate) {
347
- return this._rootContainer.getDescendants(directDescendantsOnly, predicate);
348
- };
349
- /**
350
- * Will return all controls with the given type name
351
- * @param typeName defines the type name to search for
352
- * @returns an array of all controls found
353
- */
354
- AdvancedDynamicTexture.prototype.getControlsByType = function (typeName) {
355
- return this._rootContainer.getDescendants(false, function (control) { return control.typeName === typeName; });
356
- };
357
- /**
358
- * Will return the first control with the given name
359
- * @param name defines the name to search for
360
- * @return the first control found or null
361
- */
362
- AdvancedDynamicTexture.prototype.getControlByName = function (name) {
363
- return this._getControlByKey("name", name);
364
- };
365
- AdvancedDynamicTexture.prototype._getControlByKey = function (key, value) {
366
- return this._rootContainer.getDescendants().find(function (control) { return control[key] === value; }) || null;
367
- };
368
- Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
369
- /**
370
- * Gets or sets the current focused control
371
- */
372
- get: function () {
373
- return this._focusedControl;
374
- },
375
- set: function (control) {
376
- if (this._focusedControl == control) {
377
- return;
378
- }
379
- if (this._focusedControl) {
380
- this._focusedControl.onBlur();
381
- }
382
- if (control) {
383
- control.onFocus();
384
- }
385
- this._focusedControl = control;
386
- },
387
- enumerable: false,
388
- configurable: true
389
- });
390
- Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
391
- /**
392
- * Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
393
- */
394
- get: function () {
395
- if (!this.layer) {
396
- return true;
397
- }
398
- return !this.layer.isBackground;
399
- },
400
- set: function (value) {
401
- if (!this.layer) {
402
- return;
403
- }
404
- if (this.layer.isBackground === !value) {
405
- return;
406
- }
407
- this.layer.isBackground = !value;
408
- },
409
- enumerable: false,
410
- configurable: true
411
- });
412
- Object.defineProperty(AdvancedDynamicTexture.prototype, "clipboardData", {
413
- /**
414
- * Gets or set information about clipboardData
415
- */
416
- get: function () {
417
- return this._clipboardData;
418
- },
419
- set: function (value) {
420
- this._clipboardData = value;
421
- },
422
- enumerable: false,
423
- configurable: true
424
- });
425
- /**
426
- * Get the current class name of the texture useful for serialization or dynamic coding.
427
- * @returns "AdvancedDynamicTexture"
428
- */
429
- AdvancedDynamicTexture.prototype.getClassName = function () {
430
- return "AdvancedDynamicTexture";
431
- };
432
- /**
433
- * Function used to execute a function on all controls
434
- * @param func defines the function to execute
435
- * @param container defines the container where controls belong. If null the root container will be used
436
- */
437
- AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
438
- if (!container) {
439
- container = this._rootContainer;
440
- }
441
- func(container);
442
- for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
443
- var child = _a[_i];
444
- if (child.children) {
445
- this.executeOnAllControls(func, child);
446
- continue;
447
- }
448
- func(child);
449
- }
450
- };
451
- Object.defineProperty(AdvancedDynamicTexture.prototype, "useInvalidateRectOptimization", {
452
- /**
453
- * Gets or sets a boolean indicating if the InvalidateRect optimization should be turned on
454
- */
455
- get: function () {
456
- return this._useInvalidateRectOptimization;
457
- },
458
- set: function (value) {
459
- this._useInvalidateRectOptimization = value;
460
- },
461
- enumerable: false,
462
- configurable: true
463
- });
464
- /**
465
- * Invalidates a rectangle area on the gui texture
466
- * @param invalidMinX left most position of the rectangle to invalidate in the texture
467
- * @param invalidMinY top most position of the rectangle to invalidate in the texture
468
- * @param invalidMaxX right most position of the rectangle to invalidate in the texture
469
- * @param invalidMaxY bottom most position of the rectangle to invalidate in the texture
470
- */
471
- AdvancedDynamicTexture.prototype.invalidateRect = function (invalidMinX, invalidMinY, invalidMaxX, invalidMaxY) {
472
- if (!this._useInvalidateRectOptimization) {
473
- return;
474
- }
475
- if (!this._invalidatedRectangle) {
476
- this._invalidatedRectangle = new Measure(invalidMinX, invalidMinY, invalidMaxX - invalidMinX + 1, invalidMaxY - invalidMinY + 1);
477
- }
478
- else {
479
- // Compute intersection
480
- var maxX = Math.ceil(Math.max(this._invalidatedRectangle.left + this._invalidatedRectangle.width - 1, invalidMaxX));
481
- var maxY = Math.ceil(Math.max(this._invalidatedRectangle.top + this._invalidatedRectangle.height - 1, invalidMaxY));
482
- this._invalidatedRectangle.left = Math.floor(Math.min(this._invalidatedRectangle.left, invalidMinX));
483
- this._invalidatedRectangle.top = Math.floor(Math.min(this._invalidatedRectangle.top, invalidMinY));
484
- this._invalidatedRectangle.width = maxX - this._invalidatedRectangle.left + 1;
485
- this._invalidatedRectangle.height = maxY - this._invalidatedRectangle.top + 1;
486
- }
487
- };
488
- /**
489
- * Marks the texture as dirty forcing a complete update
490
- */
491
- AdvancedDynamicTexture.prototype.markAsDirty = function () {
492
- this._isDirty = true;
493
- };
494
- /**
495
- * Helper function used to create a new style
496
- * @returns a new style
497
- * @see https://doc.babylonjs.com/how_to/gui#styles
498
- */
499
- AdvancedDynamicTexture.prototype.createStyle = function () {
500
- return new Style(this);
501
- };
502
- /**
503
- * Adds a new control to the root container
504
- * @param control defines the control to add
505
- * @returns the current texture
506
- */
507
- AdvancedDynamicTexture.prototype.addControl = function (control) {
508
- this._rootContainer.addControl(control);
509
- return this;
510
- };
511
- /**
512
- * Removes a control from the root container
513
- * @param control defines the control to remove
514
- * @returns the current texture
515
- */
516
- AdvancedDynamicTexture.prototype.removeControl = function (control) {
517
- this._rootContainer.removeControl(control);
518
- return this;
519
- };
520
- /**
521
- * Moves overlapped controls towards a position where it is not overlapping anymore.
522
- * Please note that this method alters linkOffsetXInPixels and linkOffsetYInPixels.
523
- * @param overlapGroup the overlap group which will be processed or undefined to process all overlap groups
524
- * @param deltaStep the step size (speed) to reach the target non overlapping position (default 0.1)
525
- * @param repelFactor how much is the control repelled by other controls
526
- */
527
- AdvancedDynamicTexture.prototype.moveToNonOverlappedPosition = function (overlapGroup, deltaStep, repelFactor) {
528
- if (deltaStep === void 0) { deltaStep = 1; }
529
- if (repelFactor === void 0) { repelFactor = 1; }
530
- var controlsForGroup;
531
- if (Array.isArray(overlapGroup)) {
532
- controlsForGroup = overlapGroup;
533
- }
534
- else {
535
- var descendants = this.getDescendants(true);
536
- // get only the controls with an overlapGroup property set
537
- // if the overlapGroup parameter is set, filter the controls and get only the controls belonging to that overlapGroup
538
- controlsForGroup = overlapGroup === undefined ? descendants.filter(function (c) { return c.overlapGroup !== undefined; }) : descendants.filter(function (c) { return c.overlapGroup === overlapGroup; });
539
- }
540
- controlsForGroup.forEach(function (control1) {
541
- var _a;
542
- var velocity = Vector2.Zero();
543
- var center = new Vector2(control1.centerX, control1.centerY);
544
- controlsForGroup.forEach(function (control2) {
545
- if (control1 !== control2 && AdvancedDynamicTexture._Overlaps(control1, control2)) {
546
- // if the two controls overlaps get a direction vector from one control's center to another control's center
547
- var diff = center.subtract(new Vector2(control2.centerX, control2.centerY));
548
- var diffLength = diff.length();
549
- if (diffLength > 0) {
550
- // calculate the velocity
551
- velocity = velocity.add(diff.normalize().scale(repelFactor / diffLength));
552
- }
553
- }
554
- });
555
- if (velocity.length() > 0) {
556
- // move the control along the direction vector away from the overlapping control
557
- velocity = velocity.normalize().scale(deltaStep * ((_a = control1.overlapDeltaMultiplier) !== null && _a !== void 0 ? _a : 1));
558
- control1.linkOffsetXInPixels += velocity.x;
559
- control1.linkOffsetYInPixels += velocity.y;
560
- }
561
- });
562
- };
563
- /**
564
- * Release all resources
565
- */
566
- AdvancedDynamicTexture.prototype.dispose = function () {
567
- var scene = this.getScene();
568
- if (!scene) {
569
- return;
570
- }
571
- this._rootElement = null;
572
- scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
573
- if (this._resizeObserver) {
574
- scene.getEngine().onResizeObservable.remove(this._resizeObserver);
575
- }
576
- if (this._pointerMoveObserver) {
577
- scene.onPrePointerObservable.remove(this._pointerMoveObserver);
578
- }
579
- if (this._pointerObserver) {
580
- scene.onPointerObservable.remove(this._pointerObserver);
581
- }
582
- if (this._preKeyboardObserver) {
583
- scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
584
- }
585
- if (this._canvasPointerOutObserver) {
586
- scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
587
- }
588
- if (this._canvasBlurObserver) {
589
- scene.getEngine().onCanvasBlurObservable.remove(this._canvasBlurObserver);
590
- }
591
- if (this._layerToDispose) {
592
- this._layerToDispose.texture = null;
593
- this._layerToDispose.dispose();
594
- this._layerToDispose = null;
595
- }
596
- this._rootContainer.dispose();
597
- this.onClipboardObservable.clear();
598
- this.onControlPickedObservable.clear();
599
- this.onBeginRenderObservable.clear();
600
- this.onEndRenderObservable.clear();
601
- this.onBeginLayoutObservable.clear();
602
- this.onEndLayoutObservable.clear();
603
- _super.prototype.dispose.call(this);
604
- };
605
- AdvancedDynamicTexture.prototype._onResize = function () {
606
- var scene = this.getScene();
607
- if (!scene) {
608
- return;
609
- }
610
- // Check size
611
- var engine = scene.getEngine();
612
- var textureSize = this.getSize();
613
- var renderWidth = engine.getRenderWidth() * this._renderScale;
614
- var renderHeight = engine.getRenderHeight() * this._renderScale;
615
- if (this._renderAtIdealSize) {
616
- if (this._idealWidth) {
617
- renderHeight = (renderHeight * this._idealWidth) / renderWidth;
618
- renderWidth = this._idealWidth;
619
- }
620
- else if (this._idealHeight) {
621
- renderWidth = (renderWidth * this._idealHeight) / renderHeight;
622
- renderHeight = this._idealHeight;
623
- }
624
- }
625
- if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
626
- this.scaleTo(renderWidth, renderHeight);
627
- this.markAsDirty();
628
- if (this._idealWidth || this._idealHeight) {
629
- this._rootContainer._markAllAsDirty();
630
- }
631
- }
632
- this.invalidateRect(0, 0, textureSize.width - 1, textureSize.height - 1);
633
- };
634
- /** @hidden */
635
- AdvancedDynamicTexture.prototype._getGlobalViewport = function () {
636
- var size = this.getSize();
637
- var globalViewPort = this._fullscreenViewport.toGlobal(size.width, size.height);
638
- var targetX = Math.round(globalViewPort.width * (1 / this.rootContainer.scaleX));
639
- var targetY = Math.round(globalViewPort.height * (1 / this.rootContainer.scaleY));
640
- globalViewPort.x += (globalViewPort.width - targetX) / 2;
641
- globalViewPort.y += (globalViewPort.height - targetY) / 2;
642
- globalViewPort.width = targetX;
643
- globalViewPort.height = targetY;
644
- return globalViewPort;
645
- };
646
- /**
647
- * Get screen coordinates for a vector3
648
- * @param position defines the position to project
649
- * @param worldMatrix defines the world matrix to use
650
- * @returns the projected position
651
- */
652
- AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
653
- var result = this.getProjectedPositionWithZ(position, worldMatrix);
654
- return new Vector2(result.x, result.y);
655
- };
656
- /**
657
- * Get screen coordinates for a vector3
658
- * @param position defines the position to project
659
- * @param worldMatrix defines the world matrix to use
660
- * @returns the projected position with Z
661
- */
662
- AdvancedDynamicTexture.prototype.getProjectedPositionWithZ = function (position, worldMatrix) {
663
- var scene = this.getScene();
664
- if (!scene) {
665
- return Vector3.Zero();
666
- }
667
- var globalViewport = this._getGlobalViewport();
668
- var projectedPosition = Vector3.Project(position, worldMatrix, scene.getTransformMatrix(), globalViewport);
669
- return new Vector3(projectedPosition.x, projectedPosition.y, projectedPosition.z);
670
- };
671
- AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
672
- if (this._layerToDispose) {
673
- if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
674
- return;
675
- }
676
- }
677
- if (this._isFullscreen && this._linkedControls.length) {
678
- var scene = this.getScene();
679
- if (!scene) {
680
- return;
681
- }
682
- var globalViewport = this._getGlobalViewport();
683
- var _loop_1 = function (control) {
684
- if (!control.isVisible) {
685
- return "continue";
686
- }
687
- var mesh = control._linkedMesh;
688
- if (!mesh || mesh.isDisposed()) {
689
- Tools.SetImmediate(function () {
690
- control.linkWithMesh(null);
691
- });
692
- return "continue";
693
- }
694
- var position = mesh.getBoundingInfo ? mesh.getBoundingInfo().boundingSphere.center : Vector3.ZeroReadOnly;
695
- var projectedPosition = Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
696
- if (projectedPosition.z < 0 || projectedPosition.z > 1) {
697
- control.notRenderable = true;
698
- return "continue";
699
- }
700
- control.notRenderable = false;
701
- control._moveToProjectedPosition(projectedPosition);
702
- };
703
- for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
704
- var control = _a[_i];
705
- _loop_1(control);
706
- }
707
- }
708
- if (!this._isDirty && !this._rootContainer.isDirty) {
709
- return;
710
- }
711
- this._isDirty = false;
712
- this._render();
713
- this.update(this.applyYInversionOnUpdate, this.premulAlpha, AdvancedDynamicTexture.AllowGPUOptimizations);
714
- };
715
- AdvancedDynamicTexture.prototype._render = function () {
716
- var textureSize = this.getSize();
717
- var renderWidth = textureSize.width;
718
- var renderHeight = textureSize.height;
719
- var context = this.getContext();
720
- context.font = "18px Arial";
721
- context.strokeStyle = "white";
722
- // Layout
723
- this.onBeginLayoutObservable.notifyObservers(this);
724
- var measure = new Measure(0, 0, renderWidth, renderHeight);
725
- this._numLayoutCalls = 0;
726
- this._rootContainer._layout(measure, context);
727
- this.onEndLayoutObservable.notifyObservers(this);
728
- this._isDirty = false; // Restoring the dirty state that could have been set by controls during layout processing
729
- // Clear
730
- if (this._invalidatedRectangle) {
731
- this._clearMeasure.copyFrom(this._invalidatedRectangle);
732
- }
733
- else {
734
- this._clearMeasure.copyFromFloats(0, 0, renderWidth, renderHeight);
735
- }
736
- context.clearRect(this._clearMeasure.left, this._clearMeasure.top, this._clearMeasure.width, this._clearMeasure.height);
737
- if (this._background) {
738
- context.save();
739
- context.fillStyle = this._background;
740
- context.fillRect(this._clearMeasure.left, this._clearMeasure.top, this._clearMeasure.width, this._clearMeasure.height);
741
- context.restore();
742
- }
743
- // Render
744
- this.onBeginRenderObservable.notifyObservers(this);
745
- this._numRenderCalls = 0;
746
- this._rootContainer._render(context, this._invalidatedRectangle);
747
- this.onEndRenderObservable.notifyObservers(this);
748
- this._invalidatedRectangle = null;
749
- };
750
- /** @hidden */
751
- AdvancedDynamicTexture.prototype._changeCursor = function (cursor) {
752
- if (this._rootElement) {
753
- this._rootElement.style.cursor = cursor;
754
- this._cursorChanged = true;
755
- }
756
- };
757
- /** @hidden */
758
- AdvancedDynamicTexture.prototype._registerLastControlDown = function (control, pointerId) {
759
- this._lastControlDown[pointerId] = control;
760
- this.onControlPickedObservable.notifyObservers(control);
761
- };
762
- AdvancedDynamicTexture.prototype._doPicking = function (x, y, pi, type, pointerId, buttonIndex, deltaX, deltaY) {
763
- var scene = this.getScene();
764
- if (!scene) {
765
- return;
766
- }
767
- var engine = scene.getEngine();
768
- var textureSize = this.getSize();
769
- if (this._isFullscreen) {
770
- var camera = scene.cameraToUseForPointers || scene.activeCamera;
771
- if (!camera) {
772
- return;
773
- }
774
- var viewport = camera.viewport;
775
- x = x * (textureSize.width / (engine.getRenderWidth() * viewport.width));
776
- y = y * (textureSize.height / (engine.getRenderHeight() * viewport.height));
777
- }
778
- if (this._capturingControl[pointerId]) {
779
- this._capturingControl[pointerId]._processObservables(type, x, y, pi, pointerId, buttonIndex);
780
- return;
781
- }
782
- this._cursorChanged = false;
783
- if (!this._rootContainer._processPicking(x, y, pi, type, pointerId, buttonIndex, deltaX, deltaY)) {
784
- if (!scene.doNotHandleCursors) {
785
- this._changeCursor("");
786
- }
787
- if (type === PointerEventTypes.POINTERMOVE) {
788
- if (this._lastControlOver[pointerId]) {
789
- this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId], pi);
790
- delete this._lastControlOver[pointerId];
791
- }
792
- }
793
- }
794
- if (!this._cursorChanged && !scene.doNotHandleCursors) {
795
- this._changeCursor("");
796
- }
797
- this._manageFocus();
798
- };
799
- /** @hidden */
800
- AdvancedDynamicTexture.prototype._cleanControlAfterRemovalFromList = function (list, control) {
801
- for (var pointerId in list) {
802
- if (!list.hasOwnProperty(pointerId)) {
803
- continue;
804
- }
805
- var lastControlOver = list[pointerId];
806
- if (lastControlOver === control) {
807
- delete list[pointerId];
808
- }
809
- }
810
- };
811
- /** @hidden */
812
- AdvancedDynamicTexture.prototype._cleanControlAfterRemoval = function (control) {
813
- this._cleanControlAfterRemovalFromList(this._lastControlDown, control);
814
- this._cleanControlAfterRemovalFromList(this._lastControlOver, control);
815
- };
816
- /** Attach to all scene events required to support pointer events */
817
- AdvancedDynamicTexture.prototype.attach = function () {
818
- var _this = this;
819
- var scene = this.getScene();
820
- if (!scene) {
821
- return;
822
- }
823
- var tempViewport = new Viewport(0, 0, 0, 0);
824
- this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
825
- if (scene.isPointerCaptured(pi.event.pointerId)) {
826
- return;
827
- }
828
- if (pi.type !== PointerEventTypes.POINTERMOVE &&
829
- pi.type !== PointerEventTypes.POINTERUP &&
830
- pi.type !== PointerEventTypes.POINTERDOWN &&
831
- pi.type !== PointerEventTypes.POINTERWHEEL) {
832
- return;
833
- }
834
- if (pi.type === PointerEventTypes.POINTERMOVE && pi.event.pointerId) {
835
- _this._defaultMousePointerId = pi.event.pointerId; // This is required to make sure we have the correct pointer ID for wheel
836
- }
837
- var camera = scene.cameraToUseForPointers || scene.activeCamera;
838
- var engine = scene.getEngine();
839
- var originalCameraToUseForPointers = scene.cameraToUseForPointers;
840
- if (!camera) {
841
- tempViewport.x = 0;
842
- tempViewport.y = 0;
843
- tempViewport.width = engine.getRenderWidth();
844
- tempViewport.height = engine.getRenderHeight();
845
- }
846
- else {
847
- if (camera.rigCameras.length) {
848
- // rig camera - we need to find the camera to use for this event
849
- var rigViewport_1 = new Viewport(0, 0, 1, 1);
850
- camera.rigCameras.forEach(function (rigCamera) {
851
- // generate the viewport of this camera
852
- rigCamera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), rigViewport_1);
853
- var x = scene.pointerX / engine.getHardwareScalingLevel() - rigViewport_1.x;
854
- var y = scene.pointerY / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - rigViewport_1.y - rigViewport_1.height);
855
- // check if the pointer is in the camera's viewport
856
- if (x < 0 || y < 0 || x > rigViewport_1.width || y > rigViewport_1.height) {
857
- // out of viewport - don't use this camera
858
- return;
859
- }
860
- // set the camera to use for pointers until this pointer loop is over
861
- scene.cameraToUseForPointers = rigCamera;
862
- // set the viewport
863
- tempViewport.x = rigViewport_1.x;
864
- tempViewport.y = rigViewport_1.y;
865
- tempViewport.width = rigViewport_1.width;
866
- tempViewport.height = rigViewport_1.height;
867
- });
868
- }
869
- else {
870
- camera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), tempViewport);
871
- }
872
- }
873
- var x = scene.pointerX / engine.getHardwareScalingLevel() - tempViewport.x;
874
- var y = scene.pointerY / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - tempViewport.y - tempViewport.height);
875
- _this._shouldBlockPointer = false;
876
- // Do picking modifies _shouldBlockPointer
877
- var pointerId = pi.event.pointerId || _this._defaultMousePointerId;
878
- _this._doPicking(x, y, pi, pi.type, pointerId, pi.event.button, pi.event.deltaX, pi.event.deltaY);
879
- // Avoid overwriting a true skipOnPointerObservable to false
880
- if (_this._shouldBlockPointer) {
881
- pi.skipOnPointerObservable = _this._shouldBlockPointer;
882
- }
883
- // if overridden by a rig camera - reset back to the original value
884
- scene.cameraToUseForPointers = originalCameraToUseForPointers;
885
- });
886
- this._attachToOnPointerOut(scene);
887
- this._attachToOnBlur(scene);
888
- };
889
- /**
890
- * Register the clipboard Events onto the canvas
891
- */
892
- AdvancedDynamicTexture.prototype.registerClipboardEvents = function () {
893
- self.addEventListener("copy", this.onClipboardCopy, false);
894
- self.addEventListener("cut", this.onClipboardCut, false);
895
- self.addEventListener("paste", this.onClipboardPaste, false);
896
- };
897
- /**
898
- * Unregister the clipboard Events from the canvas
899
- */
900
- AdvancedDynamicTexture.prototype.unRegisterClipboardEvents = function () {
901
- self.removeEventListener("copy", this.onClipboardCopy);
902
- self.removeEventListener("cut", this.onClipboardCut);
903
- self.removeEventListener("paste", this.onClipboardPaste);
904
- };
905
- /**
906
- * Connect the texture to a hosting mesh to enable interactions
907
- * @param mesh defines the mesh to attach to
908
- * @param supportPointerMove defines a boolean indicating if pointer move events must be catched as well
909
- */
910
- AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
911
- var _this = this;
912
- if (supportPointerMove === void 0) { supportPointerMove = true; }
913
- var scene = this.getScene();
914
- if (!scene) {
915
- return;
916
- }
917
- this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
918
- if (pi.type !== PointerEventTypes.POINTERMOVE &&
919
- pi.type !== PointerEventTypes.POINTERUP &&
920
- pi.type !== PointerEventTypes.POINTERDOWN &&
921
- pi.type !== PointerEventTypes.POINTERWHEEL) {
922
- return;
923
- }
924
- if (pi.type === PointerEventTypes.POINTERMOVE && pi.event.pointerId) {
925
- _this._defaultMousePointerId = pi.event.pointerId; // This is required to make sure we have the correct pointer ID for wheel
926
- }
927
- var pointerId = pi.event.pointerId || _this._defaultMousePointerId;
928
- if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
929
- var uv = pi.pickInfo.getTextureCoordinates();
930
- if (uv) {
931
- var size = _this.getSize();
932
- _this._doPicking(uv.x * size.width, (_this.applyYInversionOnUpdate ? 1.0 - uv.y : uv.y) * size.height, pi, pi.type, pointerId, pi.event.button, pi.event.deltaX, pi.event.deltaY);
933
- }
934
- }
935
- else if (pi.type === PointerEventTypes.POINTERUP) {
936
- if (_this._lastControlDown[pointerId]) {
937
- _this._lastControlDown[pointerId]._forcePointerUp(pointerId);
938
- }
939
- delete _this._lastControlDown[pointerId];
940
- if (_this.focusedControl) {
941
- var friendlyControls = _this.focusedControl.keepsFocusWith();
942
- var canMoveFocus = true;
943
- if (friendlyControls) {
944
- for (var _i = 0, friendlyControls_1 = friendlyControls; _i < friendlyControls_1.length; _i++) {
945
- var control = friendlyControls_1[_i];
946
- // Same host, no need to keep the focus
947
- if (_this === control._host) {
948
- continue;
949
- }
950
- // Different hosts
951
- var otherHost = control._host;
952
- if (otherHost._lastControlOver[pointerId] && otherHost._lastControlOver[pointerId].isAscendant(control)) {
953
- canMoveFocus = false;
954
- break;
955
- }
956
- }
957
- }
958
- if (canMoveFocus) {
959
- _this.focusedControl = null;
960
- }
961
- }
962
- }
963
- else if (pi.type === PointerEventTypes.POINTERMOVE) {
964
- if (_this._lastControlOver[pointerId]) {
965
- _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId], pi, true);
966
- }
967
- delete _this._lastControlOver[pointerId];
968
- }
969
- });
970
- mesh.enablePointerMoveEvents = supportPointerMove;
971
- this._attachToOnPointerOut(scene);
972
- this._attachToOnBlur(scene);
973
- };
974
- /**
975
- * Move the focus to a specific control
976
- * @param control defines the control which will receive the focus
977
- */
978
- AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
979
- this.focusedControl = control;
980
- this._lastPickedControl = control;
981
- this._blockNextFocusCheck = true;
982
- };
983
- AdvancedDynamicTexture.prototype._manageFocus = function () {
984
- if (this._blockNextFocusCheck) {
985
- this._blockNextFocusCheck = false;
986
- this._lastPickedControl = this._focusedControl;
987
- return;
988
- }
989
- // Focus management
990
- if (this._focusedControl) {
991
- if (this._focusedControl !== this._lastPickedControl) {
992
- if (this._lastPickedControl.isFocusInvisible) {
993
- return;
994
- }
995
- this.focusedControl = null;
996
- }
997
- }
998
- };
999
- AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
1000
- var _this = this;
1001
- this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function (pointerEvent) {
1002
- if (_this._lastControlOver[pointerEvent.pointerId]) {
1003
- _this._lastControlOver[pointerEvent.pointerId]._onPointerOut(_this._lastControlOver[pointerEvent.pointerId], null);
1004
- }
1005
- delete _this._lastControlOver[pointerEvent.pointerId];
1006
- if (_this._lastControlDown[pointerEvent.pointerId] && _this._lastControlDown[pointerEvent.pointerId] !== _this._capturingControl[pointerEvent.pointerId]) {
1007
- _this._lastControlDown[pointerEvent.pointerId]._forcePointerUp();
1008
- delete _this._lastControlDown[pointerEvent.pointerId];
1009
- }
1010
- });
1011
- };
1012
- AdvancedDynamicTexture.prototype._attachToOnBlur = function (scene) {
1013
- var _this = this;
1014
- this._canvasBlurObserver = scene.getEngine().onCanvasBlurObservable.add(function (pointerEvent) {
1015
- Object.entries(_this._lastControlDown).forEach(function (_a) {
1016
- var key = _a[0], value = _a[1];
1017
- value._onCanvasBlur();
1018
- });
1019
- _this.focusedControl = null;
1020
- _this._lastControlDown = {};
1021
- });
1022
- };
1023
- /**
1024
- * Serializes the entire GUI system
1025
- * @returns an object with the JSON serialized data
1026
- */
1027
- AdvancedDynamicTexture.prototype.serializeContent = function () {
1028
- var size = this.getSize();
1029
- var serializationObject = {
1030
- root: {},
1031
- width: size.width,
1032
- height: size.height,
1033
- };
1034
- this._rootContainer.serialize(serializationObject.root);
1035
- return serializationObject;
1036
- };
1037
- /**
1038
- * Recreate the content of the ADT from a JSON object
1039
- * @param serializedObject define the JSON serialized object to restore from
1040
- * @param scaleToSize defines whether to scale to texture to the saved size
1041
- */
1042
- AdvancedDynamicTexture.prototype.parseContent = function (serializedObject, scaleToSize) {
1043
- this._rootContainer = Control.Parse(serializedObject.root, this);
1044
- if (scaleToSize) {
1045
- var width = serializedObject.width;
1046
- var height = serializedObject.height;
1047
- if (typeof width === "number" && typeof height === "number" && width >= 0 && height >= 0) {
1048
- this.scaleTo(width, height);
1049
- }
1050
- else {
1051
- // scales the GUI to a default size if none was available in the serialized content
1052
- this.scaleTo(1920, 1080);
1053
- }
1054
- }
1055
- };
1056
- /**
1057
- * Recreate the content of the ADT from a snippet saved by the GUI editor
1058
- * @param snippetId defines the snippet to load
1059
- * @param scaleToSize defines whether to scale to texture to the saved size
1060
- * @returns a promise that will resolve on success
1061
- */
1062
- AdvancedDynamicTexture.prototype.parseFromSnippetAsync = function (snippetId, scaleToSize) {
1063
- var _this = this;
1064
- if (snippetId === "_BLANK") {
1065
- return Promise.resolve();
1066
- }
1067
- return new Promise(function (resolve, reject) {
1068
- var request = new WebRequest();
1069
- request.addEventListener("readystatechange", function () {
1070
- if (request.readyState == 4) {
1071
- if (request.status == 200) {
1072
- var snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);
1073
- var serializationObject = JSON.parse(snippet.gui);
1074
- _this.parseContent(serializationObject, scaleToSize);
1075
- _this.snippetId = snippetId;
1076
- resolve();
1077
- }
1078
- else {
1079
- reject("Unable to load the snippet " + snippetId);
1080
- }
1081
- }
1082
- });
1083
- request.open("GET", AdvancedDynamicTexture.SnippetUrl + "/" + snippetId.replace(/#/g, "/"));
1084
- request.send();
1085
- });
1086
- };
1087
- /**
1088
- * Recreate the content of the ADT from a url json
1089
- * @param url defines the url to load
1090
- * @param scaleToSize defines whether to scale to texture to the saved size
1091
- * @returns a promise that will resolve on success
1092
- */
1093
- AdvancedDynamicTexture.prototype.parseFromURLAsync = function (url, scaleToSize) {
1094
- var _this = this;
1095
- if (url === "") {
1096
- return Promise.resolve();
1097
- }
1098
- return new Promise(function (resolve, reject) {
1099
- var request = new WebRequest();
1100
- request.addEventListener("readystatechange", function () {
1101
- if (request.readyState == 4) {
1102
- if (request.status == 200) {
1103
- var gui = request.responseText;
1104
- var serializationObject = JSON.parse(gui);
1105
- _this.parseContent(serializationObject, scaleToSize);
1106
- resolve();
1107
- }
1108
- else {
1109
- reject("Unable to load");
1110
- }
1111
- }
1112
- });
1113
- request.open("GET", url);
1114
- request.send();
1115
- });
1116
- };
1117
- // Statics
1118
- /**
1119
- * Compares two rectangle based controls for pixel overlap
1120
- * @param control1 The first control to compare
1121
- * @param control2 The second control to compare
1122
- * @returns true if overlaps, otherwise false
1123
- */
1124
- AdvancedDynamicTexture._Overlaps = function (control1, control2) {
1125
- return !(control1.centerX > control2.centerX + control2.widthInPixels ||
1126
- control1.centerX + control1.widthInPixels < control2.centerX ||
1127
- control1.centerY + control1.heightInPixels < control2.centerY ||
1128
- control1.centerY > control2.centerY + control2.heightInPixels);
1129
- };
1130
- /**
1131
- * Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh)
1132
- * @param mesh defines the mesh which will receive the texture
1133
- * @param width defines the texture width (1024 by default)
1134
- * @param height defines the texture height (1024 by default)
1135
- * @param supportPointerMove defines a boolean indicating if the texture must capture move events (true by default)
1136
- * @param onlyAlphaTesting defines a boolean indicating that alpha blending will not be used (only alpha testing) (false by default)
1137
- * @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
1138
- * @returns a new AdvancedDynamicTexture
1139
- */
1140
- AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove, onlyAlphaTesting, invertY) {
1141
- if (width === void 0) { width = 1024; }
1142
- if (height === void 0) { height = 1024; }
1143
- if (supportPointerMove === void 0) { supportPointerMove = true; }
1144
- if (onlyAlphaTesting === void 0) { onlyAlphaTesting = false; }
1145
- // use a unique ID in name so serialization will work even if you create two ADTs for a single mesh
1146
- var uniqueId = RandomGUID();
1147
- var result = new AdvancedDynamicTexture("AdvancedDynamicTexture for ".concat(mesh.name, " [").concat(uniqueId, "]"), width, height, mesh.getScene(), true, Texture.TRILINEAR_SAMPLINGMODE, invertY);
1148
- var material = new StandardMaterial("AdvancedDynamicTextureMaterial for ".concat(mesh.name, " [").concat(uniqueId, "]"), mesh.getScene());
1149
- material.backFaceCulling = false;
1150
- material.diffuseColor = Color3.Black();
1151
- material.specularColor = Color3.Black();
1152
- if (onlyAlphaTesting) {
1153
- material.diffuseTexture = result;
1154
- material.emissiveTexture = result;
1155
- result.hasAlpha = true;
1156
- }
1157
- else {
1158
- material.emissiveTexture = result;
1159
- material.opacityTexture = result;
1160
- }
1161
- mesh.material = material;
1162
- result.attachToMesh(mesh, supportPointerMove);
1163
- return result;
1164
- };
1165
- /**
1166
- * Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh) BUT do not create a new material for the mesh. You will be responsible for connecting the texture
1167
- * @param mesh defines the mesh which will receive the texture
1168
- * @param width defines the texture width (1024 by default)
1169
- * @param height defines the texture height (1024 by default)
1170
- * @param supportPointerMove defines a boolean indicating if the texture must capture move events (true by default)
1171
- * @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
1172
- * @returns a new AdvancedDynamicTexture
1173
- */
1174
- AdvancedDynamicTexture.CreateForMeshTexture = function (mesh, width, height, supportPointerMove, invertY) {
1175
- if (width === void 0) { width = 1024; }
1176
- if (height === void 0) { height = 1024; }
1177
- if (supportPointerMove === void 0) { supportPointerMove = true; }
1178
- var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, Texture.TRILINEAR_SAMPLINGMODE, invertY);
1179
- result.attachToMesh(mesh, supportPointerMove);
1180
- return result;
1181
- };
1182
- /**
1183
- * Creates a new AdvancedDynamicTexture in fullscreen mode.
1184
- * In this mode the texture will rely on a layer for its rendering.
1185
- * This allows it to be treated like any other layer.
1186
- * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
1187
- * LayerMask is set through advancedTexture.layer.layerMask
1188
- * @param name defines name for the texture
1189
- * @param foreground defines a boolean indicating if the texture must be rendered in foreground (default is true)
1190
- * @param scene defines the hosting scene
1191
- * @param sampling defines the texture sampling mode (Texture.BILINEAR_SAMPLINGMODE by default)
1192
- * @param adaptiveScaling defines whether to automatically scale root to match hardwarescaling (false by default)
1193
- * @returns a new AdvancedDynamicTexture
1194
- */
1195
- AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling, adaptiveScaling) {
1196
- if (foreground === void 0) { foreground = true; }
1197
- if (scene === void 0) { scene = null; }
1198
- if (sampling === void 0) { sampling = Texture.BILINEAR_SAMPLINGMODE; }
1199
- if (adaptiveScaling === void 0) { adaptiveScaling = false; }
1200
- var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
1201
- // Display
1202
- var resultScene = result.getScene();
1203
- var layer = new Layer(name + "_layer", null, resultScene, !foreground);
1204
- layer.texture = result;
1205
- result._layerToDispose = layer;
1206
- result._isFullscreen = true;
1207
- if (adaptiveScaling && resultScene) {
1208
- var newScale = 1 / resultScene.getEngine().getHardwareScalingLevel();
1209
- result._rootContainer.scaleX = newScale;
1210
- result._rootContainer.scaleY = newScale;
1211
- }
1212
- // Attach
1213
- result.attach();
1214
- return result;
1215
- };
1216
- /**
1217
- * Scales the texture
1218
- * @param ratio the scale factor to apply to both width and height
1219
- */
1220
- AdvancedDynamicTexture.prototype.scale = function (ratio) {
1221
- _super.prototype.scale.call(this, ratio);
1222
- this.markAsDirty();
1223
- };
1224
- /**
1225
- * Resizes the texture
1226
- * @param width the new width
1227
- * @param height the new height
1228
- */
1229
- AdvancedDynamicTexture.prototype.scaleTo = function (width, height) {
1230
- _super.prototype.scaleTo.call(this, width, height);
1231
- this.markAsDirty();
1232
- };
1233
- /** Define the Uurl to load snippets */
1234
- AdvancedDynamicTexture.SnippetUrl = "https://snippet.babylonjs.com";
1235
- /** Indicates if some optimizations can be performed in GUI GPU management (the downside is additional memory/GPU texture memory used) */
1236
- AdvancedDynamicTexture.AllowGPUOptimizations = true;
1237
- return AdvancedDynamicTexture;
1238
- }(DynamicTexture));
1239
- export { AdvancedDynamicTexture };
1
+ import { __extends } from "tslib";
2
+ import { Observable } from "@babylonjs/core/Misc/observable.js";
3
+ import { Vector2, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
4
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
5
+ import { PointerEventTypes } from "@babylonjs/core/Events/pointerEvents.js";
6
+ import { ClipboardEventTypes, ClipboardInfo } from "@babylonjs/core/Events/clipboardEvents.js";
7
+ import { KeyboardEventTypes } from "@babylonjs/core/Events/keyboardEvents.js";
8
+ import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
9
+ import { DynamicTexture } from "@babylonjs/core/Materials/Textures/dynamicTexture.js";
10
+ import { Layer } from "@babylonjs/core/Layers/layer.js";
11
+ import { Container } from "./controls/container";
12
+ import { Control } from "./controls/control";
13
+ import { Style } from "./style";
14
+ import { Measure } from "./measure";
15
+ import { Constants } from "@babylonjs/core/Engines/constants.js";
16
+ import { Viewport } from "@babylonjs/core/Maths/math.viewport.js";
17
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
18
+ import { WebRequest } from "@babylonjs/core/Misc/webRequest.js";
19
+ import { RandomGUID } from "@babylonjs/core/Misc/guid.js";
20
+ import { GetClass } from "@babylonjs/core/Misc/typeStore.js";
21
+ /**
22
+ * Class used to create texture to support 2D GUI elements
23
+ * @see https://doc.babylonjs.com/how_to/gui
24
+ */
25
+ var AdvancedDynamicTexture = /** @class */ (function (_super) {
26
+ __extends(AdvancedDynamicTexture, _super);
27
+ /**
28
+ * Creates a new AdvancedDynamicTexture
29
+ * @param name defines the name of the texture
30
+ * @param width defines the width of the texture
31
+ * @param height defines the height of the texture
32
+ * @param scene defines the hosting scene
33
+ * @param generateMipMaps defines a boolean indicating if mipmaps must be generated (false by default)
34
+ * @param samplingMode defines the texture sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
35
+ * @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
36
+ */
37
+ function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode, invertY) {
38
+ if (width === void 0) { width = 0; }
39
+ if (height === void 0) { height = 0; }
40
+ if (generateMipMaps === void 0) { generateMipMaps = false; }
41
+ if (samplingMode === void 0) { samplingMode = Texture.NEAREST_SAMPLINGMODE; }
42
+ if (invertY === void 0) { invertY = true; }
43
+ var _this = _super.call(this, name, { width: width, height: height }, scene, generateMipMaps, samplingMode, Constants.TEXTUREFORMAT_RGBA, invertY) || this;
44
+ _this._isDirty = false;
45
+ /** @hidden */
46
+ _this._rootContainer = new Container("root");
47
+ /** @hidden */
48
+ _this._lastControlOver = {};
49
+ /** @hidden */
50
+ _this._lastControlDown = {};
51
+ /** @hidden */
52
+ _this._capturingControl = {};
53
+ /** @hidden */
54
+ _this._linkedControls = new Array();
55
+ _this._isFullscreen = false;
56
+ _this._fullscreenViewport = new Viewport(0, 0, 1, 1);
57
+ _this._idealWidth = 0;
58
+ _this._idealHeight = 0;
59
+ _this._useSmallestIdeal = false;
60
+ _this._renderAtIdealSize = false;
61
+ _this._blockNextFocusCheck = false;
62
+ _this._renderScale = 1;
63
+ _this._cursorChanged = false;
64
+ _this._defaultMousePointerId = 0;
65
+ /** @hidden */
66
+ _this._numLayoutCalls = 0;
67
+ /** @hidden */
68
+ _this._numRenderCalls = 0;
69
+ /**
70
+ * Define type to string to ensure compatibility across browsers
71
+ * Safari doesn't support DataTransfer constructor
72
+ */
73
+ _this._clipboardData = "";
74
+ /**
75
+ * Observable event triggered each time an clipboard event is received from the rendering canvas
76
+ */
77
+ _this.onClipboardObservable = new Observable();
78
+ /**
79
+ * Observable event triggered each time a pointer down is intercepted by a control
80
+ */
81
+ _this.onControlPickedObservable = new Observable();
82
+ /**
83
+ * Observable event triggered before layout is evaluated
84
+ */
85
+ _this.onBeginLayoutObservable = new Observable();
86
+ /**
87
+ * Observable event triggered after the layout was evaluated
88
+ */
89
+ _this.onEndLayoutObservable = new Observable();
90
+ /**
91
+ * Observable event triggered before the texture is rendered
92
+ */
93
+ _this.onBeginRenderObservable = new Observable();
94
+ /**
95
+ * Observable event triggered after the texture was rendered
96
+ */
97
+ _this.onEndRenderObservable = new Observable();
98
+ /**
99
+ * Gets or sets a boolean defining if alpha is stored as premultiplied
100
+ */
101
+ _this.premulAlpha = false;
102
+ /**
103
+ * Gets or sets a boolean indicating that the canvas must be reverted on Y when updating the texture
104
+ */
105
+ _this.applyYInversionOnUpdate = true;
106
+ /**
107
+ * If set to true, every scene render will trigger a pointer event for the GUI
108
+ * if it is linked to a mesh or has controls linked to a mesh. This will allow
109
+ * you to catch the pointer moving around the GUI due to camera or mesh movements,
110
+ * but it has a performance cost.
111
+ */
112
+ _this.checkPointerEveryFrame = false;
113
+ _this._useInvalidateRectOptimization = true;
114
+ // Invalidated rectangle which is the combination of all invalidated controls after they have been rotated into absolute position
115
+ _this._invalidatedRectangle = null;
116
+ _this._clearMeasure = new Measure(0, 0, 0, 0);
117
+ /**
118
+ * @param rawEvt
119
+ * @hidden
120
+ */
121
+ _this._onClipboardCopy = function (rawEvt) {
122
+ var evt = rawEvt;
123
+ var ev = new ClipboardInfo(ClipboardEventTypes.COPY, evt);
124
+ _this.onClipboardObservable.notifyObservers(ev);
125
+ evt.preventDefault();
126
+ };
127
+ /**
128
+ * @param rawEvt
129
+ * @hidden
130
+ */
131
+ _this._onClipboardCut = function (rawEvt) {
132
+ var evt = rawEvt;
133
+ var ev = new ClipboardInfo(ClipboardEventTypes.CUT, evt);
134
+ _this.onClipboardObservable.notifyObservers(ev);
135
+ evt.preventDefault();
136
+ };
137
+ /**
138
+ * @param rawEvt
139
+ * @hidden
140
+ */
141
+ _this._onClipboardPaste = function (rawEvt) {
142
+ var evt = rawEvt;
143
+ var ev = new ClipboardInfo(ClipboardEventTypes.PASTE, evt);
144
+ _this.onClipboardObservable.notifyObservers(ev);
145
+ evt.preventDefault();
146
+ };
147
+ scene = _this.getScene();
148
+ if (!scene || !_this._texture) {
149
+ return _this;
150
+ }
151
+ _this.applyYInversionOnUpdate = invertY;
152
+ _this._rootElement = scene.getEngine().getInputElement();
153
+ _this._renderObserver = scene.onBeforeCameraRenderObservable.add(function (camera) { return _this._checkUpdate(camera); });
154
+ _this._preKeyboardObserver = scene.onPreKeyboardObservable.add(function (info) {
155
+ if (!_this._focusedControl) {
156
+ return;
157
+ }
158
+ if (info.type === KeyboardEventTypes.KEYDOWN) {
159
+ _this._focusedControl.processKeyboard(info.event);
160
+ }
161
+ info.skipOnPointerObservable = true;
162
+ });
163
+ _this._rootContainer._link(_this);
164
+ _this.hasAlpha = true;
165
+ if (!width || !height) {
166
+ _this._resizeObserver = scene.getEngine().onResizeObservable.add(function () { return _this._onResize(); });
167
+ _this._onResize();
168
+ }
169
+ _this._texture.isReady = true;
170
+ return _this;
171
+ }
172
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "numLayoutCalls", {
173
+ /** Gets the number of layout calls made the last time the ADT has been rendered */
174
+ get: function () {
175
+ return this._numLayoutCalls;
176
+ },
177
+ enumerable: false,
178
+ configurable: true
179
+ });
180
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "numRenderCalls", {
181
+ /** Gets the number of render calls made the last time the ADT has been rendered */
182
+ get: function () {
183
+ return this._numRenderCalls;
184
+ },
185
+ enumerable: false,
186
+ configurable: true
187
+ });
188
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
189
+ /**
190
+ * Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
191
+ * Useful when you want more antialiasing
192
+ */
193
+ get: function () {
194
+ return this._renderScale;
195
+ },
196
+ set: function (value) {
197
+ if (value === this._renderScale) {
198
+ return;
199
+ }
200
+ this._renderScale = value;
201
+ this._onResize();
202
+ },
203
+ enumerable: false,
204
+ configurable: true
205
+ });
206
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "background", {
207
+ /** Gets or sets the background color */
208
+ get: function () {
209
+ return this._background;
210
+ },
211
+ set: function (value) {
212
+ if (this._background === value) {
213
+ return;
214
+ }
215
+ this._background = value;
216
+ this.markAsDirty();
217
+ },
218
+ enumerable: false,
219
+ configurable: true
220
+ });
221
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
222
+ /**
223
+ * Gets or sets the ideal width used to design controls.
224
+ * The GUI will then rescale everything accordingly
225
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
226
+ */
227
+ get: function () {
228
+ return this._idealWidth;
229
+ },
230
+ set: function (value) {
231
+ if (this._idealWidth === value) {
232
+ return;
233
+ }
234
+ this._idealWidth = value;
235
+ this.markAsDirty();
236
+ this._rootContainer._markAllAsDirty();
237
+ },
238
+ enumerable: false,
239
+ configurable: true
240
+ });
241
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
242
+ /**
243
+ * Gets or sets the ideal height used to design controls.
244
+ * The GUI will then rescale everything accordingly
245
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
246
+ */
247
+ get: function () {
248
+ return this._idealHeight;
249
+ },
250
+ set: function (value) {
251
+ if (this._idealHeight === value) {
252
+ return;
253
+ }
254
+ this._idealHeight = value;
255
+ this.markAsDirty();
256
+ this._rootContainer._markAllAsDirty();
257
+ },
258
+ enumerable: false,
259
+ configurable: true
260
+ });
261
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
262
+ /**
263
+ * Gets or sets a boolean indicating if the smallest ideal value must be used if idealWidth and idealHeight are both set
264
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
265
+ */
266
+ get: function () {
267
+ return this._useSmallestIdeal;
268
+ },
269
+ set: function (value) {
270
+ if (this._useSmallestIdeal === value) {
271
+ return;
272
+ }
273
+ this._useSmallestIdeal = value;
274
+ this.markAsDirty();
275
+ this._rootContainer._markAllAsDirty();
276
+ },
277
+ enumerable: false,
278
+ configurable: true
279
+ });
280
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
281
+ /**
282
+ * Gets or sets a boolean indicating if adaptive scaling must be used
283
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
284
+ */
285
+ get: function () {
286
+ return this._renderAtIdealSize;
287
+ },
288
+ set: function (value) {
289
+ if (this._renderAtIdealSize === value) {
290
+ return;
291
+ }
292
+ this._renderAtIdealSize = value;
293
+ this._onResize();
294
+ },
295
+ enumerable: false,
296
+ configurable: true
297
+ });
298
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "idealRatio", {
299
+ /**
300
+ * Gets the ratio used when in "ideal mode"
301
+ * @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
302
+ * */
303
+ get: function () {
304
+ var rwidth = 0;
305
+ var rheight = 0;
306
+ if (this._idealWidth) {
307
+ rwidth = this.getSize().width / this._idealWidth;
308
+ }
309
+ if (this._idealHeight) {
310
+ rheight = this.getSize().height / this._idealHeight;
311
+ }
312
+ if (this._useSmallestIdeal && this._idealWidth && this._idealHeight) {
313
+ return window.innerWidth < window.innerHeight ? rwidth : rheight;
314
+ }
315
+ if (this._idealWidth) {
316
+ // horizontal
317
+ return rwidth;
318
+ }
319
+ if (this._idealHeight) {
320
+ // vertical
321
+ return rheight;
322
+ }
323
+ return 1;
324
+ },
325
+ enumerable: false,
326
+ configurable: true
327
+ });
328
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
329
+ /**
330
+ * Gets the underlying layer used to render the texture when in fullscreen mode
331
+ */
332
+ get: function () {
333
+ return this._layerToDispose;
334
+ },
335
+ enumerable: false,
336
+ configurable: true
337
+ });
338
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
339
+ /**
340
+ * Gets the root container control
341
+ */
342
+ get: function () {
343
+ return this._rootContainer;
344
+ },
345
+ enumerable: false,
346
+ configurable: true
347
+ });
348
+ /**
349
+ * Returns an array containing the root container.
350
+ * This is mostly used to let the Inspector introspects the ADT
351
+ * @returns an array containing the rootContainer
352
+ */
353
+ AdvancedDynamicTexture.prototype.getChildren = function () {
354
+ return [this._rootContainer];
355
+ };
356
+ /**
357
+ * Will return all controls that are inside this texture
358
+ * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
359
+ * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
360
+ * @return all child controls
361
+ */
362
+ AdvancedDynamicTexture.prototype.getDescendants = function (directDescendantsOnly, predicate) {
363
+ return this._rootContainer.getDescendants(directDescendantsOnly, predicate);
364
+ };
365
+ /**
366
+ * Will return all controls with the given type name
367
+ * @param typeName defines the type name to search for
368
+ * @returns an array of all controls found
369
+ */
370
+ AdvancedDynamicTexture.prototype.getControlsByType = function (typeName) {
371
+ return this._rootContainer.getDescendants(false, function (control) { return control.typeName === typeName; });
372
+ };
373
+ /**
374
+ * Will return the first control with the given name
375
+ * @param name defines the name to search for
376
+ * @return the first control found or null
377
+ */
378
+ AdvancedDynamicTexture.prototype.getControlByName = function (name) {
379
+ return this._getControlByKey("name", name);
380
+ };
381
+ AdvancedDynamicTexture.prototype._getControlByKey = function (key, value) {
382
+ return this._rootContainer.getDescendants().find(function (control) { return control[key] === value; }) || null;
383
+ };
384
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
385
+ /**
386
+ * Gets or sets the current focused control
387
+ */
388
+ get: function () {
389
+ return this._focusedControl;
390
+ },
391
+ set: function (control) {
392
+ if (this._focusedControl == control) {
393
+ return;
394
+ }
395
+ if (this._focusedControl) {
396
+ this._focusedControl.onBlur();
397
+ }
398
+ if (control) {
399
+ control.onFocus();
400
+ }
401
+ this._focusedControl = control;
402
+ },
403
+ enumerable: false,
404
+ configurable: true
405
+ });
406
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
407
+ /**
408
+ * Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
409
+ */
410
+ get: function () {
411
+ if (!this.layer) {
412
+ return true;
413
+ }
414
+ return !this.layer.isBackground;
415
+ },
416
+ set: function (value) {
417
+ if (!this.layer) {
418
+ return;
419
+ }
420
+ if (this.layer.isBackground === !value) {
421
+ return;
422
+ }
423
+ this.layer.isBackground = !value;
424
+ },
425
+ enumerable: false,
426
+ configurable: true
427
+ });
428
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "clipboardData", {
429
+ /**
430
+ * Gets or set information about clipboardData
431
+ */
432
+ get: function () {
433
+ return this._clipboardData;
434
+ },
435
+ set: function (value) {
436
+ this._clipboardData = value;
437
+ },
438
+ enumerable: false,
439
+ configurable: true
440
+ });
441
+ /**
442
+ * Get the current class name of the texture useful for serialization or dynamic coding.
443
+ * @returns "AdvancedDynamicTexture"
444
+ */
445
+ AdvancedDynamicTexture.prototype.getClassName = function () {
446
+ return "AdvancedDynamicTexture";
447
+ };
448
+ /**
449
+ * Function used to execute a function on all controls
450
+ * @param func defines the function to execute
451
+ * @param container defines the container where controls belong. If null the root container will be used
452
+ */
453
+ AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
454
+ if (!container) {
455
+ container = this._rootContainer;
456
+ }
457
+ func(container);
458
+ for (var _i = 0, _a = container.children; _i < _a.length; _i++) {
459
+ var child = _a[_i];
460
+ if (child.children) {
461
+ this.executeOnAllControls(func, child);
462
+ continue;
463
+ }
464
+ func(child);
465
+ }
466
+ };
467
+ Object.defineProperty(AdvancedDynamicTexture.prototype, "useInvalidateRectOptimization", {
468
+ /**
469
+ * Gets or sets a boolean indicating if the InvalidateRect optimization should be turned on
470
+ */
471
+ get: function () {
472
+ return this._useInvalidateRectOptimization;
473
+ },
474
+ set: function (value) {
475
+ this._useInvalidateRectOptimization = value;
476
+ },
477
+ enumerable: false,
478
+ configurable: true
479
+ });
480
+ /**
481
+ * Invalidates a rectangle area on the gui texture
482
+ * @param invalidMinX left most position of the rectangle to invalidate in the texture
483
+ * @param invalidMinY top most position of the rectangle to invalidate in the texture
484
+ * @param invalidMaxX right most position of the rectangle to invalidate in the texture
485
+ * @param invalidMaxY bottom most position of the rectangle to invalidate in the texture
486
+ */
487
+ AdvancedDynamicTexture.prototype.invalidateRect = function (invalidMinX, invalidMinY, invalidMaxX, invalidMaxY) {
488
+ if (!this._useInvalidateRectOptimization) {
489
+ return;
490
+ }
491
+ if (!this._invalidatedRectangle) {
492
+ this._invalidatedRectangle = new Measure(invalidMinX, invalidMinY, invalidMaxX - invalidMinX + 1, invalidMaxY - invalidMinY + 1);
493
+ }
494
+ else {
495
+ // Compute intersection
496
+ var maxX = Math.ceil(Math.max(this._invalidatedRectangle.left + this._invalidatedRectangle.width - 1, invalidMaxX));
497
+ var maxY = Math.ceil(Math.max(this._invalidatedRectangle.top + this._invalidatedRectangle.height - 1, invalidMaxY));
498
+ this._invalidatedRectangle.left = Math.floor(Math.min(this._invalidatedRectangle.left, invalidMinX));
499
+ this._invalidatedRectangle.top = Math.floor(Math.min(this._invalidatedRectangle.top, invalidMinY));
500
+ this._invalidatedRectangle.width = maxX - this._invalidatedRectangle.left + 1;
501
+ this._invalidatedRectangle.height = maxY - this._invalidatedRectangle.top + 1;
502
+ }
503
+ };
504
+ /**
505
+ * Marks the texture as dirty forcing a complete update
506
+ */
507
+ AdvancedDynamicTexture.prototype.markAsDirty = function () {
508
+ this._isDirty = true;
509
+ };
510
+ /**
511
+ * Helper function used to create a new style
512
+ * @returns a new style
513
+ * @see https://doc.babylonjs.com/how_to/gui#styles
514
+ */
515
+ AdvancedDynamicTexture.prototype.createStyle = function () {
516
+ return new Style(this);
517
+ };
518
+ /**
519
+ * Adds a new control to the root container
520
+ * @param control defines the control to add
521
+ * @returns the current texture
522
+ */
523
+ AdvancedDynamicTexture.prototype.addControl = function (control) {
524
+ this._rootContainer.addControl(control);
525
+ return this;
526
+ };
527
+ /**
528
+ * Removes a control from the root container
529
+ * @param control defines the control to remove
530
+ * @returns the current texture
531
+ */
532
+ AdvancedDynamicTexture.prototype.removeControl = function (control) {
533
+ this._rootContainer.removeControl(control);
534
+ return this;
535
+ };
536
+ /**
537
+ * Moves overlapped controls towards a position where it is not overlapping anymore.
538
+ * Please note that this method alters linkOffsetXInPixels and linkOffsetYInPixels.
539
+ * @param overlapGroup the overlap group which will be processed or undefined to process all overlap groups
540
+ * @param deltaStep the step size (speed) to reach the target non overlapping position (default 0.1)
541
+ * @param repelFactor how much is the control repelled by other controls
542
+ */
543
+ AdvancedDynamicTexture.prototype.moveToNonOverlappedPosition = function (overlapGroup, deltaStep, repelFactor) {
544
+ if (deltaStep === void 0) { deltaStep = 1; }
545
+ if (repelFactor === void 0) { repelFactor = 1; }
546
+ var controlsForGroup;
547
+ if (Array.isArray(overlapGroup)) {
548
+ controlsForGroup = overlapGroup;
549
+ }
550
+ else {
551
+ var descendants = this.getDescendants(true);
552
+ // get only the controls with an overlapGroup property set
553
+ // if the overlapGroup parameter is set, filter the controls and get only the controls belonging to that overlapGroup
554
+ controlsForGroup = overlapGroup === undefined ? descendants.filter(function (c) { return c.overlapGroup !== undefined; }) : descendants.filter(function (c) { return c.overlapGroup === overlapGroup; });
555
+ }
556
+ controlsForGroup.forEach(function (control1) {
557
+ var _a;
558
+ var velocity = Vector2.Zero();
559
+ var center = new Vector2(control1.centerX, control1.centerY);
560
+ controlsForGroup.forEach(function (control2) {
561
+ if (control1 !== control2 && AdvancedDynamicTexture._Overlaps(control1, control2)) {
562
+ // if the two controls overlaps get a direction vector from one control's center to another control's center
563
+ var diff = center.subtract(new Vector2(control2.centerX, control2.centerY));
564
+ var diffLength = diff.length();
565
+ if (diffLength > 0) {
566
+ // calculate the velocity
567
+ velocity = velocity.add(diff.normalize().scale(repelFactor / diffLength));
568
+ }
569
+ }
570
+ });
571
+ if (velocity.length() > 0) {
572
+ // move the control along the direction vector away from the overlapping control
573
+ velocity = velocity.normalize().scale(deltaStep * ((_a = control1.overlapDeltaMultiplier) !== null && _a !== void 0 ? _a : 1));
574
+ control1.linkOffsetXInPixels += velocity.x;
575
+ control1.linkOffsetYInPixels += velocity.y;
576
+ }
577
+ });
578
+ };
579
+ /**
580
+ * Release all resources
581
+ */
582
+ AdvancedDynamicTexture.prototype.dispose = function () {
583
+ var scene = this.getScene();
584
+ if (!scene) {
585
+ return;
586
+ }
587
+ this._rootElement = null;
588
+ scene.onBeforeCameraRenderObservable.remove(this._renderObserver);
589
+ if (this._resizeObserver) {
590
+ scene.getEngine().onResizeObservable.remove(this._resizeObserver);
591
+ }
592
+ if (this._pointerMoveObserver) {
593
+ scene.onPrePointerObservable.remove(this._pointerMoveObserver);
594
+ }
595
+ if (this._sceneRenderObserver) {
596
+ scene.onBeforeRenderObservable.remove(this._sceneRenderObserver);
597
+ }
598
+ if (this._pointerObserver) {
599
+ scene.onPointerObservable.remove(this._pointerObserver);
600
+ }
601
+ if (this._preKeyboardObserver) {
602
+ scene.onPreKeyboardObservable.remove(this._preKeyboardObserver);
603
+ }
604
+ if (this._canvasPointerOutObserver) {
605
+ scene.getEngine().onCanvasPointerOutObservable.remove(this._canvasPointerOutObserver);
606
+ }
607
+ if (this._canvasBlurObserver) {
608
+ scene.getEngine().onCanvasBlurObservable.remove(this._canvasBlurObserver);
609
+ }
610
+ if (this._layerToDispose) {
611
+ this._layerToDispose.texture = null;
612
+ this._layerToDispose.dispose();
613
+ this._layerToDispose = null;
614
+ }
615
+ this._rootContainer.dispose();
616
+ this.onClipboardObservable.clear();
617
+ this.onControlPickedObservable.clear();
618
+ this.onBeginRenderObservable.clear();
619
+ this.onEndRenderObservable.clear();
620
+ this.onBeginLayoutObservable.clear();
621
+ this.onEndLayoutObservable.clear();
622
+ _super.prototype.dispose.call(this);
623
+ };
624
+ AdvancedDynamicTexture.prototype._onResize = function () {
625
+ var scene = this.getScene();
626
+ if (!scene) {
627
+ return;
628
+ }
629
+ // Check size
630
+ var engine = scene.getEngine();
631
+ var textureSize = this.getSize();
632
+ var renderWidth = engine.getRenderWidth() * this._renderScale;
633
+ var renderHeight = engine.getRenderHeight() * this._renderScale;
634
+ if (this._renderAtIdealSize) {
635
+ if (this._idealWidth) {
636
+ renderHeight = (renderHeight * this._idealWidth) / renderWidth;
637
+ renderWidth = this._idealWidth;
638
+ }
639
+ else if (this._idealHeight) {
640
+ renderWidth = (renderWidth * this._idealHeight) / renderHeight;
641
+ renderHeight = this._idealHeight;
642
+ }
643
+ }
644
+ if (textureSize.width !== renderWidth || textureSize.height !== renderHeight) {
645
+ this.scaleTo(renderWidth, renderHeight);
646
+ this.markAsDirty();
647
+ if (this._idealWidth || this._idealHeight) {
648
+ this._rootContainer._markAllAsDirty();
649
+ }
650
+ }
651
+ this.invalidateRect(0, 0, textureSize.width - 1, textureSize.height - 1);
652
+ };
653
+ /** @hidden */
654
+ AdvancedDynamicTexture.prototype._getGlobalViewport = function () {
655
+ var size = this.getSize();
656
+ var globalViewPort = this._fullscreenViewport.toGlobal(size.width, size.height);
657
+ var targetX = Math.round(globalViewPort.width * (1 / this.rootContainer.scaleX));
658
+ var targetY = Math.round(globalViewPort.height * (1 / this.rootContainer.scaleY));
659
+ globalViewPort.x += (globalViewPort.width - targetX) / 2;
660
+ globalViewPort.y += (globalViewPort.height - targetY) / 2;
661
+ globalViewPort.width = targetX;
662
+ globalViewPort.height = targetY;
663
+ return globalViewPort;
664
+ };
665
+ /**
666
+ * Get screen coordinates for a vector3
667
+ * @param position defines the position to project
668
+ * @param worldMatrix defines the world matrix to use
669
+ * @returns the projected position
670
+ */
671
+ AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
672
+ var result = this.getProjectedPositionWithZ(position, worldMatrix);
673
+ return new Vector2(result.x, result.y);
674
+ };
675
+ /**
676
+ * Get screen coordinates for a vector3
677
+ * @param position defines the position to project
678
+ * @param worldMatrix defines the world matrix to use
679
+ * @returns the projected position with Z
680
+ */
681
+ AdvancedDynamicTexture.prototype.getProjectedPositionWithZ = function (position, worldMatrix) {
682
+ var scene = this.getScene();
683
+ if (!scene) {
684
+ return Vector3.Zero();
685
+ }
686
+ var globalViewport = this._getGlobalViewport();
687
+ var projectedPosition = Vector3.Project(position, worldMatrix, scene.getTransformMatrix(), globalViewport);
688
+ return new Vector3(projectedPosition.x, projectedPosition.y, projectedPosition.z);
689
+ };
690
+ AdvancedDynamicTexture.prototype._checkUpdate = function (camera) {
691
+ if (this._layerToDispose) {
692
+ if ((camera.layerMask & this._layerToDispose.layerMask) === 0) {
693
+ return;
694
+ }
695
+ }
696
+ if (this._isFullscreen && this._linkedControls.length) {
697
+ var scene = this.getScene();
698
+ if (!scene) {
699
+ return;
700
+ }
701
+ var globalViewport = this._getGlobalViewport();
702
+ var _loop_1 = function (control) {
703
+ if (!control.isVisible) {
704
+ return "continue";
705
+ }
706
+ var mesh = control._linkedMesh;
707
+ if (!mesh || mesh.isDisposed()) {
708
+ Tools.SetImmediate(function () {
709
+ control.linkWithMesh(null);
710
+ });
711
+ return "continue";
712
+ }
713
+ var position = mesh.getBoundingInfo ? mesh.getBoundingInfo().boundingSphere.center : Vector3.ZeroReadOnly;
714
+ var projectedPosition = Vector3.Project(position, mesh.getWorldMatrix(), scene.getTransformMatrix(), globalViewport);
715
+ if (projectedPosition.z < 0 || projectedPosition.z > 1) {
716
+ control.notRenderable = true;
717
+ return "continue";
718
+ }
719
+ control.notRenderable = false;
720
+ control._moveToProjectedPosition(projectedPosition);
721
+ };
722
+ for (var _i = 0, _a = this._linkedControls; _i < _a.length; _i++) {
723
+ var control = _a[_i];
724
+ _loop_1(control);
725
+ }
726
+ }
727
+ if (!this._isDirty && !this._rootContainer.isDirty) {
728
+ return;
729
+ }
730
+ this._isDirty = false;
731
+ this._render();
732
+ this.update(this.applyYInversionOnUpdate, this.premulAlpha, AdvancedDynamicTexture.AllowGPUOptimizations);
733
+ };
734
+ AdvancedDynamicTexture.prototype._render = function () {
735
+ var textureSize = this.getSize();
736
+ var renderWidth = textureSize.width;
737
+ var renderHeight = textureSize.height;
738
+ var context = this.getContext();
739
+ context.font = "18px Arial";
740
+ context.strokeStyle = "white";
741
+ // Layout
742
+ this.onBeginLayoutObservable.notifyObservers(this);
743
+ var measure = new Measure(0, 0, renderWidth, renderHeight);
744
+ this._numLayoutCalls = 0;
745
+ this._rootContainer._layout(measure, context);
746
+ this.onEndLayoutObservable.notifyObservers(this);
747
+ this._isDirty = false; // Restoring the dirty state that could have been set by controls during layout processing
748
+ // Clear
749
+ if (this._invalidatedRectangle) {
750
+ this._clearMeasure.copyFrom(this._invalidatedRectangle);
751
+ }
752
+ else {
753
+ this._clearMeasure.copyFromFloats(0, 0, renderWidth, renderHeight);
754
+ }
755
+ context.clearRect(this._clearMeasure.left, this._clearMeasure.top, this._clearMeasure.width, this._clearMeasure.height);
756
+ if (this._background) {
757
+ context.save();
758
+ context.fillStyle = this._background;
759
+ context.fillRect(this._clearMeasure.left, this._clearMeasure.top, this._clearMeasure.width, this._clearMeasure.height);
760
+ context.restore();
761
+ }
762
+ // Render
763
+ this.onBeginRenderObservable.notifyObservers(this);
764
+ this._numRenderCalls = 0;
765
+ this._rootContainer._render(context, this._invalidatedRectangle);
766
+ this.onEndRenderObservable.notifyObservers(this);
767
+ this._invalidatedRectangle = null;
768
+ };
769
+ /**
770
+ * @param cursor
771
+ * @hidden
772
+ */
773
+ AdvancedDynamicTexture.prototype._changeCursor = function (cursor) {
774
+ if (this._rootElement) {
775
+ this._rootElement.style.cursor = cursor;
776
+ this._cursorChanged = true;
777
+ }
778
+ };
779
+ /**
780
+ * @param control
781
+ * @param pointerId
782
+ * @hidden
783
+ */
784
+ AdvancedDynamicTexture.prototype._registerLastControlDown = function (control, pointerId) {
785
+ this._lastControlDown[pointerId] = control;
786
+ this.onControlPickedObservable.notifyObservers(control);
787
+ };
788
+ AdvancedDynamicTexture.prototype._doPicking = function (x, y, pi, type, pointerId, buttonIndex, deltaX, deltaY) {
789
+ var scene = this.getScene();
790
+ if (!scene) {
791
+ return;
792
+ }
793
+ var engine = scene.getEngine();
794
+ var textureSize = this.getSize();
795
+ if (this._isFullscreen) {
796
+ var camera = scene.cameraToUseForPointers || scene.activeCamera;
797
+ if (!camera) {
798
+ return;
799
+ }
800
+ var viewport = camera.viewport;
801
+ x = x * (textureSize.width / (engine.getRenderWidth() * viewport.width));
802
+ y = y * (textureSize.height / (engine.getRenderHeight() * viewport.height));
803
+ }
804
+ if (this._capturingControl[pointerId]) {
805
+ this._capturingControl[pointerId]._processObservables(type, x, y, pi, pointerId, buttonIndex);
806
+ return;
807
+ }
808
+ this._cursorChanged = false;
809
+ if (!this._rootContainer._processPicking(x, y, pi, type, pointerId, buttonIndex, deltaX, deltaY)) {
810
+ if (!scene.doNotHandleCursors) {
811
+ this._changeCursor("");
812
+ }
813
+ if (type === PointerEventTypes.POINTERMOVE) {
814
+ if (this._lastControlOver[pointerId]) {
815
+ this._lastControlOver[pointerId]._onPointerOut(this._lastControlOver[pointerId], pi);
816
+ delete this._lastControlOver[pointerId];
817
+ }
818
+ }
819
+ }
820
+ if (!this._cursorChanged && !scene.doNotHandleCursors) {
821
+ this._changeCursor("");
822
+ }
823
+ this._manageFocus();
824
+ };
825
+ /**
826
+ * @param list
827
+ * @param control
828
+ * @hidden
829
+ */
830
+ AdvancedDynamicTexture.prototype._cleanControlAfterRemovalFromList = function (list, control) {
831
+ for (var pointerId in list) {
832
+ if (!Object.prototype.hasOwnProperty.call(list, pointerId)) {
833
+ continue;
834
+ }
835
+ var lastControlOver = list[pointerId];
836
+ if (lastControlOver === control) {
837
+ delete list[pointerId];
838
+ }
839
+ }
840
+ };
841
+ /**
842
+ * @param control
843
+ * @hidden
844
+ */
845
+ AdvancedDynamicTexture.prototype._cleanControlAfterRemoval = function (control) {
846
+ this._cleanControlAfterRemovalFromList(this._lastControlDown, control);
847
+ this._cleanControlAfterRemovalFromList(this._lastControlOver, control);
848
+ };
849
+ AdvancedDynamicTexture.prototype._translateToPicking = function (scene, tempViewport, pi) {
850
+ var camera = scene.cameraToUseForPointers || scene.activeCamera;
851
+ var engine = scene.getEngine();
852
+ var originalCameraToUseForPointers = scene.cameraToUseForPointers;
853
+ if (!camera) {
854
+ tempViewport.x = 0;
855
+ tempViewport.y = 0;
856
+ tempViewport.width = engine.getRenderWidth();
857
+ tempViewport.height = engine.getRenderHeight();
858
+ }
859
+ else {
860
+ if (camera.rigCameras.length) {
861
+ // rig camera - we need to find the camera to use for this event
862
+ var rigViewport_1 = new Viewport(0, 0, 1, 1);
863
+ camera.rigCameras.forEach(function (rigCamera) {
864
+ // generate the viewport of this camera
865
+ rigCamera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), rigViewport_1);
866
+ var x = scene.pointerX / engine.getHardwareScalingLevel() - rigViewport_1.x;
867
+ var y = scene.pointerY / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - rigViewport_1.y - rigViewport_1.height);
868
+ // check if the pointer is in the camera's viewport
869
+ if (x < 0 || y < 0 || x > rigViewport_1.width || y > rigViewport_1.height) {
870
+ // out of viewport - don't use this camera
871
+ return;
872
+ }
873
+ // set the camera to use for pointers until this pointer loop is over
874
+ scene.cameraToUseForPointers = rigCamera;
875
+ // set the viewport
876
+ tempViewport.x = rigViewport_1.x;
877
+ tempViewport.y = rigViewport_1.y;
878
+ tempViewport.width = rigViewport_1.width;
879
+ tempViewport.height = rigViewport_1.height;
880
+ });
881
+ }
882
+ else {
883
+ camera.viewport.toGlobalToRef(engine.getRenderWidth(), engine.getRenderHeight(), tempViewport);
884
+ }
885
+ }
886
+ var x = scene.pointerX / engine.getHardwareScalingLevel() - tempViewport.x;
887
+ var y = scene.pointerY / engine.getHardwareScalingLevel() - (engine.getRenderHeight() - tempViewport.y - tempViewport.height);
888
+ this._shouldBlockPointer = false;
889
+ // Do picking modifies _shouldBlockPointer
890
+ if (pi) {
891
+ var pointerId = pi.event.pointerId || this._defaultMousePointerId;
892
+ this._doPicking(x, y, pi, pi.type, pointerId, pi.event.button, pi.event.deltaX, pi.event.deltaY);
893
+ // Avoid overwriting a true skipOnPointerObservable to false
894
+ if (this._shouldBlockPointer) {
895
+ pi.skipOnPointerObservable = this._shouldBlockPointer;
896
+ }
897
+ }
898
+ else {
899
+ this._doPicking(x, y, null, PointerEventTypes.POINTERMOVE, this._defaultMousePointerId, 0);
900
+ }
901
+ // if overridden by a rig camera - reset back to the original value
902
+ scene.cameraToUseForPointers = originalCameraToUseForPointers;
903
+ };
904
+ /** Attach to all scene events required to support pointer events */
905
+ AdvancedDynamicTexture.prototype.attach = function () {
906
+ var _this = this;
907
+ var scene = this.getScene();
908
+ if (!scene) {
909
+ return;
910
+ }
911
+ var tempViewport = new Viewport(0, 0, 0, 0);
912
+ this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi) {
913
+ if (scene.isPointerCaptured(pi.event.pointerId)) {
914
+ return;
915
+ }
916
+ if (pi.type !== PointerEventTypes.POINTERMOVE &&
917
+ pi.type !== PointerEventTypes.POINTERUP &&
918
+ pi.type !== PointerEventTypes.POINTERDOWN &&
919
+ pi.type !== PointerEventTypes.POINTERWHEEL) {
920
+ return;
921
+ }
922
+ if (pi.type === PointerEventTypes.POINTERMOVE && pi.event.pointerId) {
923
+ _this._defaultMousePointerId = pi.event.pointerId; // This is required to make sure we have the correct pointer ID for wheel
924
+ }
925
+ _this._translateToPicking(scene, tempViewport, pi);
926
+ });
927
+ this._attachPickingToSceneRender(scene, function () { return _this._translateToPicking(scene, tempViewport, null); }, false);
928
+ this._attachToOnPointerOut(scene);
929
+ this._attachToOnBlur(scene);
930
+ };
931
+ /**
932
+ * Register the clipboard Events onto the canvas
933
+ */
934
+ AdvancedDynamicTexture.prototype.registerClipboardEvents = function () {
935
+ self.addEventListener("copy", this._onClipboardCopy, false);
936
+ self.addEventListener("cut", this._onClipboardCut, false);
937
+ self.addEventListener("paste", this._onClipboardPaste, false);
938
+ };
939
+ /**
940
+ * Unregister the clipboard Events from the canvas
941
+ */
942
+ AdvancedDynamicTexture.prototype.unRegisterClipboardEvents = function () {
943
+ self.removeEventListener("copy", this._onClipboardCopy);
944
+ self.removeEventListener("cut", this._onClipboardCut);
945
+ self.removeEventListener("paste", this._onClipboardPaste);
946
+ };
947
+ /**
948
+ * Connect the texture to a hosting mesh to enable interactions
949
+ * @param mesh defines the mesh to attach to
950
+ * @param supportPointerMove defines a boolean indicating if pointer move events must be catched as well
951
+ */
952
+ AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
953
+ var _this = this;
954
+ if (supportPointerMove === void 0) { supportPointerMove = true; }
955
+ var scene = this.getScene();
956
+ if (!scene) {
957
+ return;
958
+ }
959
+ this._pointerObserver = scene.onPointerObservable.add(function (pi) {
960
+ if (pi.type !== PointerEventTypes.POINTERMOVE &&
961
+ pi.type !== PointerEventTypes.POINTERUP &&
962
+ pi.type !== PointerEventTypes.POINTERDOWN &&
963
+ pi.type !== PointerEventTypes.POINTERWHEEL) {
964
+ return;
965
+ }
966
+ if (pi.type === PointerEventTypes.POINTERMOVE && pi.event.pointerId) {
967
+ _this._defaultMousePointerId = pi.event.pointerId; // This is required to make sure we have the correct pointer ID for wheel
968
+ }
969
+ var pointerId = pi.event.pointerId || _this._defaultMousePointerId;
970
+ if (pi.pickInfo && pi.pickInfo.hit && pi.pickInfo.pickedMesh === mesh) {
971
+ var uv = pi.pickInfo.getTextureCoordinates();
972
+ if (uv) {
973
+ var size = _this.getSize();
974
+ _this._doPicking(uv.x * size.width, (_this.applyYInversionOnUpdate ? 1.0 - uv.y : uv.y) * size.height, pi, pi.type, pointerId, pi.event.button, pi.event.deltaX, pi.event.deltaY);
975
+ }
976
+ }
977
+ else if (pi.type === PointerEventTypes.POINTERUP) {
978
+ if (_this._lastControlDown[pointerId]) {
979
+ _this._lastControlDown[pointerId]._forcePointerUp(pointerId);
980
+ }
981
+ delete _this._lastControlDown[pointerId];
982
+ if (_this.focusedControl) {
983
+ var friendlyControls = _this.focusedControl.keepsFocusWith();
984
+ var canMoveFocus = true;
985
+ if (friendlyControls) {
986
+ for (var _i = 0, friendlyControls_1 = friendlyControls; _i < friendlyControls_1.length; _i++) {
987
+ var control = friendlyControls_1[_i];
988
+ // Same host, no need to keep the focus
989
+ if (_this === control._host) {
990
+ continue;
991
+ }
992
+ // Different hosts
993
+ var otherHost = control._host;
994
+ if (otherHost._lastControlOver[pointerId] && otherHost._lastControlOver[pointerId].isAscendant(control)) {
995
+ canMoveFocus = false;
996
+ break;
997
+ }
998
+ }
999
+ }
1000
+ if (canMoveFocus) {
1001
+ _this.focusedControl = null;
1002
+ }
1003
+ }
1004
+ }
1005
+ else if (pi.type === PointerEventTypes.POINTERMOVE) {
1006
+ if (_this._lastControlOver[pointerId]) {
1007
+ _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId], pi, true);
1008
+ }
1009
+ delete _this._lastControlOver[pointerId];
1010
+ }
1011
+ });
1012
+ mesh.enablePointerMoveEvents = supportPointerMove;
1013
+ this._attachPickingToSceneRender(scene, function () {
1014
+ var pointerId = _this._defaultMousePointerId;
1015
+ var pick = scene === null || scene === void 0 ? void 0 : scene.pick(scene.pointerX, scene.pointerY);
1016
+ if (pick && pick.hit && pick.pickedMesh === mesh) {
1017
+ var uv = pick.getTextureCoordinates();
1018
+ if (uv) {
1019
+ var size = _this.getSize();
1020
+ _this._doPicking(uv.x * size.width, (_this.applyYInversionOnUpdate ? 1.0 - uv.y : uv.y) * size.height, null, PointerEventTypes.POINTERMOVE, pointerId, 0);
1021
+ }
1022
+ }
1023
+ else {
1024
+ if (_this._lastControlOver[pointerId]) {
1025
+ _this._lastControlOver[pointerId]._onPointerOut(_this._lastControlOver[pointerId], null, true);
1026
+ }
1027
+ delete _this._lastControlOver[pointerId];
1028
+ }
1029
+ }, true);
1030
+ this._attachToOnPointerOut(scene);
1031
+ this._attachToOnBlur(scene);
1032
+ };
1033
+ /**
1034
+ * Move the focus to a specific control
1035
+ * @param control defines the control which will receive the focus
1036
+ */
1037
+ AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
1038
+ this.focusedControl = control;
1039
+ this._lastPickedControl = control;
1040
+ this._blockNextFocusCheck = true;
1041
+ };
1042
+ AdvancedDynamicTexture.prototype._manageFocus = function () {
1043
+ if (this._blockNextFocusCheck) {
1044
+ this._blockNextFocusCheck = false;
1045
+ this._lastPickedControl = this._focusedControl;
1046
+ return;
1047
+ }
1048
+ // Focus management
1049
+ if (this._focusedControl) {
1050
+ if (this._focusedControl !== this._lastPickedControl) {
1051
+ if (this._lastPickedControl.isFocusInvisible) {
1052
+ return;
1053
+ }
1054
+ this.focusedControl = null;
1055
+ }
1056
+ }
1057
+ };
1058
+ AdvancedDynamicTexture.prototype._attachPickingToSceneRender = function (scene, pickFunction, forcePicking) {
1059
+ var _this = this;
1060
+ this._sceneRenderObserver = scene.onBeforeRenderObservable.add(function () {
1061
+ if (!_this.checkPointerEveryFrame) {
1062
+ return;
1063
+ }
1064
+ if (_this._linkedControls.length > 0 || forcePicking) {
1065
+ pickFunction();
1066
+ }
1067
+ });
1068
+ };
1069
+ AdvancedDynamicTexture.prototype._attachToOnPointerOut = function (scene) {
1070
+ var _this = this;
1071
+ this._canvasPointerOutObserver = scene.getEngine().onCanvasPointerOutObservable.add(function (pointerEvent) {
1072
+ if (_this._lastControlOver[pointerEvent.pointerId]) {
1073
+ _this._lastControlOver[pointerEvent.pointerId]._onPointerOut(_this._lastControlOver[pointerEvent.pointerId], null);
1074
+ }
1075
+ delete _this._lastControlOver[pointerEvent.pointerId];
1076
+ if (_this._lastControlDown[pointerEvent.pointerId] && _this._lastControlDown[pointerEvent.pointerId] !== _this._capturingControl[pointerEvent.pointerId]) {
1077
+ _this._lastControlDown[pointerEvent.pointerId]._forcePointerUp();
1078
+ delete _this._lastControlDown[pointerEvent.pointerId];
1079
+ }
1080
+ });
1081
+ };
1082
+ AdvancedDynamicTexture.prototype._attachToOnBlur = function (scene) {
1083
+ var _this = this;
1084
+ this._canvasBlurObserver = scene.getEngine().onCanvasBlurObservable.add(function () {
1085
+ Object.entries(_this._lastControlDown).forEach(function (_a) {
1086
+ var value = _a[1];
1087
+ value._onCanvasBlur();
1088
+ });
1089
+ _this.focusedControl = null;
1090
+ _this._lastControlDown = {};
1091
+ });
1092
+ };
1093
+ /**
1094
+ * Serializes the entire GUI system
1095
+ * @returns an object with the JSON serialized data
1096
+ */
1097
+ AdvancedDynamicTexture.prototype.serializeContent = function () {
1098
+ var size = this.getSize();
1099
+ var serializationObject = {
1100
+ root: {},
1101
+ width: size.width,
1102
+ height: size.height,
1103
+ };
1104
+ this._rootContainer.serialize(serializationObject.root);
1105
+ return serializationObject;
1106
+ };
1107
+ /**
1108
+ * Recreate the content of the ADT from a JSON object
1109
+ * @param serializedObject define the JSON serialized object to restore from
1110
+ * @param scaleToSize defines whether to scale to texture to the saved size
1111
+ */
1112
+ AdvancedDynamicTexture.prototype.parseContent = function (serializedObject, scaleToSize) {
1113
+ this._rootContainer = Control.Parse(serializedObject.root, this);
1114
+ if (scaleToSize) {
1115
+ var width = serializedObject.width;
1116
+ var height = serializedObject.height;
1117
+ if (typeof width === "number" && typeof height === "number" && width >= 0 && height >= 0) {
1118
+ this.scaleTo(width, height);
1119
+ }
1120
+ else {
1121
+ // scales the GUI to a default size if none was available in the serialized content
1122
+ this.scaleTo(1920, 1080);
1123
+ }
1124
+ }
1125
+ };
1126
+ /**
1127
+ * Recreate the content of the ADT from a snippet saved by the GUI editor
1128
+ * @param snippetId defines the snippet to load
1129
+ * @param scaleToSize defines whether to scale to texture to the saved size
1130
+ * @returns a promise that will resolve on success
1131
+ */
1132
+ AdvancedDynamicTexture.prototype.parseFromSnippetAsync = function (snippetId, scaleToSize) {
1133
+ var _this = this;
1134
+ if (snippetId === "_BLANK") {
1135
+ return Promise.resolve();
1136
+ }
1137
+ return new Promise(function (resolve, reject) {
1138
+ var request = new WebRequest();
1139
+ request.addEventListener("readystatechange", function () {
1140
+ if (request.readyState == 4) {
1141
+ if (request.status == 200) {
1142
+ var snippet = JSON.parse(JSON.parse(request.responseText).jsonPayload);
1143
+ var serializationObject = JSON.parse(snippet.gui);
1144
+ _this.parseContent(serializationObject, scaleToSize);
1145
+ _this.snippetId = snippetId;
1146
+ resolve();
1147
+ }
1148
+ else {
1149
+ reject("Unable to load the snippet " + snippetId);
1150
+ }
1151
+ }
1152
+ });
1153
+ request.open("GET", AdvancedDynamicTexture.SnippetUrl + "/" + snippetId.replace(/#/g, "/"));
1154
+ request.send();
1155
+ });
1156
+ };
1157
+ /**
1158
+ * Recreate the content of the ADT from a url json
1159
+ * @param url defines the url to load
1160
+ * @param scaleToSize defines whether to scale to texture to the saved size
1161
+ * @returns a promise that will resolve on success
1162
+ */
1163
+ AdvancedDynamicTexture.prototype.parseFromURLAsync = function (url, scaleToSize) {
1164
+ var _this = this;
1165
+ if (url === "") {
1166
+ return Promise.resolve();
1167
+ }
1168
+ return new Promise(function (resolve, reject) {
1169
+ var request = new WebRequest();
1170
+ request.addEventListener("readystatechange", function () {
1171
+ if (request.readyState == 4) {
1172
+ if (request.status == 200) {
1173
+ var gui = request.responseText;
1174
+ var serializationObject = JSON.parse(gui);
1175
+ _this.parseContent(serializationObject, scaleToSize);
1176
+ resolve();
1177
+ }
1178
+ else {
1179
+ reject("Unable to load");
1180
+ }
1181
+ }
1182
+ });
1183
+ request.open("GET", url);
1184
+ request.send();
1185
+ });
1186
+ };
1187
+ // Statics
1188
+ /**
1189
+ * Compares two rectangle based controls for pixel overlap
1190
+ * @param control1 The first control to compare
1191
+ * @param control2 The second control to compare
1192
+ * @returns true if overlaps, otherwise false
1193
+ */
1194
+ AdvancedDynamicTexture._Overlaps = function (control1, control2) {
1195
+ return !(control1.centerX > control2.centerX + control2.widthInPixels ||
1196
+ control1.centerX + control1.widthInPixels < control2.centerX ||
1197
+ control1.centerY + control1.heightInPixels < control2.centerY ||
1198
+ control1.centerY > control2.centerY + control2.heightInPixels);
1199
+ };
1200
+ /**
1201
+ * Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh)
1202
+ * @param mesh defines the mesh which will receive the texture
1203
+ * @param width defines the texture width (1024 by default)
1204
+ * @param height defines the texture height (1024 by default)
1205
+ * @param supportPointerMove defines a boolean indicating if the texture must capture move events (true by default)
1206
+ * @param onlyAlphaTesting defines a boolean indicating that alpha blending will not be used (only alpha testing) (false by default)
1207
+ * @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
1208
+ * @param materialSetupCallback defines a custom way of creating and setting up the material on the mesh
1209
+ * @returns a new AdvancedDynamicTexture
1210
+ */
1211
+ AdvancedDynamicTexture.CreateForMesh = function (mesh, width, height, supportPointerMove, onlyAlphaTesting, invertY, materialSetupCallback) {
1212
+ if (width === void 0) { width = 1024; }
1213
+ if (height === void 0) { height = 1024; }
1214
+ if (supportPointerMove === void 0) { supportPointerMove = true; }
1215
+ if (onlyAlphaTesting === void 0) { onlyAlphaTesting = false; }
1216
+ if (materialSetupCallback === void 0) { materialSetupCallback = this._CreateMaterial; }
1217
+ // use a unique ID in name so serialization will work even if you create two ADTs for a single mesh
1218
+ var uniqueId = RandomGUID();
1219
+ var result = new AdvancedDynamicTexture("AdvancedDynamicTexture for ".concat(mesh.name, " [").concat(uniqueId, "]"), width, height, mesh.getScene(), true, Texture.TRILINEAR_SAMPLINGMODE, invertY);
1220
+ materialSetupCallback(mesh, uniqueId, result, onlyAlphaTesting);
1221
+ result.attachToMesh(mesh, supportPointerMove);
1222
+ return result;
1223
+ };
1224
+ AdvancedDynamicTexture._CreateMaterial = function (mesh, uniqueId, texture, onlyAlphaTesting) {
1225
+ var internalClassType = GetClass("BABYLON.StandardMaterial");
1226
+ if (!internalClassType) {
1227
+ throw "StandardMaterial needs to be imported before as it contains a side-effect required by your code.";
1228
+ }
1229
+ var material = new internalClassType("AdvancedDynamicTextureMaterial for ".concat(mesh.name, " [").concat(uniqueId, "]"), mesh.getScene());
1230
+ material.backFaceCulling = false;
1231
+ material.diffuseColor = Color3.Black();
1232
+ material.specularColor = Color3.Black();
1233
+ if (onlyAlphaTesting) {
1234
+ material.diffuseTexture = texture;
1235
+ material.emissiveTexture = texture;
1236
+ texture.hasAlpha = true;
1237
+ }
1238
+ else {
1239
+ material.emissiveTexture = texture;
1240
+ material.opacityTexture = texture;
1241
+ }
1242
+ mesh.material = material;
1243
+ };
1244
+ /**
1245
+ * Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh) BUT do not create a new material for the mesh. You will be responsible for connecting the texture
1246
+ * @param mesh defines the mesh which will receive the texture
1247
+ * @param width defines the texture width (1024 by default)
1248
+ * @param height defines the texture height (1024 by default)
1249
+ * @param supportPointerMove defines a boolean indicating if the texture must capture move events (true by default)
1250
+ * @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
1251
+ * @returns a new AdvancedDynamicTexture
1252
+ */
1253
+ AdvancedDynamicTexture.CreateForMeshTexture = function (mesh, width, height, supportPointerMove, invertY) {
1254
+ if (width === void 0) { width = 1024; }
1255
+ if (height === void 0) { height = 1024; }
1256
+ if (supportPointerMove === void 0) { supportPointerMove = true; }
1257
+ var result = new AdvancedDynamicTexture(mesh.name + " AdvancedDynamicTexture", width, height, mesh.getScene(), true, Texture.TRILINEAR_SAMPLINGMODE, invertY);
1258
+ result.attachToMesh(mesh, supportPointerMove);
1259
+ return result;
1260
+ };
1261
+ /**
1262
+ * Creates a new AdvancedDynamicTexture in fullscreen mode.
1263
+ * In this mode the texture will rely on a layer for its rendering.
1264
+ * This allows it to be treated like any other layer.
1265
+ * As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
1266
+ * LayerMask is set through advancedTexture.layer.layerMask
1267
+ * @param name defines name for the texture
1268
+ * @param foreground defines a boolean indicating if the texture must be rendered in foreground (default is true)
1269
+ * @param scene defines the hosting scene
1270
+ * @param sampling defines the texture sampling mode (Texture.BILINEAR_SAMPLINGMODE by default)
1271
+ * @param adaptiveScaling defines whether to automatically scale root to match hardwarescaling (false by default)
1272
+ * @returns a new AdvancedDynamicTexture
1273
+ */
1274
+ AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling, adaptiveScaling) {
1275
+ if (foreground === void 0) { foreground = true; }
1276
+ if (scene === void 0) { scene = null; }
1277
+ if (sampling === void 0) { sampling = Texture.BILINEAR_SAMPLINGMODE; }
1278
+ if (adaptiveScaling === void 0) { adaptiveScaling = false; }
1279
+ var result = new AdvancedDynamicTexture(name, 0, 0, scene, false, sampling);
1280
+ // Display
1281
+ var resultScene = result.getScene();
1282
+ var layer = new Layer(name + "_layer", null, resultScene, !foreground);
1283
+ layer.texture = result;
1284
+ result._layerToDispose = layer;
1285
+ result._isFullscreen = true;
1286
+ if (adaptiveScaling && resultScene) {
1287
+ var newScale = 1 / resultScene.getEngine().getHardwareScalingLevel();
1288
+ result._rootContainer.scaleX = newScale;
1289
+ result._rootContainer.scaleY = newScale;
1290
+ }
1291
+ // Attach
1292
+ result.attach();
1293
+ return result;
1294
+ };
1295
+ /**
1296
+ * Scales the texture
1297
+ * @param ratio the scale factor to apply to both width and height
1298
+ */
1299
+ AdvancedDynamicTexture.prototype.scale = function (ratio) {
1300
+ _super.prototype.scale.call(this, ratio);
1301
+ this.markAsDirty();
1302
+ };
1303
+ /**
1304
+ * Resizes the texture
1305
+ * @param width the new width
1306
+ * @param height the new height
1307
+ */
1308
+ AdvancedDynamicTexture.prototype.scaleTo = function (width, height) {
1309
+ _super.prototype.scaleTo.call(this, width, height);
1310
+ this.markAsDirty();
1311
+ };
1312
+ /** Define the Uurl to load snippets */
1313
+ AdvancedDynamicTexture.SnippetUrl = "https://snippet.babylonjs.com";
1314
+ /** Indicates if some optimizations can be performed in GUI GPU management (the downside is additional memory/GPU texture memory used) */
1315
+ AdvancedDynamicTexture.AllowGPUOptimizations = true;
1316
+ return AdvancedDynamicTexture;
1317
+ }(DynamicTexture));
1318
+ export { AdvancedDynamicTexture };
1240
1319
  //# sourceMappingURL=advancedDynamicTexture.js.map