@babylonjs/gui 5.0.0-rc.7 → 5.0.0-rc.9

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 (203) hide show
  1. package/2D/adtInstrumentation.d.ts +52 -52
  2. package/2D/adtInstrumentation.js +126 -126
  3. package/2D/advancedDynamicTexture.d.ts +448 -448
  4. package/2D/advancedDynamicTexture.js +1318 -1318
  5. package/2D/controls/button.d.ts +135 -135
  6. package/2D/controls/button.js +276 -276
  7. package/2D/controls/checkbox.d.ts +59 -59
  8. package/2D/controls/checkbox.js +188 -188
  9. package/2D/controls/colorpicker.d.ts +103 -103
  10. package/2D/controls/colorpicker.js +1417 -1417
  11. package/2D/controls/container.d.ts +175 -175
  12. package/2D/controls/container.js +570 -570
  13. package/2D/controls/control.d.ts +866 -866
  14. package/2D/controls/control.js +2433 -2433
  15. package/2D/controls/displayGrid.d.ts +53 -53
  16. package/2D/controls/displayGrid.js +245 -245
  17. package/2D/controls/ellipse.d.ts +21 -21
  18. package/2D/controls/ellipse.js +85 -85
  19. package/2D/controls/focusableButton.d.ts +59 -59
  20. package/2D/controls/focusableButton.js +99 -99
  21. package/2D/controls/focusableControl.d.ts +34 -34
  22. package/2D/controls/focusableControl.js +1 -1
  23. package/2D/controls/grid.d.ts +139 -139
  24. package/2D/controls/grid.js +529 -529
  25. package/2D/controls/image.d.ts +204 -204
  26. package/2D/controls/image.js +887 -887
  27. package/2D/controls/index.d.ts +29 -29
  28. package/2D/controls/index.js +29 -29
  29. package/2D/controls/inputPassword.d.ts +8 -8
  30. package/2D/controls/inputPassword.js +25 -25
  31. package/2D/controls/inputText.d.ts +201 -201
  32. package/2D/controls/inputText.js +1119 -1119
  33. package/2D/controls/line.d.ts +66 -66
  34. package/2D/controls/line.js +271 -271
  35. package/2D/controls/multiLine.d.ts +75 -75
  36. package/2D/controls/multiLine.js +262 -262
  37. package/2D/controls/radioButton.d.ts +49 -49
  38. package/2D/controls/radioButton.js +205 -205
  39. package/2D/controls/rectangle.d.ts +29 -29
  40. package/2D/controls/rectangle.js +150 -150
  41. package/2D/controls/scrollViewers/scrollViewer.d.ts +182 -182
  42. package/2D/controls/scrollViewers/scrollViewer.js +677 -677
  43. package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +57 -57
  44. package/2D/controls/scrollViewers/scrollViewerWindow.js +278 -278
  45. package/2D/controls/selector.d.ts +263 -263
  46. package/2D/controls/selector.js +692 -692
  47. package/2D/controls/sliders/baseSlider.d.ts +82 -82
  48. package/2D/controls/sliders/baseSlider.js +347 -347
  49. package/2D/controls/sliders/imageBasedSlider.d.ts +49 -49
  50. package/2D/controls/sliders/imageBasedSlider.js +192 -192
  51. package/2D/controls/sliders/imageScrollBar.d.ts +65 -65
  52. package/2D/controls/sliders/imageScrollBar.js +263 -263
  53. package/2D/controls/sliders/scrollBar.d.ts +38 -38
  54. package/2D/controls/sliders/scrollBar.js +143 -143
  55. package/2D/controls/sliders/slider.d.ts +35 -35
  56. package/2D/controls/sliders/slider.js +271 -271
  57. package/2D/controls/stackPanel.d.ts +64 -64
  58. package/2D/controls/stackPanel.js +246 -246
  59. package/2D/controls/statics.d.ts +6 -6
  60. package/2D/controls/statics.js +49 -49
  61. package/2D/controls/textBlock.d.ts +175 -175
  62. package/2D/controls/textBlock.js +603 -603
  63. package/2D/controls/textWrapper.d.ts +13 -13
  64. package/2D/controls/textWrapper.js +101 -101
  65. package/2D/controls/toggleButton.d.ts +117 -117
  66. package/2D/controls/toggleButton.js +268 -268
  67. package/2D/controls/virtualKeyboard.d.ts +96 -96
  68. package/2D/controls/virtualKeyboard.js +256 -256
  69. package/2D/index.d.ts +9 -9
  70. package/2D/index.js +9 -9
  71. package/2D/math2D.d.ts +117 -117
  72. package/2D/math2D.js +221 -221
  73. package/2D/measure.d.ts +77 -77
  74. package/2D/measure.js +139 -139
  75. package/2D/multiLinePoint.d.ts +47 -47
  76. package/2D/multiLinePoint.js +127 -127
  77. package/2D/style.d.ts +46 -46
  78. package/2D/style.js +97 -97
  79. package/2D/valueAndUnit.d.ts +89 -89
  80. package/2D/valueAndUnit.js +226 -226
  81. package/2D/xmlLoader.d.ts +60 -60
  82. package/2D/xmlLoader.js +348 -348
  83. package/3D/behaviors/defaultBehavior.d.ts +73 -73
  84. package/3D/behaviors/defaultBehavior.js +121 -121
  85. package/3D/controls/abstractButton3D.d.ts +15 -15
  86. package/3D/controls/abstractButton3D.js +25 -25
  87. package/3D/controls/button3D.d.ts +30 -30
  88. package/3D/controls/button3D.js +93 -93
  89. package/3D/controls/container3D.d.ts +72 -72
  90. package/3D/controls/container3D.js +139 -139
  91. package/3D/controls/contentDisplay3D.d.ts +30 -30
  92. package/3D/controls/contentDisplay3D.js +79 -79
  93. package/3D/controls/control3D.d.ts +201 -201
  94. package/3D/controls/control3D.js +445 -445
  95. package/3D/controls/cylinderPanel.d.ts +17 -17
  96. package/3D/controls/cylinderPanel.js +66 -66
  97. package/3D/controls/handMenu.d.ts +28 -28
  98. package/3D/controls/handMenu.js +47 -47
  99. package/3D/controls/holographicBackplate.d.ts +49 -49
  100. package/3D/controls/holographicBackplate.js +120 -120
  101. package/3D/controls/holographicButton.d.ts +84 -84
  102. package/3D/controls/holographicButton.js +339 -339
  103. package/3D/controls/holographicSlate.d.ts +131 -131
  104. package/3D/controls/holographicSlate.js +431 -431
  105. package/3D/controls/index.d.ts +21 -21
  106. package/3D/controls/index.js +21 -21
  107. package/3D/controls/meshButton3D.d.ts +21 -21
  108. package/3D/controls/meshButton3D.js +62 -62
  109. package/3D/controls/nearMenu.d.ts +44 -44
  110. package/3D/controls/nearMenu.js +114 -114
  111. package/3D/controls/planePanel.d.ts +9 -9
  112. package/3D/controls/planePanel.js +36 -36
  113. package/3D/controls/scatterPanel.d.ts +18 -18
  114. package/3D/controls/scatterPanel.js +108 -108
  115. package/3D/controls/slider3D.d.ts +81 -81
  116. package/3D/controls/slider3D.js +268 -268
  117. package/3D/controls/spherePanel.d.ts +17 -17
  118. package/3D/controls/spherePanel.js +67 -67
  119. package/3D/controls/stackPanel3D.d.ts +22 -22
  120. package/3D/controls/stackPanel3D.js +107 -107
  121. package/3D/controls/touchButton3D.d.ts +80 -80
  122. package/3D/controls/touchButton3D.js +233 -233
  123. package/3D/controls/touchHolographicButton.d.ts +110 -110
  124. package/3D/controls/touchHolographicButton.js +445 -445
  125. package/3D/controls/touchHolographicMenu.d.ts +61 -61
  126. package/3D/controls/touchHolographicMenu.js +149 -149
  127. package/3D/controls/touchMeshButton3D.d.ts +21 -21
  128. package/3D/controls/touchMeshButton3D.js +62 -62
  129. package/3D/controls/volumeBasedPanel.d.ts +53 -53
  130. package/3D/controls/volumeBasedPanel.js +174 -174
  131. package/3D/gizmos/gizmoHandle.d.ts +108 -108
  132. package/3D/gizmos/gizmoHandle.js +209 -209
  133. package/3D/gizmos/index.d.ts +2 -2
  134. package/3D/gizmos/index.js +2 -2
  135. package/3D/gizmos/slateGizmo.d.ts +57 -57
  136. package/3D/gizmos/slateGizmo.js +369 -369
  137. package/3D/gui3DManager.d.ts +94 -94
  138. package/3D/gui3DManager.js +257 -257
  139. package/3D/index.d.ts +5 -5
  140. package/3D/index.js +5 -5
  141. package/3D/materials/fluent/fluentMaterial.d.ts +90 -90
  142. package/3D/materials/fluent/fluentMaterial.js +292 -292
  143. package/3D/materials/fluent/index.d.ts +1 -1
  144. package/3D/materials/fluent/index.js +1 -1
  145. package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -5
  146. package/3D/materials/fluent/shaders/fluent.fragment.js +8 -8
  147. package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -5
  148. package/3D/materials/fluent/shaders/fluent.vertex.js +8 -8
  149. package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +154 -154
  150. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +469 -469
  151. package/3D/materials/fluentBackplate/index.d.ts +1 -1
  152. package/3D/materials/fluentBackplate/index.js +1 -1
  153. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -5
  154. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +8 -8
  155. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -5
  156. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +8 -8
  157. package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +189 -189
  158. package/3D/materials/fluentButton/fluentButtonMaterial.js +539 -539
  159. package/3D/materials/fluentButton/index.d.ts +1 -1
  160. package/3D/materials/fluentButton/index.js +1 -1
  161. package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -5
  162. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +8 -8
  163. package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -5
  164. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +8 -8
  165. package/3D/materials/fluentMaterial.d.ts +4 -4
  166. package/3D/materials/fluentMaterial.js +4 -4
  167. package/3D/materials/handle/handleMaterial.d.ts +68 -68
  168. package/3D/materials/handle/handleMaterial.js +126 -126
  169. package/3D/materials/handle/index.d.ts +1 -1
  170. package/3D/materials/handle/index.js +1 -1
  171. package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -5
  172. package/3D/materials/handle/shaders/handle.fragment.js +8 -8
  173. package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -5
  174. package/3D/materials/handle/shaders/handle.vertex.js +8 -8
  175. package/3D/materials/index.d.ts +5 -5
  176. package/3D/materials/index.js +5 -5
  177. package/3D/materials/mrdl/index.d.ts +3 -3
  178. package/3D/materials/mrdl/index.js +3 -3
  179. package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +147 -147
  180. package/3D/materials/mrdl/mrdlBackplateMaterial.js +436 -436
  181. package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +333 -333
  182. package/3D/materials/mrdl/mrdlSliderBarMaterial.js +851 -851
  183. package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +333 -333
  184. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +851 -851
  185. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -5
  186. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +8 -8
  187. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -5
  188. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +8 -8
  189. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -5
  190. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +8 -8
  191. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -5
  192. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +8 -8
  193. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -5
  194. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +8 -8
  195. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -5
  196. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +8 -8
  197. package/3D/vector3WithInfo.d.ts +16 -16
  198. package/3D/vector3WithInfo.js +23 -23
  199. package/index.d.ts +2 -2
  200. package/index.js +2 -2
  201. package/legacy/legacy.d.ts +1 -1
  202. package/legacy/legacy.js +13 -13
  203. package/package.json +2 -2
@@ -1,1319 +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 { 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.js";
12
- import { Control } from "./controls/control.js";
13
- import { Style } from "./style.js";
14
- import { Measure } from "./measure.js";
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 };
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 };
1319
1319
  //# sourceMappingURL=advancedDynamicTexture.js.map