@babylonjs/gui 5.0.0-rc.1 → 5.0.0-rc.12

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 (306) hide show
  1. package/2D/adtInstrumentation.d.ts +52 -52
  2. package/2D/adtInstrumentation.js +126 -126
  3. package/2D/adtInstrumentation.js.map +1 -1
  4. package/2D/advancedDynamicTexture.d.ts +449 -423
  5. package/2D/advancedDynamicTexture.js +1318 -1286
  6. package/2D/advancedDynamicTexture.js.map +1 -1
  7. package/2D/controls/button.d.ts +135 -97
  8. package/2D/controls/button.js +276 -238
  9. package/2D/controls/button.js.map +1 -1
  10. package/2D/controls/checkbox.d.ts +59 -51
  11. package/2D/controls/checkbox.js +188 -178
  12. package/2D/controls/checkbox.js.map +1 -1
  13. package/2D/controls/colorpicker.d.ts +103 -90
  14. package/2D/controls/colorpicker.js +1417 -1400
  15. package/2D/controls/colorpicker.js.map +1 -1
  16. package/2D/controls/container.d.ts +175 -130
  17. package/2D/controls/container.js +570 -525
  18. package/2D/controls/container.js.map +1 -1
  19. package/2D/controls/control.d.ts +866 -743
  20. package/2D/controls/control.js +2433 -2308
  21. package/2D/controls/control.js.map +1 -1
  22. package/2D/controls/displayGrid.d.ts +53 -55
  23. package/2D/controls/displayGrid.js +245 -245
  24. package/2D/controls/displayGrid.js.map +1 -1
  25. package/2D/controls/ellipse.d.ts +21 -21
  26. package/2D/controls/ellipse.js +85 -85
  27. package/2D/controls/ellipse.js.map +1 -1
  28. package/2D/controls/focusableButton.d.ts +59 -52
  29. package/2D/controls/focusableButton.js +99 -92
  30. package/2D/controls/focusableButton.js.map +1 -1
  31. package/2D/controls/focusableControl.d.ts +34 -34
  32. package/2D/controls/focusableControl.js +1 -1
  33. package/2D/controls/focusableControl.js.map +1 -1
  34. package/2D/controls/grid.d.ts +139 -135
  35. package/2D/controls/grid.js +529 -525
  36. package/2D/controls/grid.js.map +1 -1
  37. package/2D/controls/image.d.ts +204 -197
  38. package/2D/controls/image.js +887 -879
  39. package/2D/controls/image.js.map +1 -1
  40. package/2D/controls/index.d.ts +29 -29
  41. package/2D/controls/index.js +29 -29
  42. package/2D/controls/index.js.map +1 -1
  43. package/2D/controls/inputPassword.d.ts +9 -8
  44. package/2D/controls/inputPassword.js +28 -25
  45. package/2D/controls/inputPassword.js.map +1 -1
  46. package/2D/controls/inputText.d.ts +201 -182
  47. package/2D/controls/inputText.js +1119 -1096
  48. package/2D/controls/inputText.js.map +1 -1
  49. package/2D/controls/line.d.ts +66 -66
  50. package/2D/controls/line.js +271 -271
  51. package/2D/controls/line.js.map +1 -1
  52. package/2D/controls/multiLine.d.ts +75 -77
  53. package/2D/controls/multiLine.js +262 -262
  54. package/2D/controls/multiLine.js.map +1 -1
  55. package/2D/controls/radioButton.d.ts +49 -49
  56. package/2D/controls/radioButton.js +205 -205
  57. package/2D/controls/radioButton.js.map +1 -1
  58. package/2D/controls/rectangle.d.ts +29 -29
  59. package/2D/controls/rectangle.js +150 -150
  60. package/2D/controls/rectangle.js.map +1 -1
  61. package/2D/controls/scrollViewers/scrollViewer.d.ts +182 -175
  62. package/2D/controls/scrollViewers/scrollViewer.js +677 -676
  63. package/2D/controls/scrollViewers/scrollViewer.js.map +1 -1
  64. package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +57 -45
  65. package/2D/controls/scrollViewers/scrollViewerWindow.js +278 -263
  66. package/2D/controls/scrollViewers/scrollViewerWindow.js.map +1 -1
  67. package/2D/controls/selector.d.ts +263 -209
  68. package/2D/controls/selector.js +692 -629
  69. package/2D/controls/selector.js.map +1 -1
  70. package/2D/controls/sliders/baseSlider.d.ts +82 -78
  71. package/2D/controls/sliders/baseSlider.js +347 -343
  72. package/2D/controls/sliders/baseSlider.js.map +1 -1
  73. package/2D/controls/sliders/imageBasedSlider.d.ts +49 -47
  74. package/2D/controls/sliders/imageBasedSlider.js +192 -188
  75. package/2D/controls/sliders/imageBasedSlider.js.map +1 -1
  76. package/2D/controls/sliders/imageScrollBar.d.ts +65 -61
  77. package/2D/controls/sliders/imageScrollBar.js +263 -256
  78. package/2D/controls/sliders/imageScrollBar.js.map +1 -1
  79. package/2D/controls/sliders/scrollBar.d.ts +38 -34
  80. package/2D/controls/sliders/scrollBar.js +143 -136
  81. package/2D/controls/sliders/scrollBar.js.map +1 -1
  82. package/2D/controls/sliders/slider.d.ts +35 -37
  83. package/2D/controls/sliders/slider.js +271 -271
  84. package/2D/controls/sliders/slider.js.map +1 -1
  85. package/2D/controls/stackPanel.d.ts +64 -56
  86. package/2D/controls/stackPanel.js +246 -236
  87. package/2D/controls/stackPanel.js.map +1 -1
  88. package/2D/controls/statics.d.ts +6 -6
  89. package/2D/controls/statics.js +49 -47
  90. package/2D/controls/statics.js.map +1 -1
  91. package/2D/controls/textBlock.d.ts +175 -172
  92. package/2D/controls/textBlock.js +603 -598
  93. package/2D/controls/textBlock.js.map +1 -1
  94. package/2D/controls/textWrapper.d.ts +13 -13
  95. package/2D/controls/textWrapper.js +101 -101
  96. package/2D/controls/textWrapper.js.map +1 -1
  97. package/2D/controls/toggleButton.d.ts +117 -83
  98. package/2D/controls/toggleButton.js +268 -234
  99. package/2D/controls/toggleButton.js.map +1 -1
  100. package/2D/controls/virtualKeyboard.d.ts +96 -96
  101. package/2D/controls/virtualKeyboard.js +256 -256
  102. package/2D/controls/virtualKeyboard.js.map +1 -1
  103. package/2D/index.d.ts +9 -9
  104. package/2D/index.js +10 -9
  105. package/2D/index.js.map +1 -1
  106. package/2D/math2D.d.ts +117 -117
  107. package/2D/math2D.js +221 -221
  108. package/2D/math2D.js.map +1 -1
  109. package/2D/measure.d.ts +77 -77
  110. package/2D/measure.js +139 -149
  111. package/2D/measure.js.map +1 -1
  112. package/2D/multiLinePoint.d.ts +47 -47
  113. package/2D/multiLinePoint.js +127 -127
  114. package/2D/multiLinePoint.js.map +1 -1
  115. package/2D/style.d.ts +46 -46
  116. package/2D/style.js +97 -97
  117. package/2D/style.js.map +1 -1
  118. package/2D/valueAndUnit.d.ts +89 -89
  119. package/2D/valueAndUnit.js +226 -222
  120. package/2D/valueAndUnit.js.map +1 -1
  121. package/2D/xmlLoader.d.ts +60 -60
  122. package/2D/xmlLoader.js +348 -348
  123. package/2D/xmlLoader.js.map +1 -1
  124. package/3D/behaviors/defaultBehavior.d.ts +73 -73
  125. package/3D/behaviors/defaultBehavior.js +121 -121
  126. package/3D/behaviors/defaultBehavior.js.map +1 -1
  127. package/3D/controls/abstractButton3D.d.ts +15 -15
  128. package/3D/controls/abstractButton3D.js +25 -25
  129. package/3D/controls/abstractButton3D.js.map +1 -1
  130. package/3D/controls/button3D.d.ts +30 -30
  131. package/3D/controls/button3D.js +93 -93
  132. package/3D/controls/button3D.js.map +1 -1
  133. package/3D/controls/container3D.d.ts +72 -72
  134. package/3D/controls/container3D.js +139 -140
  135. package/3D/controls/container3D.js.map +1 -1
  136. package/3D/controls/contentDisplay3D.d.ts +30 -30
  137. package/3D/controls/contentDisplay3D.js +79 -78
  138. package/3D/controls/contentDisplay3D.js.map +1 -1
  139. package/3D/controls/control3D.d.ts +201 -165
  140. package/3D/controls/control3D.js +445 -408
  141. package/3D/controls/control3D.js.map +1 -1
  142. package/3D/controls/cylinderPanel.d.ts +17 -17
  143. package/3D/controls/cylinderPanel.js +66 -66
  144. package/3D/controls/cylinderPanel.js.map +1 -1
  145. package/3D/controls/handMenu.d.ts +28 -28
  146. package/3D/controls/handMenu.js +47 -47
  147. package/3D/controls/handMenu.js.map +1 -1
  148. package/3D/controls/holographicBackplate.d.ts +49 -48
  149. package/3D/controls/holographicBackplate.js +120 -120
  150. package/3D/controls/holographicBackplate.js.map +1 -1
  151. package/3D/controls/holographicButton.d.ts +84 -83
  152. package/3D/controls/holographicButton.js +339 -338
  153. package/3D/controls/holographicButton.js.map +1 -1
  154. package/3D/controls/holographicSlate.d.ts +131 -128
  155. package/3D/controls/holographicSlate.js +431 -428
  156. package/3D/controls/holographicSlate.js.map +1 -1
  157. package/3D/controls/index.d.ts +21 -21
  158. package/3D/controls/index.js +21 -21
  159. package/3D/controls/index.js.map +1 -1
  160. package/3D/controls/meshButton3D.d.ts +21 -21
  161. package/3D/controls/meshButton3D.js +62 -61
  162. package/3D/controls/meshButton3D.js.map +1 -1
  163. package/3D/controls/nearMenu.d.ts +44 -44
  164. package/3D/controls/nearMenu.js +114 -112
  165. package/3D/controls/nearMenu.js.map +1 -1
  166. package/3D/controls/planePanel.d.ts +9 -9
  167. package/3D/controls/planePanel.js +36 -36
  168. package/3D/controls/planePanel.js.map +1 -1
  169. package/3D/controls/scatterPanel.d.ts +18 -18
  170. package/3D/controls/scatterPanel.js +108 -108
  171. package/3D/controls/scatterPanel.js.map +1 -1
  172. package/3D/controls/slider3D.d.ts +81 -81
  173. package/3D/controls/slider3D.js +268 -267
  174. package/3D/controls/slider3D.js.map +1 -1
  175. package/3D/controls/spherePanel.d.ts +17 -17
  176. package/3D/controls/spherePanel.js +67 -67
  177. package/3D/controls/spherePanel.js.map +1 -1
  178. package/3D/controls/stackPanel3D.d.ts +22 -22
  179. package/3D/controls/stackPanel3D.js +107 -107
  180. package/3D/controls/stackPanel3D.js.map +1 -1
  181. package/3D/controls/touchButton3D.d.ts +80 -75
  182. package/3D/controls/touchButton3D.js +233 -227
  183. package/3D/controls/touchButton3D.js.map +1 -1
  184. package/3D/controls/touchHolographicButton.d.ts +110 -109
  185. package/3D/controls/touchHolographicButton.js +445 -445
  186. package/3D/controls/touchHolographicButton.js.map +1 -1
  187. package/3D/controls/touchHolographicMenu.d.ts +61 -61
  188. package/3D/controls/touchHolographicMenu.js +149 -148
  189. package/3D/controls/touchHolographicMenu.js.map +1 -1
  190. package/3D/controls/touchMeshButton3D.d.ts +21 -22
  191. package/3D/controls/touchMeshButton3D.js +62 -62
  192. package/3D/controls/touchMeshButton3D.js.map +1 -1
  193. package/3D/controls/volumeBasedPanel.d.ts +53 -52
  194. package/3D/controls/volumeBasedPanel.js +174 -174
  195. package/3D/controls/volumeBasedPanel.js.map +1 -1
  196. package/3D/gizmos/gizmoHandle.d.ts +108 -108
  197. package/3D/gizmos/gizmoHandle.js +209 -209
  198. package/3D/gizmos/gizmoHandle.js.map +1 -1
  199. package/3D/gizmos/index.d.ts +2 -2
  200. package/3D/gizmos/index.js +2 -2
  201. package/3D/gizmos/index.js.map +1 -1
  202. package/3D/gizmos/slateGizmo.d.ts +57 -57
  203. package/3D/gizmos/slateGizmo.js +369 -369
  204. package/3D/gizmos/slateGizmo.js.map +1 -1
  205. package/3D/gui3DManager.d.ts +94 -94
  206. package/3D/gui3DManager.js +257 -257
  207. package/3D/gui3DManager.js.map +1 -1
  208. package/3D/index.d.ts +5 -5
  209. package/3D/index.js +6 -5
  210. package/3D/index.js.map +1 -1
  211. package/3D/materials/fluent/fluentMaterial.d.ts +91 -90
  212. package/3D/materials/fluent/fluentMaterial.js +292 -281
  213. package/3D/materials/fluent/fluentMaterial.js.map +1 -1
  214. package/3D/materials/fluent/index.d.ts +1 -1
  215. package/3D/materials/fluent/index.js +1 -1
  216. package/3D/materials/fluent/index.js.map +1 -1
  217. package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -5
  218. package/3D/materials/fluent/shaders/fluent.fragment.js +8 -6
  219. package/3D/materials/fluent/shaders/fluent.fragment.js.map +1 -1
  220. package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -5
  221. package/3D/materials/fluent/shaders/fluent.vertex.js +8 -6
  222. package/3D/materials/fluent/shaders/fluent.vertex.js.map +1 -1
  223. package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +155 -154
  224. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +469 -434
  225. package/3D/materials/fluentBackplate/fluentBackplateMaterial.js.map +1 -1
  226. package/3D/materials/fluentBackplate/index.d.ts +1 -1
  227. package/3D/materials/fluentBackplate/index.js +1 -1
  228. package/3D/materials/fluentBackplate/index.js.map +1 -1
  229. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -5
  230. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +8 -6
  231. package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js.map +1 -1
  232. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -5
  233. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +8 -6
  234. package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js.map +1 -1
  235. package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +190 -189
  236. package/3D/materials/fluentButton/fluentButtonMaterial.js +539 -537
  237. package/3D/materials/fluentButton/fluentButtonMaterial.js.map +1 -1
  238. package/3D/materials/fluentButton/index.d.ts +1 -1
  239. package/3D/materials/fluentButton/index.js +1 -1
  240. package/3D/materials/fluentButton/index.js.map +1 -1
  241. package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -5
  242. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +8 -6
  243. package/3D/materials/fluentButton/shaders/fluentButton.fragment.js.map +1 -1
  244. package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -5
  245. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +8 -6
  246. package/3D/materials/fluentButton/shaders/fluentButton.vertex.js.map +1 -1
  247. package/3D/materials/fluentMaterial.d.ts +4 -4
  248. package/3D/materials/fluentMaterial.js +4 -4
  249. package/3D/materials/fluentMaterial.js.map +1 -1
  250. package/3D/materials/handle/handleMaterial.d.ts +68 -68
  251. package/3D/materials/handle/handleMaterial.js +126 -126
  252. package/3D/materials/handle/handleMaterial.js.map +1 -1
  253. package/3D/materials/handle/index.d.ts +1 -1
  254. package/3D/materials/handle/index.js +1 -1
  255. package/3D/materials/handle/index.js.map +1 -1
  256. package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -5
  257. package/3D/materials/handle/shaders/handle.fragment.js +8 -6
  258. package/3D/materials/handle/shaders/handle.fragment.js.map +1 -1
  259. package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -5
  260. package/3D/materials/handle/shaders/handle.vertex.js +8 -6
  261. package/3D/materials/handle/shaders/handle.vertex.js.map +1 -1
  262. package/3D/materials/index.d.ts +5 -5
  263. package/3D/materials/index.js +6 -5
  264. package/3D/materials/index.js.map +1 -1
  265. package/3D/materials/mrdl/index.d.ts +3 -3
  266. package/3D/materials/mrdl/index.js +3 -3
  267. package/3D/materials/mrdl/index.js.map +1 -1
  268. package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +148 -147
  269. package/3D/materials/mrdl/mrdlBackplateMaterial.js +436 -409
  270. package/3D/materials/mrdl/mrdlBackplateMaterial.js.map +1 -1
  271. package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +334 -333
  272. package/3D/materials/mrdl/mrdlSliderBarMaterial.js +851 -786
  273. package/3D/materials/mrdl/mrdlSliderBarMaterial.js.map +1 -1
  274. package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +334 -333
  275. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +851 -786
  276. package/3D/materials/mrdl/mrdlSliderThumbMaterial.js.map +1 -1
  277. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -5
  278. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +8 -6
  279. package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js.map +1 -1
  280. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -5
  281. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +8 -6
  282. package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js.map +1 -1
  283. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -5
  284. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +8 -6
  285. package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js.map +1 -1
  286. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -5
  287. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +8 -6
  288. package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js.map +1 -1
  289. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -5
  290. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +8 -6
  291. package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js.map +1 -1
  292. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -5
  293. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +8 -6
  294. package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js.map +1 -1
  295. package/3D/vector3WithInfo.d.ts +16 -16
  296. package/3D/vector3WithInfo.js +23 -23
  297. package/3D/vector3WithInfo.js.map +1 -1
  298. package/index.d.ts +2 -2
  299. package/index.js +3 -2
  300. package/index.js.map +1 -1
  301. package/legacy/legacy.d.ts +1 -1
  302. package/legacy/legacy.js +14 -13
  303. package/legacy/legacy.js.map +1 -1
  304. package/license.md +71 -0
  305. package/package.json +37 -325
  306. package/readme.md +2 -2
@@ -1,880 +1,888 @@
1
- import { __decorate, __extends } from "tslib";
2
- import { Observable } from "@babylonjs/core/Misc/observable.js";
3
- import { Tools } from "@babylonjs/core/Misc/tools.js";
4
- import { Control } from "./control.js";
5
- import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
6
- import { serialize } from "@babylonjs/core/Misc/decorators.js";
7
- import { EngineStore } from "@babylonjs/core/Engines/engineStore.js";
8
- /**
9
- * Class used to create 2D images
10
- */
11
- var Image = /** @class */ (function (_super) {
12
- __extends(Image, _super);
13
- /**
14
- * Creates a new Image
15
- * @param name defines the control name
16
- * @param url defines the image url
17
- */
18
- function Image(name, url) {
19
- if (url === void 0) { url = null; }
20
- var _this = _super.call(this, name) || this;
21
- _this.name = name;
22
- _this._workingCanvas = null;
23
- _this._loaded = false;
24
- _this._stretch = Image.STRETCH_FILL;
25
- _this._autoScale = false;
26
- _this._sourceLeft = 0;
27
- _this._sourceTop = 0;
28
- _this._sourceWidth = 0;
29
- _this._sourceHeight = 0;
30
- _this._svgAttributesComputationCompleted = false;
31
- _this._isSVG = false;
32
- _this._cellWidth = 0;
33
- _this._cellHeight = 0;
34
- _this._cellId = -1;
35
- _this._populateNinePatchSlicesFromImage = false;
36
- _this._imageDataCache = { data: null, key: "" };
37
- /**
38
- * Observable notified when the content is loaded
39
- */
40
- _this.onImageLoadedObservable = new Observable();
41
- /**
42
- * Observable notified when _sourceLeft, _sourceTop, _sourceWidth and _sourceHeight are computed
43
- */
44
- _this.onSVGAttributesComputedObservable = new Observable();
45
- _this.source = url;
46
- return _this;
47
- }
48
- Object.defineProperty(Image.prototype, "isLoaded", {
49
- /**
50
- * Gets a boolean indicating that the content is loaded
51
- */
52
- get: function () {
53
- return this._loaded;
54
- },
55
- enumerable: false,
56
- configurable: true
57
- });
58
- Object.defineProperty(Image.prototype, "detectPointerOnOpaqueOnly", {
59
- /**
60
- * Gets or sets a boolean indicating if pointers should only be validated on pixels with alpha > 0.
61
- * Beware using this as this will comsume more memory as the image has to be stored twice
62
- */
63
- get: function () {
64
- return this._detectPointerOnOpaqueOnly;
65
- },
66
- set: function (value) {
67
- if (this._detectPointerOnOpaqueOnly === value) {
68
- return;
69
- }
70
- this._detectPointerOnOpaqueOnly = value;
71
- },
72
- enumerable: false,
73
- configurable: true
74
- });
75
- Object.defineProperty(Image.prototype, "sliceLeft", {
76
- /**
77
- * Gets or sets the left value for slicing (9-patch)
78
- */
79
- get: function () {
80
- return this._sliceLeft;
81
- },
82
- set: function (value) {
83
- if (this._sliceLeft === value) {
84
- return;
85
- }
86
- this._sliceLeft = value;
87
- this._markAsDirty();
88
- },
89
- enumerable: false,
90
- configurable: true
91
- });
92
- Object.defineProperty(Image.prototype, "sliceRight", {
93
- /**
94
- * Gets or sets the right value for slicing (9-patch)
95
- */
96
- get: function () {
97
- return this._sliceRight;
98
- },
99
- set: function (value) {
100
- if (this._sliceRight === value) {
101
- return;
102
- }
103
- this._sliceRight = value;
104
- this._markAsDirty();
105
- },
106
- enumerable: false,
107
- configurable: true
108
- });
109
- Object.defineProperty(Image.prototype, "sliceTop", {
110
- /**
111
- * Gets or sets the top value for slicing (9-patch)
112
- */
113
- get: function () {
114
- return this._sliceTop;
115
- },
116
- set: function (value) {
117
- if (this._sliceTop === value) {
118
- return;
119
- }
120
- this._sliceTop = value;
121
- this._markAsDirty();
122
- },
123
- enumerable: false,
124
- configurable: true
125
- });
126
- Object.defineProperty(Image.prototype, "sliceBottom", {
127
- /**
128
- * Gets or sets the bottom value for slicing (9-patch)
129
- */
130
- get: function () {
131
- return this._sliceBottom;
132
- },
133
- set: function (value) {
134
- if (this._sliceBottom === value) {
135
- return;
136
- }
137
- this._sliceBottom = value;
138
- this._markAsDirty();
139
- },
140
- enumerable: false,
141
- configurable: true
142
- });
143
- Object.defineProperty(Image.prototype, "sourceLeft", {
144
- /**
145
- * Gets or sets the left coordinate in the source image
146
- */
147
- get: function () {
148
- return this._sourceLeft;
149
- },
150
- set: function (value) {
151
- if (this._sourceLeft === value) {
152
- return;
153
- }
154
- this._sourceLeft = value;
155
- this._markAsDirty();
156
- },
157
- enumerable: false,
158
- configurable: true
159
- });
160
- Object.defineProperty(Image.prototype, "sourceTop", {
161
- /**
162
- * Gets or sets the top coordinate in the source image
163
- */
164
- get: function () {
165
- return this._sourceTop;
166
- },
167
- set: function (value) {
168
- if (this._sourceTop === value) {
169
- return;
170
- }
171
- this._sourceTop = value;
172
- this._markAsDirty();
173
- },
174
- enumerable: false,
175
- configurable: true
176
- });
177
- Object.defineProperty(Image.prototype, "sourceWidth", {
178
- /**
179
- * Gets or sets the width to capture in the source image
180
- */
181
- get: function () {
182
- return this._sourceWidth;
183
- },
184
- set: function (value) {
185
- if (this._sourceWidth === value) {
186
- return;
187
- }
188
- this._sourceWidth = value;
189
- this._markAsDirty();
190
- },
191
- enumerable: false,
192
- configurable: true
193
- });
194
- Object.defineProperty(Image.prototype, "sourceHeight", {
195
- /**
196
- * Gets or sets the height to capture in the source image
197
- */
198
- get: function () {
199
- return this._sourceHeight;
200
- },
201
- set: function (value) {
202
- if (this._sourceHeight === value) {
203
- return;
204
- }
205
- this._sourceHeight = value;
206
- this._markAsDirty();
207
- },
208
- enumerable: false,
209
- configurable: true
210
- });
211
- Object.defineProperty(Image.prototype, "imageWidth", {
212
- /**
213
- * Gets the image width
214
- */
215
- get: function () {
216
- return this._imageWidth;
217
- },
218
- enumerable: false,
219
- configurable: true
220
- });
221
- Object.defineProperty(Image.prototype, "imageHeight", {
222
- /**
223
- * Gets the image height
224
- */
225
- get: function () {
226
- return this._imageHeight;
227
- },
228
- enumerable: false,
229
- configurable: true
230
- });
231
- Object.defineProperty(Image.prototype, "populateNinePatchSlicesFromImage", {
232
- /**
233
- * Gets or sets a boolean indicating if nine patch slices (left, top, right, bottom) should be read from image data
234
- */
235
- get: function () {
236
- return this._populateNinePatchSlicesFromImage;
237
- },
238
- set: function (value) {
239
- if (this._populateNinePatchSlicesFromImage === value) {
240
- return;
241
- }
242
- this._populateNinePatchSlicesFromImage = value;
243
- if (this._populateNinePatchSlicesFromImage && this._loaded) {
244
- this._extractNinePatchSliceDataFromImage();
245
- }
246
- },
247
- enumerable: false,
248
- configurable: true
249
- });
250
- Object.defineProperty(Image.prototype, "isSVG", {
251
- /** Indicates if the format of the image is SVG */
252
- get: function () {
253
- return this._isSVG;
254
- },
255
- enumerable: false,
256
- configurable: true
257
- });
258
- Object.defineProperty(Image.prototype, "svgAttributesComputationCompleted", {
259
- /** Gets the status of the SVG attributes computation (sourceLeft, sourceTop, sourceWidth, sourceHeight) */
260
- get: function () {
261
- return this._svgAttributesComputationCompleted;
262
- },
263
- enumerable: false,
264
- configurable: true
265
- });
266
- Object.defineProperty(Image.prototype, "autoScale", {
267
- /**
268
- * Gets or sets a boolean indicating if the image can force its container to adapt its size
269
- * @see https://doc.babylonjs.com/how_to/gui#image
270
- */
271
- get: function () {
272
- return this._autoScale;
273
- },
274
- set: function (value) {
275
- if (this._autoScale === value) {
276
- return;
277
- }
278
- this._autoScale = value;
279
- if (value && this._loaded) {
280
- this.synchronizeSizeWithContent();
281
- }
282
- },
283
- enumerable: false,
284
- configurable: true
285
- });
286
- Object.defineProperty(Image.prototype, "stretch", {
287
- /** Gets or sets the streching mode used by the image */
288
- get: function () {
289
- return this._stretch;
290
- },
291
- set: function (value) {
292
- if (this._stretch === value) {
293
- return;
294
- }
295
- this._stretch = value;
296
- this._markAsDirty();
297
- },
298
- enumerable: false,
299
- configurable: true
300
- });
301
- /** @hidden */
302
- Image.prototype._rotate90 = function (n, preserveProperties) {
303
- var _a, _b;
304
- if (preserveProperties === void 0) { preserveProperties = false; }
305
- var width = this._domImage.width;
306
- var height = this._domImage.height;
307
- // Should abstract platform instead of using LastCreatedEngine
308
- var engine = ((_b = (_a = this._host) === null || _a === void 0 ? void 0 : _a.getScene()) === null || _b === void 0 ? void 0 : _b.getEngine()) || EngineStore.LastCreatedEngine;
309
- if (!engine) {
310
- throw new Error("Invalid engine. Unable to create a canvas.");
311
- }
312
- var canvas = engine.createCanvas(height, width);
313
- var context = canvas.getContext("2d");
314
- context.translate(canvas.width / 2, canvas.height / 2);
315
- context.rotate((n * Math.PI) / 2);
316
- context.drawImage(this._domImage, 0, 0, width, height, -width / 2, -height / 2, width, height);
317
- var dataUrl = canvas.toDataURL("image/jpg");
318
- var rotatedImage = new Image(this.name + "rotated", dataUrl);
319
- if (preserveProperties) {
320
- rotatedImage._stretch = this._stretch;
321
- rotatedImage._autoScale = this._autoScale;
322
- rotatedImage._cellId = this._cellId;
323
- rotatedImage._cellWidth = n % 1 ? this._cellHeight : this._cellWidth;
324
- rotatedImage._cellHeight = n % 1 ? this._cellWidth : this._cellHeight;
325
- }
326
- this._handleRotationForSVGImage(this, rotatedImage, n);
327
- this._imageDataCache.data = null;
328
- return rotatedImage;
329
- };
330
- Image.prototype._handleRotationForSVGImage = function (srcImage, dstImage, n) {
331
- var _this = this;
332
- if (!srcImage._isSVG) {
333
- return;
334
- }
335
- if (srcImage._svgAttributesComputationCompleted) {
336
- this._rotate90SourceProperties(srcImage, dstImage, n);
337
- this._markAsDirty();
338
- }
339
- else {
340
- srcImage.onSVGAttributesComputedObservable.addOnce(function () {
341
- _this._rotate90SourceProperties(srcImage, dstImage, n);
342
- _this._markAsDirty();
343
- });
344
- }
345
- };
346
- Image.prototype._rotate90SourceProperties = function (srcImage, dstImage, n) {
347
- var _a, _b;
348
- var srcLeft = srcImage.sourceLeft, srcTop = srcImage.sourceTop, srcWidth = srcImage.domImage.width, srcHeight = srcImage.domImage.height;
349
- var dstLeft = srcLeft, dstTop = srcTop, dstWidth = srcImage.sourceWidth, dstHeight = srcImage.sourceHeight;
350
- if (n != 0) {
351
- var mult = n < 0 ? -1 : 1;
352
- n = n % 4;
353
- for (var i = 0; i < Math.abs(n); ++i) {
354
- dstLeft = -(srcTop - srcHeight / 2) * mult + srcHeight / 2;
355
- dstTop = (srcLeft - srcWidth / 2) * mult + srcWidth / 2;
356
- _a = [dstHeight, dstWidth], dstWidth = _a[0], dstHeight = _a[1];
357
- if (n < 0) {
358
- dstTop -= dstHeight;
359
- }
360
- else {
361
- dstLeft -= dstWidth;
362
- }
363
- srcLeft = dstLeft;
364
- srcTop = dstTop;
365
- _b = [srcHeight, srcWidth], srcWidth = _b[0], srcHeight = _b[1];
366
- }
367
- }
368
- dstImage.sourceLeft = dstLeft;
369
- dstImage.sourceTop = dstTop;
370
- dstImage.sourceWidth = dstWidth;
371
- dstImage.sourceHeight = dstHeight;
372
- };
373
- Image.prototype._extractNinePatchSliceDataFromImage = function () {
374
- var _a, _b;
375
- var width = this._domImage.width;
376
- var height = this._domImage.height;
377
- if (!this._workingCanvas) {
378
- var engine = ((_b = (_a = this._host) === null || _a === void 0 ? void 0 : _a.getScene()) === null || _b === void 0 ? void 0 : _b.getEngine()) || EngineStore.LastCreatedEngine;
379
- if (!engine) {
380
- throw new Error("Invalid engine. Unable to create a canvas.");
381
- }
382
- this._workingCanvas = engine.createCanvas(width, height);
383
- }
384
- var canvas = this._workingCanvas;
385
- var context = canvas.getContext("2d");
386
- context.drawImage(this._domImage, 0, 0, width, height);
387
- var imageData = context.getImageData(0, 0, width, height);
388
- // Left and right
389
- this._sliceLeft = -1;
390
- this._sliceRight = -1;
391
- for (var x = 0; x < width; x++) {
392
- var alpha = imageData.data[x * 4 + 3];
393
- if (alpha > 127 && this._sliceLeft === -1) {
394
- this._sliceLeft = x;
395
- continue;
396
- }
397
- if (alpha < 127 && this._sliceLeft > -1) {
398
- this._sliceRight = x;
399
- break;
400
- }
401
- }
402
- // top and bottom
403
- this._sliceTop = -1;
404
- this._sliceBottom = -1;
405
- for (var y = 0; y < height; y++) {
406
- var alpha = imageData.data[y * width * 4 + 3];
407
- if (alpha > 127 && this._sliceTop === -1) {
408
- this._sliceTop = y;
409
- continue;
410
- }
411
- if (alpha < 127 && this._sliceTop > -1) {
412
- this._sliceBottom = y;
413
- break;
414
- }
415
- }
416
- };
417
- Object.defineProperty(Image.prototype, "domImage", {
418
- get: function () {
419
- return this._domImage;
420
- },
421
- /**
422
- * Gets or sets the internal DOM image used to render the control
423
- */
424
- set: function (value) {
425
- var _this = this;
426
- this._domImage = value;
427
- this._loaded = false;
428
- this._imageDataCache.data = null;
429
- if (this._domImage.width) {
430
- this._onImageLoaded();
431
- }
432
- else {
433
- this._domImage.onload = function () {
434
- _this._onImageLoaded();
435
- };
436
- }
437
- },
438
- enumerable: false,
439
- configurable: true
440
- });
441
- Image.prototype._onImageLoaded = function () {
442
- this._imageDataCache.data = null;
443
- this._imageWidth = this._domImage.width;
444
- this._imageHeight = this._domImage.height;
445
- this._loaded = true;
446
- if (this._populateNinePatchSlicesFromImage) {
447
- this._extractNinePatchSliceDataFromImage();
448
- }
449
- if (this._autoScale) {
450
- this.synchronizeSizeWithContent();
451
- }
452
- this.onImageLoadedObservable.notifyObservers(this);
453
- this._markAsDirty();
454
- };
455
- Object.defineProperty(Image.prototype, "source", {
456
- /**
457
- * Gets the image source url
458
- */
459
- get: function () {
460
- return this._source;
461
- },
462
- /**
463
- * Gets or sets image source url
464
- */
465
- set: function (value) {
466
- var _this = this;
467
- var _a, _b;
468
- if (this._source === value) {
469
- return;
470
- }
471
- this._loaded = false;
472
- this._source = value;
473
- this._imageDataCache.data = null;
474
- if (value) {
475
- value = this._svgCheck(value);
476
- }
477
- // Should abstract platform instead of using LastCreatedEngine
478
- var engine = ((_b = (_a = this._host) === null || _a === void 0 ? void 0 : _a.getScene()) === null || _b === void 0 ? void 0 : _b.getEngine()) || EngineStore.LastCreatedEngine;
479
- if (!engine) {
480
- throw new Error("Invalid engine. Unable to create a canvas.");
481
- }
482
- this._domImage = engine.createCanvasImage();
483
- this._domImage.onload = function () {
484
- _this._onImageLoaded();
485
- };
486
- if (value) {
487
- Tools.SetCorsBehavior(value, this._domImage);
488
- this._domImage.src = value;
489
- }
490
- },
491
- enumerable: false,
492
- configurable: true
493
- });
494
- /**
495
- * Checks for svg document with icon id present
496
- */
497
- Image.prototype._svgCheck = function (value) {
498
- var _this = this;
499
- if (window.SVGSVGElement && value.search(/.svg#/gi) !== -1 && value.indexOf("#") === value.lastIndexOf("#")) {
500
- this._isSVG = true;
501
- var svgsrc = value.split("#")[0];
502
- var elemid = value.split("#")[1];
503
- // check if object alr exist in document
504
- var svgExist = document.body.querySelector('object[data="' + svgsrc + '"]');
505
- if (svgExist) {
506
- var svgDoc = svgExist.contentDocument;
507
- // get viewbox width and height, get svg document width and height in px
508
- if (svgDoc && svgDoc.documentElement) {
509
- var vb = svgDoc.documentElement.getAttribute("viewBox");
510
- var docwidth = Number(svgDoc.documentElement.getAttribute("width"));
511
- var docheight = Number(svgDoc.documentElement.getAttribute("height"));
512
- var elem = svgDoc.getElementById(elemid);
513
- if (elem && vb && docwidth && docheight) {
514
- this._getSVGAttribs(svgExist, elemid);
515
- return value;
516
- }
517
- }
518
- // wait for object to load
519
- svgExist.addEventListener("load", function () {
520
- _this._getSVGAttribs(svgExist, elemid);
521
- });
522
- }
523
- else {
524
- // create document object
525
- var svgImage = document.createElement("object");
526
- svgImage.data = svgsrc;
527
- svgImage.type = "image/svg+xml";
528
- svgImage.width = "0%";
529
- svgImage.height = "0%";
530
- document.body.appendChild(svgImage);
531
- // when the object has loaded, get the element attribs
532
- svgImage.onload = function () {
533
- var svgobj = document.body.querySelector('object[data="' + svgsrc + '"]');
534
- if (svgobj) {
535
- _this._getSVGAttribs(svgobj, elemid);
536
- }
537
- };
538
- }
539
- return svgsrc;
540
- }
541
- else {
542
- return value;
543
- }
544
- };
545
- /**
546
- * Sets sourceLeft, sourceTop, sourceWidth, sourceHeight automatically
547
- * given external svg file and icon id
548
- */
549
- Image.prototype._getSVGAttribs = function (svgsrc, elemid) {
550
- var svgDoc = svgsrc.contentDocument;
551
- // get viewbox width and height, get svg document width and height in px
552
- if (svgDoc && svgDoc.documentElement) {
553
- var vb = svgDoc.documentElement.getAttribute("viewBox");
554
- var docwidth = Number(svgDoc.documentElement.getAttribute("width"));
555
- var docheight = Number(svgDoc.documentElement.getAttribute("height"));
556
- // get element bbox and matrix transform
557
- var elem = svgDoc.getElementById(elemid);
558
- if (vb && docwidth && docheight && elem) {
559
- var vb_width = Number(vb.split(" ")[2]);
560
- var vb_height = Number(vb.split(" ")[3]);
561
- var elem_bbox = elem.getBBox();
562
- var elem_matrix_a = 1;
563
- var elem_matrix_d = 1;
564
- var elem_matrix_e = 0;
565
- var elem_matrix_f = 0;
566
- var mainMatrix = elem.transform.baseVal.consolidate().matrix;
567
- if (elem.transform && elem.transform.baseVal.consolidate()) {
568
- elem_matrix_a = mainMatrix.a;
569
- elem_matrix_d = mainMatrix.d;
570
- elem_matrix_e = mainMatrix.e;
571
- elem_matrix_f = mainMatrix.f;
572
- }
573
- // compute source coordinates and dimensions
574
- this.sourceLeft = ((elem_matrix_a * elem_bbox.x + elem_matrix_e) * docwidth) / vb_width;
575
- this.sourceTop = ((elem_matrix_d * elem_bbox.y + elem_matrix_f) * docheight) / vb_height;
576
- this.sourceWidth = elem_bbox.width * elem_matrix_a * (docwidth / vb_width);
577
- this.sourceHeight = elem_bbox.height * elem_matrix_d * (docheight / vb_height);
578
- this._svgAttributesComputationCompleted = true;
579
- this.onSVGAttributesComputedObservable.notifyObservers(this);
580
- }
581
- }
582
- };
583
- Object.defineProperty(Image.prototype, "cellWidth", {
584
- /**
585
- * Gets or sets the cell width to use when animation sheet is enabled
586
- * @see https://doc.babylonjs.com/how_to/gui#image
587
- */
588
- get: function () {
589
- return this._cellWidth;
590
- },
591
- set: function (value) {
592
- if (this._cellWidth === value) {
593
- return;
594
- }
595
- this._cellWidth = value;
596
- this._markAsDirty();
597
- },
598
- enumerable: false,
599
- configurable: true
600
- });
601
- Object.defineProperty(Image.prototype, "cellHeight", {
602
- /**
603
- * Gets or sets the cell height to use when animation sheet is enabled
604
- * @see https://doc.babylonjs.com/how_to/gui#image
605
- */
606
- get: function () {
607
- return this._cellHeight;
608
- },
609
- set: function (value) {
610
- if (this._cellHeight === value) {
611
- return;
612
- }
613
- this._cellHeight = value;
614
- this._markAsDirty();
615
- },
616
- enumerable: false,
617
- configurable: true
618
- });
619
- Object.defineProperty(Image.prototype, "cellId", {
620
- /**
621
- * Gets or sets the cell id to use (this will turn on the animation sheet mode)
622
- * @see https://doc.babylonjs.com/how_to/gui#image
623
- */
624
- get: function () {
625
- return this._cellId;
626
- },
627
- set: function (value) {
628
- if (this._cellId === value) {
629
- return;
630
- }
631
- this._cellId = value;
632
- this._markAsDirty();
633
- },
634
- enumerable: false,
635
- configurable: true
636
- });
637
- /**
638
- * Tests if a given coordinates belong to the current control
639
- * @param x defines x coordinate to test
640
- * @param y defines y coordinate to test
641
- * @returns true if the coordinates are inside the control
642
- */
643
- Image.prototype.contains = function (x, y) {
644
- if (!_super.prototype.contains.call(this, x, y)) {
645
- return false;
646
- }
647
- if (!this._detectPointerOnOpaqueOnly || !this._workingCanvas) {
648
- return true;
649
- }
650
- var width = this._currentMeasure.width | 0;
651
- var height = this._currentMeasure.height | 0;
652
- var key = width + "_" + height;
653
- var imageData = this._imageDataCache.data;
654
- if (!imageData || this._imageDataCache.key !== key) {
655
- var canvas = this._workingCanvas;
656
- var context_1 = canvas.getContext("2d");
657
- this._imageDataCache.data = imageData = context_1.getImageData(0, 0, width, height).data;
658
- this._imageDataCache.key = key;
659
- }
660
- x = (x - this._currentMeasure.left) | 0;
661
- y = (y - this._currentMeasure.top) | 0;
662
- var pickedPixel = imageData[(x + y * width) * 4 + 3];
663
- return pickedPixel > 0;
664
- };
665
- Image.prototype._getTypeName = function () {
666
- return "Image";
667
- };
668
- /** Force the control to synchronize with its content */
669
- Image.prototype.synchronizeSizeWithContent = function () {
670
- if (!this._loaded) {
671
- return;
672
- }
673
- this.width = this._domImage.width + "px";
674
- this.height = this._domImage.height + "px";
675
- };
676
- Image.prototype._processMeasures = function (parentMeasure, context) {
677
- if (this._loaded) {
678
- switch (this._stretch) {
679
- case Image.STRETCH_NONE:
680
- break;
681
- case Image.STRETCH_FILL:
682
- break;
683
- case Image.STRETCH_UNIFORM:
684
- break;
685
- case Image.STRETCH_NINE_PATCH:
686
- break;
687
- case Image.STRETCH_EXTEND:
688
- if (this._autoScale) {
689
- this.synchronizeSizeWithContent();
690
- }
691
- if (this.parent && this.parent.parent) {
692
- // Will update root size if root is not the top root
693
- this.parent.adaptWidthToChildren = true;
694
- this.parent.adaptHeightToChildren = true;
695
- }
696
- break;
697
- }
698
- }
699
- _super.prototype._processMeasures.call(this, parentMeasure, context);
700
- };
701
- Image.prototype._prepareWorkingCanvasForOpaqueDetection = function () {
702
- var _a, _b;
703
- if (!this._detectPointerOnOpaqueOnly) {
704
- return;
705
- }
706
- var width = this._currentMeasure.width;
707
- var height = this._currentMeasure.height;
708
- if (!this._workingCanvas) {
709
- var engine = ((_b = (_a = this._host) === null || _a === void 0 ? void 0 : _a.getScene()) === null || _b === void 0 ? void 0 : _b.getEngine()) || EngineStore.LastCreatedEngine;
710
- if (!engine) {
711
- throw new Error("Invalid engine. Unable to create a canvas.");
712
- }
713
- this._workingCanvas = engine.createCanvas(width, height);
714
- }
715
- var canvas = this._workingCanvas;
716
- var context = canvas.getContext("2d");
717
- context.clearRect(0, 0, width, height);
718
- };
719
- Image.prototype._drawImage = function (context, sx, sy, sw, sh, tx, ty, tw, th) {
720
- context.drawImage(this._domImage, sx, sy, sw, sh, tx, ty, tw, th);
721
- if (!this._detectPointerOnOpaqueOnly) {
722
- return;
723
- }
724
- var canvas = this._workingCanvas;
725
- context = canvas.getContext("2d");
726
- context.drawImage(this._domImage, sx, sy, sw, sh, tx - this._currentMeasure.left, ty - this._currentMeasure.top, tw, th);
727
- };
728
- Image.prototype._draw = function (context) {
729
- context.save();
730
- if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
731
- context.shadowColor = this.shadowColor;
732
- context.shadowBlur = this.shadowBlur;
733
- context.shadowOffsetX = this.shadowOffsetX;
734
- context.shadowOffsetY = this.shadowOffsetY;
735
- }
736
- var x, y, width, height;
737
- if (this.cellId == -1) {
738
- x = this._sourceLeft;
739
- y = this._sourceTop;
740
- width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
741
- height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
742
- }
743
- else {
744
- var rowCount = this._domImage.naturalWidth / this.cellWidth;
745
- var column = (this.cellId / rowCount) >> 0;
746
- var row = this.cellId % rowCount;
747
- x = this.cellWidth * row;
748
- y = this.cellHeight * column;
749
- width = this.cellWidth;
750
- height = this.cellHeight;
751
- }
752
- this._prepareWorkingCanvasForOpaqueDetection();
753
- this._applyStates(context);
754
- if (this._loaded) {
755
- switch (this._stretch) {
756
- case Image.STRETCH_NONE:
757
- this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
758
- break;
759
- case Image.STRETCH_FILL:
760
- this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
761
- break;
762
- case Image.STRETCH_UNIFORM:
763
- var hRatio = this._currentMeasure.width / width;
764
- var vRatio = this._currentMeasure.height / height;
765
- var ratio = Math.min(hRatio, vRatio);
766
- var centerX = (this._currentMeasure.width - width * ratio) / 2;
767
- var centerY = (this._currentMeasure.height - height * ratio) / 2;
768
- this._drawImage(context, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
769
- break;
770
- case Image.STRETCH_EXTEND:
771
- this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
772
- break;
773
- case Image.STRETCH_NINE_PATCH:
774
- this._renderNinePatch(context);
775
- break;
776
- }
777
- }
778
- context.restore();
779
- };
780
- Image.prototype._renderNinePatch = function (context) {
781
- var leftWidth = this._sliceLeft;
782
- var topHeight = this._sliceTop;
783
- var bottomHeight = this._imageHeight - this._sliceBottom;
784
- var rightWidth = this._imageWidth - this._sliceRight;
785
- var centerWidth = this._sliceRight - this._sliceLeft;
786
- var centerHeight = this._sliceBottom - this._sliceTop;
787
- var targetCenterWidth = (this._currentMeasure.width - rightWidth - leftWidth) + 2;
788
- var targetCenterHeight = (this._currentMeasure.height - bottomHeight - topHeight) + 2;
789
- var centerLeftOffset = this._currentMeasure.left + leftWidth - 1;
790
- var centerTopOffset = this._currentMeasure.top + topHeight - 1;
791
- var rightOffset = this._currentMeasure.left + this._currentMeasure.width - rightWidth;
792
- var bottomOffset = this._currentMeasure.top + this._currentMeasure.height - bottomHeight;
793
- //Top Left
794
- this._drawImage(context, 0, 0, leftWidth, topHeight, this._currentMeasure.left, this._currentMeasure.top, leftWidth, topHeight);
795
- //Top
796
- this._drawImage(context, this._sliceLeft, 0, centerWidth, topHeight, centerLeftOffset, this._currentMeasure.top, targetCenterWidth, topHeight);
797
- //Top Right
798
- this._drawImage(context, this.sliceRight, 0, rightWidth, topHeight, rightOffset, this._currentMeasure.top, rightWidth, topHeight);
799
- //Left
800
- this._drawImage(context, 0, this._sliceTop, leftWidth, centerHeight, this._currentMeasure.left, centerTopOffset, leftWidth, targetCenterHeight);
801
- // Center
802
- this._drawImage(context, this._sliceLeft, this._sliceTop, centerWidth, centerHeight, centerLeftOffset, centerTopOffset, targetCenterWidth, targetCenterHeight);
803
- //Right
804
- this._drawImage(context, this._sliceRight, this._sliceTop, rightWidth, centerHeight, rightOffset, centerTopOffset, rightWidth, targetCenterHeight);
805
- //Bottom Left
806
- this._drawImage(context, 0, this._sliceBottom, leftWidth, bottomHeight, this._currentMeasure.left, bottomOffset, leftWidth, bottomHeight);
807
- //Bottom
808
- this._drawImage(context, this.sliceLeft, this._sliceBottom, centerWidth, bottomHeight, centerLeftOffset, bottomOffset, targetCenterWidth, bottomHeight);
809
- //Bottom Right
810
- this._drawImage(context, this._sliceRight, this._sliceBottom, rightWidth, bottomHeight, rightOffset, bottomOffset, rightWidth, bottomHeight);
811
- };
812
- Image.prototype.dispose = function () {
813
- _super.prototype.dispose.call(this);
814
- this.onImageLoadedObservable.clear();
815
- this.onSVGAttributesComputedObservable.clear();
816
- };
817
- // Static
818
- /** STRETCH_NONE */
819
- Image.STRETCH_NONE = 0;
820
- /** STRETCH_FILL */
821
- Image.STRETCH_FILL = 1;
822
- /** STRETCH_UNIFORM */
823
- Image.STRETCH_UNIFORM = 2;
824
- /** STRETCH_EXTEND */
825
- Image.STRETCH_EXTEND = 3;
826
- /** NINE_PATCH */
827
- Image.STRETCH_NINE_PATCH = 4;
828
- __decorate([
829
- serialize()
830
- ], Image.prototype, "detectPointerOnOpaqueOnly", null);
831
- __decorate([
832
- serialize()
833
- ], Image.prototype, "sliceLeft", null);
834
- __decorate([
835
- serialize()
836
- ], Image.prototype, "sliceRight", null);
837
- __decorate([
838
- serialize()
839
- ], Image.prototype, "sliceTop", null);
840
- __decorate([
841
- serialize()
842
- ], Image.prototype, "sliceBottom", null);
843
- __decorate([
844
- serialize()
845
- ], Image.prototype, "sourceLeft", null);
846
- __decorate([
847
- serialize()
848
- ], Image.prototype, "sourceTop", null);
849
- __decorate([
850
- serialize()
851
- ], Image.prototype, "sourceWidth", null);
852
- __decorate([
853
- serialize()
854
- ], Image.prototype, "sourceHeight", null);
855
- __decorate([
856
- serialize()
857
- ], Image.prototype, "populateNinePatchSlicesFromImage", null);
858
- __decorate([
859
- serialize()
860
- ], Image.prototype, "autoScale", null);
861
- __decorate([
862
- serialize()
863
- ], Image.prototype, "stretch", null);
864
- __decorate([
865
- serialize()
866
- ], Image.prototype, "source", null);
867
- __decorate([
868
- serialize()
869
- ], Image.prototype, "cellWidth", null);
870
- __decorate([
871
- serialize()
872
- ], Image.prototype, "cellHeight", null);
873
- __decorate([
874
- serialize()
875
- ], Image.prototype, "cellId", null);
876
- return Image;
877
- }(Control));
878
- export { Image };
879
- RegisterClass("BABYLON.GUI.Image", Image);
1
+ import { __decorate, __extends } from "tslib";
2
+ import { Observable } from "@babylonjs/core/Misc/observable.js";
3
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
4
+ import { Control } from "./control";
5
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
6
+ import { serialize } from "@babylonjs/core/Misc/decorators.js";
7
+ import { EngineStore } from "@babylonjs/core/Engines/engineStore.js";
8
+ /**
9
+ * Class used to create 2D images
10
+ */
11
+ var Image = /** @class */ (function (_super) {
12
+ __extends(Image, _super);
13
+ /**
14
+ * Creates a new Image
15
+ * @param name defines the control name
16
+ * @param url defines the image url
17
+ */
18
+ function Image(name, url) {
19
+ if (url === void 0) { url = null; }
20
+ var _this = _super.call(this, name) || this;
21
+ _this.name = name;
22
+ _this._workingCanvas = null;
23
+ _this._loaded = false;
24
+ _this._stretch = Image.STRETCH_FILL;
25
+ _this._autoScale = false;
26
+ _this._sourceLeft = 0;
27
+ _this._sourceTop = 0;
28
+ _this._sourceWidth = 0;
29
+ _this._sourceHeight = 0;
30
+ _this._svgAttributesComputationCompleted = false;
31
+ _this._isSVG = false;
32
+ _this._cellWidth = 0;
33
+ _this._cellHeight = 0;
34
+ _this._cellId = -1;
35
+ _this._populateNinePatchSlicesFromImage = false;
36
+ _this._imageDataCache = { data: null, key: "" };
37
+ /**
38
+ * Observable notified when the content is loaded
39
+ */
40
+ _this.onImageLoadedObservable = new Observable();
41
+ /**
42
+ * Observable notified when _sourceLeft, _sourceTop, _sourceWidth and _sourceHeight are computed
43
+ */
44
+ _this.onSVGAttributesComputedObservable = new Observable();
45
+ _this.source = url;
46
+ return _this;
47
+ }
48
+ Object.defineProperty(Image.prototype, "isLoaded", {
49
+ /**
50
+ * Gets a boolean indicating that the content is loaded
51
+ */
52
+ get: function () {
53
+ return this._loaded;
54
+ },
55
+ enumerable: false,
56
+ configurable: true
57
+ });
58
+ Object.defineProperty(Image.prototype, "detectPointerOnOpaqueOnly", {
59
+ /**
60
+ * Gets or sets a boolean indicating if pointers should only be validated on pixels with alpha > 0.
61
+ * Beware using this as this will consume more memory as the image has to be stored twice
62
+ */
63
+ get: function () {
64
+ return this._detectPointerOnOpaqueOnly;
65
+ },
66
+ set: function (value) {
67
+ if (this._detectPointerOnOpaqueOnly === value) {
68
+ return;
69
+ }
70
+ this._detectPointerOnOpaqueOnly = value;
71
+ },
72
+ enumerable: false,
73
+ configurable: true
74
+ });
75
+ Object.defineProperty(Image.prototype, "sliceLeft", {
76
+ /**
77
+ * Gets or sets the left value for slicing (9-patch)
78
+ */
79
+ get: function () {
80
+ return this._sliceLeft;
81
+ },
82
+ set: function (value) {
83
+ if (this._sliceLeft === value) {
84
+ return;
85
+ }
86
+ this._sliceLeft = value;
87
+ this._markAsDirty();
88
+ },
89
+ enumerable: false,
90
+ configurable: true
91
+ });
92
+ Object.defineProperty(Image.prototype, "sliceRight", {
93
+ /**
94
+ * Gets or sets the right value for slicing (9-patch)
95
+ */
96
+ get: function () {
97
+ return this._sliceRight;
98
+ },
99
+ set: function (value) {
100
+ if (this._sliceRight === value) {
101
+ return;
102
+ }
103
+ this._sliceRight = value;
104
+ this._markAsDirty();
105
+ },
106
+ enumerable: false,
107
+ configurable: true
108
+ });
109
+ Object.defineProperty(Image.prototype, "sliceTop", {
110
+ /**
111
+ * Gets or sets the top value for slicing (9-patch)
112
+ */
113
+ get: function () {
114
+ return this._sliceTop;
115
+ },
116
+ set: function (value) {
117
+ if (this._sliceTop === value) {
118
+ return;
119
+ }
120
+ this._sliceTop = value;
121
+ this._markAsDirty();
122
+ },
123
+ enumerable: false,
124
+ configurable: true
125
+ });
126
+ Object.defineProperty(Image.prototype, "sliceBottom", {
127
+ /**
128
+ * Gets or sets the bottom value for slicing (9-patch)
129
+ */
130
+ get: function () {
131
+ return this._sliceBottom;
132
+ },
133
+ set: function (value) {
134
+ if (this._sliceBottom === value) {
135
+ return;
136
+ }
137
+ this._sliceBottom = value;
138
+ this._markAsDirty();
139
+ },
140
+ enumerable: false,
141
+ configurable: true
142
+ });
143
+ Object.defineProperty(Image.prototype, "sourceLeft", {
144
+ /**
145
+ * Gets or sets the left coordinate in the source image
146
+ */
147
+ get: function () {
148
+ return this._sourceLeft;
149
+ },
150
+ set: function (value) {
151
+ if (this._sourceLeft === value) {
152
+ return;
153
+ }
154
+ this._sourceLeft = value;
155
+ this._markAsDirty();
156
+ },
157
+ enumerable: false,
158
+ configurable: true
159
+ });
160
+ Object.defineProperty(Image.prototype, "sourceTop", {
161
+ /**
162
+ * Gets or sets the top coordinate in the source image
163
+ */
164
+ get: function () {
165
+ return this._sourceTop;
166
+ },
167
+ set: function (value) {
168
+ if (this._sourceTop === value) {
169
+ return;
170
+ }
171
+ this._sourceTop = value;
172
+ this._markAsDirty();
173
+ },
174
+ enumerable: false,
175
+ configurable: true
176
+ });
177
+ Object.defineProperty(Image.prototype, "sourceWidth", {
178
+ /**
179
+ * Gets or sets the width to capture in the source image
180
+ */
181
+ get: function () {
182
+ return this._sourceWidth;
183
+ },
184
+ set: function (value) {
185
+ if (this._sourceWidth === value) {
186
+ return;
187
+ }
188
+ this._sourceWidth = value;
189
+ this._markAsDirty();
190
+ },
191
+ enumerable: false,
192
+ configurable: true
193
+ });
194
+ Object.defineProperty(Image.prototype, "sourceHeight", {
195
+ /**
196
+ * Gets or sets the height to capture in the source image
197
+ */
198
+ get: function () {
199
+ return this._sourceHeight;
200
+ },
201
+ set: function (value) {
202
+ if (this._sourceHeight === value) {
203
+ return;
204
+ }
205
+ this._sourceHeight = value;
206
+ this._markAsDirty();
207
+ },
208
+ enumerable: false,
209
+ configurable: true
210
+ });
211
+ Object.defineProperty(Image.prototype, "imageWidth", {
212
+ /**
213
+ * Gets the image width
214
+ */
215
+ get: function () {
216
+ return this._imageWidth;
217
+ },
218
+ enumerable: false,
219
+ configurable: true
220
+ });
221
+ Object.defineProperty(Image.prototype, "imageHeight", {
222
+ /**
223
+ * Gets the image height
224
+ */
225
+ get: function () {
226
+ return this._imageHeight;
227
+ },
228
+ enumerable: false,
229
+ configurable: true
230
+ });
231
+ Object.defineProperty(Image.prototype, "populateNinePatchSlicesFromImage", {
232
+ /**
233
+ * Gets or sets a boolean indicating if nine patch slices (left, top, right, bottom) should be read from image data
234
+ */
235
+ get: function () {
236
+ return this._populateNinePatchSlicesFromImage;
237
+ },
238
+ set: function (value) {
239
+ if (this._populateNinePatchSlicesFromImage === value) {
240
+ return;
241
+ }
242
+ this._populateNinePatchSlicesFromImage = value;
243
+ if (this._populateNinePatchSlicesFromImage && this._loaded) {
244
+ this._extractNinePatchSliceDataFromImage();
245
+ }
246
+ },
247
+ enumerable: false,
248
+ configurable: true
249
+ });
250
+ Object.defineProperty(Image.prototype, "isSVG", {
251
+ /** Indicates if the format of the image is SVG */
252
+ get: function () {
253
+ return this._isSVG;
254
+ },
255
+ enumerable: false,
256
+ configurable: true
257
+ });
258
+ Object.defineProperty(Image.prototype, "svgAttributesComputationCompleted", {
259
+ /** Gets the status of the SVG attributes computation (sourceLeft, sourceTop, sourceWidth, sourceHeight) */
260
+ get: function () {
261
+ return this._svgAttributesComputationCompleted;
262
+ },
263
+ enumerable: false,
264
+ configurable: true
265
+ });
266
+ Object.defineProperty(Image.prototype, "autoScale", {
267
+ /**
268
+ * Gets or sets a boolean indicating if the image can force its container to adapt its size
269
+ * @see https://doc.babylonjs.com/how_to/gui#image
270
+ */
271
+ get: function () {
272
+ return this._autoScale;
273
+ },
274
+ set: function (value) {
275
+ if (this._autoScale === value) {
276
+ return;
277
+ }
278
+ this._autoScale = value;
279
+ if (value && this._loaded) {
280
+ this.synchronizeSizeWithContent();
281
+ }
282
+ },
283
+ enumerable: false,
284
+ configurable: true
285
+ });
286
+ Object.defineProperty(Image.prototype, "stretch", {
287
+ /** Gets or sets the stretching mode used by the image */
288
+ get: function () {
289
+ return this._stretch;
290
+ },
291
+ set: function (value) {
292
+ if (this._stretch === value) {
293
+ return;
294
+ }
295
+ this._stretch = value;
296
+ this._markAsDirty();
297
+ },
298
+ enumerable: false,
299
+ configurable: true
300
+ });
301
+ /**
302
+ * @param n
303
+ * @param preserveProperties
304
+ * @hidden
305
+ */
306
+ Image.prototype._rotate90 = function (n, preserveProperties) {
307
+ var _a, _b;
308
+ if (preserveProperties === void 0) { preserveProperties = false; }
309
+ var width = this._domImage.width;
310
+ var height = this._domImage.height;
311
+ // Should abstract platform instead of using LastCreatedEngine
312
+ var engine = ((_b = (_a = this._host) === null || _a === void 0 ? void 0 : _a.getScene()) === null || _b === void 0 ? void 0 : _b.getEngine()) || EngineStore.LastCreatedEngine;
313
+ if (!engine) {
314
+ throw new Error("Invalid engine. Unable to create a canvas.");
315
+ }
316
+ var canvas = engine.createCanvas(height, width);
317
+ var context = canvas.getContext("2d");
318
+ context.translate(canvas.width / 2, canvas.height / 2);
319
+ context.rotate((n * Math.PI) / 2);
320
+ context.drawImage(this._domImage, 0, 0, width, height, -width / 2, -height / 2, width, height);
321
+ var dataUrl = canvas.toDataURL("image/jpg");
322
+ var rotatedImage = new Image(this.name + "rotated", dataUrl);
323
+ if (preserveProperties) {
324
+ rotatedImage._stretch = this._stretch;
325
+ rotatedImage._autoScale = this._autoScale;
326
+ rotatedImage._cellId = this._cellId;
327
+ rotatedImage._cellWidth = n % 1 ? this._cellHeight : this._cellWidth;
328
+ rotatedImage._cellHeight = n % 1 ? this._cellWidth : this._cellHeight;
329
+ }
330
+ this._handleRotationForSVGImage(this, rotatedImage, n);
331
+ this._imageDataCache.data = null;
332
+ return rotatedImage;
333
+ };
334
+ Image.prototype._handleRotationForSVGImage = function (srcImage, dstImage, n) {
335
+ var _this = this;
336
+ if (!srcImage._isSVG) {
337
+ return;
338
+ }
339
+ if (srcImage._svgAttributesComputationCompleted) {
340
+ this._rotate90SourceProperties(srcImage, dstImage, n);
341
+ this._markAsDirty();
342
+ }
343
+ else {
344
+ srcImage.onSVGAttributesComputedObservable.addOnce(function () {
345
+ _this._rotate90SourceProperties(srcImage, dstImage, n);
346
+ _this._markAsDirty();
347
+ });
348
+ }
349
+ };
350
+ Image.prototype._rotate90SourceProperties = function (srcImage, dstImage, n) {
351
+ var _a, _b;
352
+ var srcLeft = srcImage.sourceLeft, srcTop = srcImage.sourceTop, srcWidth = srcImage.domImage.width, srcHeight = srcImage.domImage.height;
353
+ var dstLeft = srcLeft, dstTop = srcTop, dstWidth = srcImage.sourceWidth, dstHeight = srcImage.sourceHeight;
354
+ if (n != 0) {
355
+ var mult = n < 0 ? -1 : 1;
356
+ n = n % 4;
357
+ for (var i = 0; i < Math.abs(n); ++i) {
358
+ dstLeft = -(srcTop - srcHeight / 2) * mult + srcHeight / 2;
359
+ dstTop = (srcLeft - srcWidth / 2) * mult + srcWidth / 2;
360
+ _a = [dstHeight, dstWidth], dstWidth = _a[0], dstHeight = _a[1];
361
+ if (n < 0) {
362
+ dstTop -= dstHeight;
363
+ }
364
+ else {
365
+ dstLeft -= dstWidth;
366
+ }
367
+ srcLeft = dstLeft;
368
+ srcTop = dstTop;
369
+ _b = [srcHeight, srcWidth], srcWidth = _b[0], srcHeight = _b[1];
370
+ }
371
+ }
372
+ dstImage.sourceLeft = dstLeft;
373
+ dstImage.sourceTop = dstTop;
374
+ dstImage.sourceWidth = dstWidth;
375
+ dstImage.sourceHeight = dstHeight;
376
+ };
377
+ Image.prototype._extractNinePatchSliceDataFromImage = function () {
378
+ var _a, _b;
379
+ var width = this._domImage.width;
380
+ var height = this._domImage.height;
381
+ if (!this._workingCanvas) {
382
+ var engine = ((_b = (_a = this._host) === null || _a === void 0 ? void 0 : _a.getScene()) === null || _b === void 0 ? void 0 : _b.getEngine()) || EngineStore.LastCreatedEngine;
383
+ if (!engine) {
384
+ throw new Error("Invalid engine. Unable to create a canvas.");
385
+ }
386
+ this._workingCanvas = engine.createCanvas(width, height);
387
+ }
388
+ var canvas = this._workingCanvas;
389
+ var context = canvas.getContext("2d");
390
+ context.drawImage(this._domImage, 0, 0, width, height);
391
+ var imageData = context.getImageData(0, 0, width, height);
392
+ // Left and right
393
+ this._sliceLeft = -1;
394
+ this._sliceRight = -1;
395
+ for (var x = 0; x < width; x++) {
396
+ var alpha = imageData.data[x * 4 + 3];
397
+ if (alpha > 127 && this._sliceLeft === -1) {
398
+ this._sliceLeft = x;
399
+ continue;
400
+ }
401
+ if (alpha < 127 && this._sliceLeft > -1) {
402
+ this._sliceRight = x;
403
+ break;
404
+ }
405
+ }
406
+ // top and bottom
407
+ this._sliceTop = -1;
408
+ this._sliceBottom = -1;
409
+ for (var y = 0; y < height; y++) {
410
+ var alpha = imageData.data[y * width * 4 + 3];
411
+ if (alpha > 127 && this._sliceTop === -1) {
412
+ this._sliceTop = y;
413
+ continue;
414
+ }
415
+ if (alpha < 127 && this._sliceTop > -1) {
416
+ this._sliceBottom = y;
417
+ break;
418
+ }
419
+ }
420
+ };
421
+ Object.defineProperty(Image.prototype, "domImage", {
422
+ get: function () {
423
+ return this._domImage;
424
+ },
425
+ /**
426
+ * Gets or sets the internal DOM image used to render the control
427
+ */
428
+ set: function (value) {
429
+ var _this = this;
430
+ this._domImage = value;
431
+ this._loaded = false;
432
+ this._imageDataCache.data = null;
433
+ if (this._domImage.width) {
434
+ this._onImageLoaded();
435
+ }
436
+ else {
437
+ this._domImage.onload = function () {
438
+ _this._onImageLoaded();
439
+ };
440
+ }
441
+ },
442
+ enumerable: false,
443
+ configurable: true
444
+ });
445
+ Image.prototype._onImageLoaded = function () {
446
+ this._imageDataCache.data = null;
447
+ this._imageWidth = this._domImage.width;
448
+ this._imageHeight = this._domImage.height;
449
+ this._loaded = true;
450
+ if (this._populateNinePatchSlicesFromImage) {
451
+ this._extractNinePatchSliceDataFromImage();
452
+ }
453
+ if (this._autoScale) {
454
+ this.synchronizeSizeWithContent();
455
+ }
456
+ this.onImageLoadedObservable.notifyObservers(this);
457
+ this._markAsDirty();
458
+ };
459
+ Object.defineProperty(Image.prototype, "source", {
460
+ /**
461
+ * Gets the image source url
462
+ */
463
+ get: function () {
464
+ return this._source;
465
+ },
466
+ /**
467
+ * Gets or sets image source url
468
+ */
469
+ set: function (value) {
470
+ var _this = this;
471
+ var _a, _b;
472
+ if (this._source === value) {
473
+ return;
474
+ }
475
+ this._loaded = false;
476
+ this._source = value;
477
+ this._imageDataCache.data = null;
478
+ if (value) {
479
+ value = this._svgCheck(value);
480
+ }
481
+ // Should abstract platform instead of using LastCreatedEngine
482
+ var engine = ((_b = (_a = this._host) === null || _a === void 0 ? void 0 : _a.getScene()) === null || _b === void 0 ? void 0 : _b.getEngine()) || EngineStore.LastCreatedEngine;
483
+ if (!engine) {
484
+ throw new Error("Invalid engine. Unable to create a canvas.");
485
+ }
486
+ this._domImage = engine.createCanvasImage();
487
+ this._domImage.onload = function () {
488
+ _this._onImageLoaded();
489
+ };
490
+ if (value) {
491
+ Tools.SetCorsBehavior(value, this._domImage);
492
+ this._domImage.src = value;
493
+ }
494
+ },
495
+ enumerable: false,
496
+ configurable: true
497
+ });
498
+ /**
499
+ * Checks for svg document with icon id present
500
+ * @param value
501
+ */
502
+ Image.prototype._svgCheck = function (value) {
503
+ var _this = this;
504
+ if (window.SVGSVGElement && value.search(/.svg#/gi) !== -1 && value.indexOf("#") === value.lastIndexOf("#")) {
505
+ this._isSVG = true;
506
+ var svgsrc_1 = value.split("#")[0];
507
+ var elemid_1 = value.split("#")[1];
508
+ // check if object alr exist in document
509
+ var svgExist_1 = document.body.querySelector('object[data="' + svgsrc_1 + '"]');
510
+ if (svgExist_1) {
511
+ var svgDoc = svgExist_1.contentDocument;
512
+ // get viewbox width and height, get svg document width and height in px
513
+ if (svgDoc && svgDoc.documentElement) {
514
+ var vb = svgDoc.documentElement.getAttribute("viewBox");
515
+ var docwidth = Number(svgDoc.documentElement.getAttribute("width"));
516
+ var docheight = Number(svgDoc.documentElement.getAttribute("height"));
517
+ var elem = svgDoc.getElementById(elemid_1);
518
+ if (elem && vb && docwidth && docheight) {
519
+ this._getSVGAttribs(svgExist_1, elemid_1);
520
+ return value;
521
+ }
522
+ }
523
+ // wait for object to load
524
+ svgExist_1.addEventListener("load", function () {
525
+ _this._getSVGAttribs(svgExist_1, elemid_1);
526
+ });
527
+ }
528
+ else {
529
+ // create document object
530
+ var svgImage = document.createElement("object");
531
+ svgImage.data = svgsrc_1;
532
+ svgImage.type = "image/svg+xml";
533
+ svgImage.width = "0%";
534
+ svgImage.height = "0%";
535
+ document.body.appendChild(svgImage);
536
+ // when the object has loaded, get the element attribs
537
+ svgImage.onload = function () {
538
+ var svgobj = document.body.querySelector('object[data="' + svgsrc_1 + '"]');
539
+ if (svgobj) {
540
+ _this._getSVGAttribs(svgobj, elemid_1);
541
+ }
542
+ };
543
+ }
544
+ return svgsrc_1;
545
+ }
546
+ else {
547
+ return value;
548
+ }
549
+ };
550
+ /**
551
+ * Sets sourceLeft, sourceTop, sourceWidth, sourceHeight automatically
552
+ * given external svg file and icon id
553
+ * @param svgsrc
554
+ * @param elemid
555
+ */
556
+ Image.prototype._getSVGAttribs = function (svgsrc, elemid) {
557
+ var svgDoc = svgsrc.contentDocument;
558
+ // get viewbox width and height, get svg document width and height in px
559
+ if (svgDoc && svgDoc.documentElement) {
560
+ var vb = svgDoc.documentElement.getAttribute("viewBox");
561
+ var docwidth = Number(svgDoc.documentElement.getAttribute("width"));
562
+ var docheight = Number(svgDoc.documentElement.getAttribute("height"));
563
+ // get element bbox and matrix transform
564
+ var elem = svgDoc.getElementById(elemid);
565
+ if (vb && docwidth && docheight && elem) {
566
+ var vb_width = Number(vb.split(" ")[2]);
567
+ var vb_height = Number(vb.split(" ")[3]);
568
+ var elem_bbox = elem.getBBox();
569
+ var elem_matrix_a = 1;
570
+ var elem_matrix_d = 1;
571
+ var elem_matrix_e = 0;
572
+ var elem_matrix_f = 0;
573
+ var mainMatrix = elem.transform.baseVal.consolidate().matrix;
574
+ if (elem.transform && elem.transform.baseVal.consolidate()) {
575
+ elem_matrix_a = mainMatrix.a;
576
+ elem_matrix_d = mainMatrix.d;
577
+ elem_matrix_e = mainMatrix.e;
578
+ elem_matrix_f = mainMatrix.f;
579
+ }
580
+ // compute source coordinates and dimensions
581
+ this.sourceLeft = ((elem_matrix_a * elem_bbox.x + elem_matrix_e) * docwidth) / vb_width;
582
+ this.sourceTop = ((elem_matrix_d * elem_bbox.y + elem_matrix_f) * docheight) / vb_height;
583
+ this.sourceWidth = elem_bbox.width * elem_matrix_a * (docwidth / vb_width);
584
+ this.sourceHeight = elem_bbox.height * elem_matrix_d * (docheight / vb_height);
585
+ this._svgAttributesComputationCompleted = true;
586
+ this.onSVGAttributesComputedObservable.notifyObservers(this);
587
+ }
588
+ }
589
+ };
590
+ Object.defineProperty(Image.prototype, "cellWidth", {
591
+ /**
592
+ * Gets or sets the cell width to use when animation sheet is enabled
593
+ * @see https://doc.babylonjs.com/how_to/gui#image
594
+ */
595
+ get: function () {
596
+ return this._cellWidth;
597
+ },
598
+ set: function (value) {
599
+ if (this._cellWidth === value) {
600
+ return;
601
+ }
602
+ this._cellWidth = value;
603
+ this._markAsDirty();
604
+ },
605
+ enumerable: false,
606
+ configurable: true
607
+ });
608
+ Object.defineProperty(Image.prototype, "cellHeight", {
609
+ /**
610
+ * Gets or sets the cell height to use when animation sheet is enabled
611
+ * @see https://doc.babylonjs.com/how_to/gui#image
612
+ */
613
+ get: function () {
614
+ return this._cellHeight;
615
+ },
616
+ set: function (value) {
617
+ if (this._cellHeight === value) {
618
+ return;
619
+ }
620
+ this._cellHeight = value;
621
+ this._markAsDirty();
622
+ },
623
+ enumerable: false,
624
+ configurable: true
625
+ });
626
+ Object.defineProperty(Image.prototype, "cellId", {
627
+ /**
628
+ * Gets or sets the cell id to use (this will turn on the animation sheet mode)
629
+ * @see https://doc.babylonjs.com/how_to/gui#image
630
+ */
631
+ get: function () {
632
+ return this._cellId;
633
+ },
634
+ set: function (value) {
635
+ if (this._cellId === value) {
636
+ return;
637
+ }
638
+ this._cellId = value;
639
+ this._markAsDirty();
640
+ },
641
+ enumerable: false,
642
+ configurable: true
643
+ });
644
+ /**
645
+ * Tests if a given coordinates belong to the current control
646
+ * @param x defines x coordinate to test
647
+ * @param y defines y coordinate to test
648
+ * @returns true if the coordinates are inside the control
649
+ */
650
+ Image.prototype.contains = function (x, y) {
651
+ if (!_super.prototype.contains.call(this, x, y)) {
652
+ return false;
653
+ }
654
+ if (!this._detectPointerOnOpaqueOnly || !this._workingCanvas) {
655
+ return true;
656
+ }
657
+ var width = this._currentMeasure.width | 0;
658
+ var height = this._currentMeasure.height | 0;
659
+ var key = width + "_" + height;
660
+ var imageData = this._imageDataCache.data;
661
+ if (!imageData || this._imageDataCache.key !== key) {
662
+ var canvas = this._workingCanvas;
663
+ var context_1 = canvas.getContext("2d");
664
+ this._imageDataCache.data = imageData = context_1.getImageData(0, 0, width, height).data;
665
+ this._imageDataCache.key = key;
666
+ }
667
+ x = (x - this._currentMeasure.left) | 0;
668
+ y = (y - this._currentMeasure.top) | 0;
669
+ var pickedPixel = imageData[(x + y * width) * 4 + 3];
670
+ return pickedPixel > 0;
671
+ };
672
+ Image.prototype._getTypeName = function () {
673
+ return "Image";
674
+ };
675
+ /** Force the control to synchronize with its content */
676
+ Image.prototype.synchronizeSizeWithContent = function () {
677
+ if (!this._loaded) {
678
+ return;
679
+ }
680
+ this.width = this._domImage.width + "px";
681
+ this.height = this._domImage.height + "px";
682
+ };
683
+ Image.prototype._processMeasures = function (parentMeasure, context) {
684
+ if (this._loaded) {
685
+ switch (this._stretch) {
686
+ case Image.STRETCH_NONE:
687
+ break;
688
+ case Image.STRETCH_FILL:
689
+ break;
690
+ case Image.STRETCH_UNIFORM:
691
+ break;
692
+ case Image.STRETCH_NINE_PATCH:
693
+ break;
694
+ case Image.STRETCH_EXTEND:
695
+ if (this._autoScale) {
696
+ this.synchronizeSizeWithContent();
697
+ }
698
+ if (this.parent && this.parent.parent) {
699
+ // Will update root size if root is not the top root
700
+ this.parent.adaptWidthToChildren = true;
701
+ this.parent.adaptHeightToChildren = true;
702
+ }
703
+ break;
704
+ }
705
+ }
706
+ _super.prototype._processMeasures.call(this, parentMeasure, context);
707
+ };
708
+ Image.prototype._prepareWorkingCanvasForOpaqueDetection = function () {
709
+ var _a, _b;
710
+ if (!this._detectPointerOnOpaqueOnly) {
711
+ return;
712
+ }
713
+ var width = this._currentMeasure.width;
714
+ var height = this._currentMeasure.height;
715
+ if (!this._workingCanvas) {
716
+ var engine = ((_b = (_a = this._host) === null || _a === void 0 ? void 0 : _a.getScene()) === null || _b === void 0 ? void 0 : _b.getEngine()) || EngineStore.LastCreatedEngine;
717
+ if (!engine) {
718
+ throw new Error("Invalid engine. Unable to create a canvas.");
719
+ }
720
+ this._workingCanvas = engine.createCanvas(width, height);
721
+ }
722
+ var canvas = this._workingCanvas;
723
+ var context = canvas.getContext("2d");
724
+ context.clearRect(0, 0, width, height);
725
+ };
726
+ Image.prototype._drawImage = function (context, sx, sy, sw, sh, tx, ty, tw, th) {
727
+ context.drawImage(this._domImage, sx, sy, sw, sh, tx, ty, tw, th);
728
+ if (!this._detectPointerOnOpaqueOnly) {
729
+ return;
730
+ }
731
+ var canvas = this._workingCanvas;
732
+ context = canvas.getContext("2d");
733
+ context.drawImage(this._domImage, sx, sy, sw, sh, tx - this._currentMeasure.left, ty - this._currentMeasure.top, tw, th);
734
+ };
735
+ Image.prototype._draw = function (context) {
736
+ context.save();
737
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
738
+ context.shadowColor = this.shadowColor;
739
+ context.shadowBlur = this.shadowBlur;
740
+ context.shadowOffsetX = this.shadowOffsetX;
741
+ context.shadowOffsetY = this.shadowOffsetY;
742
+ }
743
+ var x, y, width, height;
744
+ if (this.cellId == -1) {
745
+ x = this._sourceLeft;
746
+ y = this._sourceTop;
747
+ width = this._sourceWidth ? this._sourceWidth : this._imageWidth;
748
+ height = this._sourceHeight ? this._sourceHeight : this._imageHeight;
749
+ }
750
+ else {
751
+ var rowCount = this._domImage.naturalWidth / this.cellWidth;
752
+ var column = (this.cellId / rowCount) >> 0;
753
+ var row = this.cellId % rowCount;
754
+ x = this.cellWidth * row;
755
+ y = this.cellHeight * column;
756
+ width = this.cellWidth;
757
+ height = this.cellHeight;
758
+ }
759
+ this._prepareWorkingCanvasForOpaqueDetection();
760
+ this._applyStates(context);
761
+ if (this._loaded) {
762
+ switch (this._stretch) {
763
+ case Image.STRETCH_NONE:
764
+ this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
765
+ break;
766
+ case Image.STRETCH_FILL:
767
+ this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
768
+ break;
769
+ case Image.STRETCH_UNIFORM: {
770
+ var hRatio = this._currentMeasure.width / width;
771
+ var vRatio = this._currentMeasure.height / height;
772
+ var ratio = Math.min(hRatio, vRatio);
773
+ var centerX = (this._currentMeasure.width - width * ratio) / 2;
774
+ var centerY = (this._currentMeasure.height - height * ratio) / 2;
775
+ this._drawImage(context, x, y, width, height, this._currentMeasure.left + centerX, this._currentMeasure.top + centerY, width * ratio, height * ratio);
776
+ break;
777
+ }
778
+ case Image.STRETCH_EXTEND:
779
+ this._drawImage(context, x, y, width, height, this._currentMeasure.left, this._currentMeasure.top, this._currentMeasure.width, this._currentMeasure.height);
780
+ break;
781
+ case Image.STRETCH_NINE_PATCH:
782
+ this._renderNinePatch(context);
783
+ break;
784
+ }
785
+ }
786
+ context.restore();
787
+ };
788
+ Image.prototype._renderNinePatch = function (context) {
789
+ var leftWidth = this._sliceLeft;
790
+ var topHeight = this._sliceTop;
791
+ var bottomHeight = this._imageHeight - this._sliceBottom;
792
+ var rightWidth = this._imageWidth - this._sliceRight;
793
+ var centerWidth = this._sliceRight - this._sliceLeft;
794
+ var centerHeight = this._sliceBottom - this._sliceTop;
795
+ var targetCenterWidth = this._currentMeasure.width - rightWidth - leftWidth + 2;
796
+ var targetCenterHeight = this._currentMeasure.height - bottomHeight - topHeight + 2;
797
+ var centerLeftOffset = this._currentMeasure.left + leftWidth - 1;
798
+ var centerTopOffset = this._currentMeasure.top + topHeight - 1;
799
+ var rightOffset = this._currentMeasure.left + this._currentMeasure.width - rightWidth;
800
+ var bottomOffset = this._currentMeasure.top + this._currentMeasure.height - bottomHeight;
801
+ //Top Left
802
+ this._drawImage(context, 0, 0, leftWidth, topHeight, this._currentMeasure.left, this._currentMeasure.top, leftWidth, topHeight);
803
+ //Top
804
+ this._drawImage(context, this._sliceLeft, 0, centerWidth, topHeight, centerLeftOffset, this._currentMeasure.top, targetCenterWidth, topHeight);
805
+ //Top Right
806
+ this._drawImage(context, this.sliceRight, 0, rightWidth, topHeight, rightOffset, this._currentMeasure.top, rightWidth, topHeight);
807
+ //Left
808
+ this._drawImage(context, 0, this._sliceTop, leftWidth, centerHeight, this._currentMeasure.left, centerTopOffset, leftWidth, targetCenterHeight);
809
+ // Center
810
+ this._drawImage(context, this._sliceLeft, this._sliceTop, centerWidth, centerHeight, centerLeftOffset, centerTopOffset, targetCenterWidth, targetCenterHeight);
811
+ //Right
812
+ this._drawImage(context, this._sliceRight, this._sliceTop, rightWidth, centerHeight, rightOffset, centerTopOffset, rightWidth, targetCenterHeight);
813
+ //Bottom Left
814
+ this._drawImage(context, 0, this._sliceBottom, leftWidth, bottomHeight, this._currentMeasure.left, bottomOffset, leftWidth, bottomHeight);
815
+ //Bottom
816
+ this._drawImage(context, this.sliceLeft, this._sliceBottom, centerWidth, bottomHeight, centerLeftOffset, bottomOffset, targetCenterWidth, bottomHeight);
817
+ //Bottom Right
818
+ this._drawImage(context, this._sliceRight, this._sliceBottom, rightWidth, bottomHeight, rightOffset, bottomOffset, rightWidth, bottomHeight);
819
+ };
820
+ Image.prototype.dispose = function () {
821
+ _super.prototype.dispose.call(this);
822
+ this.onImageLoadedObservable.clear();
823
+ this.onSVGAttributesComputedObservable.clear();
824
+ };
825
+ // Static
826
+ /** STRETCH_NONE */
827
+ Image.STRETCH_NONE = 0;
828
+ /** STRETCH_FILL */
829
+ Image.STRETCH_FILL = 1;
830
+ /** STRETCH_UNIFORM */
831
+ Image.STRETCH_UNIFORM = 2;
832
+ /** STRETCH_EXTEND */
833
+ Image.STRETCH_EXTEND = 3;
834
+ /** NINE_PATCH */
835
+ Image.STRETCH_NINE_PATCH = 4;
836
+ __decorate([
837
+ serialize()
838
+ ], Image.prototype, "detectPointerOnOpaqueOnly", null);
839
+ __decorate([
840
+ serialize()
841
+ ], Image.prototype, "sliceLeft", null);
842
+ __decorate([
843
+ serialize()
844
+ ], Image.prototype, "sliceRight", null);
845
+ __decorate([
846
+ serialize()
847
+ ], Image.prototype, "sliceTop", null);
848
+ __decorate([
849
+ serialize()
850
+ ], Image.prototype, "sliceBottom", null);
851
+ __decorate([
852
+ serialize()
853
+ ], Image.prototype, "sourceLeft", null);
854
+ __decorate([
855
+ serialize()
856
+ ], Image.prototype, "sourceTop", null);
857
+ __decorate([
858
+ serialize()
859
+ ], Image.prototype, "sourceWidth", null);
860
+ __decorate([
861
+ serialize()
862
+ ], Image.prototype, "sourceHeight", null);
863
+ __decorate([
864
+ serialize()
865
+ ], Image.prototype, "populateNinePatchSlicesFromImage", null);
866
+ __decorate([
867
+ serialize()
868
+ ], Image.prototype, "autoScale", null);
869
+ __decorate([
870
+ serialize()
871
+ ], Image.prototype, "stretch", null);
872
+ __decorate([
873
+ serialize()
874
+ ], Image.prototype, "source", null);
875
+ __decorate([
876
+ serialize()
877
+ ], Image.prototype, "cellWidth", null);
878
+ __decorate([
879
+ serialize()
880
+ ], Image.prototype, "cellHeight", null);
881
+ __decorate([
882
+ serialize()
883
+ ], Image.prototype, "cellId", null);
884
+ return Image;
885
+ }(Control));
886
+ export { Image };
887
+ RegisterClass("BABYLON.GUI.Image", Image);
880
888
  //# sourceMappingURL=image.js.map