|
@@ -3,10 +3,10 @@
|
|
module BABYLON.GUI {
|
|
module BABYLON.GUI {
|
|
export class Slider extends Control {
|
|
export class Slider extends Control {
|
|
private _thumbWidth = new ValueAndUnit(30, ValueAndUnit.UNITMODE_PIXEL, false);
|
|
private _thumbWidth = new ValueAndUnit(30, ValueAndUnit.UNITMODE_PIXEL, false);
|
|
- private _minimum = 0;
|
|
|
|
|
|
+ private _minimum = 0;
|
|
private _maximum = 100;
|
|
private _maximum = 100;
|
|
private _value = 50;
|
|
private _value = 50;
|
|
- 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;
|
|
private _isThumbCircle = false;
|
|
@@ -24,7 +24,7 @@ module BABYLON.GUI {
|
|
|
|
|
|
this._borderColor = value;
|
|
this._borderColor = value;
|
|
this._markAsDirty();
|
|
this._markAsDirty();
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public get background(): string {
|
|
public get background(): string {
|
|
return this._background;
|
|
return this._background;
|
|
@@ -37,17 +37,17 @@ module BABYLON.GUI {
|
|
|
|
|
|
this._background = value;
|
|
this._background = value;
|
|
this._markAsDirty();
|
|
this._markAsDirty();
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- public get barOffset(): string | number {
|
|
|
|
|
|
+ public get barOffset(): string | number {
|
|
return this._barOffset.toString(this._host);
|
|
return this._barOffset.toString(this._host);
|
|
}
|
|
}
|
|
|
|
|
|
- public get barOffsetInPixels(): number {
|
|
|
|
|
|
+ public get barOffsetInPixels(): number {
|
|
return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
|
|
return this._barOffset.getValueInPixel(this._host, this._cachedParentMeasure.width);
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- public set barOffset(value: string | number ) {
|
|
|
|
|
|
+ public set barOffset(value: string | number) {
|
|
if (this._barOffset.toString(this._host) === value) {
|
|
if (this._barOffset.toString(this._host) === value) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -55,17 +55,17 @@ module BABYLON.GUI {
|
|
if (this._barOffset.fromString(value)) {
|
|
if (this._barOffset.fromString(value)) {
|
|
this._markAsDirty();
|
|
this._markAsDirty();
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- public get thumbWidth(): string | number {
|
|
|
|
|
|
+ public get thumbWidth(): string | number {
|
|
return this._thumbWidth.toString(this._host);
|
|
return this._thumbWidth.toString(this._host);
|
|
}
|
|
}
|
|
|
|
|
|
- public get thumbWidthInPixels(): number {
|
|
|
|
|
|
+ public get thumbWidthInPixels(): number {
|
|
return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
|
|
return this._thumbWidth.getValueInPixel(this._host, this._cachedParentMeasure.width);
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- public set thumbWidth(value: string | number ) {
|
|
|
|
|
|
+ public set thumbWidth(value: string | number) {
|
|
if (this._thumbWidth.toString(this._host) === value) {
|
|
if (this._thumbWidth.toString(this._host) === value) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -73,7 +73,7 @@ module BABYLON.GUI {
|
|
if (this._thumbWidth.fromString(value)) {
|
|
if (this._thumbWidth.fromString(value)) {
|
|
this._markAsDirty();
|
|
this._markAsDirty();
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public get minimum(): number {
|
|
public get minimum(): number {
|
|
return this._minimum;
|
|
return this._minimum;
|
|
@@ -88,7 +88,7 @@ module BABYLON.GUI {
|
|
this._markAsDirty();
|
|
this._markAsDirty();
|
|
|
|
|
|
this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
|
|
this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public get maximum(): number {
|
|
public get maximum(): number {
|
|
return this._maximum;
|
|
return this._maximum;
|
|
@@ -103,7 +103,7 @@ module BABYLON.GUI {
|
|
this._markAsDirty();
|
|
this._markAsDirty();
|
|
|
|
|
|
this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
|
|
this.value = Math.max(Math.min(this.value, this._maximum), this._minimum);
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public get value(): number {
|
|
public get value(): number {
|
|
return this._value;
|
|
return this._value;
|
|
@@ -119,7 +119,7 @@ module BABYLON.GUI {
|
|
this._markAsDirty();
|
|
this._markAsDirty();
|
|
|
|
|
|
this.onValueChangedObservable.notifyObservers(this._value);
|
|
this.onValueChangedObservable.notifyObservers(this._value);
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public get isThumbCircle(): boolean {
|
|
public get isThumbCircle(): boolean {
|
|
return this._isThumbCircle;
|
|
return this._isThumbCircle;
|
|
@@ -142,7 +142,7 @@ module BABYLON.GUI {
|
|
|
|
|
|
protected _getTypeName(): string {
|
|
protected _getTypeName(): string {
|
|
return "Slider";
|
|
return "Slider";
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
|
|
public _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
|
|
context.save();
|
|
context.save();
|
|
@@ -153,7 +153,7 @@ module BABYLON.GUI {
|
|
var effectiveThumbWidth;
|
|
var effectiveThumbWidth;
|
|
var effectiveBarOffset;
|
|
var effectiveBarOffset;
|
|
|
|
|
|
- if(this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY){
|
|
|
|
|
|
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
context.shadowColor = this.shadowColor;
|
|
context.shadowColor = this.shadowColor;
|
|
context.shadowBlur = this.shadowBlur;
|
|
context.shadowBlur = this.shadowBlur;
|
|
context.shadowOffsetX = this.shadowOffsetX;
|
|
context.shadowOffsetX = this.shadowOffsetX;
|
|
@@ -161,16 +161,16 @@ module BABYLON.GUI {
|
|
}
|
|
}
|
|
|
|
|
|
if (this._thumbWidth.isPixel) {
|
|
if (this._thumbWidth.isPixel) {
|
|
- effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.height);
|
|
|
|
|
|
+ effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.width);
|
|
} else {
|
|
} else {
|
|
- effectiveThumbWidth = this._currentMeasure.height * this._thumbWidth.getValue(this._host);
|
|
|
|
|
|
+ effectiveThumbWidth = this._currentMeasure.width * this._thumbWidth.getValue(this._host);
|
|
}
|
|
}
|
|
|
|
|
|
if (this._barOffset.isPixel) {
|
|
if (this._barOffset.isPixel) {
|
|
effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
|
|
effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
|
|
} else {
|
|
} else {
|
|
- effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
|
|
|
|
- }
|
|
|
|
|
|
+ effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
var left = this._currentMeasure.left + effectiveThumbWidth / 2;
|
|
var left = this._currentMeasure.left + effectiveThumbWidth / 2;
|
|
@@ -181,7 +181,7 @@ module BABYLON.GUI {
|
|
context.fillStyle = this._background;
|
|
context.fillStyle = this._background;
|
|
context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
|
|
context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
|
|
|
|
|
|
- if(this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY){
|
|
|
|
|
|
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
context.shadowBlur = 0;
|
|
context.shadowBlur = 0;
|
|
context.shadowOffsetX = 0;
|
|
context.shadowOffsetX = 0;
|
|
context.shadowOffsetY = 0;
|
|
context.shadowOffsetY = 0;
|
|
@@ -190,7 +190,7 @@ module BABYLON.GUI {
|
|
context.fillStyle = this.color;
|
|
context.fillStyle = this.color;
|
|
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);
|
|
|
|
|
|
- if(this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY){
|
|
|
|
|
|
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
context.shadowColor = this.shadowColor;
|
|
context.shadowColor = this.shadowColor;
|
|
context.shadowBlur = this.shadowBlur;
|
|
context.shadowBlur = this.shadowBlur;
|
|
context.shadowOffsetX = this.shadowOffsetX;
|
|
context.shadowOffsetX = this.shadowOffsetX;
|
|
@@ -203,7 +203,7 @@ module BABYLON.GUI {
|
|
context.arc(left + thumbPosition, this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
|
|
context.arc(left + thumbPosition, this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
|
|
context.fill();
|
|
context.fill();
|
|
|
|
|
|
- if(this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY){
|
|
|
|
|
|
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
context.shadowBlur = 0;
|
|
context.shadowBlur = 0;
|
|
context.shadowOffsetX = 0;
|
|
context.shadowOffsetX = 0;
|
|
context.shadowOffsetY = 0;
|
|
context.shadowOffsetY = 0;
|
|
@@ -214,8 +214,8 @@ module BABYLON.GUI {
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
context.fillRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
|
|
context.fillRect(left + thumbPosition - effectiveThumbWidth / 2, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
|
|
-
|
|
|
|
- if(this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY){
|
|
|
|
|
|
+
|
|
|
|
+ if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
context.shadowBlur = 0;
|
|
context.shadowBlur = 0;
|
|
context.shadowOffsetX = 0;
|
|
context.shadowOffsetX = 0;
|
|
context.shadowOffsetY = 0;
|
|
context.shadowOffsetY = 0;
|
|
@@ -231,8 +231,8 @@ module BABYLON.GUI {
|
|
// Events
|
|
// Events
|
|
private _pointerIsDown = false;
|
|
private _pointerIsDown = false;
|
|
|
|
|
|
- private _updateValueFromPointer(x: number, y:number): void {
|
|
|
|
- if(this.rotation != 0){
|
|
|
|
|
|
+ private _updateValueFromPointer(x: number, y: number): void {
|
|
|
|
+ if (this.rotation != 0) {
|
|
this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
|
|
this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
|
|
x = this._transformedPosition.x;
|
|
x = this._transformedPosition.x;
|
|
}
|
|
}
|
|
@@ -260,11 +260,11 @@ module BABYLON.GUI {
|
|
super._onPointerMove(target, coordinates);
|
|
super._onPointerMove(target, coordinates);
|
|
}
|
|
}
|
|
|
|
|
|
- public _onPointerUp (target: Control, coordinates: Vector2, buttonIndex: number): void {
|
|
|
|
|
|
+ public _onPointerUp(target: Control, coordinates: Vector2, buttonIndex: number): void {
|
|
this._pointerIsDown = false;
|
|
this._pointerIsDown = false;
|
|
-
|
|
|
|
|
|
+
|
|
this._host._capturingControl = null;
|
|
this._host._capturingControl = null;
|
|
super._onPointerUp(target, coordinates, buttonIndex);
|
|
super._onPointerUp(target, coordinates, buttonIndex);
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|