|
@@ -5,6 +5,7 @@ import { StackPanel } from "../../2D/controls/stackPanel";
|
|
import { Image } from "../../2D/controls/image";
|
|
import { Image } from "../../2D/controls/image";
|
|
import { TextBlock } from "../../2D/controls/textBlock";
|
|
import { TextBlock } from "../../2D/controls/textBlock";
|
|
import { AdvancedDynamicTexture } from "../../2D/advancedDynamicTexture";
|
|
import { AdvancedDynamicTexture } from "../../2D/advancedDynamicTexture";
|
|
|
|
+import { Control3D } from "./control3D";
|
|
|
|
|
|
/**
|
|
/**
|
|
* Class used to create a holographic button in 3D
|
|
* Class used to create a holographic button in 3D
|
|
@@ -21,6 +22,88 @@ export class HolographicButton extends Button3D {
|
|
private _plateMaterial: StandardMaterial;
|
|
private _plateMaterial: StandardMaterial;
|
|
private _pickedPointObserver: Nullable<Observer<Nullable<Vector3>>>;
|
|
private _pickedPointObserver: Nullable<Observer<Nullable<Vector3>>>;
|
|
|
|
|
|
|
|
+ // Tooltip
|
|
|
|
+ private _tooltipFade: Nullable<BABYLON.FadeInOutBehavior>;
|
|
|
|
+ private _tooltipTextBlock: Nullable<TextBlock>;
|
|
|
|
+ private _tooltipTexture: Nullable<AdvancedDynamicTexture>;
|
|
|
|
+ private _tooltipMesh: Nullable<Mesh>;
|
|
|
|
+ private _tooltipHoverObserver:Nullable<Observer<Control3D>>
|
|
|
|
+ private _tooltipOutObserver:Nullable<Observer<Control3D>>
|
|
|
|
+
|
|
|
|
+ private _disposeTooltip(){
|
|
|
|
+ this._tooltipFade = null;
|
|
|
|
+ if(this._tooltipTextBlock){
|
|
|
|
+ this._tooltipTextBlock.dispose();
|
|
|
|
+ }
|
|
|
|
+ if(this._tooltipTexture){
|
|
|
|
+ this._tooltipTexture.dispose();
|
|
|
|
+ }
|
|
|
|
+ if(this._tooltipMesh){
|
|
|
|
+ this._tooltipMesh.dispose();
|
|
|
|
+ }
|
|
|
|
+ this.onPointerEnterObservable.remove(this._tooltipHoverObserver);
|
|
|
|
+ this.onPointerOutObservable.remove(this._tooltipOutObserver);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Text to be displayed on the tooltip shown when hovering on the button. When set to null tooltip is disabled. (Default: null)
|
|
|
|
+ */
|
|
|
|
+ public set tooltipText(text:Nullable<string>){
|
|
|
|
+ if(!text){
|
|
|
|
+ this._disposeTooltip();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if(!this._tooltipFade){
|
|
|
|
+ // Create tooltip with mesh and text
|
|
|
|
+ this._tooltipMesh = BABYLON.MeshBuilder.CreatePlane("", {size: 1}, this._backPlate._scene)
|
|
|
|
+ var tooltipBackground = BABYLON.MeshBuilder.CreatePlane("", {size: 1, sideOrientation: BABYLON.Mesh.DOUBLESIDE}, this._backPlate._scene)
|
|
|
|
+ var mat = new StandardMaterial("", this._backPlate._scene);
|
|
|
|
+ mat.diffuseColor = BABYLON.Color3.FromHexString("#212121")
|
|
|
|
+ tooltipBackground.material = mat
|
|
|
|
+ tooltipBackground.isPickable = false;
|
|
|
|
+ this._tooltipMesh.addChild(tooltipBackground)
|
|
|
|
+ tooltipBackground.position.z = 0.05
|
|
|
|
+ this._tooltipMesh.scaling.y = 1/3
|
|
|
|
+ this._tooltipMesh.position.y = 0.7;
|
|
|
|
+ this._tooltipMesh.position.z = -0.15;
|
|
|
|
+ this._tooltipMesh.isPickable = false;
|
|
|
|
+ this._tooltipMesh.parent = this._backPlate;
|
|
|
|
+
|
|
|
|
+ // Create text texture for the tooltip
|
|
|
|
+ this._tooltipTexture = AdvancedDynamicTexture.CreateForMesh(this._tooltipMesh)
|
|
|
|
+ this._tooltipTextBlock = new TextBlock();
|
|
|
|
+ this._tooltipTextBlock.scaleY = 3
|
|
|
|
+ this._tooltipTextBlock.color = "white";
|
|
|
|
+ this._tooltipTextBlock.fontSize = 130;
|
|
|
|
+ this._tooltipTexture.addControl(this._tooltipTextBlock);
|
|
|
|
+
|
|
|
|
+ // Add hover action to tooltip
|
|
|
|
+ this._tooltipFade = new BABYLON.FadeInOutBehavior();
|
|
|
|
+ this._tooltipFade.delay = 500;
|
|
|
|
+ this._tooltipMesh.addBehavior(this._tooltipFade);
|
|
|
|
+ this._tooltipHoverObserver = this.onPointerEnterObservable.add(()=>{
|
|
|
|
+ if(this._tooltipFade){
|
|
|
|
+ this._tooltipFade.fadeIn(true)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ this._tooltipOutObserver = this.onPointerOutObservable.add(()=>{
|
|
|
|
+ if(this._tooltipFade){
|
|
|
|
+ this._tooltipFade.fadeIn(false)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ if(this._tooltipTextBlock){
|
|
|
|
+ this._tooltipTextBlock.text = text;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public get tooltipText(){
|
|
|
|
+ if(this._tooltipTextBlock){
|
|
|
|
+ return this._tooltipTextBlock.text;
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Gets or sets text for the button
|
|
* Gets or sets text for the button
|
|
*/
|
|
*/
|
|
@@ -233,6 +316,8 @@ export class HolographicButton extends Button3D {
|
|
public dispose() {
|
|
public dispose() {
|
|
super.dispose(); // will dispose main mesh ie. back plate
|
|
super.dispose(); // will dispose main mesh ie. back plate
|
|
|
|
|
|
|
|
+ this._disposeTooltip();
|
|
|
|
+
|
|
if (!this.shareMaterials) {
|
|
if (!this.shareMaterials) {
|
|
this._backMaterial.dispose();
|
|
this._backMaterial.dispose();
|
|
this._frontMaterial.dispose();
|
|
this._frontMaterial.dispose();
|