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