ソースを参照

Merge pull request #2210 from brianzinn/master

PointerUp triggered when leaving Button control.
David Catuhe 8 年 前
コミット
edcc97fcdd
1 ファイル変更18 行追加4 行削除
  1. 18 4
      gui/src/controls/button.ts

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

@@ -7,6 +7,8 @@ module BABYLON.GUI {
         public pointerDownAnimation: () => void;
         public pointerUpAnimation: () => void;
 
+        private _buttonIsDown : boolean = false;
+
         constructor(public name?: string) {
             super(name);
             this.thickness = 1;
@@ -31,6 +33,15 @@ module BABYLON.GUI {
             }                      
         }
 
+        private _ensureButtonUp (): void {
+            if (this._buttonIsDown === true) {
+                if (this.pointerUpAnimation) {
+                    this.pointerUpAnimation();
+                }
+                this._buttonIsDown = false;
+            }
+        }
+
         // While being a container, the button behaves like a control.
         public _processPicking(x: number, y: number, type: number): boolean {
             if (!this.contains(x, y)) {
@@ -53,6 +64,10 @@ module BABYLON.GUI {
             if (this.pointerOutAnimation) {
                 this.pointerOutAnimation();
             }
+
+            // in case you move the pointer out of view while pointer is "down".
+            this._ensureButtonUp()
+
             super._onPointerOut();
         }
 
@@ -60,15 +75,14 @@ module BABYLON.GUI {
             if (this.pointerDownAnimation) {
                 this.pointerDownAnimation();
             }
+            this._buttonIsDown = true;
 
             super._onPointerDown();
         }
 
         protected _onPointerUp (): void {
-            if (this.pointerUpAnimation) {
-                this.pointerUpAnimation();
-            }
-
+            this._ensureButtonUp()
+            
             super._onPointerUp();
         }