浏览代码

ADT: adding button

David Catuhe 8 年之前
父节点
当前提交
6ab2581f1c
共有 2 个文件被更改,包括 32 次插入1 次删除
  1. 2 1
      Tools/Gulp/config.json
  2. 30 0
      gui/src/controls/button.ts

+ 2 - 1
Tools/Gulp/config.json

@@ -1222,7 +1222,8 @@
                     "../../gui/src/controls/container.ts",
                     "../../gui/src/controls/rectangle.ts",
                     "../../gui/src/controls/textBlock.ts",
-                    "../../gui/src/controls/image.ts"
+                    "../../gui/src/controls/image.ts",
+                    "../../gui/src/controls/button.ts"
                 ],
                 "output": "babylon.gui.js"
             }

+ 30 - 0
gui/src/controls/button.ts

@@ -0,0 +1,30 @@
+/// <reference path="../../../dist/preview release/babylon.d.ts"/>
+
+module BABYLON.GUI {
+    export class Button extends Rectangle {      
+        constructor(public name: string) {
+            super(name);
+        }
+
+        // Statics
+        public static CreateImageButton(name: string, text: string, imageUrl: string): Button {
+            var result = new Button(name);
+
+            // Adding text
+            var textBlock = new BABYLON.GUI.TextBlock(name + "_button", text);
+            textBlock.textWrapping = true;
+            textBlock.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
+            textBlock.marginLeft = 0.2;
+            result.addControl(textBlock);   
+
+            // Adding image
+            var iconImage = new BABYLON.GUI.Image(name + "_icon", imageUrl);
+            iconImage.width = 0.2;
+            iconImage.stretch = BABYLON.GUI.Image.STRETCH_UNIFORM;
+            iconImage.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_LEFT;
+            result.addControl(iconImage);            
+
+            return result;
+        }
+    }    
+}