瀏覽代碼

GUI: add slider

David Catuhe 8 年之前
父節點
當前提交
72aa60b0ce
共有 2 個文件被更改,包括 33 次插入0 次删除
  1. 1 0
      Tools/Gulp/config.json
  2. 32 0
      gui/src/controls/slider.ts

+ 1 - 0
Tools/Gulp/config.json

@@ -1300,6 +1300,7 @@
                     "../../gui/src/controls/rectangle.ts",
                     "../../gui/src/controls/ellipse.ts",
                     "../../gui/src/controls/line.ts",
+                    "../../gui/src/controls/slider.ts",
                     "../../gui/src/controls/textBlock.ts",
                     "../../gui/src/controls/image.ts",
                     "../../gui/src/controls/button.ts"

+ 32 - 0
gui/src/controls/slider.ts

@@ -0,0 +1,32 @@
+/// <reference path="../../../dist/preview release/babylon.d.ts"/>
+
+var DOMImage = Image;
+
+module BABYLON.GUI {
+    export class Slider extends Control {
+        private _barHeight = new ValueAndUnit(0.5, ValueAndUnit.UNITMODE_PERCENTAGE, false);
+
+        constructor(public name?: string) {
+            super(name);
+        }
+
+        public _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
+            context.save();
+
+            this._applyStates(context);
+            if (this._processMeasures(parentMeasure, context)) {
+                // Main bar
+                var effectiveBarHeight = 0;
+
+                if (this._barHeight.isPixel) {
+                    effectiveBarHeight = Math.min(this._barHeight.getValue(this._host), this._currentMeasure.height);
+                } else {
+                    effectiveBarHeight = this._currentMeasure.height * this._barHeight.getValue(this._host); 
+                }
+
+                context.fillRect(this._currentMeasure.left, this._currentMeasure.top + (this._currentMeasure.height - effectiveBarHeight) / 2, this._currentMeasure.width, effectiveBarHeight);
+            }
+            context.restore();
+        }
+    }    
+}