diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index a5ea49f33..1e72f05b8 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -33,6 +33,9 @@ #include "platform/platformInput.h" #include "core/util/journal/journal.h" #include "core/util/uuid.h" +#include "core/color.h" +#include "math/mPoint3.h" +#include "math/mathTypes.h" #ifdef TORQUE_DEMO_PURCHASE #include "gui/core/guiCanvas.h" @@ -815,6 +818,86 @@ DefineConsoleFunction( strrchrpos, S32, ( const char* str, const char* chr, S32 return index; } +//---------------------------------------------------------------- + +DefineConsoleFunction(ColorFloatToInt, ColorI, (ColorF color), , + "Convert from a float color to an integer color (0.0 - 1.0 to 0 to 255).\n" + "@param color Float color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha.\n" + "@return Converted color value (0 - 255)\n\n" + "@tsexample\n" + "ColorFloatToInt( \"0 0 1 0.5\" ) // Returns \"0 0 255 128\".\n" + "@endtsexample\n" + "@ingroup Strings") +{ + return (ColorI)color; +} + +DefineConsoleFunction(ColorIntToFloat, ColorF, (ColorI color), , + "Convert from a integer color to an float color (0 to 255 to 0.0 - 1.0).\n" + "@param color Integer color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha.\n" + "@return Converted color value (0.0 - 1.0)\n\n" + "@tsexample\n" + "ColorIntToFloat( \"0 0 255 128\" ) // Returns \"0 0 1 0.5\".\n" + "@endtsexample\n" + "@ingroup Strings") +{ + return (ColorF)color; +} + +DefineConsoleFunction(ColorRGBToHEX, const char*, (ColorI color), , + "Convert from a integer RGB (red, green, blue) color to hex color value (0 to 255 to 00 - FF).\n" + "@param color Integer color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha. It excepts an alpha, but keep in mind this will not be converted.\n" + "@return Hex color value (#000000 - #FFFFFF), alpha isn't handled/converted so it is only the RGB value\n\n" + "@tsexample\n" + "ColorRBGToHEX( \"0 0 255 128\" ) // Returns \"#0000FF\".\n" + "@endtsexample\n" + "@ingroup Strings") +{ + return Con::getReturnBuffer(color.getHex()); +} + +DefineConsoleFunction(ColorRGBToHSB, const char*, (ColorI color), , + "Convert from a integer RGB (red, green, blue) color to HSB (hue, saturation, brightness). HSB is also know as HSL or HSV as well, with the last letter standing for lightness or value.\n" + "@param color Integer color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha. It excepts an alpha, but keep in mind this will not be converted.\n" + "@return HSB color value, alpha isn't handled/converted so it is only the RGB value\n\n" + "@tsexample\n" + "ColorRBGToHSB( \"0 0 255 128\" ) // Returns \"240 100 100\".\n" + "@endtsexample\n" + "@ingroup Strings") +{ + ColorI::Hsb hsb(color.getHSB()); + String s(String::ToString(hsb.hue) + " " + String::ToString(hsb.sat) + " " + String::ToString(hsb.brightness)); + return Con::getReturnBuffer(s); +} + +DefineConsoleFunction(ColorHEXToRGB, ColorI, (const char* hex), , + "Convert from a hex color value to an integer RGB (red, green, blue) color (00 - FF to 0 to 255).\n" + "@param hex Hex color value (#000000 - #FFFFFF) to be converted to an RGB (red, green, blue) value.\n" + "@return Integer color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha. Alpha isn't handled/converted so only pay attention to the RGB value\n\n" + "@tsexample\n" + "ColorHEXToRGB( \"#0000FF\" ) // Returns \"0 0 255 0\".\n" + "@endtsexample\n" + "@ingroup Strings") +{ + ColorI color; + color.set(hex); + return color; +} + +DefineConsoleFunction(ColorHSBToRGB, ColorI, (Point3I hsb), , + "Convert from a HSB (hue, saturation, brightness) to an integer RGB (red, green, blue) color. HSB is also know as HSL or HSV as well, with the last letter standing for lightness or value.\n" + "@param hsb HSB (hue, saturation, brightness) value to be converted.\n" + "@return Integer color value to be converted in the form \"R G B A\", where R is red, G is green, B is blue, and A is alpha. Alpha isn't handled/converted so only pay attention to the RGB value\n\n" + "@tsexample\n" + "ColorHSBToRGB( \"240 100 100\" ) // Returns \"0 0 255 0\".\n" + "@endtsexample\n" + "@ingroup Strings") +{ + ColorI color; + color.set(ColorI::Hsb(hsb.x, hsb.y, hsb.z)); + return color; +} + //============================================================================= // Field Manipulators. //============================================================================= diff --git a/Engine/source/core/color.h b/Engine/source/core/color.h index b0620fc4f..ddb98c8a8 100644 --- a/Engine/source/core/color.h +++ b/Engine/source/core/color.h @@ -30,6 +30,10 @@ #include "math/mPoint4.h" #endif +#ifndef _ENGINEAPI_H_ +#include "console/engineAPI.h" +#endif + class ColorI; @@ -121,9 +125,20 @@ class ColorI U8 blue; U8 alpha; + struct Hsb + { + Hsb() :hue(0), sat(0), brightness(0){}; + Hsb(U32 h, U32 s, U32 b) :hue(h), sat(s), brightness(b){}; + + U32 hue; ///Hue + U32 sat; ///Saturation + U32 brightness; //Brightness/Value/Lightness + }; + public: ColorI() { } ColorI(const ColorI& in_rCopy); + ColorI(const Hsb& color); ColorI(const U8 in_r, const U8 in_g, const U8 in_b, @@ -132,6 +147,12 @@ class ColorI ColorI( const char* pStockColorName ); + void set(const Hsb& color); + + void HSLtoRGB_Subfunction(U32& c, const F64& temp1, const F64& temp2, const F64& temp3); + + void set(const String& hex); + void set(const U8 in_r, const U8 in_g, const U8 in_b, @@ -176,6 +197,11 @@ class ColorI U16 get565() const; U16 get4444() const; + Hsb getHSB() const; + + String getHex() const; + S32 convertFromHex(const String& hex) const; + operator ColorF() const; operator const U8*() const { return &red; } @@ -459,6 +485,174 @@ inline void ColorI::set(const ColorI& in_rCopy, alpha = in_a; } +inline void ColorI::set(const Hsb& color) +{ + U32 r = 0; + U32 g = 0; + U32 b = 0; + + F64 L = ((F64)color.brightness) / 100.0; + F64 S = ((F64)color.sat) / 100.0; + F64 H = ((F64)color.hue) / 360.0; + + if (color.sat == 0) + { + r = color.brightness; + g = color.brightness; + b = color.brightness; + } + else + { + F64 temp1 = 0; + if (L < 0.50) + { + temp1 = L*(1 + S); + } + else + { + temp1 = L + S - (L*S); + } + + F64 temp2 = 2.0*L - temp1; + + F64 temp3 = 0; + for (S32 i = 0; i < 3; i++) + { + switch (i) + { + case 0: // red + { + temp3 = H + 0.33333; + if (temp3 > 1.0) + temp3 -= 1.0; + HSLtoRGB_Subfunction(r, temp1, temp2, temp3); + break; + } + case 1: // green + { + temp3 = H; + HSLtoRGB_Subfunction(g, temp1, temp2, temp3); + break; + } + case 2: // blue + { + temp3 = H - 0.33333; + if (temp3 < 0) + temp3 += 1; + HSLtoRGB_Subfunction(b, temp1, temp2, temp3); + break; + } + default: + { + + } + } + } + } + red = (U32)((((F64)r) / 100) * 255); + green = (U32)((((F64)g) / 100) * 255); + blue = (U32)((((F64)b) / 100) * 255); +} + +// This is a subfunction of HSLtoRGB +inline void ColorI::HSLtoRGB_Subfunction(U32& c, const F64& temp1, const F64& temp2, const F64& temp3) +{ + if ((temp3 * 6.0) < 1.0) + c = (U32)((temp2 + (temp1 - temp2)*6.0*temp3)*100.0); + else + if ((temp3 * 2.0) < 1.0) + c = (U32)(temp1*100.0); + else + if ((temp3 * 3.0) < 2.0) + c = (U32)((temp2 + (temp1 - temp2)*(0.66666 - temp3)*6.0)*100.0); + else + c = (U32)(temp2*100.0); + return; +} + +inline void ColorI::set(const String& hex) +{ + String redString; + String greenString; + String blueString; + + //if the prefix # was attached to hex + if (hex[0] == '#') + { + redString = hex.substr(1, 2); + greenString = hex.substr(3, 2); + blueString = hex.substr(5, 2); + } + else + { + // since there is no prefix attached to hex + redString = hex.substr(0, 2); + greenString = hex.substr(2, 2); + blueString = hex.substr(4, 2); + } + + red = (U8)(convertFromHex(redString)); + green = (U8)(convertFromHex(greenString)); + blue = (U8)(convertFromHex(blueString)); +} + +inline S32 ColorI::convertFromHex(const String& hex) const +{ + S32 hexValue = 0; + + S32 a = 0; + S32 b = hex.length() - 1; + + for (; b >= 0; a++, b--) + { + if (hex[b] >= '0' && hex[b] <= '9') + { + hexValue += (hex[b] - '0') * (1 << (a * 4)); + } + else + { + switch (hex[b]) + { + case 'A': + case 'a': + hexValue += 10 * (1 << (a * 4)); + break; + + case 'B': + case 'b': + hexValue += 11 * (1 << (a * 4)); + break; + + case 'C': + case 'c': + hexValue += 12 * (1 << (a * 4)); + break; + + case 'D': + case 'd': + hexValue += 13 * (1 << (a * 4)); + break; + + case 'E': + case 'e': + hexValue += 14 * (1 << (a * 4)); + break; + + case 'F': + case 'f': + hexValue += 15 * (1 << (a * 4)); + break; + + default: + Con::errorf("Error, invalid character '%c' in hex number", hex[a]); + break; + } + } + } + + return hexValue; +} + inline ColorI::ColorI(const ColorI& in_rCopy) { red = in_rCopy.red; @@ -467,6 +661,11 @@ inline ColorI::ColorI(const ColorI& in_rCopy) alpha = in_rCopy.alpha; } +inline ColorI::ColorI(const Hsb& color) +{ + set(color); +} + inline ColorI::ColorI(const U8 in_r, const U8 in_g, const U8 in_b, @@ -647,6 +846,91 @@ inline U16 ColorI::get4444() const U16(U16(blue >> 4) << 0)); } +inline ColorI::Hsb ColorI::getHSB() const +{ + F64 rPercent = ((F64)red) / 255; + F64 gPercent = ((F64)green) / 255; + F64 bPercent = ((F64)blue) / 255; + + F64 maxColor = 0.0; + if ((rPercent >= gPercent) && (rPercent >= bPercent)) + maxColor = rPercent; + if ((gPercent >= rPercent) && (gPercent >= bPercent)) + maxColor = gPercent; + if ((bPercent >= rPercent) && (bPercent >= gPercent)) + maxColor = bPercent; + + F64 minColor = 0.0; + if ((rPercent <= gPercent) && (rPercent <= bPercent)) + minColor = rPercent; + if ((gPercent <= rPercent) && (gPercent <= bPercent)) + minColor = gPercent; + if ((bPercent <= rPercent) && (bPercent <= gPercent)) + minColor = bPercent; + + F64 H = 0.0; + F64 S = 0.0; + F64 B = 0.0; + + B = (maxColor + minColor) / 2.0; + + if (maxColor == minColor) + { + H = 0.0; + S = 0.0; + } + else + { + if (B < 0.50) + { + S = (maxColor - minColor) / (maxColor + minColor); + } + else + { + S = (maxColor - minColor) / (2.0 - maxColor - minColor); + } + if (maxColor == rPercent) + { + H = (gPercent - bPercent) / (maxColor - minColor); + } + if (maxColor == gPercent) + { + H = 2.0 + (bPercent - rPercent) / (maxColor - minColor); + } + if (maxColor == bPercent) + { + H = 4.0 + (rPercent - gPercent) / (maxColor - minColor); + } + } + + ColorI::Hsb val; + val.sat = (U32)(S * 100); + val.brightness = (U32)(B * 100); + H = H*60.0; + if (H < 0.0) + H += 360.0; + val.hue = (U32)H; + + return val; +} + +inline String ColorI::getHex() const +{ + char r[255]; + dSprintf(r, sizeof(r), "%.2X", red); + String result(r); + + char g[255]; + dSprintf(g, sizeof(g), "%.2X", green); + result += g; + + char b[255]; + dSprintf(b, sizeof(b), "%.2X", blue); + result += b; + + return result; +} + //-------------------------------------- INLINE CONVERSION OPERATORS inline ColorF::operator ColorI() const { diff --git a/Engine/source/gui/controls/guiColorPicker.cpp b/Engine/source/gui/controls/guiColorPicker.cpp index 0b8676240..39c140434 100644 --- a/Engine/source/gui/controls/guiColorPicker.cpp +++ b/Engine/source/gui/controls/guiColorPicker.cpp @@ -71,6 +71,18 @@ GuiColorPickerCtrl::GuiColorPickerCtrl() mSelectorGap = 1; mActionOnMove = false; mShowReticle = true; + mSelectColor = false; + mSetColor = mSetColor.BLACK; + mBitmap = NULL; +} + +GuiColorPickerCtrl::~GuiColorPickerCtrl() +{ + if (mBitmap) + { + delete mBitmap; + mBitmap = NULL; + } } //-------------------------------------------------------------------------- @@ -331,60 +343,180 @@ void GuiColorPickerCtrl::renderColorBox(RectI &bounds) void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) { - if (mStateBlock.isNull()) - { - GFXStateBlockDesc desc; - desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha); - desc.setZReadWrite(false); - desc.zWriteEnable = false; - desc.setCullMode(GFXCullNone); - mStateBlock = GFX->createStateBlock( desc ); - } + if (mStateBlock.isNull()) + { + GFXStateBlockDesc desc; + desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha); + desc.setZReadWrite(false); + desc.zWriteEnable = false; + desc.setCullMode(GFXCullNone); + mStateBlock = GFX->createStateBlock(desc); + } - RectI boundsRect(offset, getExtent()); - renderColorBox(boundsRect); + RectI boundsRect(offset, getExtent()); + renderColorBox(boundsRect); - if (mPositionChanged) - { - mPositionChanged = false; - Point2I extent = getRoot()->getExtent(); - // If we are anything but a pallete, change the pick color - if (mDisplayMode != pPallet) - { - Point2I resolution = getRoot()->getExtent(); + if (mPositionChanged || mBitmap == NULL) + { + bool nullBitmap = false; - U32 buf_x = offset.x + mSelectorPos.x + 1; - U32 buf_y = resolution.y - ( extent.y - ( offset.y + mSelectorPos.y + 1 ) ); + if (mPositionChanged == false && mBitmap == NULL) + nullBitmap = true; - GFXTexHandle bb( resolution.x, - resolution.y, - GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) ); - - Point2I tmpPt( buf_x, buf_y ); + mPositionChanged = false; + Point2I extent = getRoot()->getExtent(); + // If we are anything but a pallete, change the pick color + if (mDisplayMode != pPallet) + { + Point2I resolution = getRoot()->getExtent(); - GFXTarget *targ = GFX->getActiveRenderTarget(); - targ->resolveTo( bb ); - - GBitmap bmp( bb.getWidth(), bb.getHeight() ); + U32 buf_x = offset.x + mSelectorPos.x + 1; + U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1)); - bb.copyToBmp( &bmp ); - - //bmp.writePNGDebug( "foo.png" ); + GFXTexHandle bb(resolution.x, + resolution.y, + GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__)); - ColorI tmp; - bmp.getColor( buf_x, buf_y, tmp ); + Point2I tmpPt(buf_x, buf_y); - mPickColor = (ColorF)tmp; + GFXTarget *targ = GFX->getActiveRenderTarget(); + targ->resolveTo(bb); - // Now do onAction() if we are allowed - if (mActionOnMove) - onAction(); - } - - } - - //render the children - renderChildControls( offset, updateRect); + if (mBitmap) + { + delete mBitmap; + mBitmap = NULL; + } + + mBitmap = new GBitmap(bb.getWidth(), bb.getHeight()); + + bb.copyToBmp(mBitmap); + + //bmp.writePNGDebug( "foo.png" ); + + if (!nullBitmap) + { + if (mSelectColor) + { + Point2I pos = findColor(mSetColor, offset, resolution, *mBitmap); + mSetColor = mSetColor.BLACK; + mSelectColor = false; + + setSelectorPos(pos); + } + else + { + ColorI tmp; + mBitmap->getColor(buf_x, buf_y, tmp); + + mPickColor = (ColorF)tmp; + + // Now do onAction() if we are allowed + if (mActionOnMove) + onAction(); + } + } + } + + } + + //render the children + renderChildControls(offset, updateRect); +} + +void GuiColorPickerCtrl::setSelectorPos(const ColorF & color) +{ + if (mBitmap && !mPositionChanged) + { + Point2I resolution = getRoot() ? getRoot()->getExtent() : Point2I(1024, 768); + RectI rect(getGlobalBounds()); + Point2I pos = findColor(color, rect.point, resolution, *mBitmap); + mSetColor = mSetColor.BLACK; + mSelectColor = false; + + setSelectorPos(pos); + } + else + { + mSetColor = color; + mSelectColor = true; + mPositionChanged = true; + } +} + +Point2I GuiColorPickerCtrl::findColor(const ColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp) +{ + RectI rect; + Point2I ext = getExtent(); + if (mDisplayMode != pDropperBackground) + { + ext.x -= 3; + ext.y -= 2; + rect = RectI(Point2I(1, 1), ext); + } + else + { + rect = RectI(Point2I(0, 0), ext); + } + + Point2I closestPos(-1, -1); + + /* Debugging + char filename[256]; + dSprintf( filename, 256, "%s.%s", "colorPickerTest", "png" ); + + // Open up the file on disk. + FileStream fs; + if ( !fs.open( filename, Torque::FS::File::Write ) ) + Con::errorf( "GuiObjectView::saveAsImage() - Failed to open output file '%s'!", filename ); + else + { + // Write it and close. + bmp.writeBitmap( "png", fs ); + + fs.close(); + } + */ + + ColorI tmp; + U32 buf_x; + U32 buf_y; + ColorF curColor; + F32 val(10000.0f); + F32 closestVal(10000.0f); + bool closestSet = false; + + for (S32 x = rect.point.x; x <= rect.extent.x; x++) + { + for (S32 y = rect.point.y; y <= rect.extent.y; y++) + { + buf_x = offset.x + x + 1; + buf_y = (resolution.y - (offset.y + y + 1)); + if (GFX->getAdapterType() != OpenGL) + buf_y = resolution.y - buf_y; + + //Get the color at that position + bmp.getColor(buf_x, buf_y, tmp); + curColor = (ColorF)tmp; + + //Evaluate how close the color is to our desired color + val = mFabs(color.red - curColor.red) + mFabs(color.green - curColor.green) + mFabs(color.blue - curColor.blue); + + if (!closestSet) + { + closestVal = val; + closestPos.set(x, y); + closestSet = true; + } + else if (val < closestVal) + { + closestVal = val; + closestPos.set(x, y); + } + } + } + + return closestPos; } //-------------------------------------------------------------------------- @@ -539,3 +671,10 @@ DefineConsoleMethod(GuiColorPickerCtrl, updateColor, void, (), , "Forces update { object->updateColor(); } + +DefineEngineMethod(GuiColorPickerCtrl, setSelectorColor, void, (ColorF color), , + "Sets the current position of the selector based on a color.n" + "@param color Color to look for.n") +{ + object->setSelectorPos(color); +} \ No newline at end of file diff --git a/Engine/source/gui/controls/guiColorPicker.h b/Engine/source/gui/controls/guiColorPicker.h index a9421b7f7..202a2b5ca 100644 --- a/Engine/source/gui/controls/guiColorPicker.h +++ b/Engine/source/gui/controls/guiColorPicker.h @@ -98,7 +98,11 @@ class GuiColorPickerCtrl : public GuiControl bool mMouseDown; ///< Mouse button down? bool mActionOnMove; ///< Perform onAction() when position has changed? - + bool mSelectColor; + ColorF mSetColor; + GBitmap* mBitmap; + + Point2I findColor(const ColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp); S32 mSelectorGap; ///< The half-way "gap" between the selector pos and where the selector is allowed to draw. @@ -113,6 +117,7 @@ class GuiColorPickerCtrl : public GuiControl DECLARE_CATEGORY( "Gui Editor" ); GuiColorPickerCtrl(); + ~GuiColorPickerCtrl(); static void initPersistFields(); void onRender(Point2I offset, const RectI &updateRect); @@ -131,6 +136,7 @@ class GuiColorPickerCtrl : public GuiControl /// @name Selector Functions /// @{ void setSelectorPos(const Point2I &pos); ///< Set new pos (in local coords) + void setSelectorPos(const ColorF & color); Point2I getSelectorPos() {return mSelectorPos;} /// @} diff --git a/Engine/source/gui/controls/guiTextEditCtrl.cpp b/Engine/source/gui/controls/guiTextEditCtrl.cpp index 450be5280..7224f3eb8 100644 --- a/Engine/source/gui/controls/guiTextEditCtrl.cpp +++ b/Engine/source/gui/controls/guiTextEditCtrl.cpp @@ -128,6 +128,8 @@ GuiTextEditCtrl::GuiTextEditCtrl() mActive = true; + mTextValid = true; + mTextOffsetReset = true; mHistoryDirty = false; @@ -1257,15 +1259,21 @@ void GuiTextEditCtrl::onRender(Point2I offset, const RectI &updateRect) //if opaque, fill the update rect with the fill color if ( mProfile->mOpaque ) { - if(isFirstResponder()) - GFX->getDrawUtil()->drawRectFill( ctrlRect, mProfile->mFillColorHL ); - else - GFX->getDrawUtil()->drawRectFill( ctrlRect, mProfile->mFillColor ); + if (!mTextValid) + GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorNA); + else if (isFirstResponder()) + GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorHL); + else + GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColor); } //if there's a border, draw the border - if ( mProfile->mBorder ) - renderBorder( ctrlRect, mProfile ); + if (mProfile->mBorder) + { + renderBorder(ctrlRect, mProfile); + if (!mTextValid) + GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorNA); + } drawText( ctrlRect, isFirstResponder() ); } @@ -1491,6 +1499,24 @@ bool GuiTextEditCtrl::hasText() return (mTextBuffer.length()); } +void GuiTextEditCtrl::invalidText(bool playSound) +{ + mTextValid = false; + + if (playSound) + playDeniedSound(); +} + +void GuiTextEditCtrl::validText() +{ + mTextValid = true; +} + +bool GuiTextEditCtrl::isValidText() +{ + return mTextValid; +} + void GuiTextEditCtrl::playDeniedSound() { if ( mDeniedSound ) @@ -1518,27 +1544,29 @@ void GuiTextEditCtrl::handleCharInput( U16 ascii ) //see if it's a number field if ( mProfile->mNumbersOnly ) { - if ( ascii == '-') - { - //a minus sign only exists at the beginning, and only a single minus sign - if ( mCursorPos != 0 && !isAllTextSelected() ) - { - playDeniedSound(); - return; - } + if (ascii == '-') + { + //a minus sign only exists at the beginning, and only a single minus sign + if (mCursorPos != 0 && !isAllTextSelected()) + { + invalidText(); + return; + } - if ( mInsertOn && ( mTextBuffer.getChar(0) == '-' ) ) - { - playDeniedSound(); - return; - } - } - // BJTODO: This is probably not unicode safe. - else if ( ascii != '.' && (ascii < '0' || ascii > '9') ) - { - playDeniedSound(); - return; - } + if (mInsertOn && (mTextBuffer.getChar(0) == '-')) + { + invalidText(); + return; + } + } + // BJTODO: This is probably not unicode safe. + else if (ascii != '.' && (ascii < '0' || ascii > '9')) + { + invalidText(); + return; + } + else + validText(); } //save the current state @@ -1746,3 +1774,24 @@ DefineEngineMethod( GuiTextEditCtrl, forceValidateText, void, (),, { object->forceValidateText(); } + +DefineEngineMethod(GuiTextEditCtrl, invalidText, void, (bool playSound), (true), + "@brief Trigger the invalid sound and make the box red.nn" + "@param playSound Play the invalid text sound or not.n") +{ + object->invalidText(playSound); +} + + +DefineEngineMethod(GuiTextEditCtrl, validText, void, (), , + "@brief Restores the box to normal color.nn") +{ + object->validText(); +} + +DefineEngineMethod(GuiTextEditCtrl, isValidText, bool, (), , + "@brief Returns if the text is set to valid or not.n" + "@Return true if text is set to valid, false if not.nn") +{ + return object->isValidText(); +} diff --git a/Engine/source/gui/controls/guiTextEditCtrl.h b/Engine/source/gui/controls/guiTextEditCtrl.h index 1821ef182..9d29038f7 100644 --- a/Engine/source/gui/controls/guiTextEditCtrl.h +++ b/Engine/source/gui/controls/guiTextEditCtrl.h @@ -93,6 +93,8 @@ protected: void playDeniedSound(); void execConsoleCallback(); + bool mTextValid; + virtual void handleCharInput( U16 ascii ); S32 findNextWord(); @@ -119,6 +121,10 @@ public: S32 getCursorPos() { return( mCursorPos ); } void setCursorPos( const S32 newPos ); + void invalidText(bool playSound = true); + void validText(); + bool isValidText(); + bool isAllTextSelected(); void selectAllText(); void clearSelectedText(); diff --git a/Engine/source/math/mConsoleFunctions.cpp b/Engine/source/math/mConsoleFunctions.cpp index 1a11fe23e..df380da1b 100644 --- a/Engine/source/math/mConsoleFunctions.cpp +++ b/Engine/source/math/mConsoleFunctions.cpp @@ -103,6 +103,19 @@ DefineConsoleFunction( mRound, S32, ( F32 v ),, return mRound(v); } +DefineConsoleFunction( mRoundColour, F32, ( F32 v, S32 n ), (0), + "Round v to the nth decimal place or the nearest whole number by default." + "@param v Value to roundn" + "@param n Number of decimal places to round to, 0 by defaultn" + "@return The rounded value as a S32." + "@ingroup Math") +{ + if (n <= 0) + return mRound(v); + else + return mRound(v, n); +} + DefineConsoleFunction( mCeil, S32, ( F32 v ),, "Round v up to the nearest integer.\n" "@param v Number to convert to integer." diff --git a/Templates/Empty/game/tools/gui/colorPicker.ed.gui b/Templates/Empty/game/tools/gui/colorPicker.ed.gui index 18dad276e..c203ca52e 100644 --- a/Templates/Empty/game/tools/gui/colorPicker.ed.gui +++ b/Templates/Empty/game/tools/gui/colorPicker.ed.gui @@ -1,289 +1,722 @@ //--- OBJECT WRITE BEGIN --- %guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) { - canSaveDynamicFields = "0"; - isContainer = "1"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; + displayMode = "Dropper"; // this makes the background visible + actionOnMove = "1"; position = "0 0"; - Extent = "800 600"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; + extent = "1024 768"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; hovertime = "1000"; - DisplayMode = "Dropper"; // this makes the background visible - ActionOnMove = "1"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; new GuiWindowCtrl(GuiPickerDlg) { - canSaveDynamicFields = "0"; - isContainer = "1"; - Profile = "ToolsGuiWindowProfile"; - HorizSizing = "windowRelative"; - VertSizing = "windowRelative"; - position = "170 100"; - Extent = "348 347"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; text = "Color Picker"; - maxLength = "255"; resizeWidth = "0"; resizeHeight = "0"; canMove = "1"; canClose = "1"; canMinimize = "0"; canMaximize = "0"; - minSize = "50 50"; + canCollapse = "0"; closeCommand = "DoColorPickerCancelCallback(); ColorPickerDlg.getRoot().popDialog(ColorPickerDlg);"; - + position = "170 100"; + extent = "439 317"; + minExtent = "8 2"; + horizSizing = "windowRelative"; + vertSizing = "windowRelative"; + profile = "ToolsGuiWindowProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + new GuiBitmapBorderCtrl(){ // color blend - Profile = "ToolsGuiGroupBorderProfile"; position = "3 24"; - Extent = "255 258"; + extent = "255 258"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiColorPickerCtrl(ColorBlendSelect) { + baseColor = "1 0 0 1"; + pickColor = "0 0 0 1"; + selectorGap = "1"; + displayMode = "BlendColor"; + actionOnMove = "1"; + position = "1 0"; + extent = "255 258"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + command = "updateRGBValues(1);"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; }; new GuiBitmapBorderCtrl(){ // Hue - Profile = "ToolsGuiGroupBorderProfile"; position = "263 23"; - Extent = "25 261"; - }; - new GuiBitmapBorderCtrl(){ // new old color - Profile = "ToolsGuiGroupBorderProfile"; - position = "292 37"; - Extent = "52 99"; - }; - new GuiBitmapBorderCtrl(){ // rgb - Profile = "ToolsGuiGroupBorderProfile"; - position = "292 209"; - Extent = "52 75"; - }; - new GuiBitmapBorderCtrl(){ // alpha - Profile = "ToolsGuiGroupBorderProfile"; - position = "3 287"; - Extent = "341 24"; - }; - new GuiColorPickerCtrl(ColorBlendSelect) { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "3 24"; - Extent = "255 258"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - command = "updateRGBValues(1);"; + extent = "25 261"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; hovertime = "1000"; - baseColor = "1 0 0 1"; - PickColor = "0 0 0 1"; - SelectorGap = "1"; - DisplayMode = "BlendColor"; - ActionOnMove = "1"; - }; - new GuiColorPickerCtrl(ColorRangeSelect) { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "264 24"; - Extent = "21 257"; - MinExtent = "8 2"; + isContainer = "1"; canSave = "1"; - Visible = "1"; - Command = "updatePickerBaseColor(1);"; - hovertime = "1000"; - baseColor = "1 0 0 1"; - PickColor = "1 0 0 1"; - SelectorGap = "1"; - DisplayMode = "VertColor"; - ActionOnMove = "1"; - }; - new GuiTextCtrl() { canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "298 215"; - Extent = "8 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - text = "R"; - maxLength = "255"; - }; - new GuiTextEditCtrl(Channel_R_Val) { // Red Channal - Profile = "ToolsGuiNumericTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "307 215"; - Extent = "34 18"; - text = "0"; - maxLength = "4"; - altCommand = "setColorInfo();"; - }; - new GuiTextCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "297 238"; - Extent = "8 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - text = "G"; - maxLength = "255"; - }; - new GuiTextEditCtrl(Channel_G_Val) { // Green Channal - Profile = "ToolsGuiNumericTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "307 238"; - Extent = "34 18"; - text = "0"; - maxLength = "4"; - altCommand = "setColorInfo();"; - }; - new GuiTextCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "298 261"; - Extent = "8 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - text = "B"; - maxLength = "255"; - }; - new GuiTextEditCtrl(Channel_B_Val) { // Blue Channal - Profile = "ToolsGuiNumericTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "307 261"; - Extent = "34 18"; - text = "0"; - maxLength = "4"; - altCommand = "setColorInfo();"; - }; - - - new GuiControl() { - class = "AggregateControl"; - position = "2 290"; - Extent = "341 18"; - - new GuiTextCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "267 0"; - Extent = "29 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; + + new GuiColorPickerCtrl(ColorRangeSelect) { + baseColor = "1 0 0 1"; + pickColor = "1 0 0 1"; + selectorGap = "1"; + displayMode = "VertColor"; + actionOnMove = "1"; + position = "1 1"; + extent = "21 257"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + command = "updatePickerBaseColor(1);"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; hovertime = "1000"; - text = "Alpha"; - maxLength = "255"; - }; - new GuiSliderCtrl(ColorAlphaSelect) { - internalName = "slider"; - canSaveDynamicFields = "0"; isContainer = "0"; - Profile = "ToolsGuiSliderProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "5 3"; - Extent = "251 13"; - MinExtent = "8 2"; canSave = "1"; - Visible = "1"; - altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); updateColorPickerAlpha( $ThisControl.getValue() );"; - hovertime = "1000"; - range = "0 1"; - ticks = "0"; - value = "1"; - }; - new GuiTextEditCtrl(Channel_A_Val) { // Alpha Channal - internalName = "textEdit"; - Profile = "ToolsGuiNumericTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "305 0"; - Extent = "34 18"; - text = "0"; - maxLength = "4"; - altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); updateColorPickerAlpha( $ThisControl.getValue() );"; + canSaveDynamicFields = "0"; }; }; - new GuiSwatchButtonCtrl(myColor){ // New Color // - Profile = "ToolsGuiDefaultProfile"; - position = "293 38"; - Extent = "50 50"; - }; - new GuiTextCtrl(){ - Profile = "ToolsGuiDefaultProfile"; + new GuiTextCtrl() { text = "New"; position = "306 22"; - Extent = "26 14"; + extent = "26 14"; + profile = "GuiDefaultProfile"; }; - new GuiSwatchButtonCtrl(oldColor){ // Old Color // - Profile = "ToolsGuiDefaultProfile"; - position = "293 85"; - Extent = "50 50"; + new GuiBitmapBorderCtrl(){ // new old color + position = "292 37"; + extent = "52 99"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiSwatchButtonCtrl(myColor){ // New Color // + position = "1 1"; + extent = "50 50"; + profile = "GuiDefaultProfile"; + }; + new GuiSwatchButtonCtrl(oldColor){ // Old Color // + position = "1 48"; + extent = "50 50"; + profile = "GuiDefaultProfile"; + }; }; - new GuiTextCtrl(){ - Profile = "ToolsGuiDefaultProfile"; + new GuiTextCtrl() { text = "Old"; position = "310 138"; - Extent = "26 14"; + extent = "26 14"; + profile = "GuiDefaultProfile"; + }; + new GuiBitmapBorderCtrl(){ // Color Text Fields + position = "291 165"; + extent = "141 118"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiControl() { // rgb + position = "4 0"; + extent = "52 75"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiTextCtrl() { + text = "R"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "5 6"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Red Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_R_Val) { // Red Channal + text = "0"; + maxLength = "4"; + position = "14 6"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerRGBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Red Channel color value."; + }; + new GuiTextCtrl() { + text = "G"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "4 29"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Green Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_G_Val) { // Green Channal + text = "0"; + maxLength = "4"; + position = "14 29"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerRGBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Green Channel color value."; + }; + new GuiTextCtrl() { + text = "B"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "5 52"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Blue Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_B_Val) { // Blue Channal + text = "0"; + maxLength = "4"; + position = "14 52"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerRGBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Blue Channel color value."; + }; + }; + new GuiControl() { + position = "71 0"; + extent = "61 75"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiTextCtrl() { + text = "H"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "5 6"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Hue Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_H_Val) { // Hue Channal + text = "0"; + maxLength = "4"; + position = "14 6"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerHSBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Hue Channel color value."; + }; + new GuiTextCtrl() { + text = "o"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "51 2"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextCtrl() { + text = "S"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "4 29"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Saturation Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_S_Val) { // Saturation Channal + text = "0"; + maxLength = "4"; + position = "14 29"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerHSBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Saturation Channel color value."; + }; + new GuiTextCtrl() { + text = "%"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "51 29"; + extent = "10 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextCtrl() { + text = "B"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "5 52"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Brightness Channel color value. Aka value or lightness."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_Br_Val) { // Brightness Channal + text = "0"; + maxLength = "4"; + position = "14 52"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerHSBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Brightness Channel color value. Aka value or lightness."; + }; + new GuiTextCtrl() { + text = "%"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "51 52"; + extent = "10 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; + new GuiControl() { + position = "3 87"; + extent = "138 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiTextCtrl() { + text = "#"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "3 5"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Hex representation of Red, Green, Blue Color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(HexColor_Val) { // Hex Color Field + text = "0"; + maxLength = "6"; + position = "13 5"; + extent = "116 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfile"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Hex representation of Red, Green, Blue Color value."; + command = "$thisControl.onKeyDown();"; + }; + }; + }; + new GuiBitmapBorderCtrl(){ // alpha + position = "3 287"; + extent = "429 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiControl() { + position = "-1 3"; + extent = "428 18"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + class = "AggregateControl"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiSliderCtrl(ColorAlphaSelect) { + range = "0 1"; + ticks = "0"; + value = "1"; + position = "5 3"; + extent = "341 13"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiSliderProfile"; + visible = "1"; + active = "1"; + altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); updateColorPickerAlpha( $ThisControl.getValue() );"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + internalName = "slider"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextCtrl() { + text = "Alpha"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "355 0"; + extent = "28 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_A_Val) { // Alpha Channal + text = "0"; + maxLength = "4"; + position = "392 0"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); updateColorPickerAlpha( $ThisControl.getValue() );"; + internalName = "TextEdit"; + }; + }; }; new GuiButtonCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiButtonProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "144 316"; - Extent = "115 24"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "DoColorPickerCallback();"; - hovertime = "1000"; text = "Select"; groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; + position = "349 37"; + extent = "84 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiButtonProfile"; + visible = "1"; + active = "1"; + command = "DoColorPickerCallback();"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; }; new GuiButtonCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiButtonProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "268 316"; - Extent = "73 24"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "DoColorPickerCancelCallback();"; - hovertime = "1000"; text = "Cancel"; groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; + position = "349 68"; + extent = "84 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiButtonProfile"; + visible = "1"; + active = "1"; + command = "DoColorPickerCancelCallback();"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; }; }; }; @@ -294,26 +727,6 @@ $ColorPickerCancelCallback = ""; $ColorPickerUpdateCallback = ""; $ColorCallbackType = 1; // ColorI -function ColorFloatToInt( %color ) -{ - %red = getWord( %color, 0 ); - %green = getWord( %color, 1 ); - %blue = getWord( %color, 2 ); - %alpha = getWord( %color, 3 ); - - return mCeil( %red * 255 ) SPC mCeil( %green * 255 ) SPC mCeil( %blue * 255 ) SPC mCeil( %alpha * 255 ); -} - -function ColorIntToFloat( %color ) -{ - %red = getWord( %color, 0 ); - %green = getWord( %color, 1 ); - %blue = getWord( %color, 2 ); - %alpha = getWord( %color, 3 ); - - return ( %red / 255 ) SPC ( %green / 255 ) SPC ( %blue / 255 ) SPC ( %alpha / 255 ); -} - // This function pushes the color picker dialog and returns to a callback the selected value function GetColorI( %currentColor, %callback, %root, %updateCallback, %cancelCallback ) { @@ -333,15 +746,18 @@ function GetColorI( %currentColor, %callback, %root, %updateCallback, %cancelCal ColorAlphaSelect.range = "0 255"; // Set the RGBA displays accordingly - %red = getWord(%currentColor, 0) / 255; - %green = getWord(%currentColor, 1) / 255; - %blue = getWord(%currentColor, 2) / 255; + %red = getWord(%currentColor, 0); + %green = getWord(%currentColor, 1); + %blue = getWord(%currentColor, 2); %alpha = getWord(%currentColor, 3); - // set the initial range blend to correct color, no alpha needed - // this should also set the color blend select right now - ColorRangeSelect.baseColor = %red SPC %green SPC %blue SPC "1.0"; - ColorRangeSelect.updateColor(); + //Set the red green blue text fields + Channel_R_Val.setValue(%red); + Channel_G_Val.setValue(%green); + Channel_B_Val.setValue(%blue); + + //Have the rgb text fields update the rest + Channel_R_Val.onValidate(); if(!isObject(%root)) %root = Canvas; @@ -371,15 +787,18 @@ function GetColorF( %currentColor, %callback, %root, %updateCallback, %cancelCal ColorAlphaSelect.range = "0 1"; // Set the RGBA displays accordingly - %red = getWord(%currentColor, 0); - %green = getWord(%currentColor, 1); - %blue = getWord(%currentColor, 2); - %alpha = getWord(%currentColor, 3); + %red = mRoundColour(getWord(%currentColor, 0), 3); + %green = mRoundColour(getWord(%currentColor, 1), 3); + %blue = mRoundColour(getWord(%currentColor, 2), 3); + %alpha = mRoundColour(getWord(%currentColor, 3), 3); - // set the initial range blend to correct color, no alpha needed - // this should also set the color blend select right now - ColorRangeSelect.baseColor = %red SPC %green SPC %blue SPC "1.0"; - ColorRangeSelect.updateColor(); + //Set the red green blue text fields + Channel_R_Val.setValue(%red); + Channel_G_Val.setValue(%green); + Channel_B_Val.setValue(%blue); + + //Have the rgb text fields update the rest + Channel_R_Val.onValidate(); if(!isObject(%root)) %root = Canvas; @@ -390,6 +809,133 @@ function GetColorF( %currentColor, %callback, %root, %updateCallback, %cancelCal Channel_A_Val.setText( %alpha ); } +function ColorPickerRGBClass::onValidate(%this) +{ + %red = Channel_R_Val.getValue(); + %green = Channel_G_Val.getValue(); + %blue = Channel_B_Val.getValue(); + + //Rest of the fields just do everything with ints so convert + if( $ColorCallbackType != 1 ) + { + %rgb = ColorFloatToInt(%red SPC %green SPC %blue SPC "1.0"); + %red = getWord(%rgb, 0); + %green = getWord(%rgb, 1); + %blue = getWord(%rgb, 2); + } + + //Update all the other color fields + %hsb = ColorRGBToHSB(%red SPC %green SPC %blue); + Channel_H_Val.setValue(getWord(%hsb, 0)); + Channel_S_Val.setValue(getWord(%hsb, 1)); + Channel_Br_Val.setValue(getWord(%hsb, 2)); + + %hex = ColorRGBToHEX(%red SPC %green SPC %blue); + HexColor_Val.setValue(%hex); + HexColor_Val.onKeyDown(); + + //Update everything else with our new color + setColorInfo(); +} + +function ColorPickerHSBClass::onValidate(%this) +{ + %hue = Channel_H_Val.getValue(); + %saturation = Channel_S_Val.getValue(); + %brightness = Channel_Br_Val.getValue(); + + //Update all the other color fields + %rgb = ColorHSBToRGB(%hue SPC %saturation SPC %brightness); + %hex = ColorRGBToHEX(%rgb); + HexColor_Val.setValue(%hex); + HexColor_Val.onKeyDown(); + + //convert to float for rgb if we need to + if( $ColorCallbackType != 1 ) + { + %rgb = ColorIntToFloat(%rgb); + } + %red = getWord(%rgb, 0); + %green = getWord(%rgb, 1); + %blue = getWord(%rgb, 2); + Channel_R_Val.setValue(%red); + Channel_G_Val.setValue(%green); + Channel_B_Val.setValue(%blue); + + //Update everything else with our new color + setColorInfo(); +} + +function HexColor_Val::onKeyDown(%this) +{ + //Get the value + %value = %this.getValue(); + + //It's hex so keep it all uppercase + %value = strupr(%value); + %pos = %this.getCursorPos(); + %this.setValue(%value); + %this.setCursorPos(%pos); + + //Verify that it's a hex value + %value = stripChars(%value, "0123456789ABCDEF"); + if(%value $= "") + { + %this.validText(); + } + else + { + %this.invalidText(false); + } +} + +function HexColor_Val::onValidate(%this) +{ + //if the current text is invalid don't do anyting + if(!%this.isValidText()) + { + %this.invalidText(true); + return; + } + + //Get the current value + %hex = %this.getValue(); + + //Make sure we have 6 characters + while(strlen(%hex) < 6) + { + %hex = "0" @ %hex; + } + %hex = strupr(%hex); + + //Update the value in case there were missing characters + %this.setValue(%hex); + + //Update all the other color fields + %rgb = ColorHEXToRGB(%hex); + %hsb = ColorRGBToHSB(%rgb); + + //convert to float for rgb if we need to + if( $ColorCallbackType != 1 ) + { + %rgb = ColorIntToFloat(%rgb); + } + + %red = getWord(%rgb, 0); + %green = getWord(%rgb, 1); + %blue = getWord(%rgb, 2); + Channel_R_Val.setValue(%red); + Channel_G_Val.setValue(%green); + Channel_B_Val.setValue(%blue); + + Channel_H_Val.setValue(getWord(%hsb, 0)); + Channel_S_Val.setValue(getWord(%hsb, 1)); + Channel_Br_Val.setValue(getWord(%hsb, 2)); + + //Update everything else with our new color + setColorInfo(); +} + // This function is used to update the text controls at the top function setColorInfo() { @@ -398,16 +944,40 @@ function setColorInfo() %blue = Channel_B_Val.getValue(); if( $ColorCallbackType == 1) - { - %red = (%red / 255); - %green = (%green / 255); - %blue = (%blue / 255); - } + %rgb = ColorIntToFloat(%red SPC %green SPC %blue SPC "255"); + else + %rgb = %red SPC %green SPC %blue SPC "1.0"; - $ColorPickerSignal = 1; + $ColorPickerSignal = 0; - ColorBlendSelect.baseColor = %red SPC %green SPC %blue SPC "1.0"; + //Convert color over to hue color + %hsb = ColorRGBToHSB(ColorFloatToInt(%rgb)); + %tempColor = ColorHSBToRGB( getWord(%hsb, 0) SPC 100 SPC 50); + %tempColor = ColorIntToFloat(setWord(%tempColor, 3, 255)); + + //Make sure all the text fields and everything don't update because of the cursors + ColorRangeSelect.update = false; + ColorBlendSelect.update = false; + + //Set values for the hue color picker + ColorRangeSelect.baseColor = %tempColor; + ColorRangeSelect.pickColor = %tempColor; + ColorRangeSelect.updateColor(); + + //Set the cursor for the hue picker + ColorRangeSelect.setSelectorColor(%tempColor); + + //Set the values for the gradient color picker + ColorBlendSelect.baseColor = %tempColor; + ColorBlendSelect.pickColor = %rgb; ColorBlendSelect.updateColor(); + + //Set the cursor for the gradiant color picker + ColorBlendSelect.setSelectorColor(%rgb); + + //Update our current color + %alpha = getWord(myColor.color, 3); + myColor.color = setWord(%rgb, 3, %alpha); } // return mycolor.color @@ -433,11 +1003,17 @@ function DoColorPickerUpdateCallback() // this is called from ColorRangeSelect.updateColor function updatePickerBaseColor( %location ) { + if(!ColorRangeSelect.update) + { + ColorRangeSelect.update = true; + return; + } + if( $ColorPickerSignal && %location ) %pickColor = ColorRangeSelect.baseColor; else %pickColor = ColorRangeSelect.pickColor; - $ColorPickerSignal = 1; + $ColorPickerSignal = 0; %red = getWord(%pickColor, 0); %green = getWord(%pickColor, 1); @@ -451,6 +1027,12 @@ function updatePickerBaseColor( %location ) // this is called from ColorBlendSelect.updateColor function updateRGBValues( %location ) { + if(!ColorBlendSelect.update) + { + ColorBlendSelect.update = true; + return; + } + //update the color based on where it came from if( $ColorPickerSignal && %location ) %pickColor = ColorBlendSelect.baseColor; @@ -465,7 +1047,7 @@ function updateRGBValues( %location ) %alpha = getWord(myColor.color, 3); // set the color! - myColor.color = %red SPC %green SPC %blue SPC %alpha ; + myColor.color = %red SPC %green SPC %blue SPC %alpha; DoColorPickerUpdateCallback(); @@ -488,6 +1070,25 @@ function updateRGBValues( %location ) Channel_G_Val.setValue(%green); Channel_B_Val.setValue(%blue); + //Rest of the fields just do everything with ints so convert + if( $ColorCallbackType != 1 ) + { + %rgb = ColorFloatToInt(%red SPC %green SPC %blue SPC "1.0"); + %red = getWord(%rgb, 0); + %green = getWord(%rgb, 1); + %blue = getWord(%rgb, 2); + } + + //Update all the other color fields + %hsb = ColorRGBToHSB(%red SPC %green SPC %blue); + Channel_H_Val.setValue(getWord(%hsb, 0)); + Channel_S_Val.setValue(getWord(%hsb, 1)); + Channel_Br_Val.setValue(getWord(%hsb, 2)); + + %hex = ColorRGBToHEX(%red SPC %green SPC %blue); + HexColor_Val.setValue(%hex); + HexColor_Val.onKeyDown(); + $ColorPickerSignal = 0; } diff --git a/Templates/Full/game/tools/gui/colorPicker.ed.gui b/Templates/Full/game/tools/gui/colorPicker.ed.gui index 18dad276e..c203ca52e 100644 --- a/Templates/Full/game/tools/gui/colorPicker.ed.gui +++ b/Templates/Full/game/tools/gui/colorPicker.ed.gui @@ -1,289 +1,722 @@ //--- OBJECT WRITE BEGIN --- %guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) { - canSaveDynamicFields = "0"; - isContainer = "1"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; + displayMode = "Dropper"; // this makes the background visible + actionOnMove = "1"; position = "0 0"; - Extent = "800 600"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; + extent = "1024 768"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; hovertime = "1000"; - DisplayMode = "Dropper"; // this makes the background visible - ActionOnMove = "1"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; new GuiWindowCtrl(GuiPickerDlg) { - canSaveDynamicFields = "0"; - isContainer = "1"; - Profile = "ToolsGuiWindowProfile"; - HorizSizing = "windowRelative"; - VertSizing = "windowRelative"; - position = "170 100"; - Extent = "348 347"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; text = "Color Picker"; - maxLength = "255"; resizeWidth = "0"; resizeHeight = "0"; canMove = "1"; canClose = "1"; canMinimize = "0"; canMaximize = "0"; - minSize = "50 50"; + canCollapse = "0"; closeCommand = "DoColorPickerCancelCallback(); ColorPickerDlg.getRoot().popDialog(ColorPickerDlg);"; - + position = "170 100"; + extent = "439 317"; + minExtent = "8 2"; + horizSizing = "windowRelative"; + vertSizing = "windowRelative"; + profile = "ToolsGuiWindowProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + new GuiBitmapBorderCtrl(){ // color blend - Profile = "ToolsGuiGroupBorderProfile"; position = "3 24"; - Extent = "255 258"; + extent = "255 258"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiColorPickerCtrl(ColorBlendSelect) { + baseColor = "1 0 0 1"; + pickColor = "0 0 0 1"; + selectorGap = "1"; + displayMode = "BlendColor"; + actionOnMove = "1"; + position = "1 0"; + extent = "255 258"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + command = "updateRGBValues(1);"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; }; new GuiBitmapBorderCtrl(){ // Hue - Profile = "ToolsGuiGroupBorderProfile"; position = "263 23"; - Extent = "25 261"; - }; - new GuiBitmapBorderCtrl(){ // new old color - Profile = "ToolsGuiGroupBorderProfile"; - position = "292 37"; - Extent = "52 99"; - }; - new GuiBitmapBorderCtrl(){ // rgb - Profile = "ToolsGuiGroupBorderProfile"; - position = "292 209"; - Extent = "52 75"; - }; - new GuiBitmapBorderCtrl(){ // alpha - Profile = "ToolsGuiGroupBorderProfile"; - position = "3 287"; - Extent = "341 24"; - }; - new GuiColorPickerCtrl(ColorBlendSelect) { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "3 24"; - Extent = "255 258"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - command = "updateRGBValues(1);"; + extent = "25 261"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; hovertime = "1000"; - baseColor = "1 0 0 1"; - PickColor = "0 0 0 1"; - SelectorGap = "1"; - DisplayMode = "BlendColor"; - ActionOnMove = "1"; - }; - new GuiColorPickerCtrl(ColorRangeSelect) { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiDefaultProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "264 24"; - Extent = "21 257"; - MinExtent = "8 2"; + isContainer = "1"; canSave = "1"; - Visible = "1"; - Command = "updatePickerBaseColor(1);"; - hovertime = "1000"; - baseColor = "1 0 0 1"; - PickColor = "1 0 0 1"; - SelectorGap = "1"; - DisplayMode = "VertColor"; - ActionOnMove = "1"; - }; - new GuiTextCtrl() { canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "298 215"; - Extent = "8 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - text = "R"; - maxLength = "255"; - }; - new GuiTextEditCtrl(Channel_R_Val) { // Red Channal - Profile = "ToolsGuiNumericTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "307 215"; - Extent = "34 18"; - text = "0"; - maxLength = "4"; - altCommand = "setColorInfo();"; - }; - new GuiTextCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "297 238"; - Extent = "8 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - text = "G"; - maxLength = "255"; - }; - new GuiTextEditCtrl(Channel_G_Val) { // Green Channal - Profile = "ToolsGuiNumericTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "307 238"; - Extent = "34 18"; - text = "0"; - maxLength = "4"; - altCommand = "setColorInfo();"; - }; - new GuiTextCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "298 261"; - Extent = "8 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - hovertime = "1000"; - text = "B"; - maxLength = "255"; - }; - new GuiTextEditCtrl(Channel_B_Val) { // Blue Channal - Profile = "ToolsGuiNumericTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "307 261"; - Extent = "34 18"; - text = "0"; - maxLength = "4"; - altCommand = "setColorInfo();"; - }; - - - new GuiControl() { - class = "AggregateControl"; - position = "2 290"; - Extent = "341 18"; - - new GuiTextCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiTextProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "267 0"; - Extent = "29 18"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; + + new GuiColorPickerCtrl(ColorRangeSelect) { + baseColor = "1 0 0 1"; + pickColor = "1 0 0 1"; + selectorGap = "1"; + displayMode = "VertColor"; + actionOnMove = "1"; + position = "1 1"; + extent = "21 257"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiDefaultProfile"; + visible = "1"; + active = "1"; + command = "updatePickerBaseColor(1);"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; hovertime = "1000"; - text = "Alpha"; - maxLength = "255"; - }; - new GuiSliderCtrl(ColorAlphaSelect) { - internalName = "slider"; - canSaveDynamicFields = "0"; isContainer = "0"; - Profile = "ToolsGuiSliderProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "5 3"; - Extent = "251 13"; - MinExtent = "8 2"; canSave = "1"; - Visible = "1"; - altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); updateColorPickerAlpha( $ThisControl.getValue() );"; - hovertime = "1000"; - range = "0 1"; - ticks = "0"; - value = "1"; - }; - new GuiTextEditCtrl(Channel_A_Val) { // Alpha Channal - internalName = "textEdit"; - Profile = "ToolsGuiNumericTextEditProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "305 0"; - Extent = "34 18"; - text = "0"; - maxLength = "4"; - altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); updateColorPickerAlpha( $ThisControl.getValue() );"; + canSaveDynamicFields = "0"; }; }; - new GuiSwatchButtonCtrl(myColor){ // New Color // - Profile = "ToolsGuiDefaultProfile"; - position = "293 38"; - Extent = "50 50"; - }; - new GuiTextCtrl(){ - Profile = "ToolsGuiDefaultProfile"; + new GuiTextCtrl() { text = "New"; position = "306 22"; - Extent = "26 14"; + extent = "26 14"; + profile = "GuiDefaultProfile"; }; - new GuiSwatchButtonCtrl(oldColor){ // Old Color // - Profile = "ToolsGuiDefaultProfile"; - position = "293 85"; - Extent = "50 50"; + new GuiBitmapBorderCtrl(){ // new old color + position = "292 37"; + extent = "52 99"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiSwatchButtonCtrl(myColor){ // New Color // + position = "1 1"; + extent = "50 50"; + profile = "GuiDefaultProfile"; + }; + new GuiSwatchButtonCtrl(oldColor){ // Old Color // + position = "1 48"; + extent = "50 50"; + profile = "GuiDefaultProfile"; + }; }; - new GuiTextCtrl(){ - Profile = "ToolsGuiDefaultProfile"; + new GuiTextCtrl() { text = "Old"; position = "310 138"; - Extent = "26 14"; + extent = "26 14"; + profile = "GuiDefaultProfile"; + }; + new GuiBitmapBorderCtrl(){ // Color Text Fields + position = "291 165"; + extent = "141 118"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiControl() { // rgb + position = "4 0"; + extent = "52 75"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiTextCtrl() { + text = "R"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "5 6"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Red Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_R_Val) { // Red Channal + text = "0"; + maxLength = "4"; + position = "14 6"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerRGBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Red Channel color value."; + }; + new GuiTextCtrl() { + text = "G"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "4 29"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Green Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_G_Val) { // Green Channal + text = "0"; + maxLength = "4"; + position = "14 29"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerRGBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Green Channel color value."; + }; + new GuiTextCtrl() { + text = "B"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "5 52"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Blue Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_B_Val) { // Blue Channal + text = "0"; + maxLength = "4"; + position = "14 52"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerRGBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Blue Channel color value."; + }; + }; + new GuiControl() { + position = "71 0"; + extent = "61 75"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiTextCtrl() { + text = "H"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "5 6"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Hue Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_H_Val) { // Hue Channal + text = "0"; + maxLength = "4"; + position = "14 6"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerHSBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Hue Channel color value."; + }; + new GuiTextCtrl() { + text = "o"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "51 2"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextCtrl() { + text = "S"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "4 29"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Saturation Channel color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_S_Val) { // Saturation Channal + text = "0"; + maxLength = "4"; + position = "14 29"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerHSBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Saturation Channel color value."; + }; + new GuiTextCtrl() { + text = "%"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "51 29"; + extent = "10 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextCtrl() { + text = "B"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "5 52"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Brightness Channel color value. Aka value or lightness."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_Br_Val) { // Brightness Channal + text = "0"; + maxLength = "4"; + position = "14 52"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + class = "ColorPickerHSBClass"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Brightness Channel color value. Aka value or lightness."; + }; + new GuiTextCtrl() { + text = "%"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "51 52"; + extent = "10 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + }; + new GuiControl() { + position = "3 87"; + extent = "138 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiTextCtrl() { + text = "#"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "3 5"; + extent = "8 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Hex representation of Red, Green, Blue Color value."; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(HexColor_Val) { // Hex Color Field + text = "0"; + maxLength = "6"; + position = "13 5"; + extent = "116 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfile"; + tooltipProfile = "GuiToolTipProfile"; + tooltip = "Hex representation of Red, Green, Blue Color value."; + command = "$thisControl.onKeyDown();"; + }; + }; + }; + new GuiBitmapBorderCtrl(){ // alpha + position = "3 287"; + extent = "429 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiGroupBorderProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiControl() { + position = "-1 3"; + extent = "428 18"; + minExtent = "8 2"; + horizSizing = "width"; + vertSizing = "bottom"; + profile = "ToolsGuiDefaultProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "1"; + class = "AggregateControl"; + canSave = "1"; + canSaveDynamicFields = "0"; + + new GuiSliderCtrl(ColorAlphaSelect) { + range = "0 1"; + ticks = "0"; + value = "1"; + position = "5 3"; + extent = "341 13"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiSliderProfile"; + visible = "1"; + active = "1"; + altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); updateColorPickerAlpha( $ThisControl.getValue() );"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + internalName = "slider"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextCtrl() { + text = "Alpha"; + maxLength = "255"; + margin = "0 0 0 0"; + padding = "0 0 0 0"; + anchorTop = "1"; + anchorBottom = "0"; + anchorLeft = "1"; + anchorRight = "0"; + position = "355 0"; + extent = "28 18"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiTextProfile"; + visible = "1"; + active = "1"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl(Channel_A_Val) { // Alpha Channal + text = "0"; + maxLength = "4"; + position = "392 0"; + extent = "34 18"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "GuiTextEditProfileNumbersOnly"; + altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); updateColorPickerAlpha( $ThisControl.getValue() );"; + internalName = "TextEdit"; + }; + }; }; new GuiButtonCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiButtonProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "144 316"; - Extent = "115 24"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "DoColorPickerCallback();"; - hovertime = "1000"; text = "Select"; groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; + position = "349 37"; + extent = "84 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiButtonProfile"; + visible = "1"; + active = "1"; + command = "DoColorPickerCallback();"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; }; new GuiButtonCtrl() { - canSaveDynamicFields = "0"; - isContainer = "0"; - Profile = "ToolsGuiButtonProfile"; - HorizSizing = "right"; - VertSizing = "bottom"; - position = "268 316"; - Extent = "73 24"; - MinExtent = "8 2"; - canSave = "1"; - Visible = "1"; - Command = "DoColorPickerCancelCallback();"; - hovertime = "1000"; text = "Cancel"; groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; + position = "349 68"; + extent = "84 24"; + minExtent = "8 2"; + horizSizing = "right"; + vertSizing = "bottom"; + profile = "ToolsGuiButtonProfile"; + visible = "1"; + active = "1"; + command = "DoColorPickerCancelCallback();"; + Clickable = "1"; + AffectChildren = "1"; + tooltipProfile = "GuiToolTipProfile"; + hovertime = "1000"; + isContainer = "0"; + canSave = "1"; + canSaveDynamicFields = "0"; }; }; }; @@ -294,26 +727,6 @@ $ColorPickerCancelCallback = ""; $ColorPickerUpdateCallback = ""; $ColorCallbackType = 1; // ColorI -function ColorFloatToInt( %color ) -{ - %red = getWord( %color, 0 ); - %green = getWord( %color, 1 ); - %blue = getWord( %color, 2 ); - %alpha = getWord( %color, 3 ); - - return mCeil( %red * 255 ) SPC mCeil( %green * 255 ) SPC mCeil( %blue * 255 ) SPC mCeil( %alpha * 255 ); -} - -function ColorIntToFloat( %color ) -{ - %red = getWord( %color, 0 ); - %green = getWord( %color, 1 ); - %blue = getWord( %color, 2 ); - %alpha = getWord( %color, 3 ); - - return ( %red / 255 ) SPC ( %green / 255 ) SPC ( %blue / 255 ) SPC ( %alpha / 255 ); -} - // This function pushes the color picker dialog and returns to a callback the selected value function GetColorI( %currentColor, %callback, %root, %updateCallback, %cancelCallback ) { @@ -333,15 +746,18 @@ function GetColorI( %currentColor, %callback, %root, %updateCallback, %cancelCal ColorAlphaSelect.range = "0 255"; // Set the RGBA displays accordingly - %red = getWord(%currentColor, 0) / 255; - %green = getWord(%currentColor, 1) / 255; - %blue = getWord(%currentColor, 2) / 255; + %red = getWord(%currentColor, 0); + %green = getWord(%currentColor, 1); + %blue = getWord(%currentColor, 2); %alpha = getWord(%currentColor, 3); - // set the initial range blend to correct color, no alpha needed - // this should also set the color blend select right now - ColorRangeSelect.baseColor = %red SPC %green SPC %blue SPC "1.0"; - ColorRangeSelect.updateColor(); + //Set the red green blue text fields + Channel_R_Val.setValue(%red); + Channel_G_Val.setValue(%green); + Channel_B_Val.setValue(%blue); + + //Have the rgb text fields update the rest + Channel_R_Val.onValidate(); if(!isObject(%root)) %root = Canvas; @@ -371,15 +787,18 @@ function GetColorF( %currentColor, %callback, %root, %updateCallback, %cancelCal ColorAlphaSelect.range = "0 1"; // Set the RGBA displays accordingly - %red = getWord(%currentColor, 0); - %green = getWord(%currentColor, 1); - %blue = getWord(%currentColor, 2); - %alpha = getWord(%currentColor, 3); + %red = mRoundColour(getWord(%currentColor, 0), 3); + %green = mRoundColour(getWord(%currentColor, 1), 3); + %blue = mRoundColour(getWord(%currentColor, 2), 3); + %alpha = mRoundColour(getWord(%currentColor, 3), 3); - // set the initial range blend to correct color, no alpha needed - // this should also set the color blend select right now - ColorRangeSelect.baseColor = %red SPC %green SPC %blue SPC "1.0"; - ColorRangeSelect.updateColor(); + //Set the red green blue text fields + Channel_R_Val.setValue(%red); + Channel_G_Val.setValue(%green); + Channel_B_Val.setValue(%blue); + + //Have the rgb text fields update the rest + Channel_R_Val.onValidate(); if(!isObject(%root)) %root = Canvas; @@ -390,6 +809,133 @@ function GetColorF( %currentColor, %callback, %root, %updateCallback, %cancelCal Channel_A_Val.setText( %alpha ); } +function ColorPickerRGBClass::onValidate(%this) +{ + %red = Channel_R_Val.getValue(); + %green = Channel_G_Val.getValue(); + %blue = Channel_B_Val.getValue(); + + //Rest of the fields just do everything with ints so convert + if( $ColorCallbackType != 1 ) + { + %rgb = ColorFloatToInt(%red SPC %green SPC %blue SPC "1.0"); + %red = getWord(%rgb, 0); + %green = getWord(%rgb, 1); + %blue = getWord(%rgb, 2); + } + + //Update all the other color fields + %hsb = ColorRGBToHSB(%red SPC %green SPC %blue); + Channel_H_Val.setValue(getWord(%hsb, 0)); + Channel_S_Val.setValue(getWord(%hsb, 1)); + Channel_Br_Val.setValue(getWord(%hsb, 2)); + + %hex = ColorRGBToHEX(%red SPC %green SPC %blue); + HexColor_Val.setValue(%hex); + HexColor_Val.onKeyDown(); + + //Update everything else with our new color + setColorInfo(); +} + +function ColorPickerHSBClass::onValidate(%this) +{ + %hue = Channel_H_Val.getValue(); + %saturation = Channel_S_Val.getValue(); + %brightness = Channel_Br_Val.getValue(); + + //Update all the other color fields + %rgb = ColorHSBToRGB(%hue SPC %saturation SPC %brightness); + %hex = ColorRGBToHEX(%rgb); + HexColor_Val.setValue(%hex); + HexColor_Val.onKeyDown(); + + //convert to float for rgb if we need to + if( $ColorCallbackType != 1 ) + { + %rgb = ColorIntToFloat(%rgb); + } + %red = getWord(%rgb, 0); + %green = getWord(%rgb, 1); + %blue = getWord(%rgb, 2); + Channel_R_Val.setValue(%red); + Channel_G_Val.setValue(%green); + Channel_B_Val.setValue(%blue); + + //Update everything else with our new color + setColorInfo(); +} + +function HexColor_Val::onKeyDown(%this) +{ + //Get the value + %value = %this.getValue(); + + //It's hex so keep it all uppercase + %value = strupr(%value); + %pos = %this.getCursorPos(); + %this.setValue(%value); + %this.setCursorPos(%pos); + + //Verify that it's a hex value + %value = stripChars(%value, "0123456789ABCDEF"); + if(%value $= "") + { + %this.validText(); + } + else + { + %this.invalidText(false); + } +} + +function HexColor_Val::onValidate(%this) +{ + //if the current text is invalid don't do anyting + if(!%this.isValidText()) + { + %this.invalidText(true); + return; + } + + //Get the current value + %hex = %this.getValue(); + + //Make sure we have 6 characters + while(strlen(%hex) < 6) + { + %hex = "0" @ %hex; + } + %hex = strupr(%hex); + + //Update the value in case there were missing characters + %this.setValue(%hex); + + //Update all the other color fields + %rgb = ColorHEXToRGB(%hex); + %hsb = ColorRGBToHSB(%rgb); + + //convert to float for rgb if we need to + if( $ColorCallbackType != 1 ) + { + %rgb = ColorIntToFloat(%rgb); + } + + %red = getWord(%rgb, 0); + %green = getWord(%rgb, 1); + %blue = getWord(%rgb, 2); + Channel_R_Val.setValue(%red); + Channel_G_Val.setValue(%green); + Channel_B_Val.setValue(%blue); + + Channel_H_Val.setValue(getWord(%hsb, 0)); + Channel_S_Val.setValue(getWord(%hsb, 1)); + Channel_Br_Val.setValue(getWord(%hsb, 2)); + + //Update everything else with our new color + setColorInfo(); +} + // This function is used to update the text controls at the top function setColorInfo() { @@ -398,16 +944,40 @@ function setColorInfo() %blue = Channel_B_Val.getValue(); if( $ColorCallbackType == 1) - { - %red = (%red / 255); - %green = (%green / 255); - %blue = (%blue / 255); - } + %rgb = ColorIntToFloat(%red SPC %green SPC %blue SPC "255"); + else + %rgb = %red SPC %green SPC %blue SPC "1.0"; - $ColorPickerSignal = 1; + $ColorPickerSignal = 0; - ColorBlendSelect.baseColor = %red SPC %green SPC %blue SPC "1.0"; + //Convert color over to hue color + %hsb = ColorRGBToHSB(ColorFloatToInt(%rgb)); + %tempColor = ColorHSBToRGB( getWord(%hsb, 0) SPC 100 SPC 50); + %tempColor = ColorIntToFloat(setWord(%tempColor, 3, 255)); + + //Make sure all the text fields and everything don't update because of the cursors + ColorRangeSelect.update = false; + ColorBlendSelect.update = false; + + //Set values for the hue color picker + ColorRangeSelect.baseColor = %tempColor; + ColorRangeSelect.pickColor = %tempColor; + ColorRangeSelect.updateColor(); + + //Set the cursor for the hue picker + ColorRangeSelect.setSelectorColor(%tempColor); + + //Set the values for the gradient color picker + ColorBlendSelect.baseColor = %tempColor; + ColorBlendSelect.pickColor = %rgb; ColorBlendSelect.updateColor(); + + //Set the cursor for the gradiant color picker + ColorBlendSelect.setSelectorColor(%rgb); + + //Update our current color + %alpha = getWord(myColor.color, 3); + myColor.color = setWord(%rgb, 3, %alpha); } // return mycolor.color @@ -433,11 +1003,17 @@ function DoColorPickerUpdateCallback() // this is called from ColorRangeSelect.updateColor function updatePickerBaseColor( %location ) { + if(!ColorRangeSelect.update) + { + ColorRangeSelect.update = true; + return; + } + if( $ColorPickerSignal && %location ) %pickColor = ColorRangeSelect.baseColor; else %pickColor = ColorRangeSelect.pickColor; - $ColorPickerSignal = 1; + $ColorPickerSignal = 0; %red = getWord(%pickColor, 0); %green = getWord(%pickColor, 1); @@ -451,6 +1027,12 @@ function updatePickerBaseColor( %location ) // this is called from ColorBlendSelect.updateColor function updateRGBValues( %location ) { + if(!ColorBlendSelect.update) + { + ColorBlendSelect.update = true; + return; + } + //update the color based on where it came from if( $ColorPickerSignal && %location ) %pickColor = ColorBlendSelect.baseColor; @@ -465,7 +1047,7 @@ function updateRGBValues( %location ) %alpha = getWord(myColor.color, 3); // set the color! - myColor.color = %red SPC %green SPC %blue SPC %alpha ; + myColor.color = %red SPC %green SPC %blue SPC %alpha; DoColorPickerUpdateCallback(); @@ -488,6 +1070,25 @@ function updateRGBValues( %location ) Channel_G_Val.setValue(%green); Channel_B_Val.setValue(%blue); + //Rest of the fields just do everything with ints so convert + if( $ColorCallbackType != 1 ) + { + %rgb = ColorFloatToInt(%red SPC %green SPC %blue SPC "1.0"); + %red = getWord(%rgb, 0); + %green = getWord(%rgb, 1); + %blue = getWord(%rgb, 2); + } + + //Update all the other color fields + %hsb = ColorRGBToHSB(%red SPC %green SPC %blue); + Channel_H_Val.setValue(getWord(%hsb, 0)); + Channel_S_Val.setValue(getWord(%hsb, 1)); + Channel_Br_Val.setValue(getWord(%hsb, 2)); + + %hex = ColorRGBToHEX(%red SPC %green SPC %blue); + HexColor_Val.setValue(%hex); + HexColor_Val.onKeyDown(); + $ColorPickerSignal = 0; }