소스 검색

Added an option in GUI slider to have a rounded thumb

Baptiste VIALE 7 년 전
부모
커밋
6721317b3d
1개의 변경된 파일27개의 추가작업 그리고 3개의 파일을 삭제
  1. 27 3
      gui/src/controls/slider.ts

+ 27 - 3
gui/src/controls/slider.ts

@@ -9,6 +9,7 @@ module BABYLON.GUI {
         private _background = "black";   
         private _background = "black";   
         private _borderColor = "white";
         private _borderColor = "white";
         private _barOffset = new ValueAndUnit(5, ValueAndUnit.UNITMODE_PIXEL, false);
         private _barOffset = new ValueAndUnit(5, ValueAndUnit.UNITMODE_PIXEL, false);
+        private _isThumbCircle = false;
 
 
         public onValueChangedObservable = new Observable<number>();
         public onValueChangedObservable = new Observable<number>();
 
 
@@ -120,6 +121,19 @@ module BABYLON.GUI {
             this.onValueChangedObservable.notifyObservers(this._value);
             this.onValueChangedObservable.notifyObservers(this._value);
         }                             
         }                             
 
 
+        public get isThumbCircle(): boolean {
+            return this._isThumbCircle;
+        }
+
+        public set isThumbCircle(value: boolean) {
+            if (this._isThumbCircle === value) {
+                return;
+            }
+
+            this._isThumbCircle = value;
+            this._markAsDirty();
+        }
+
         constructor(public name?: string) {
         constructor(public name?: string) {
             super(name);
             super(name);
 
 
@@ -164,10 +178,20 @@ module BABYLON.GUI {
                 context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
                 context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
 
 
                 // Thumb
                 // Thumb
-                context.fillRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
+                if (this._isThumbCircle) {
+                    context.beginPath();
+                    context.arc(left + thumbPosition, this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
+                    context.fill();
 
 
-                context.strokeStyle = this._borderColor;
-                context.strokeRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
+                    context.strokeStyle = this._borderColor;
+                    context.stroke();
+                }
+                else {
+                    context.fillRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
+                    
+                    context.strokeStyle = this._borderColor;
+                    context.strokeRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
+                }
             }
             }
             context.restore();
             context.restore();
         }
         }