A few type aliases can be added:
/**
* Alias type for number that represents a minimum value
* @ignorenaming
*/
type min = number;
/**
* Alias type for number that represents a maximum value
* @ignorenaming
*/
type max = number;
/**
* Alias type for array that represents a range
* @ignorenaming
*/
type range = [min,max];
/**
* Alias type for array that represents an array of range types
* @ignorenaming
*/
type hsvRanges = [range,range,range];
A few private properties can be added:
private _hRange: range = [0, 360];
private _sRange: range = [0, 1];
private _vRange: range = [0, 1];
The ColorPicker constructor can be adapted as:
/**
* Creates a new ColorPicker
* @param name defines the control name
*/
constructor(public name?: string, hsvRanges?: hsvRanges) {
super(name);
this._hRange = (hsvRanges) ? hsvRanges[0] : this._hRange;
this._sRange = (hsvRanges) ? hsvRanges[1] : this._sRange;
this._vRange = (hsvRanges) ? hsvRanges[2] : this._vRange;
this.value = new Color3(.88, .1, .1);
this.size = "200px";
this.isPointerBlocker = true;
}
The ColorWheelCanvas can be adapted as:
// ang is in radians from -PI to PI
var hDeg = ang * 180 / Math.PI + 180; // degrees from 0 to 360
var hDegPrime = hDeg * (this._hRange[1] - this._hRange[0]) / 360 + this._hRange[0]; // map range
Color3.HSVtoRGBToRef(hDegPrime, dist / radius, 1, color);
For picking within the specified range, the same mapping can be applied in the updateValueFromPointer function. (NOT IMPLEMENTED)
Finally, the _sRange and _vRange values would be used to restrict their respective domains. (NOT IMPLEMENTED)
https://indigo-tick-swu94thh.ws-us10.gitpod.io/?workspace=vscode-remote%3A%2F%2Findigo-tick-swu94thh.ws-us10.gitpod.io%2Fworkspace%2FBabylon.js%2Fgui%2Fsrc%2F2D%2Fcontrols%2Fworkspace.code-workspace