var ColorPicker = jsx3.gui.ColorPicker;
objJSX._onColorPick = function(intRGB, strSkip) {
var hsb = ColorPicker.RGBtoHSB(intRGB);
if (strSkip != "hsbH") hsbH.setValue(Math.round(hsb[0] * 100));
if (strSkip != "hsbS") hsbS.setValue(Math.round(hsb[1] * 100));
if (strSkip != "hsbB") hsbB.setValue(Math.round(hsb[2] * 100));
if (strSkip != "rgbR") rgbR.setValue((intRGB & 0xFF0000) >> 16);
if (strSkip != "rgbG") rgbG.setValue((intRGB & 0x00FF00) >> 8);
if (strSkip != "rgbB") rgbB.setValue((intRGB & 0x0000FF) >> 0);
var hex = "#" + (0x1000000 + intRGB).toString(16).substring(1).toUpperCase();
if (strSkip != "rgbHex") rgbHex.setValue(hex);
preview.setBackgroundColor(hex, true);
};
objJSX._onAxisPicker = function(strMode) {
var intAxis = null;
switch (strMode) {
case "h": intAxis = ColorPicker.HUE; break;
case "s": intAxis = ColorPicker.SATURATION; break;
case "b": intAxis = ColorPicker.BRIGHTNESS; break;
}
if (intAxis != null) {
colorPicker.setAxis(intAxis);
colorPicker.repaint();
}
};
objJSX._onPreviewClick = function() {
var intRGB = colorPicker.getRGB();
var hex = "#" + (0x1000000 + intRGB).toString(16).substring(1).toUpperCase();
jsx3.html.copy(hex);
};
objJSX._onTextChange = function(objText, strValue) {
if (objText.getName() == "rgbHex") {
strValue = strValue.replace(/[^a-fA-F0-9]/g, "");
strValue = parseInt("0x" + strValue);
colorPicker.setRGB(strValue);
this._onColorPick(colorPicker.getRGB(), objText.getName());
} else {
var val = Math.max(objText.cpmin, Math.min(objText.cpmax, parseInt(strValue)));
if (isNaN(val)) val = 0;
this._updateOneAxis(objText.cpindex, objText.getName().indexOf("hsb") == 0, val, objText.getName());
}
};
objJSX._onTextWheel = function(objText, objEvent) {
var val = Math.round(Math.max(objText.cpmin, Math.min(objText.cpmax, parseInt(objText.getValue()) + objEvent.getWheelDelta())));
if (isNaN(val)) val = 0;
objText.setValue(val);
this._updateOneAxis(objText.cpindex, objText.getName().indexOf("hsb") == 0, val, objText.getName());
objEvent.cancelBubble();
};
objJSX._onTextKeyDown = function(objText, objEvent) {
if (objEvent.downArrow() || objEvent.upArrow()) {
var val = Math.max(objText.cpmin, Math.min(objText.cpmax, parseInt(objText.getValue()) + (objEvent.upArrow() ? 1 : -1)));
if (isNaN(val)) val = 0;
objText.setValue(val);
this._updateOneAxis(objText.cpindex, objText.getName().indexOf("hsb") == 0, val, objText.getName());
objEvent.cancelAll();
}
};
objJSX._updateOneAxis = function(intIndex, bHSB, intValue, strSkip) {
if (bHSB) {
var hsb = ColorPicker.RGBtoHSB(colorPicker.getRGB());
hsb[intIndex] = intValue/100;
colorPicker.setHSB(hsb[0], hsb[1], hsb[2]);
this._onColorPick(colorPicker.getRGB(), strSkip);
} else {
var rgb = colorPicker.getRGB();
rgb = [(rgb & 0xFF0000) >> 16, (rgb & 0xFF00) >> 8, (rgb & 0xFF) >> 0];
rgb[intIndex] = intValue;
colorPicker.setRGB((rgb[0] << 16) + (rgb[1] << 8) + rgb[2]);
this._onColorPick(colorPicker.getRGB(), strSkip);
}
}