Pārlūkot izejas kodu

Add an InputPassword control

Jens Pall Hafsteinsson 7 gadi atpakaļ
vecāks
revīzija
5cc7b89055

+ 2 - 1
Tools/Gulp/config.json

@@ -1794,6 +1794,7 @@
                     "../../gui/src/2D/controls/button.ts",
                     "../../gui/src/2D/controls/colorpicker.ts",
                     "../../gui/src/2D/controls/inputText.ts",
+                    "../../gui/src/2D/controls/inputPassword.ts",
                     "../../gui/src/2D/controls/virtualKeyboard.ts",
                     "../../gui/src/2D/controls/multiLine.ts",
                     "../../gui/src/2D/controls/grid.ts",                    
@@ -2008,4 +2009,4 @@
             ]
         }
     }
-}
+}

+ 16 - 0
gui/src/2D/controls/inputPassword.ts

@@ -0,0 +1,16 @@
+/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
+
+module BABYLON.GUI {
+    /**
+     * Class used to create a password control
+     */
+    export class InputPassword extends InputText {
+        protected _beforeRenderText(text: string): string {
+            let txt = "";
+            for (let i = 0; i < text.length; i++) {
+                txt += "\u2022";
+            }
+            return txt;
+        }
+    }
+}

+ 9 - 5
gui/src/2D/controls/inputText.ts

@@ -239,7 +239,7 @@ module BABYLON.GUI {
             // Specific cases
             switch (keyCode) {
                 case 32: //SPACE
-                    key = " "; //ie11 key for space is "Spacebar" 
+                    key = " "; //ie11 key for space is "Spacebar"
                     break;
                 case 8: // BACKSPACE
                     if (this._text && this._text.length > 0) {
@@ -310,7 +310,7 @@ module BABYLON.GUI {
             }
         }
 
-        /** @hidden */       
+        /** @hidden */
         public processKeyboard(evt: KeyboardEvent): void {
             this.processKey(evt.keyCode, evt.key);
         }
@@ -357,7 +357,7 @@ module BABYLON.GUI {
                     context.fillStyle = this.color;
                 }
 
-                let text = this._text;
+                let text = this._beforeRenderText(this._text);
 
                 if (!this._isFocused && !this._text && this._placeholderText) {
                     text = this._placeholderText;
@@ -460,7 +460,7 @@ module BABYLON.GUI {
             context.restore();
         }
 
-        public _onPointerDown(target: Control, coordinates: Vector2, pointerId:number, buttonIndex: number): boolean {
+        public _onPointerDown(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number): boolean {
             if (!super._onPointerDown(target, coordinates, pointerId, buttonIndex)) {
                 return false;
             }
@@ -477,10 +477,14 @@ module BABYLON.GUI {
             return true;
         }
 
-        public _onPointerUp(target: Control, coordinates: Vector2, pointerId:number, buttonIndex: number, notifyClick: boolean): void {
+        public _onPointerUp(target: Control, coordinates: Vector2, pointerId: number, buttonIndex: number, notifyClick: boolean): void {
             super._onPointerUp(target, coordinates, pointerId, buttonIndex, notifyClick);
         }
 
+        protected _beforeRenderText(text: string): string {
+            return text;
+        }
+
         public dispose() {
             super.dispose();