Explorar el Código

Fixed issue with pointer down when in projected mode

David Catuhe hace 8 años
padre
commit
7118886cd8

+ 9 - 7
dist/preview release/gui/babylon.gui.d.ts

@@ -148,6 +148,8 @@ declare module BABYLON.GUI {
         _linkedMesh: AbstractMesh;
         private _fontSet;
         private _dummyVector2;
+        private _downCount;
+        private _enterCount;
         isHitTestVisible: boolean;
         isPointerBlocker: boolean;
         protected _linkOffsetX: ValueAndUnit;
@@ -227,9 +229,9 @@ declare module BABYLON.GUI {
         contains(x: number, y: number): boolean;
         _processPicking(x: number, y: number, type: number): boolean;
         protected _onPointerMove(coordinates: Vector2): void;
-        protected _onPointerEnter(): void;
+        protected _onPointerEnter(): boolean;
         protected _onPointerOut(): void;
-        protected _onPointerDown(coordinates: Vector2): void;
+        protected _onPointerDown(coordinates: Vector2): boolean;
         protected _onPointerUp(coordinates: Vector2): void;
         forcePointerUp(): void;
         _processObservables(type: number, x: number, y: number): boolean;
@@ -383,7 +385,7 @@ declare module BABYLON.GUI {
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
         private _pointerIsDown;
         private _updateValueFromPointer(x);
-        protected _onPointerDown(coordinates: Vector2): void;
+        protected _onPointerDown(coordinates: Vector2): boolean;
         protected _onPointerMove(coordinates: Vector2): void;
         protected _onPointerUp(coordinates: Vector2): void;
     }
@@ -405,7 +407,7 @@ declare module BABYLON.GUI {
         isChecked: boolean;
         constructor(name?: string);
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
-        protected _onPointerDown(coordinates: Vector2): void;
+        protected _onPointerDown(coordinates: Vector2): boolean;
     }
 }
 
@@ -426,7 +428,7 @@ declare module BABYLON.GUI {
         isChecked: boolean;
         constructor(name?: string);
         _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
-        protected _onPointerDown(coordinates: Vector2): void;
+        protected _onPointerDown(coordinates: Vector2): boolean;
     }
 }
 
@@ -494,9 +496,9 @@ declare module BABYLON.GUI {
         pointerUpAnimation: () => void;
         constructor(name?: string);
         _processPicking(x: number, y: number, type: number): boolean;
-        protected _onPointerEnter(): void;
+        protected _onPointerEnter(): boolean;
         protected _onPointerOut(): void;
-        protected _onPointerDown(coordinates: Vector2): void;
+        protected _onPointerDown(coordinates: Vector2): boolean;
         protected _onPointerUp(coordinates: Vector2): void;
         static CreateImageButton(name: string, text: string, imageUrl: string): Button;
         static CreateImageOnlyButton(name: string, imageUrl: string): Button;

+ 40 - 5
dist/preview release/gui/babylon.gui.js

@@ -246,6 +246,12 @@ var BABYLON;
                         var size = _this.getSize();
                         _this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type);
                     }
+                    else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
+                        if (_this._lastControlDown) {
+                            _this._lastControlDown.forcePointerUp();
+                        }
+                        _this._lastControlDown = null;
+                    }
                 });
             };
             // Statics
@@ -601,6 +607,8 @@ var BABYLON;
                 this._isVisible = true;
                 this._fontSet = false;
                 this._dummyVector2 = BABYLON.Vector2.Zero();
+                this._downCount = 0;
+                this._enterCount = 0;
                 this.isHitTestVisible = true;
                 this.isPointerBlocker = false;
                 this._linkOffsetX = new GUI.ValueAndUnit(0);
@@ -1233,21 +1241,33 @@ var BABYLON;
                 }
             };
             Control.prototype._onPointerEnter = function () {
+                if (this._enterCount !== 0) {
+                    return false;
+                }
+                this._enterCount++;
                 if (this.onPointerEnterObservable.hasObservers()) {
                     this.onPointerEnterObservable.notifyObservers(this);
                 }
+                return true;
             };
             Control.prototype._onPointerOut = function () {
+                this._enterCount = 0;
                 if (this.onPointerOutObservable.hasObservers()) {
                     this.onPointerOutObservable.notifyObservers(this);
                 }
             };
             Control.prototype._onPointerDown = function (coordinates) {
+                if (this._downCount !== 0) {
+                    return false;
+                }
+                this._downCount++;
                 if (this.onPointerDownObservable.hasObservers()) {
                     this.onPointerDownObservable.notifyObservers(coordinates);
                 }
+                return true;
             };
             Control.prototype._onPointerUp = function (coordinates) {
+                this._downCount = 0;
                 if (this.onPointerUpObservable.hasObservers()) {
                     this.onPointerUpObservable.notifyObservers(coordinates);
                 }
@@ -2230,10 +2250,13 @@ var BABYLON;
                 this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
             };
             Slider.prototype._onPointerDown = function (coordinates) {
+                if (!_super.prototype._onPointerDown.call(this, coordinates)) {
+                    return false;
+                }
                 this._pointerIsDown = true;
                 this._updateValueFromPointer(coordinates.x);
                 this._host._capturingControl = this;
-                _super.prototype._onPointerDown.call(this, coordinates);
+                return true;
             };
             Slider.prototype._onPointerMove = function (coordinates) {
                 if (this._pointerIsDown) {
@@ -2362,8 +2385,11 @@ var BABYLON;
             };
             // Events
             Checkbox.prototype._onPointerDown = function (coordinates) {
+                if (!_super.prototype._onPointerDown.call(this, coordinates)) {
+                    return false;
+                }
                 this.isChecked = !this.isChecked;
-                _super.prototype._onPointerDown.call(this, coordinates);
+                return true;
             };
             return Checkbox;
         }(GUI.Control));
@@ -2507,8 +2533,11 @@ var BABYLON;
             };
             // Events
             RadioButton.prototype._onPointerDown = function (coordinates) {
+                if (!_super.prototype._onPointerDown.call(this, coordinates)) {
+                    return false;
+                }
                 this.isChecked = !this.isChecked;
-                _super.prototype._onPointerDown.call(this, coordinates);
+                return true;
             };
             return RadioButton;
         }(GUI.Control));
@@ -2918,10 +2947,13 @@ var BABYLON;
                 return true;
             };
             Button.prototype._onPointerEnter = function () {
+                if (!_super.prototype._onPointerEnter.call(this)) {
+                    return false;
+                }
                 if (this.pointerEnterAnimation) {
                     this.pointerEnterAnimation();
                 }
-                _super.prototype._onPointerEnter.call(this);
+                return true;
             };
             Button.prototype._onPointerOut = function () {
                 if (this.pointerOutAnimation) {
@@ -2930,10 +2962,13 @@ var BABYLON;
                 _super.prototype._onPointerOut.call(this);
             };
             Button.prototype._onPointerDown = function (coordinates) {
+                if (!_super.prototype._onPointerDown.call(this, coordinates)) {
+                    return false;
+                }
                 if (this.pointerDownAnimation) {
                     this.pointerDownAnimation();
                 }
-                _super.prototype._onPointerDown.call(this, coordinates);
+                return true;
             };
             Button.prototype._onPointerUp = function (coordinates) {
                 if (this.pointerUpAnimation) {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 2
dist/preview release/gui/babylon.gui.min.js


+ 5 - 0
gui/src/advancedDynamicTexture.ts

@@ -273,6 +273,11 @@ module BABYLON.GUI {
                     var uv = pi.pickInfo.getTextureCoordinates();
                     var size = this.getSize();
                     this._doPicking(uv.x * size.width, (1.0 - uv.y) * size.height, pi.type);
+                } else if (pi.type === BABYLON.PointerEventTypes.POINTERUP) {
+                    if (this._lastControlDown) {
+                        this._lastControlDown.forcePointerUp();
+                    }
+                    this._lastControlDown = null;  
                 }
             });
         }

+ 14 - 4
gui/src/controls/button.ts

@@ -42,11 +42,16 @@ module BABYLON.GUI {
             return true;
         }
 
-        protected _onPointerEnter(): void {
+        protected _onPointerEnter(): boolean {
+            if (!super._onPointerEnter()) {
+                return false;
+            }
+
             if (this.pointerEnterAnimation) {
                 this.pointerEnterAnimation();
             }
-            super._onPointerEnter();
+
+            return true;
         }
 
         protected _onPointerOut(): void {
@@ -57,12 +62,17 @@ module BABYLON.GUI {
             super._onPointerOut();
         }
 
-        protected _onPointerDown(coordinates: Vector2): void {
+        protected _onPointerDown(coordinates: Vector2): boolean {
+            if (!super._onPointerDown(coordinates)) {
+                return false;
+            }
+
+
             if (this.pointerDownAnimation) {
                 this.pointerDownAnimation();
             }
 
-            super._onPointerDown(coordinates);
+            return true;
         }
 
         protected _onPointerUp(coordinates: Vector2): void {

+ 6 - 2
gui/src/controls/checkbox.ts

@@ -101,10 +101,14 @@ module BABYLON.GUI {
         }
 
         // Events
-        protected _onPointerDown(coordinates: Vector2): void {
+        protected _onPointerDown(coordinates: Vector2): boolean {
+            if (!super._onPointerDown(coordinates)) {
+                return false;
+            }
+
             this.isChecked = !this.isChecked;
 
-            super._onPointerDown(coordinates);
+            return true;
         }
     }    
 }

+ 20 - 2
gui/src/controls/control.ts

@@ -41,6 +41,8 @@ module BABYLON.GUI {
         public _linkedMesh: AbstractMesh;
         private _fontSet = false;
         private _dummyVector2 = Vector2.Zero();
+        private _downCount = 0;
+        private _enterCount = 0;
 
         public isHitTestVisible = true;
         public isPointerBlocker = false;
@@ -705,25 +707,41 @@ module BABYLON.GUI {
             }
         }
 
-        protected _onPointerEnter(): void {
+        protected _onPointerEnter(): boolean {
+            if (this._enterCount !== 0) {
+                return false;
+            }
+
+            this._enterCount++;
             if (this.onPointerEnterObservable.hasObservers()) {
                 this.onPointerEnterObservable.notifyObservers(this);
             }
+
+            return true;
         }
 
         protected _onPointerOut(): void {
+            this._enterCount = 0;
             if (this.onPointerOutObservable.hasObservers()) {
                 this.onPointerOutObservable.notifyObservers(this);
             }
         }
 
-        protected _onPointerDown(coordinates: Vector2): void {
+        protected _onPointerDown(coordinates: Vector2): boolean {
+            if (this._downCount !== 0) {
+                return false;
+            }
+
+            this._downCount++;            
             if (this.onPointerDownObservable.hasObservers()) {
                 this.onPointerDownObservable.notifyObservers(coordinates);
             }
+
+            return true;
         }
 
         protected _onPointerUp(coordinates: Vector2): void {
+            this._downCount = 0;
             if (this.onPointerUpObservable.hasObservers()) {
                 this.onPointerUpObservable.notifyObservers(coordinates);
             }

+ 5 - 2
gui/src/controls/radioButton.ts

@@ -133,10 +133,13 @@ module BABYLON.GUI {
         }
 
         // Events
-        protected _onPointerDown(coordinates: Vector2): void {
+        protected _onPointerDown(coordinates: Vector2): boolean {
+            if (!super._onPointerDown(coordinates)) {
+                return false;
+            }
             this.isChecked = !this.isChecked;
 
-            super._onPointerDown(coordinates);
+            return true;
         }
     }    
 }

+ 6 - 2
gui/src/controls/slider.ts

@@ -169,13 +169,17 @@ module BABYLON.GUI {
             this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
         }
 
-        protected _onPointerDown(coordinates: Vector2): void {
+        protected _onPointerDown(coordinates: Vector2): boolean {
+            if (!super._onPointerDown(coordinates)) {
+                return false;
+            }
+
             this._pointerIsDown = true;
 
             this._updateValueFromPointer(coordinates.x);
             this._host._capturingControl = this;
 
-            super._onPointerDown(coordinates);
+            return true;
         }
 
         protected _onPointerMove(coordinates: Vector2): void {