@babylonjs/gui 5.0.0-rc.0 → 5.0.0-rc.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/2D/adtInstrumentation.d.ts +52 -52
- package/2D/adtInstrumentation.js +126 -126
- package/2D/adtInstrumentation.js.map +1 -1
- package/2D/advancedDynamicTexture.d.ts +449 -423
- package/2D/advancedDynamicTexture.js +1318 -1286
- package/2D/advancedDynamicTexture.js.map +1 -1
- package/2D/controls/button.d.ts +135 -97
- package/2D/controls/button.js +276 -238
- package/2D/controls/button.js.map +1 -1
- package/2D/controls/checkbox.d.ts +59 -51
- package/2D/controls/checkbox.js +188 -178
- package/2D/controls/checkbox.js.map +1 -1
- package/2D/controls/colorpicker.d.ts +103 -90
- package/2D/controls/colorpicker.js +1417 -1400
- package/2D/controls/colorpicker.js.map +1 -1
- package/2D/controls/container.d.ts +175 -130
- package/2D/controls/container.js +570 -525
- package/2D/controls/container.js.map +1 -1
- package/2D/controls/control.d.ts +866 -743
- package/2D/controls/control.js +2433 -2308
- package/2D/controls/control.js.map +1 -1
- package/2D/controls/displayGrid.d.ts +53 -55
- package/2D/controls/displayGrid.js +245 -245
- package/2D/controls/displayGrid.js.map +1 -1
- package/2D/controls/ellipse.d.ts +21 -21
- package/2D/controls/ellipse.js +85 -85
- package/2D/controls/ellipse.js.map +1 -1
- package/2D/controls/focusableButton.d.ts +59 -52
- package/2D/controls/focusableButton.js +99 -92
- package/2D/controls/focusableButton.js.map +1 -1
- package/2D/controls/focusableControl.d.ts +34 -34
- package/2D/controls/focusableControl.js +1 -1
- package/2D/controls/focusableControl.js.map +1 -1
- package/2D/controls/grid.d.ts +139 -135
- package/2D/controls/grid.js +529 -525
- package/2D/controls/grid.js.map +1 -1
- package/2D/controls/image.d.ts +204 -197
- package/2D/controls/image.js +887 -879
- package/2D/controls/image.js.map +1 -1
- package/2D/controls/index.d.ts +29 -29
- package/2D/controls/index.js +29 -29
- package/2D/controls/index.js.map +1 -1
- package/2D/controls/inputPassword.d.ts +9 -8
- package/2D/controls/inputPassword.js +28 -25
- package/2D/controls/inputPassword.js.map +1 -1
- package/2D/controls/inputText.d.ts +201 -182
- package/2D/controls/inputText.js +1119 -1096
- package/2D/controls/inputText.js.map +1 -1
- package/2D/controls/line.d.ts +66 -66
- package/2D/controls/line.js +271 -271
- package/2D/controls/line.js.map +1 -1
- package/2D/controls/multiLine.d.ts +75 -77
- package/2D/controls/multiLine.js +262 -262
- package/2D/controls/multiLine.js.map +1 -1
- package/2D/controls/radioButton.d.ts +49 -49
- package/2D/controls/radioButton.js +205 -205
- package/2D/controls/radioButton.js.map +1 -1
- package/2D/controls/rectangle.d.ts +29 -29
- package/2D/controls/rectangle.js +150 -150
- package/2D/controls/rectangle.js.map +1 -1
- package/2D/controls/scrollViewers/scrollViewer.d.ts +182 -175
- package/2D/controls/scrollViewers/scrollViewer.js +677 -676
- package/2D/controls/scrollViewers/scrollViewer.js.map +1 -1
- package/2D/controls/scrollViewers/scrollViewerWindow.d.ts +57 -45
- package/2D/controls/scrollViewers/scrollViewerWindow.js +278 -263
- package/2D/controls/scrollViewers/scrollViewerWindow.js.map +1 -1
- package/2D/controls/selector.d.ts +263 -209
- package/2D/controls/selector.js +692 -629
- package/2D/controls/selector.js.map +1 -1
- package/2D/controls/sliders/baseSlider.d.ts +82 -78
- package/2D/controls/sliders/baseSlider.js +347 -343
- package/2D/controls/sliders/baseSlider.js.map +1 -1
- package/2D/controls/sliders/imageBasedSlider.d.ts +49 -47
- package/2D/controls/sliders/imageBasedSlider.js +192 -188
- package/2D/controls/sliders/imageBasedSlider.js.map +1 -1
- package/2D/controls/sliders/imageScrollBar.d.ts +65 -61
- package/2D/controls/sliders/imageScrollBar.js +263 -256
- package/2D/controls/sliders/imageScrollBar.js.map +1 -1
- package/2D/controls/sliders/scrollBar.d.ts +38 -34
- package/2D/controls/sliders/scrollBar.js +143 -136
- package/2D/controls/sliders/scrollBar.js.map +1 -1
- package/2D/controls/sliders/slider.d.ts +35 -37
- package/2D/controls/sliders/slider.js +271 -271
- package/2D/controls/sliders/slider.js.map +1 -1
- package/2D/controls/stackPanel.d.ts +64 -56
- package/2D/controls/stackPanel.js +246 -236
- package/2D/controls/stackPanel.js.map +1 -1
- package/2D/controls/statics.d.ts +6 -6
- package/2D/controls/statics.js +49 -47
- package/2D/controls/statics.js.map +1 -1
- package/2D/controls/textBlock.d.ts +175 -172
- package/2D/controls/textBlock.js +603 -598
- package/2D/controls/textBlock.js.map +1 -1
- package/2D/controls/textWrapper.d.ts +13 -13
- package/2D/controls/textWrapper.js +101 -101
- package/2D/controls/textWrapper.js.map +1 -1
- package/2D/controls/toggleButton.d.ts +117 -83
- package/2D/controls/toggleButton.js +268 -234
- package/2D/controls/toggleButton.js.map +1 -1
- package/2D/controls/virtualKeyboard.d.ts +96 -96
- package/2D/controls/virtualKeyboard.js +256 -256
- package/2D/controls/virtualKeyboard.js.map +1 -1
- package/2D/index.d.ts +9 -9
- package/2D/index.js +10 -9
- package/2D/index.js.map +1 -1
- package/2D/math2D.d.ts +117 -117
- package/2D/math2D.js +221 -221
- package/2D/math2D.js.map +1 -1
- package/2D/measure.d.ts +77 -77
- package/2D/measure.js +139 -149
- package/2D/measure.js.map +1 -1
- package/2D/multiLinePoint.d.ts +47 -47
- package/2D/multiLinePoint.js +127 -127
- package/2D/multiLinePoint.js.map +1 -1
- package/2D/style.d.ts +46 -46
- package/2D/style.js +97 -97
- package/2D/style.js.map +1 -1
- package/2D/valueAndUnit.d.ts +89 -89
- package/2D/valueAndUnit.js +226 -222
- package/2D/valueAndUnit.js.map +1 -1
- package/2D/xmlLoader.d.ts +60 -60
- package/2D/xmlLoader.js +348 -348
- package/2D/xmlLoader.js.map +1 -1
- package/3D/behaviors/defaultBehavior.d.ts +73 -73
- package/3D/behaviors/defaultBehavior.js +121 -121
- package/3D/behaviors/defaultBehavior.js.map +1 -1
- package/3D/controls/abstractButton3D.d.ts +15 -15
- package/3D/controls/abstractButton3D.js +25 -25
- package/3D/controls/abstractButton3D.js.map +1 -1
- package/3D/controls/button3D.d.ts +30 -30
- package/3D/controls/button3D.js +93 -93
- package/3D/controls/button3D.js.map +1 -1
- package/3D/controls/container3D.d.ts +72 -72
- package/3D/controls/container3D.js +139 -140
- package/3D/controls/container3D.js.map +1 -1
- package/3D/controls/contentDisplay3D.d.ts +30 -30
- package/3D/controls/contentDisplay3D.js +79 -78
- package/3D/controls/contentDisplay3D.js.map +1 -1
- package/3D/controls/control3D.d.ts +201 -165
- package/3D/controls/control3D.js +445 -408
- package/3D/controls/control3D.js.map +1 -1
- package/3D/controls/cylinderPanel.d.ts +17 -17
- package/3D/controls/cylinderPanel.js +66 -66
- package/3D/controls/cylinderPanel.js.map +1 -1
- package/3D/controls/handMenu.d.ts +28 -28
- package/3D/controls/handMenu.js +47 -47
- package/3D/controls/handMenu.js.map +1 -1
- package/3D/controls/holographicBackplate.d.ts +49 -48
- package/3D/controls/holographicBackplate.js +120 -120
- package/3D/controls/holographicBackplate.js.map +1 -1
- package/3D/controls/holographicButton.d.ts +84 -83
- package/3D/controls/holographicButton.js +339 -338
- package/3D/controls/holographicButton.js.map +1 -1
- package/3D/controls/holographicSlate.d.ts +131 -128
- package/3D/controls/holographicSlate.js +431 -428
- package/3D/controls/holographicSlate.js.map +1 -1
- package/3D/controls/index.d.ts +21 -21
- package/3D/controls/index.js +21 -21
- package/3D/controls/index.js.map +1 -1
- package/3D/controls/meshButton3D.d.ts +21 -21
- package/3D/controls/meshButton3D.js +62 -61
- package/3D/controls/meshButton3D.js.map +1 -1
- package/3D/controls/nearMenu.d.ts +44 -44
- package/3D/controls/nearMenu.js +114 -112
- package/3D/controls/nearMenu.js.map +1 -1
- package/3D/controls/planePanel.d.ts +9 -9
- package/3D/controls/planePanel.js +36 -36
- package/3D/controls/planePanel.js.map +1 -1
- package/3D/controls/scatterPanel.d.ts +18 -18
- package/3D/controls/scatterPanel.js +108 -108
- package/3D/controls/scatterPanel.js.map +1 -1
- package/3D/controls/slider3D.d.ts +81 -80
- package/3D/controls/slider3D.js +268 -267
- package/3D/controls/slider3D.js.map +1 -1
- package/3D/controls/spherePanel.d.ts +17 -17
- package/3D/controls/spherePanel.js +67 -67
- package/3D/controls/spherePanel.js.map +1 -1
- package/3D/controls/stackPanel3D.d.ts +22 -22
- package/3D/controls/stackPanel3D.js +107 -107
- package/3D/controls/stackPanel3D.js.map +1 -1
- package/3D/controls/touchButton3D.d.ts +80 -75
- package/3D/controls/touchButton3D.js +233 -227
- package/3D/controls/touchButton3D.js.map +1 -1
- package/3D/controls/touchHolographicButton.d.ts +110 -109
- package/3D/controls/touchHolographicButton.js +445 -445
- package/3D/controls/touchHolographicButton.js.map +1 -1
- package/3D/controls/touchHolographicMenu.d.ts +61 -61
- package/3D/controls/touchHolographicMenu.js +149 -148
- package/3D/controls/touchHolographicMenu.js.map +1 -1
- package/3D/controls/touchMeshButton3D.d.ts +21 -22
- package/3D/controls/touchMeshButton3D.js +62 -62
- package/3D/controls/touchMeshButton3D.js.map +1 -1
- package/3D/controls/volumeBasedPanel.d.ts +53 -52
- package/3D/controls/volumeBasedPanel.js +174 -174
- package/3D/controls/volumeBasedPanel.js.map +1 -1
- package/3D/gizmos/gizmoHandle.d.ts +108 -108
- package/3D/gizmos/gizmoHandle.js +209 -209
- package/3D/gizmos/gizmoHandle.js.map +1 -1
- package/3D/gizmos/index.d.ts +2 -2
- package/3D/gizmos/index.js +2 -2
- package/3D/gizmos/index.js.map +1 -1
- package/3D/gizmos/slateGizmo.d.ts +57 -57
- package/3D/gizmos/slateGizmo.js +369 -369
- package/3D/gizmos/slateGizmo.js.map +1 -1
- package/3D/gui3DManager.d.ts +94 -94
- package/3D/gui3DManager.js +257 -257
- package/3D/gui3DManager.js.map +1 -1
- package/3D/index.d.ts +5 -5
- package/3D/index.js +6 -5
- package/3D/index.js.map +1 -1
- package/3D/materials/fluent/fluentMaterial.d.ts +91 -90
- package/3D/materials/fluent/fluentMaterial.js +292 -281
- package/3D/materials/fluent/fluentMaterial.js.map +1 -1
- package/3D/materials/fluent/index.d.ts +1 -1
- package/3D/materials/fluent/index.js +1 -1
- package/3D/materials/fluent/index.js.map +1 -1
- package/3D/materials/fluent/shaders/fluent.fragment.d.ts +5 -5
- package/3D/materials/fluent/shaders/fluent.fragment.js +8 -6
- package/3D/materials/fluent/shaders/fluent.fragment.js.map +1 -1
- package/3D/materials/fluent/shaders/fluent.vertex.d.ts +5 -5
- package/3D/materials/fluent/shaders/fluent.vertex.js +8 -6
- package/3D/materials/fluent/shaders/fluent.vertex.js.map +1 -1
- package/3D/materials/fluentBackplate/fluentBackplateMaterial.d.ts +155 -154
- package/3D/materials/fluentBackplate/fluentBackplateMaterial.js +469 -434
- package/3D/materials/fluentBackplate/fluentBackplateMaterial.js.map +1 -1
- package/3D/materials/fluentBackplate/index.d.ts +1 -1
- package/3D/materials/fluentBackplate/index.js +1 -1
- package/3D/materials/fluentBackplate/index.js.map +1 -1
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.d.ts +5 -5
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js +8 -6
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.fragment.js.map +1 -1
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.d.ts +5 -5
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js +8 -6
- package/3D/materials/fluentBackplate/shaders/fluentBackplate.vertex.js.map +1 -1
- package/3D/materials/fluentButton/fluentButtonMaterial.d.ts +190 -189
- package/3D/materials/fluentButton/fluentButtonMaterial.js +539 -537
- package/3D/materials/fluentButton/fluentButtonMaterial.js.map +1 -1
- package/3D/materials/fluentButton/index.d.ts +1 -1
- package/3D/materials/fluentButton/index.js +1 -1
- package/3D/materials/fluentButton/index.js.map +1 -1
- package/3D/materials/fluentButton/shaders/fluentButton.fragment.d.ts +5 -5
- package/3D/materials/fluentButton/shaders/fluentButton.fragment.js +8 -6
- package/3D/materials/fluentButton/shaders/fluentButton.fragment.js.map +1 -1
- package/3D/materials/fluentButton/shaders/fluentButton.vertex.d.ts +5 -5
- package/3D/materials/fluentButton/shaders/fluentButton.vertex.js +8 -6
- package/3D/materials/fluentButton/shaders/fluentButton.vertex.js.map +1 -1
- package/3D/materials/fluentMaterial.d.ts +4 -4
- package/3D/materials/fluentMaterial.js +4 -4
- package/3D/materials/fluentMaterial.js.map +1 -1
- package/3D/materials/handle/handleMaterial.d.ts +68 -68
- package/3D/materials/handle/handleMaterial.js +126 -126
- package/3D/materials/handle/handleMaterial.js.map +1 -1
- package/3D/materials/handle/index.d.ts +1 -1
- package/3D/materials/handle/index.js +1 -1
- package/3D/materials/handle/index.js.map +1 -1
- package/3D/materials/handle/shaders/handle.fragment.d.ts +5 -5
- package/3D/materials/handle/shaders/handle.fragment.js +8 -6
- package/3D/materials/handle/shaders/handle.fragment.js.map +1 -1
- package/3D/materials/handle/shaders/handle.vertex.d.ts +5 -5
- package/3D/materials/handle/shaders/handle.vertex.js +8 -6
- package/3D/materials/handle/shaders/handle.vertex.js.map +1 -1
- package/3D/materials/index.d.ts +5 -5
- package/3D/materials/index.js +6 -5
- package/3D/materials/index.js.map +1 -1
- package/3D/materials/mrdl/index.d.ts +3 -3
- package/3D/materials/mrdl/index.js +3 -3
- package/3D/materials/mrdl/index.js.map +1 -1
- package/3D/materials/mrdl/mrdlBackplateMaterial.d.ts +148 -147
- package/3D/materials/mrdl/mrdlBackplateMaterial.js +436 -409
- package/3D/materials/mrdl/mrdlBackplateMaterial.js.map +1 -1
- package/3D/materials/mrdl/mrdlSliderBarMaterial.d.ts +334 -333
- package/3D/materials/mrdl/mrdlSliderBarMaterial.js +851 -786
- package/3D/materials/mrdl/mrdlSliderBarMaterial.js.map +1 -1
- package/3D/materials/mrdl/mrdlSliderThumbMaterial.d.ts +334 -333
- package/3D/materials/mrdl/mrdlSliderThumbMaterial.js +851 -786
- package/3D/materials/mrdl/mrdlSliderThumbMaterial.js.map +1 -1
- package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js +8 -6
- package/3D/materials/mrdl/shaders/mrdlBackplate.fragment.js.map +1 -1
- package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js +8 -6
- package/3D/materials/mrdl/shaders/mrdlBackplate.vertex.js.map +1 -1
- package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js +8 -6
- package/3D/materials/mrdl/shaders/mrdlSliderBar.fragment.js.map +1 -1
- package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js +8 -6
- package/3D/materials/mrdl/shaders/mrdlSliderBar.vertex.js.map +1 -1
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js +8 -6
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.fragment.js.map +1 -1
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.d.ts +5 -5
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js +8 -6
- package/3D/materials/mrdl/shaders/mrdlSliderThumb.vertex.js.map +1 -1
- package/3D/vector3WithInfo.d.ts +16 -16
- package/3D/vector3WithInfo.js +23 -23
- package/3D/vector3WithInfo.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +3 -2
- package/index.js.map +1 -1
- package/legacy/legacy.d.ts +1 -1
- package/legacy/legacy.js +14 -13
- package/legacy/legacy.js.map +1 -1
- package/package.json +21 -328
- package/readme.md +2 -2
package/2D/controls/image.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
var
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
var
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
rotatedImage.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
this.
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
this.
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
if (alpha
|
|
398
|
-
this.
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (alpha
|
|
412
|
-
this.
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
this.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
this._source
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
this.
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
document.
|
|
531
|
-
|
|
532
|
-
svgImage.
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
var
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
this.
|
|
597
|
-
},
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
this.
|
|
615
|
-
},
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
this.
|
|
633
|
-
},
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
if (!
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
Image.prototype.
|
|
677
|
-
if (this._loaded) {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
if (this.
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
this.
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
var
|
|
790
|
-
var
|
|
791
|
-
var
|
|
792
|
-
var
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
//
|
|
802
|
-
this._drawImage(context,
|
|
803
|
-
//
|
|
804
|
-
this._drawImage(context, this.
|
|
805
|
-
//
|
|
806
|
-
this._drawImage(context, 0,
|
|
807
|
-
//
|
|
808
|
-
this._drawImage(context,
|
|
809
|
-
//
|
|
810
|
-
this._drawImage(context, this.
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
this.
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
/**
|
|
827
|
-
Image.
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
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
|