@babylonjs/gui 5.0.0-alpha.59 → 5.0.0-alpha.62
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/advancedDynamicTexture.d.ts +151 -134
- package/2D/advancedDynamicTexture.js +212 -153
- package/2D/advancedDynamicTexture.js.map +1 -1
- package/2D/controls/control.d.ts +45 -32
- package/2D/controls/control.js +56 -43
- package/2D/controls/control.js.map +1 -1
- package/2D/controls/inputText.js +1 -1
- package/2D/controls/inputText.js.map +1 -1
- package/2D/controls/textBlock.js +1 -1
- package/2D/controls/textBlock.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import { __extends } from "tslib";
|
|
|
2
2
|
import { Observable } from "@babylonjs/core/Misc/observable.js";
|
|
3
3
|
import { Vector2, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
|
|
4
4
|
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
|
5
|
-
import { PointerEventTypes } from
|
|
5
|
+
import { PointerEventTypes } from "@babylonjs/core/Events/pointerEvents.js";
|
|
6
6
|
import { ClipboardEventTypes, ClipboardInfo } from "@babylonjs/core/Events/clipboardEvents.js";
|
|
7
7
|
import { KeyboardEventTypes } from "@babylonjs/core/Events/keyboardEvents.js";
|
|
8
8
|
import { StandardMaterial } from "@babylonjs/core/Materials/standardMaterial.js";
|
|
@@ -13,26 +13,26 @@ import { Container } from "./controls/container.js";
|
|
|
13
13
|
import { Control } from "./controls/control.js";
|
|
14
14
|
import { Style } from "./style.js";
|
|
15
15
|
import { Measure } from "./measure.js";
|
|
16
|
-
import { Constants } from
|
|
17
|
-
import { Viewport } from
|
|
18
|
-
import { Color3 } from
|
|
16
|
+
import { Constants } from "@babylonjs/core/Engines/constants.js";
|
|
17
|
+
import { Viewport } from "@babylonjs/core/Maths/math.viewport.js";
|
|
18
|
+
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
|
19
19
|
import { WebRequest } from "@babylonjs/core/Misc/webRequest.js";
|
|
20
20
|
/**
|
|
21
|
-
* Class used to create texture to support 2D GUI elements
|
|
22
|
-
* @see https://doc.babylonjs.com/how_to/gui
|
|
23
|
-
*/
|
|
21
|
+
* Class used to create texture to support 2D GUI elements
|
|
22
|
+
* @see https://doc.babylonjs.com/how_to/gui
|
|
23
|
+
*/
|
|
24
24
|
var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
25
25
|
__extends(AdvancedDynamicTexture, _super);
|
|
26
26
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
* Creates a new AdvancedDynamicTexture
|
|
28
|
+
* @param name defines the name of the texture
|
|
29
|
+
* @param width defines the width of the texture
|
|
30
|
+
* @param height defines the height of the texture
|
|
31
|
+
* @param scene defines the hosting scene
|
|
32
|
+
* @param generateMipMaps defines a boolean indicating if mipmaps must be generated (false by default)
|
|
33
|
+
* @param samplingMode defines the texture sampling mode (Texture.NEAREST_SAMPLINGMODE by default)
|
|
34
|
+
* @param invertY defines if the texture needs to be inverted on the y axis during loading (true by default)
|
|
35
|
+
*/
|
|
36
36
|
function AdvancedDynamicTexture(name, width, height, scene, generateMipMaps, samplingMode, invertY) {
|
|
37
37
|
if (width === void 0) { width = 0; }
|
|
38
38
|
if (height === void 0) { height = 0; }
|
|
@@ -66,37 +66,37 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
66
66
|
/** @hidden */
|
|
67
67
|
_this._numRenderCalls = 0;
|
|
68
68
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
* Define type to string to ensure compatibility across browsers
|
|
70
|
+
* Safari doesn't support DataTransfer constructor
|
|
71
|
+
*/
|
|
72
72
|
_this._clipboardData = "";
|
|
73
73
|
/**
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
* Observable event triggered each time an clipboard event is received from the rendering canvas
|
|
75
|
+
*/
|
|
76
76
|
_this.onClipboardObservable = new Observable();
|
|
77
77
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
* Observable event triggered each time a pointer down is intercepted by a control
|
|
79
|
+
*/
|
|
80
80
|
_this.onControlPickedObservable = new Observable();
|
|
81
81
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
* Observable event triggered before layout is evaluated
|
|
83
|
+
*/
|
|
84
84
|
_this.onBeginLayoutObservable = new Observable();
|
|
85
85
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
* Observable event triggered after the layout was evaluated
|
|
87
|
+
*/
|
|
88
88
|
_this.onEndLayoutObservable = new Observable();
|
|
89
89
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
* Observable event triggered before the texture is rendered
|
|
91
|
+
*/
|
|
92
92
|
_this.onBeginRenderObservable = new Observable();
|
|
93
93
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
* Observable event triggered after the texture was rendered
|
|
95
|
+
*/
|
|
96
96
|
_this.onEndRenderObservable = new Observable();
|
|
97
97
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
* Gets or sets a boolean defining if alpha is stored as premultiplied
|
|
99
|
+
*/
|
|
100
100
|
_this.premulAlpha = false;
|
|
101
101
|
/**
|
|
102
102
|
* Gets or sets a boolean indicating that the canvas must be reverted on Y when updating the texture
|
|
@@ -170,9 +170,9 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
170
170
|
});
|
|
171
171
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "renderScale", {
|
|
172
172
|
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
* Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
|
|
174
|
+
* Useful when you want more antialiasing
|
|
175
|
+
*/
|
|
176
176
|
get: function () {
|
|
177
177
|
return this._renderScale;
|
|
178
178
|
},
|
|
@@ -203,10 +203,10 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
203
203
|
});
|
|
204
204
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "idealWidth", {
|
|
205
205
|
/**
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
* Gets or sets the ideal width used to design controls.
|
|
207
|
+
* The GUI will then rescale everything accordingly
|
|
208
|
+
* @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
|
|
209
|
+
*/
|
|
210
210
|
get: function () {
|
|
211
211
|
return this._idealWidth;
|
|
212
212
|
},
|
|
@@ -223,10 +223,10 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
223
223
|
});
|
|
224
224
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "idealHeight", {
|
|
225
225
|
/**
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
* Gets or sets the ideal height used to design controls.
|
|
227
|
+
* The GUI will then rescale everything accordingly
|
|
228
|
+
* @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
|
|
229
|
+
*/
|
|
230
230
|
get: function () {
|
|
231
231
|
return this._idealHeight;
|
|
232
232
|
},
|
|
@@ -243,9 +243,9 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
243
243
|
});
|
|
244
244
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "useSmallestIdeal", {
|
|
245
245
|
/**
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
* Gets or sets a boolean indicating if the smallest ideal value must be used if idealWidth and idealHeight are both set
|
|
247
|
+
* @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
|
|
248
|
+
*/
|
|
249
249
|
get: function () {
|
|
250
250
|
return this._useSmallestIdeal;
|
|
251
251
|
},
|
|
@@ -262,9 +262,9 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
262
262
|
});
|
|
263
263
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "renderAtIdealSize", {
|
|
264
264
|
/**
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
* Gets or sets a boolean indicating if adaptive scaling must be used
|
|
266
|
+
* @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
|
|
267
|
+
*/
|
|
268
268
|
get: function () {
|
|
269
269
|
return this._renderAtIdealSize;
|
|
270
270
|
},
|
|
@@ -281,24 +281,26 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
281
281
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "idealRatio", {
|
|
282
282
|
/**
|
|
283
283
|
* Gets the ratio used when in "ideal mode"
|
|
284
|
-
|
|
284
|
+
* @see https://doc.babylonjs.com/how_to/gui#adaptive-scaling
|
|
285
285
|
* */
|
|
286
286
|
get: function () {
|
|
287
287
|
var rwidth = 0;
|
|
288
288
|
var rheight = 0;
|
|
289
289
|
if (this._idealWidth) {
|
|
290
|
-
rwidth =
|
|
290
|
+
rwidth = this.getSize().width / this._idealWidth;
|
|
291
291
|
}
|
|
292
292
|
if (this._idealHeight) {
|
|
293
|
-
rheight =
|
|
293
|
+
rheight = this.getSize().height / this._idealHeight;
|
|
294
294
|
}
|
|
295
295
|
if (this._useSmallestIdeal && this._idealWidth && this._idealHeight) {
|
|
296
296
|
return window.innerWidth < window.innerHeight ? rwidth : rheight;
|
|
297
297
|
}
|
|
298
|
-
if (this._idealWidth) {
|
|
298
|
+
if (this._idealWidth) {
|
|
299
|
+
// horizontal
|
|
299
300
|
return rwidth;
|
|
300
301
|
}
|
|
301
|
-
if (this._idealHeight) {
|
|
302
|
+
if (this._idealHeight) {
|
|
303
|
+
// vertical
|
|
302
304
|
return rheight;
|
|
303
305
|
}
|
|
304
306
|
return 1;
|
|
@@ -308,8 +310,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
308
310
|
});
|
|
309
311
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "layer", {
|
|
310
312
|
/**
|
|
311
|
-
|
|
312
|
-
|
|
313
|
+
* Gets the underlying layer used to render the texture when in fullscreen mode
|
|
314
|
+
*/
|
|
313
315
|
get: function () {
|
|
314
316
|
return this._layerToDispose;
|
|
315
317
|
},
|
|
@@ -318,8 +320,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
318
320
|
});
|
|
319
321
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "rootContainer", {
|
|
320
322
|
/**
|
|
321
|
-
|
|
322
|
-
|
|
323
|
+
* Gets the root container control
|
|
324
|
+
*/
|
|
323
325
|
get: function () {
|
|
324
326
|
return this._rootContainer;
|
|
325
327
|
},
|
|
@@ -327,35 +329,35 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
327
329
|
configurable: true
|
|
328
330
|
});
|
|
329
331
|
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
* Returns an array containing the root container.
|
|
333
|
+
* This is mostly used to let the Inspector introspects the ADT
|
|
334
|
+
* @returns an array containing the rootContainer
|
|
335
|
+
*/
|
|
334
336
|
AdvancedDynamicTexture.prototype.getChildren = function () {
|
|
335
337
|
return [this._rootContainer];
|
|
336
338
|
};
|
|
337
339
|
/**
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
340
|
+
* Will return all controls that are inside this texture
|
|
341
|
+
* @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
|
|
342
|
+
* @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
|
|
343
|
+
* @return all child controls
|
|
344
|
+
*/
|
|
343
345
|
AdvancedDynamicTexture.prototype.getDescendants = function (directDescendantsOnly, predicate) {
|
|
344
346
|
return this._rootContainer.getDescendants(directDescendantsOnly, predicate);
|
|
345
347
|
};
|
|
346
348
|
/**
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
349
|
+
* Will return all controls with the given type name
|
|
350
|
+
* @param typeName defines the type name to search for
|
|
351
|
+
* @returns an array of all controls found
|
|
352
|
+
*/
|
|
351
353
|
AdvancedDynamicTexture.prototype.getControlsByType = function (typeName) {
|
|
352
354
|
return this._rootContainer.getDescendants(false, function (control) { return control.typeName === typeName; });
|
|
353
355
|
};
|
|
354
356
|
/**
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
357
|
+
* Will return the first control with the given name
|
|
358
|
+
* @param name defines the name to search for
|
|
359
|
+
* @return the first control found or null
|
|
360
|
+
*/
|
|
359
361
|
AdvancedDynamicTexture.prototype.getControlByName = function (name) {
|
|
360
362
|
return this._getControlByKey("name", name);
|
|
361
363
|
};
|
|
@@ -364,8 +366,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
364
366
|
};
|
|
365
367
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "focusedControl", {
|
|
366
368
|
/**
|
|
367
|
-
|
|
368
|
-
|
|
369
|
+
* Gets or sets the current focused control
|
|
370
|
+
*/
|
|
369
371
|
get: function () {
|
|
370
372
|
return this._focusedControl;
|
|
371
373
|
},
|
|
@@ -386,13 +388,13 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
386
388
|
});
|
|
387
389
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "isForeground", {
|
|
388
390
|
/**
|
|
389
|
-
|
|
390
|
-
|
|
391
|
+
* Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
|
|
392
|
+
*/
|
|
391
393
|
get: function () {
|
|
392
394
|
if (!this.layer) {
|
|
393
395
|
return true;
|
|
394
396
|
}
|
|
395
|
-
return
|
|
397
|
+
return !this.layer.isBackground;
|
|
396
398
|
},
|
|
397
399
|
set: function (value) {
|
|
398
400
|
if (!this.layer) {
|
|
@@ -408,8 +410,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
408
410
|
});
|
|
409
411
|
Object.defineProperty(AdvancedDynamicTexture.prototype, "clipboardData", {
|
|
410
412
|
/**
|
|
411
|
-
|
|
412
|
-
|
|
413
|
+
* Gets or set information about clipboardData
|
|
414
|
+
*/
|
|
413
415
|
get: function () {
|
|
414
416
|
return this._clipboardData;
|
|
415
417
|
},
|
|
@@ -420,17 +422,17 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
420
422
|
configurable: true
|
|
421
423
|
});
|
|
422
424
|
/**
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
425
|
+
* Get the current class name of the texture useful for serialization or dynamic coding.
|
|
426
|
+
* @returns "AdvancedDynamicTexture"
|
|
427
|
+
*/
|
|
426
428
|
AdvancedDynamicTexture.prototype.getClassName = function () {
|
|
427
429
|
return "AdvancedDynamicTexture";
|
|
428
430
|
};
|
|
429
431
|
/**
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
432
|
+
* Function used to execute a function on all controls
|
|
433
|
+
* @param func defines the function to execute
|
|
434
|
+
* @param container defines the container where controls belong. If null the root container will be used
|
|
435
|
+
*/
|
|
434
436
|
AdvancedDynamicTexture.prototype.executeOnAllControls = function (func, container) {
|
|
435
437
|
if (!container) {
|
|
436
438
|
container = this._rootContainer;
|
|
@@ -483,40 +485,83 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
483
485
|
}
|
|
484
486
|
};
|
|
485
487
|
/**
|
|
486
|
-
|
|
487
|
-
|
|
488
|
+
* Marks the texture as dirty forcing a complete update
|
|
489
|
+
*/
|
|
488
490
|
AdvancedDynamicTexture.prototype.markAsDirty = function () {
|
|
489
491
|
this._isDirty = true;
|
|
490
492
|
};
|
|
491
493
|
/**
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
494
|
+
* Helper function used to create a new style
|
|
495
|
+
* @returns a new style
|
|
496
|
+
* @see https://doc.babylonjs.com/how_to/gui#styles
|
|
497
|
+
*/
|
|
496
498
|
AdvancedDynamicTexture.prototype.createStyle = function () {
|
|
497
499
|
return new Style(this);
|
|
498
500
|
};
|
|
499
501
|
/**
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
502
|
+
* Adds a new control to the root container
|
|
503
|
+
* @param control defines the control to add
|
|
504
|
+
* @returns the current texture
|
|
505
|
+
*/
|
|
504
506
|
AdvancedDynamicTexture.prototype.addControl = function (control) {
|
|
505
507
|
this._rootContainer.addControl(control);
|
|
506
508
|
return this;
|
|
507
509
|
};
|
|
508
510
|
/**
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
511
|
+
* Removes a control from the root container
|
|
512
|
+
* @param control defines the control to remove
|
|
513
|
+
* @returns the current texture
|
|
514
|
+
*/
|
|
513
515
|
AdvancedDynamicTexture.prototype.removeControl = function (control) {
|
|
514
516
|
this._rootContainer.removeControl(control);
|
|
515
517
|
return this;
|
|
516
518
|
};
|
|
517
519
|
/**
|
|
518
|
-
|
|
519
|
-
|
|
520
|
+
* Moves overlapped controls towards a position where it is not overlapping anymore.
|
|
521
|
+
* Please note that this method alters linkOffsetXInPixels and linkOffsetYInPixels.
|
|
522
|
+
* @param overlapGroup the overlap group which will be processed or undefined to process all overlap groups
|
|
523
|
+
* @param deltaStep the step size (speed) to reach the target non overlapping position (default 0.1)
|
|
524
|
+
* @param repelFactor how much is the control repelled by other controls
|
|
525
|
+
*/
|
|
526
|
+
AdvancedDynamicTexture.prototype.moveToNonOverlappedPosition = function (overlapGroup, deltaStep, repelFactor) {
|
|
527
|
+
if (deltaStep === void 0) { deltaStep = 1; }
|
|
528
|
+
if (repelFactor === void 0) { repelFactor = 1; }
|
|
529
|
+
var controlsForGroup;
|
|
530
|
+
if (Array.isArray(overlapGroup)) {
|
|
531
|
+
controlsForGroup = overlapGroup;
|
|
532
|
+
}
|
|
533
|
+
else {
|
|
534
|
+
var descendants = this.getDescendants(true);
|
|
535
|
+
// get only the controls with an overlapGroup property set
|
|
536
|
+
// if the overlapGroup parameter is set, filter the controls and get only the controls belonging to that overlapGroup
|
|
537
|
+
controlsForGroup = overlapGroup === undefined ? descendants.filter(function (c) { return c.overlapGroup !== undefined; }) : descendants.filter(function (c) { return c.overlapGroup === overlapGroup; });
|
|
538
|
+
}
|
|
539
|
+
controlsForGroup.forEach(function (control1) {
|
|
540
|
+
var _a;
|
|
541
|
+
var velocity = Vector2.Zero();
|
|
542
|
+
var center = new Vector2(control1.centerX, control1.centerY);
|
|
543
|
+
controlsForGroup.forEach(function (control2) {
|
|
544
|
+
if (control1 !== control2 && AdvancedDynamicTexture._Overlaps(control1, control2)) {
|
|
545
|
+
// if the two controls overlaps get a direction vector from one control's center to another control's center
|
|
546
|
+
var diff = center.subtract(new Vector2(control2.centerX, control2.centerY));
|
|
547
|
+
var diffLength = diff.length();
|
|
548
|
+
if (diffLength > 0) {
|
|
549
|
+
// calculate the velocity
|
|
550
|
+
velocity = velocity.add(diff.normalize().scale(repelFactor / diffLength));
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
if (velocity.length() > 0) {
|
|
555
|
+
// move the control along the direction vector away from the overlapping control
|
|
556
|
+
velocity = velocity.normalize().scale(deltaStep * ((_a = control1.overlapDeltaMultiplier) !== null && _a !== void 0 ? _a : 1));
|
|
557
|
+
control1.linkOffsetXInPixels += velocity.x;
|
|
558
|
+
control1.linkOffsetYInPixels += velocity.y;
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
};
|
|
562
|
+
/**
|
|
563
|
+
* Release all resources
|
|
564
|
+
*/
|
|
520
565
|
AdvancedDynamicTexture.prototype.dispose = function () {
|
|
521
566
|
var scene = this.getScene();
|
|
522
567
|
if (!scene) {
|
|
@@ -591,21 +636,21 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
591
636
|
return this._fullscreenViewport.toGlobal(size.width, size.height);
|
|
592
637
|
};
|
|
593
638
|
/**
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
639
|
+
* Get screen coordinates for a vector3
|
|
640
|
+
* @param position defines the position to project
|
|
641
|
+
* @param worldMatrix defines the world matrix to use
|
|
642
|
+
* @returns the projected position
|
|
643
|
+
*/
|
|
599
644
|
AdvancedDynamicTexture.prototype.getProjectedPosition = function (position, worldMatrix) {
|
|
600
645
|
var result = this.getProjectedPositionWithZ(position, worldMatrix);
|
|
601
646
|
return new Vector2(result.x, result.y);
|
|
602
647
|
};
|
|
603
648
|
/**
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
649
|
+
* Get screen coordinates for a vector3
|
|
650
|
+
* @param position defines the position to project
|
|
651
|
+
* @param worldMatrix defines the world matrix to use
|
|
652
|
+
* @returns the projected position with Z
|
|
653
|
+
*/
|
|
609
654
|
AdvancedDynamicTexture.prototype.getProjectedPositionWithZ = function (position, worldMatrix) {
|
|
610
655
|
var scene = this.getScene();
|
|
611
656
|
if (!scene) {
|
|
@@ -657,7 +702,7 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
657
702
|
}
|
|
658
703
|
this._isDirty = false;
|
|
659
704
|
this._render();
|
|
660
|
-
this.update(this.applyYInversionOnUpdate, this.premulAlpha);
|
|
705
|
+
this.update(this.applyYInversionOnUpdate, this.premulAlpha, AdvancedDynamicTexture.AllowGPUOptimizations);
|
|
661
706
|
};
|
|
662
707
|
AdvancedDynamicTexture.prototype._render = function () {
|
|
663
708
|
var textureSize = this.getSize();
|
|
@@ -769,13 +814,13 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
769
814
|
}
|
|
770
815
|
var tempViewport = new Viewport(0, 0, 0, 0);
|
|
771
816
|
this._pointerMoveObserver = scene.onPrePointerObservable.add(function (pi, state) {
|
|
772
|
-
if (scene.isPointerCaptured(
|
|
817
|
+
if (scene.isPointerCaptured(pi.event.pointerId)) {
|
|
773
818
|
return;
|
|
774
819
|
}
|
|
775
|
-
if (pi.type !== PointerEventTypes.POINTERMOVE
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
820
|
+
if (pi.type !== PointerEventTypes.POINTERMOVE &&
|
|
821
|
+
pi.type !== PointerEventTypes.POINTERUP &&
|
|
822
|
+
pi.type !== PointerEventTypes.POINTERDOWN &&
|
|
823
|
+
pi.type !== PointerEventTypes.POINTERWHEEL) {
|
|
779
824
|
return;
|
|
780
825
|
}
|
|
781
826
|
if (pi.type === PointerEventTypes.POINTERMOVE && pi.event.pointerId) {
|
|
@@ -807,8 +852,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
807
852
|
this._attachToOnBlur(scene);
|
|
808
853
|
};
|
|
809
854
|
/**
|
|
810
|
-
|
|
811
|
-
|
|
855
|
+
* Register the clipboard Events onto the canvas
|
|
856
|
+
*/
|
|
812
857
|
AdvancedDynamicTexture.prototype.registerClipboardEvents = function () {
|
|
813
858
|
self.addEventListener("copy", this.onClipboardCopy, false);
|
|
814
859
|
self.addEventListener("cut", this.onClipboardCut, false);
|
|
@@ -823,10 +868,10 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
823
868
|
self.removeEventListener("paste", this.onClipboardPaste);
|
|
824
869
|
};
|
|
825
870
|
/**
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
871
|
+
* Connect the texture to a hosting mesh to enable interactions
|
|
872
|
+
* @param mesh defines the mesh to attach to
|
|
873
|
+
* @param supportPointerMove defines a boolean indicating if pointer move events must be catched as well
|
|
874
|
+
*/
|
|
830
875
|
AdvancedDynamicTexture.prototype.attachToMesh = function (mesh, supportPointerMove) {
|
|
831
876
|
var _this = this;
|
|
832
877
|
if (supportPointerMove === void 0) { supportPointerMove = true; }
|
|
@@ -835,10 +880,10 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
835
880
|
return;
|
|
836
881
|
}
|
|
837
882
|
this._pointerObserver = scene.onPointerObservable.add(function (pi, state) {
|
|
838
|
-
if (pi.type !== PointerEventTypes.POINTERMOVE
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
883
|
+
if (pi.type !== PointerEventTypes.POINTERMOVE &&
|
|
884
|
+
pi.type !== PointerEventTypes.POINTERUP &&
|
|
885
|
+
pi.type !== PointerEventTypes.POINTERDOWN &&
|
|
886
|
+
pi.type !== PointerEventTypes.POINTERWHEEL) {
|
|
842
887
|
return;
|
|
843
888
|
}
|
|
844
889
|
if (pi.type === PointerEventTypes.POINTERMOVE && pi.event.pointerId) {
|
|
@@ -849,7 +894,7 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
849
894
|
var uv = pi.pickInfo.getTextureCoordinates();
|
|
850
895
|
if (uv) {
|
|
851
896
|
var size = _this.getSize();
|
|
852
|
-
_this._doPicking(uv.x * size.width, (_this.applyYInversionOnUpdate ?
|
|
897
|
+
_this._doPicking(uv.x * size.width, (_this.applyYInversionOnUpdate ? 1.0 - uv.y : uv.y) * size.height, pi, pi.type, pointerId, pi.event.button, pi.event.deltaX, pi.event.deltaY);
|
|
853
898
|
}
|
|
854
899
|
}
|
|
855
900
|
else if (pi.type === PointerEventTypes.POINTERUP) {
|
|
@@ -892,9 +937,9 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
892
937
|
this._attachToOnBlur(scene);
|
|
893
938
|
};
|
|
894
939
|
/**
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
940
|
+
* Move the focus to a specific control
|
|
941
|
+
* @param control defines the control which will receive the focus
|
|
942
|
+
*/
|
|
898
943
|
AdvancedDynamicTexture.prototype.moveFocusToControl = function (control) {
|
|
899
944
|
this.focusedControl = control;
|
|
900
945
|
this._lastPickedControl = control;
|
|
@@ -964,7 +1009,7 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
964
1009
|
if (scaleToSize) {
|
|
965
1010
|
var width = serializedObject.width;
|
|
966
1011
|
var height = serializedObject.height;
|
|
967
|
-
if (typeof
|
|
1012
|
+
if (typeof width === "number" && typeof height === "number" && width >= 0 && height >= 0) {
|
|
968
1013
|
this.scaleTo(width, height);
|
|
969
1014
|
}
|
|
970
1015
|
}
|
|
@@ -1001,11 +1046,11 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
1001
1046
|
});
|
|
1002
1047
|
};
|
|
1003
1048
|
/**
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1049
|
+
* Recreate the content of the ADT from a url json
|
|
1050
|
+
* @param url defines the url to load
|
|
1051
|
+
* @param scaleToSize defines whether to scale to texture to the saved size
|
|
1052
|
+
* @returns a promise that will resolve on success
|
|
1053
|
+
*/
|
|
1009
1054
|
AdvancedDynamicTexture.prototype.parseFromURLAsync = function (url, scaleToSize) {
|
|
1010
1055
|
var _this = this;
|
|
1011
1056
|
if (url === "") {
|
|
@@ -1031,6 +1076,18 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
1031
1076
|
});
|
|
1032
1077
|
};
|
|
1033
1078
|
// Statics
|
|
1079
|
+
/**
|
|
1080
|
+
* Compares two rectangle based controls for pixel overlap
|
|
1081
|
+
* @param control1 The first control to compare
|
|
1082
|
+
* @param control2 The second control to compare
|
|
1083
|
+
* @returns true if overlaps, otherwise false
|
|
1084
|
+
*/
|
|
1085
|
+
AdvancedDynamicTexture._Overlaps = function (control1, control2) {
|
|
1086
|
+
return !(control1.centerX > control2.centerX + control2.widthInPixels ||
|
|
1087
|
+
control1.centerX + control1.widthInPixels < control2.centerX ||
|
|
1088
|
+
control1.centerY + control1.heightInPixels < control2.centerY ||
|
|
1089
|
+
control1.centerY > control2.centerY + control2.heightInPixels);
|
|
1090
|
+
};
|
|
1034
1091
|
/**
|
|
1035
1092
|
* Creates a new AdvancedDynamicTexture in projected mode (ie. attached to a mesh)
|
|
1036
1093
|
* @param mesh defines the mesh which will receive the texture
|
|
@@ -1082,17 +1139,17 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
1082
1139
|
return result;
|
|
1083
1140
|
};
|
|
1084
1141
|
/**
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1142
|
+
* Creates a new AdvancedDynamicTexture in fullscreen mode.
|
|
1143
|
+
* In this mode the texture will rely on a layer for its rendering.
|
|
1144
|
+
* This allows it to be treated like any other layer.
|
|
1145
|
+
* As such, if you have a multi camera setup, you can set the layerMask on the GUI as well.
|
|
1146
|
+
* LayerMask is set through advancedTexture.layer.layerMask
|
|
1147
|
+
* @param name defines name for the texture
|
|
1148
|
+
* @param foreground defines a boolean indicating if the texture must be rendered in foreground (default is true)
|
|
1149
|
+
* @param scene defines the hosting scene
|
|
1150
|
+
* @param sampling defines the texture sampling mode (Texture.BILINEAR_SAMPLINGMODE by default)
|
|
1151
|
+
* @returns a new AdvancedDynamicTexture
|
|
1152
|
+
*/
|
|
1096
1153
|
AdvancedDynamicTexture.CreateFullscreenUI = function (name, foreground, scene, sampling) {
|
|
1097
1154
|
if (foreground === void 0) { foreground = true; }
|
|
1098
1155
|
if (scene === void 0) { scene = null; }
|
|
@@ -1109,6 +1166,8 @@ var AdvancedDynamicTexture = /** @class */ (function (_super) {
|
|
|
1109
1166
|
};
|
|
1110
1167
|
/** Define the Uurl to load snippets */
|
|
1111
1168
|
AdvancedDynamicTexture.SnippetUrl = "https://snippet.babylonjs.com";
|
|
1169
|
+
/** Indicates if some optimizations can be performed in GUI GPU management (the downside is additional memory/GPU texture memory used) */
|
|
1170
|
+
AdvancedDynamicTexture.AllowGPUOptimizations = true;
|
|
1112
1171
|
return AdvancedDynamicTexture;
|
|
1113
1172
|
}(DynamicTexture));
|
|
1114
1173
|
export { AdvancedDynamicTexture };
|