|
@@ -3738,10 +3738,11 @@ var BABYLON;
|
|
|
function Slider(name) {
|
|
|
var _this = _super.call(this, name) || this;
|
|
|
_this.name = name;
|
|
|
- _this._thumbWidth = new GUI.ValueAndUnit(30, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
|
|
|
+ _this._thumbWidth = new GUI.ValueAndUnit(20, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
|
|
|
_this._minimum = 0;
|
|
|
_this._maximum = 100;
|
|
|
_this._value = 50;
|
|
|
+ _this._isVertical = false;
|
|
|
_this._background = "black";
|
|
|
_this._borderColor = "white";
|
|
|
_this._barOffset = new GUI.ValueAndUnit(5, GUI.ValueAndUnit.UNITMODE_PIXEL, false);
|
|
@@ -3881,6 +3882,21 @@ var BABYLON;
|
|
|
enumerable: true,
|
|
|
configurable: true
|
|
|
});
|
|
|
+ Object.defineProperty(Slider.prototype, "isVertical", {
|
|
|
+ /**Gets or sets a boolean indicating if the slider should be vertical or horizontal */
|
|
|
+ get: function () {
|
|
|
+ return this._isVertical;
|
|
|
+ },
|
|
|
+ set: function (value) {
|
|
|
+ if (this._isVertical === value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this._isVertical = value;
|
|
|
+ this._markAsDirty();
|
|
|
+ },
|
|
|
+ enumerable: true,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
Object.defineProperty(Slider.prototype, "isThumbCircle", {
|
|
|
/** Gets or sets a boolean indicating if the thumb should be round or square */
|
|
|
get: function () {
|
|
@@ -3914,24 +3930,80 @@ var BABYLON;
|
|
|
Slider.prototype._getTypeName = function () {
|
|
|
return "Slider";
|
|
|
};
|
|
|
+ Slider.prototype._getThumbThickness = function (type, backgroundLength) {
|
|
|
+ var thumbThickness = 0;
|
|
|
+ switch (type) {
|
|
|
+ case "circle":
|
|
|
+ if (this._thumbWidth.isPixel) {
|
|
|
+ thumbThickness = Math.max(this._thumbWidth.getValue(this._host), backgroundLength);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ thumbThickness = backgroundLength * this._thumbWidth.getValue(this._host);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "rectangle":
|
|
|
+ if (this._thumbWidth.isPixel) {
|
|
|
+ thumbThickness = Math.min(this._thumbWidth.getValue(this._host), backgroundLength);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ thumbThickness = backgroundLength * this._thumbWidth.getValue(this._host);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return thumbThickness;
|
|
|
+ };
|
|
|
Slider.prototype._draw = function (parentMeasure, context) {
|
|
|
context.save();
|
|
|
this._applyStates(context);
|
|
|
if (this._processMeasures(parentMeasure, context)) {
|
|
|
// Main bar
|
|
|
- var effectiveThumbWidth;
|
|
|
- var effectiveBarOffset;
|
|
|
- if (this._thumbWidth.isPixel) {
|
|
|
- effectiveThumbWidth = Math.min(this._thumbWidth.getValue(this._host), this._currentMeasure.width);
|
|
|
+ var effectiveBarOffset = 0;
|
|
|
+ var type = this.isThumbCircle ? "circle" : "rectangle";
|
|
|
+ var left = this._currentMeasure.left;
|
|
|
+ var top = this._currentMeasure.top;
|
|
|
+ var width = this._currentMeasure.width;
|
|
|
+ var height = this._currentMeasure.height;
|
|
|
+ var backgroundBoxLength = Math.max(this._currentMeasure.width, this._currentMeasure.height);
|
|
|
+ var backgroundBoxThickness = Math.min(this._currentMeasure.width, this._currentMeasure.height);
|
|
|
+ var effectiveThumbThickness = this._getThumbThickness(type, backgroundBoxThickness);
|
|
|
+ backgroundBoxLength -= effectiveThumbThickness;
|
|
|
+ var radius = 0;
|
|
|
+ //throw error when height is less than width for vertical slider
|
|
|
+ if ((this._isVertical && this._currentMeasure.height < this._currentMeasure.width)) {
|
|
|
+ console.error("Height should be greater than width");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this._barOffset.isPixel) {
|
|
|
+ effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), backgroundBoxThickness);
|
|
|
}
|
|
|
else {
|
|
|
- effectiveThumbWidth = this._currentMeasure.width * this._thumbWidth.getValue(this._host);
|
|
|
+ effectiveBarOffset = backgroundBoxThickness * this._barOffset.getValue(this._host);
|
|
|
}
|
|
|
- if (this._barOffset.isPixel) {
|
|
|
- effectiveBarOffset = Math.min(this._barOffset.getValue(this._host), this._currentMeasure.height);
|
|
|
+ backgroundBoxThickness -= (effectiveBarOffset * 2);
|
|
|
+ if (this._isVertical) {
|
|
|
+ left += effectiveBarOffset;
|
|
|
+ if (!this.isThumbClamped) {
|
|
|
+ top += (effectiveThumbThickness / 2);
|
|
|
+ }
|
|
|
+ height = backgroundBoxLength;
|
|
|
+ width = backgroundBoxThickness;
|
|
|
}
|
|
|
else {
|
|
|
- effectiveBarOffset = this._currentMeasure.height * this._barOffset.getValue(this._host);
|
|
|
+ top += effectiveBarOffset;
|
|
|
+ if (!this.isThumbClamped) {
|
|
|
+ left += (effectiveThumbThickness / 2);
|
|
|
+ }
|
|
|
+ height = backgroundBoxThickness;
|
|
|
+ width = backgroundBoxLength;
|
|
|
+ }
|
|
|
+ if (this.isThumbClamped && this.isThumbCircle) {
|
|
|
+ if (this._isVertical)
|
|
|
+ top += (effectiveThumbThickness / 2);
|
|
|
+ else
|
|
|
+ left += (effectiveThumbThickness / 2);
|
|
|
+ radius = backgroundBoxThickness / 2;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ radius = (effectiveThumbThickness - effectiveBarOffset) / 2;
|
|
|
}
|
|
|
if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
|
context.shadowColor = this.shadowColor;
|
|
@@ -3939,15 +4011,39 @@ var BABYLON;
|
|
|
context.shadowOffsetX = this.shadowOffsetX;
|
|
|
context.shadowOffsetY = this.shadowOffsetY;
|
|
|
}
|
|
|
- var left = this._currentMeasure.left;
|
|
|
- var width = this._currentMeasure.width - effectiveThumbWidth;
|
|
|
- var thumbPosition = ((this._value - this._minimum) / (this._maximum - this._minimum)) * width;
|
|
|
+ var thumbPosition = (this._isVertical) ? ((this._maximum - this._value) / (this._maximum - this._minimum)) * backgroundBoxLength : ((this._value - this._minimum) / (this._maximum - this._minimum)) * backgroundBoxLength;
|
|
|
context.fillStyle = this._background;
|
|
|
- if (this.isThumbClamped) {
|
|
|
- context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, width + effectiveThumbWidth, this._currentMeasure.height - effectiveBarOffset * 2);
|
|
|
+ if (this._isVertical) {
|
|
|
+ if (this.isThumbClamped) {
|
|
|
+ if (this.isThumbCircle) {
|
|
|
+ context.beginPath();
|
|
|
+ context.arc(left + backgroundBoxThickness / 2, top, radius, Math.PI, 2 * Math.PI);
|
|
|
+ context.fill();
|
|
|
+ context.fillRect(left, top, width, height);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(left, top, width, height + effectiveThumbThickness);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(left, top, width, height);
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
- context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, width, this._currentMeasure.height - effectiveBarOffset * 2);
|
|
|
+ if (this.isThumbClamped) {
|
|
|
+ if (this.isThumbCircle) {
|
|
|
+ context.beginPath();
|
|
|
+ context.arc(left + backgroundBoxLength, top + (backgroundBoxThickness / 2), radius, 0, 2 * Math.PI);
|
|
|
+ context.fill();
|
|
|
+ context.fillRect(left, top, width, height);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(left, top, width + effectiveThumbThickness, height);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(left, top, width, height);
|
|
|
+ }
|
|
|
}
|
|
|
if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
|
context.shadowBlur = 0;
|
|
@@ -3955,11 +4051,37 @@ var BABYLON;
|
|
|
context.shadowOffsetY = 0;
|
|
|
}
|
|
|
context.fillStyle = this.color;
|
|
|
- if (this.isThumbClamped) {
|
|
|
- context.fillRect(left, this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
|
|
|
+ if (this._isVertical) {
|
|
|
+ if (this.isThumbClamped) {
|
|
|
+ if (this.isThumbCircle) {
|
|
|
+ context.beginPath();
|
|
|
+ context.arc(left + backgroundBoxThickness / 2, top + backgroundBoxLength, radius, 0, 2 * Math.PI);
|
|
|
+ context.fill();
|
|
|
+ context.fillRect(left, top + thumbPosition, width, height - thumbPosition);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(left, top + thumbPosition, width, this._currentMeasure.height - thumbPosition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(left, top + thumbPosition, width, height - thumbPosition);
|
|
|
+ }
|
|
|
}
|
|
|
else {
|
|
|
- context.fillRect(left + (effectiveThumbWidth / 2), this._currentMeasure.top + effectiveBarOffset, thumbPosition, this._currentMeasure.height - effectiveBarOffset * 2);
|
|
|
+ if (this.isThumbClamped) {
|
|
|
+ if (this.isThumbCircle) {
|
|
|
+ context.beginPath();
|
|
|
+ context.arc(left, top + backgroundBoxThickness / 2, radius, 0, 2 * Math.PI);
|
|
|
+ context.fill();
|
|
|
+ context.fillRect(left, top, thumbPosition, height);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(left, top, thumbPosition, height);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(left, top, thumbPosition, height);
|
|
|
+ }
|
|
|
}
|
|
|
if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
|
context.shadowColor = this.shadowColor;
|
|
@@ -3969,7 +4091,12 @@ var BABYLON;
|
|
|
}
|
|
|
if (this._isThumbCircle) {
|
|
|
context.beginPath();
|
|
|
- context.arc(left + thumbPosition + (effectiveThumbWidth / 2), this._currentMeasure.top + this._currentMeasure.height / 2, effectiveThumbWidth / 2, 0, 2 * Math.PI);
|
|
|
+ if (this._isVertical) {
|
|
|
+ context.arc(left + backgroundBoxThickness / 2, top + thumbPosition, radius, 0, 2 * Math.PI);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.arc(left + thumbPosition, top + (backgroundBoxThickness / 2), radius, 0, 2 * Math.PI);
|
|
|
+ }
|
|
|
context.fill();
|
|
|
if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
|
context.shadowBlur = 0;
|
|
@@ -3980,14 +4107,24 @@ var BABYLON;
|
|
|
context.stroke();
|
|
|
}
|
|
|
else {
|
|
|
- context.fillRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
|
|
|
+ if (this._isVertical) {
|
|
|
+ context.fillRect(left - effectiveBarOffset, this._currentMeasure.top + thumbPosition, this._currentMeasure.width, effectiveThumbThickness);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.fillRect(this._currentMeasure.left + thumbPosition, this._currentMeasure.top, effectiveThumbThickness, this._currentMeasure.height);
|
|
|
+ }
|
|
|
if (this.shadowBlur || this.shadowOffsetX || this.shadowOffsetY) {
|
|
|
context.shadowBlur = 0;
|
|
|
context.shadowOffsetX = 0;
|
|
|
context.shadowOffsetY = 0;
|
|
|
}
|
|
|
context.strokeStyle = this._borderColor;
|
|
|
- context.strokeRect(left + thumbPosition, this._currentMeasure.top, effectiveThumbWidth, this._currentMeasure.height);
|
|
|
+ if (this._isVertical) {
|
|
|
+ context.strokeRect(left - effectiveBarOffset, this._currentMeasure.top + thumbPosition, this._currentMeasure.width, effectiveThumbThickness);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ context.strokeRect(this._currentMeasure.left + thumbPosition, this._currentMeasure.top, effectiveThumbThickness, this._currentMeasure.height);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
context.restore();
|
|
@@ -3996,8 +4133,14 @@ var BABYLON;
|
|
|
if (this.rotation != 0) {
|
|
|
this._invertTransformMatrix.transformCoordinates(x, y, this._transformedPosition);
|
|
|
x = this._transformedPosition.x;
|
|
|
+ y = this._transformedPosition.y;
|
|
|
+ }
|
|
|
+ if (this._isVertical) {
|
|
|
+ this.value = this._minimum + (1 - ((y - this._currentMeasure.top) / this._currentMeasure.height)) * (this._maximum - this._minimum);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
|
|
|
}
|
|
|
- this.value = this._minimum + ((x - this._currentMeasure.left) / this._currentMeasure.width) * (this._maximum - this._minimum);
|
|
|
};
|
|
|
Slider.prototype._onPointerDown = function (target, coordinates, pointerId, buttonIndex) {
|
|
|
if (!_super.prototype._onPointerDown.call(this, target, coordinates, pointerId, buttonIndex)) {
|