babylonjs-gui 5.41.0 → 5.42.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/babylon.gui.d.ts CHANGED
@@ -2063,6 +2063,10 @@ declare module BABYLON.GUI {
2063
2063
  private _populateNinePatchSlicesFromImage;
2064
2064
  private _detectPointerOnOpaqueOnly;
2065
2065
  private _imageDataCache;
2066
+ static SourceImgCache: Map<string, {
2067
+ img: BABYLON.IImage;
2068
+ timesUsed: number;
2069
+ }>;
2066
2070
  /**
2067
2071
  * BABYLON.Observable notified when the content is loaded
2068
2072
  */
@@ -2169,6 +2173,11 @@ declare module BABYLON.GUI {
2169
2173
  * Gets the image source url
2170
2174
  */
2171
2175
  get source(): BABYLON.Nullable<string>;
2176
+ /**
2177
+ * Resets the internal Image Element cache. Can reduce memory usage.
2178
+ */
2179
+ static ResetImageCache(): void;
2180
+ private _removeCacheUsage;
2172
2181
  /**
2173
2182
  * Gets or sets image source url
2174
2183
  */
@@ -2430,6 +2439,10 @@ declare module BABYLON.GUI {
2430
2439
  _onPointerMove(target: Control, coordinates: BABYLON.Vector2, pointerId: number, pi: BABYLON.PointerInfoBase): void;
2431
2440
  _onPointerUp(target: Control, coordinates: BABYLON.Vector2, pointerId: number, buttonIndex: number, notifyClick: boolean): void;
2432
2441
  protected _beforeRenderText(textWrapper: TextWrapper): TextWrapper;
2442
+ /** @internal */
2443
+ private set isTextHighlightOn(value);
2444
+ /** @internal */
2445
+ private get isTextHighlightOn();
2433
2446
  dispose(): void;
2434
2447
  }
2435
2448
 
package/babylon.gui.js CHANGED
@@ -8406,6 +8406,7 @@ var Image = /** @class */ (function (_super) {
8406
8406
  if (this._source === value) {
8407
8407
  return;
8408
8408
  }
8409
+ this._removeCacheUsage(this._source);
8409
8410
  this._loaded = false;
8410
8411
  this._source = value;
8411
8412
  this._imageDataCache.data = null;
@@ -8417,7 +8418,17 @@ var Image = /** @class */ (function (_super) {
8417
8418
  if (!engine) {
8418
8419
  throw new Error("Invalid engine. Unable to create a canvas.");
8419
8420
  }
8421
+ if (value && Image.SourceImgCache.has(value)) {
8422
+ var cachedData = Image.SourceImgCache.get(value);
8423
+ this._domImage = cachedData.img;
8424
+ cachedData.timesUsed += 1;
8425
+ this._onImageLoaded();
8426
+ return;
8427
+ }
8420
8428
  this._domImage = engine.createCanvasImage();
8429
+ if (value) {
8430
+ Image.SourceImgCache.set(value, { img: this._domImage, timesUsed: 1 });
8431
+ }
8421
8432
  this._domImage.onload = function () {
8422
8433
  _this._onImageLoaded();
8423
8434
  };
@@ -8430,6 +8441,22 @@ var Image = /** @class */ (function (_super) {
8430
8441
  enumerable: false,
8431
8442
  configurable: true
8432
8443
  });
8444
+ /**
8445
+ * Resets the internal Image Element cache. Can reduce memory usage.
8446
+ */
8447
+ Image.ResetImageCache = function () {
8448
+ Image.SourceImgCache.clear();
8449
+ };
8450
+ Image.prototype._removeCacheUsage = function (source) {
8451
+ var value = source && Image.SourceImgCache.get(source);
8452
+ if (value) {
8453
+ value.timesUsed -= 1;
8454
+ // Since the image isn't being used anymore, we can clean it from the cache
8455
+ if (value.timesUsed === 0) {
8456
+ Image.SourceImgCache.delete(source);
8457
+ }
8458
+ }
8459
+ };
8433
8460
  /**
8434
8461
  * Checks for svg document with icon id present
8435
8462
  * @param value
@@ -8764,7 +8791,9 @@ var Image = /** @class */ (function (_super) {
8764
8791
  _super.prototype.dispose.call(this);
8765
8792
  this.onImageLoadedObservable.clear();
8766
8793
  this.onSVGAttributesComputedObservable.clear();
8794
+ this._removeCacheUsage(this._source);
8767
8795
  };
8796
+ Image.SourceImgCache = new Map();
8768
8797
  // Static
8769
8798
  /** STRETCH_NONE */
8770
8799
  Image.STRETCH_NONE = 0;
@@ -9494,10 +9523,10 @@ var InputText = /** @class */ (function (_super) {
9494
9523
  case 8: // BACKSPACE
9495
9524
  if (this._textWrapper.text && this._textWrapper.length > 0) {
9496
9525
  //delete the highlighted text
9497
- if (this._isTextHighlightOn) {
9526
+ if (this.isTextHighlightOn) {
9498
9527
  this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
9499
9528
  this._textHasChanged();
9500
- this._isTextHighlightOn = false;
9529
+ this.isTextHighlightOn = false;
9501
9530
  this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
9502
9531
  this._blinkIsEven = false;
9503
9532
  if (evt) {
@@ -9522,10 +9551,10 @@ var InputText = /** @class */ (function (_super) {
9522
9551
  }
9523
9552
  return;
9524
9553
  case 46: // DELETE
9525
- if (this._isTextHighlightOn) {
9554
+ if (this.isTextHighlightOn) {
9526
9555
  this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
9527
9556
  this._textHasChanged();
9528
- this._isTextHighlightOn = false;
9557
+ this.isTextHighlightOn = false;
9529
9558
  this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
9530
9559
  if (evt) {
9531
9560
  evt.preventDefault();
@@ -9544,18 +9573,18 @@ var InputText = /** @class */ (function (_super) {
9544
9573
  return;
9545
9574
  case 13: // RETURN
9546
9575
  this._host.focusedControl = null;
9547
- this._isTextHighlightOn = false;
9576
+ this.isTextHighlightOn = false;
9548
9577
  return;
9549
9578
  case 35: // END
9550
9579
  this._cursorOffset = 0;
9551
9580
  this._blinkIsEven = false;
9552
- this._isTextHighlightOn = false;
9581
+ this.isTextHighlightOn = false;
9553
9582
  this._markAsDirty();
9554
9583
  return;
9555
9584
  case 36: // HOME
9556
9585
  this._cursorOffset = this._textWrapper.length;
9557
9586
  this._blinkIsEven = false;
9558
- this._isTextHighlightOn = false;
9587
+ this.isTextHighlightOn = false;
9559
9588
  this._markAsDirty();
9560
9589
  return;
9561
9590
  case 37: // LEFT
@@ -9568,7 +9597,7 @@ var InputText = /** @class */ (function (_super) {
9568
9597
  this._blinkIsEven = false;
9569
9598
  // shift + ctrl/cmd + <-
9570
9599
  if (evt.ctrlKey || evt.metaKey) {
9571
- if (!this._isTextHighlightOn) {
9600
+ if (!this.isTextHighlightOn) {
9572
9601
  if (this._textWrapper.length === this._cursorOffset) {
9573
9602
  return;
9574
9603
  }
@@ -9579,13 +9608,13 @@ var InputText = /** @class */ (function (_super) {
9579
9608
  this._startHighlightIndex = 0;
9580
9609
  this._cursorIndex = this._textWrapper.length - this._endHighlightIndex;
9581
9610
  this._cursorOffset = this._textWrapper.length;
9582
- this._isTextHighlightOn = true;
9611
+ this.isTextHighlightOn = true;
9583
9612
  this._markAsDirty();
9584
9613
  return;
9585
9614
  }
9586
9615
  //store the starting point
9587
- if (!this._isTextHighlightOn) {
9588
- this._isTextHighlightOn = true;
9616
+ if (!this.isTextHighlightOn) {
9617
+ this.isTextHighlightOn = true;
9589
9618
  this._cursorIndex = this._cursorOffset >= this._textWrapper.length ? this._textWrapper.length : this._cursorOffset - 1;
9590
9619
  }
9591
9620
  //if text is already highlighted
@@ -9603,21 +9632,21 @@ var InputText = /** @class */ (function (_super) {
9603
9632
  this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
9604
9633
  }
9605
9634
  else {
9606
- this._isTextHighlightOn = false;
9635
+ this.isTextHighlightOn = false;
9607
9636
  }
9608
9637
  this._markAsDirty();
9609
9638
  return;
9610
9639
  }
9611
- if (this._isTextHighlightOn) {
9640
+ if (this.isTextHighlightOn) {
9612
9641
  this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
9613
- this._isTextHighlightOn = false;
9642
+ this.isTextHighlightOn = false;
9614
9643
  }
9615
9644
  if (evt && (evt.ctrlKey || evt.metaKey)) {
9616
9645
  this._cursorOffset = this._textWrapper.length;
9617
9646
  evt.preventDefault();
9618
9647
  }
9619
9648
  this._blinkIsEven = false;
9620
- this._isTextHighlightOn = false;
9649
+ this.isTextHighlightOn = false;
9621
9650
  this._cursorIndex = -1;
9622
9651
  this._markAsDirty();
9623
9652
  return;
@@ -9631,7 +9660,7 @@ var InputText = /** @class */ (function (_super) {
9631
9660
  this._blinkIsEven = false;
9632
9661
  //shift + ctrl/cmd + ->
9633
9662
  if (evt.ctrlKey || evt.metaKey) {
9634
- if (!this._isTextHighlightOn) {
9663
+ if (!this.isTextHighlightOn) {
9635
9664
  if (this._cursorOffset === 0) {
9636
9665
  return;
9637
9666
  }
@@ -9640,14 +9669,14 @@ var InputText = /** @class */ (function (_super) {
9640
9669
  }
9641
9670
  }
9642
9671
  this._endHighlightIndex = this._textWrapper.length;
9643
- this._isTextHighlightOn = true;
9672
+ this.isTextHighlightOn = true;
9644
9673
  this._cursorIndex = this._textWrapper.length - this._startHighlightIndex;
9645
9674
  this._cursorOffset = 0;
9646
9675
  this._markAsDirty();
9647
9676
  return;
9648
9677
  }
9649
- if (!this._isTextHighlightOn) {
9650
- this._isTextHighlightOn = true;
9678
+ if (!this.isTextHighlightOn) {
9679
+ this.isTextHighlightOn = true;
9651
9680
  this._cursorIndex = this._cursorOffset <= 0 ? 0 : this._cursorOffset + 1;
9652
9681
  }
9653
9682
  //if text is already highlighted
@@ -9665,14 +9694,14 @@ var InputText = /** @class */ (function (_super) {
9665
9694
  this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
9666
9695
  }
9667
9696
  else {
9668
- this._isTextHighlightOn = false;
9697
+ this.isTextHighlightOn = false;
9669
9698
  }
9670
9699
  this._markAsDirty();
9671
9700
  return;
9672
9701
  }
9673
- if (this._isTextHighlightOn) {
9702
+ if (this.isTextHighlightOn) {
9674
9703
  this._cursorOffset = this._textWrapper.length - this._endHighlightIndex;
9675
- this._isTextHighlightOn = false;
9704
+ this.isTextHighlightOn = false;
9676
9705
  }
9677
9706
  //ctr + ->
9678
9707
  if (evt && (evt.ctrlKey || evt.metaKey)) {
@@ -9680,7 +9709,7 @@ var InputText = /** @class */ (function (_super) {
9680
9709
  evt.preventDefault();
9681
9710
  }
9682
9711
  this._blinkIsEven = false;
9683
- this._isTextHighlightOn = false;
9712
+ this.isTextHighlightOn = false;
9684
9713
  this._cursorIndex = -1;
9685
9714
  this._markAsDirty();
9686
9715
  return;
@@ -9705,11 +9734,11 @@ var InputText = /** @class */ (function (_super) {
9705
9734
  this.onBeforeKeyAddObservable.notifyObservers(this);
9706
9735
  key = this._currentKey;
9707
9736
  if (this._addKey && !this._deadKey) {
9708
- if (this._isTextHighlightOn) {
9737
+ if (this.isTextHighlightOn) {
9709
9738
  this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex, key);
9710
9739
  this._textHasChanged();
9711
9740
  this._cursorOffset = this._textWrapper.length - (this._startHighlightIndex + 1);
9712
- this._isTextHighlightOn = false;
9741
+ this.isTextHighlightOn = false;
9713
9742
  this._blinkIsEven = false;
9714
9743
  this._markAsDirty();
9715
9744
  }
@@ -9743,12 +9772,12 @@ var InputText = /** @class */ (function (_super) {
9743
9772
  this._startHighlightIndex = this._textWrapper.length - this._cursorIndex;
9744
9773
  }
9745
9774
  else {
9746
- this._isTextHighlightOn = false;
9775
+ this.isTextHighlightOn = false;
9747
9776
  this._markAsDirty();
9748
9777
  return;
9749
9778
  }
9750
9779
  }
9751
- this._isTextHighlightOn = true;
9780
+ this.isTextHighlightOn = true;
9752
9781
  this._markAsDirty();
9753
9782
  };
9754
9783
  /**
@@ -9765,8 +9794,7 @@ var InputText = /** @class */ (function (_super) {
9765
9794
  moveLeft = this._startHighlightIndex > 0 && this._textWrapper.isWord(this._startHighlightIndex - 1) ? --this._startHighlightIndex : 0;
9766
9795
  } while (moveLeft || moveRight);
9767
9796
  this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
9768
- this.onTextHighlightObservable.notifyObservers(this);
9769
- this._isTextHighlightOn = true;
9797
+ this.isTextHighlightOn = true;
9770
9798
  this._clickedCoordinate = null;
9771
9799
  this._blinkIsEven = true;
9772
9800
  this._cursorIndex = -1;
@@ -9775,7 +9803,7 @@ var InputText = /** @class */ (function (_super) {
9775
9803
  /** @internal */
9776
9804
  InputText.prototype._selectAllText = function () {
9777
9805
  this._blinkIsEven = true;
9778
- this._isTextHighlightOn = true;
9806
+ this.isTextHighlightOn = true;
9779
9807
  this._startHighlightIndex = 0;
9780
9808
  this._endHighlightIndex = this._textWrapper.length;
9781
9809
  this._cursorOffset = this._textWrapper.length;
@@ -9795,7 +9823,7 @@ var InputText = /** @class */ (function (_super) {
9795
9823
  * @internal
9796
9824
  */
9797
9825
  InputText.prototype._onCopyText = function (ev) {
9798
- this._isTextHighlightOn = false;
9826
+ this.isTextHighlightOn = false;
9799
9827
  //when write permission to clipbaord data is denied
9800
9828
  try {
9801
9829
  ev.clipboardData && ev.clipboardData.setData("text/plain", this._highlightedText);
@@ -9812,7 +9840,7 @@ var InputText = /** @class */ (function (_super) {
9812
9840
  }
9813
9841
  this._textWrapper.removePart(this._startHighlightIndex, this._endHighlightIndex);
9814
9842
  this._textHasChanged();
9815
- this._isTextHighlightOn = false;
9843
+ this.isTextHighlightOn = false;
9816
9844
  this._cursorOffset = this._textWrapper.length - this._startHighlightIndex;
9817
9845
  //when write permission to clipbaord data is denied
9818
9846
  try {
@@ -9940,7 +9968,7 @@ var InputText = /** @class */ (function (_super) {
9940
9968
  cursorLeft = clipTextLeft + availableWidth;
9941
9969
  this._markAsDirty();
9942
9970
  }
9943
- if (!this._isTextHighlightOn) {
9971
+ if (!this.isTextHighlightOn) {
9944
9972
  context.fillRect(cursorLeft, this._currentMeasure.top + (this._currentMeasure.height - this._fontOffset.height) / 2, 2, this._fontOffset.height);
9945
9973
  }
9946
9974
  }
@@ -9950,7 +9978,7 @@ var InputText = /** @class */ (function (_super) {
9950
9978
  _this._markAsDirty();
9951
9979
  }, 500);
9952
9980
  //show the highlighted text
9953
- if (this._isTextHighlightOn) {
9981
+ if (this.isTextHighlightOn) {
9954
9982
  clearTimeout(this._blinkTimeout);
9955
9983
  var highlightCursorOffsetWidth = context.measureText(text.substring(this._startHighlightIndex)).width;
9956
9984
  var highlightCursorLeft = this._scrollLeft + this._textWidth - highlightCursorOffsetWidth;
@@ -9998,7 +10026,7 @@ var InputText = /** @class */ (function (_super) {
9998
10026
  return true;
9999
10027
  }
10000
10028
  this._clickedCoordinate = coordinates.x;
10001
- this._isTextHighlightOn = false;
10029
+ this.isTextHighlightOn = false;
10002
10030
  this._highlightedText = "";
10003
10031
  this._cursorIndex = -1;
10004
10032
  this._isPointerDown = true;
@@ -10032,6 +10060,24 @@ var InputText = /** @class */ (function (_super) {
10032
10060
  InputText.prototype._beforeRenderText = function (textWrapper) {
10033
10061
  return textWrapper;
10034
10062
  };
10063
+ Object.defineProperty(InputText.prototype, "isTextHighlightOn", {
10064
+ /** @internal */
10065
+ get: function () {
10066
+ return this._isTextHighlightOn;
10067
+ },
10068
+ /** @internal */
10069
+ set: function (value) {
10070
+ if (this._isTextHighlightOn === value) {
10071
+ return;
10072
+ }
10073
+ if (value) {
10074
+ this.onTextHighlightObservable.notifyObservers(this);
10075
+ }
10076
+ this._isTextHighlightOn = value;
10077
+ },
10078
+ enumerable: false,
10079
+ configurable: true
10080
+ });
10035
10081
  InputText.prototype.dispose = function () {
10036
10082
  _super.prototype.dispose.call(this);
10037
10083
  this.onBlurObservable.clear();
@@ -21961,6 +22007,10 @@ var Slider3D = /** @class */ (function (_super) {
21961
22007
  sliderBackplate.visibility = 0;
21962
22008
  sliderBackplate.scaling = new core_Misc_observable__WEBPACK_IMPORTED_MODULE_1__.Vector3(1, 0.5, 0.8);
21963
22009
  core_Misc_observable__WEBPACK_IMPORTED_MODULE_1__.SceneLoader.ImportMeshAsync(undefined, Slider3D.MODEL_BASE_URL, Slider3D.MODEL_FILENAME, scene).then(function (result) {
22010
+ // make all meshes not pickable. Required meshes' pickable state will be set later.
22011
+ result.meshes.forEach(function (m) {
22012
+ m.isPickable = false;
22013
+ });
21964
22014
  var sliderBackplateModel = result.meshes[1];
21965
22015
  var sliderBarModel = result.meshes[1].clone("".concat(_this.name, "_sliderbar"), sliderBackplate);
21966
22016
  var sliderThumbModel = result.meshes[1].clone("".concat(_this.name, "_sliderthumb"), sliderBackplate);
@@ -21968,7 +22018,6 @@ var Slider3D = /** @class */ (function (_super) {
21968
22018
  if (_this._sliderBackplateVisible) {
21969
22019
  sliderBackplateModel.visibility = 1;
21970
22020
  sliderBackplateModel.name = "".concat(_this.name, "_sliderbackplate");
21971
- sliderBackplateModel.isPickable = false;
21972
22021
  sliderBackplateModel.scaling.x = 1;
21973
22022
  sliderBackplateModel.scaling.z = 0.2;
21974
22023
  sliderBackplateModel.parent = sliderBackplate;
@@ -21981,7 +22030,6 @@ var Slider3D = /** @class */ (function (_super) {
21981
22030
  sliderBarModel.parent = sliderBackplate;
21982
22031
  sliderBarModel.position.z = -0.1;
21983
22032
  sliderBarModel.scaling = new core_Misc_observable__WEBPACK_IMPORTED_MODULE_1__.Vector3(SLIDER_SCALING - SLIDER_MARGIN, 0.04, 0.3);
21984
- sliderBarModel.isPickable = false;
21985
22033
  if (_this._sliderBarMaterial) {
21986
22034
  sliderBarModel.material = _this._sliderBarMaterial;
21987
22035
  }
@@ -29036,6 +29084,9 @@ var MRDLSliderThumbMaterial = /** @class */ (function (_super) {
29036
29084
  _this.alphaMode = core_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__.Constants.ALPHA_DISABLE;
29037
29085
  _this.backFaceCulling = false;
29038
29086
  _this._blueGradientTexture = new core_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__.Texture(MRDLSliderThumbMaterial.BLUE_GRADIENT_TEXTURE_URL, scene, true, false, core_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__.Texture.NEAREST_SAMPLINGMODE);
29087
+ _this._decalTexture = new core_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__.Texture("", _this.getScene());
29088
+ _this._reflectionMapTexture = new core_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__.Texture("", _this.getScene());
29089
+ _this._indirectEnvTexture = new core_Misc_decorators__WEBPACK_IMPORTED_MODULE_1__.Texture("", _this.getScene());
29039
29090
  return _this;
29040
29091
  }
29041
29092
  MRDLSliderThumbMaterial.prototype.needAlphaBlending = function () {