From 03109c9d6d613d51902fa8451fc862acf2214af7 Mon Sep 17 00:00:00 2001 From: Lopuska Date: Wed, 21 Jan 2015 23:14:53 +0100 Subject: [PATCH 01/12] Color Picker --- Engine/source/console/consoleFunctions.cpp | 83 ++ Engine/source/core/color.h | 284 ++++ Engine/source/gui/controls/guiColorPicker.cpp | 229 +++- Engine/source/gui/controls/guiColorPicker.h | 8 +- .../source/gui/controls/guiTextEditCtrl.cpp | 101 +- Engine/source/gui/controls/guiTextEditCtrl.h | 6 + Engine/source/math/mConsoleFunctions.cpp | 13 + .../Empty/game/tools/gui/colorPicker.ed.gui | 1171 +++++++++++++---- .../Full/game/tools/gui/colorPicker.ed.gui | 1171 +++++++++++++---- 9 files changed, 2424 insertions(+), 642 deletions(-) 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; } From c4590f6e3db39b57e08e56501dbd62f08cf18a2d Mon Sep 17 00:00:00 2001 From: Anis Date: Thu, 18 Feb 2016 23:30:09 +0100 Subject: [PATCH 02/12] Update guiTextEditCtrl.cpp --- Engine/source/gui/controls/guiTextEditCtrl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/source/gui/controls/guiTextEditCtrl.cpp b/Engine/source/gui/controls/guiTextEditCtrl.cpp index 7224f3eb8..6c1935bb1 100644 --- a/Engine/source/gui/controls/guiTextEditCtrl.cpp +++ b/Engine/source/gui/controls/guiTextEditCtrl.cpp @@ -1260,7 +1260,7 @@ void GuiTextEditCtrl::onRender(Point2I offset, const RectI &updateRect) if ( mProfile->mOpaque ) { if (!mTextValid) - GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorNA); + GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorERR); else if (isFirstResponder()) GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorHL); else @@ -1272,7 +1272,7 @@ void GuiTextEditCtrl::onRender(Point2I offset, const RectI &updateRect) { renderBorder(ctrlRect, mProfile); if (!mTextValid) - GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorNA); + GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorERR); } drawText( ctrlRect, isFirstResponder() ); From 3ca67b31487dc44a72fbdff2ca4abadb276e66bb Mon Sep 17 00:00:00 2001 From: Anis Date: Thu, 18 Feb 2016 23:32:19 +0100 Subject: [PATCH 03/12] Update guiTypes.h --- Engine/source/gui/core/guiTypes.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Engine/source/gui/core/guiTypes.h b/Engine/source/gui/core/guiTypes.h index c9dc36bad..51f33d21b 100644 --- a/Engine/source/gui/core/guiTypes.h +++ b/Engine/source/gui/core/guiTypes.h @@ -385,6 +385,7 @@ public: ColorI mFillColor; ///< Fill color, this is used to fill the bounds of the control if it is opaque ColorI mFillColorHL; ///< This is used instead of mFillColor if the object is highlighted ColorI mFillColorNA; ///< This is used instead of mFillColor if the object is not active or disabled + ColorI mFillColorERR; ///< This is used instead of mFillColor if the object has an error or is invalid ColorI mFillColorSEL; ///< This is used instead of mFillColor if the object is selected S32 mBorder; ///< For most controls, if mBorder is > 0 a border will be drawn, some controls use this to draw different types of borders however @see guiDefaultControlRender.cc From df283a270999683a0507c4a4b3cfe1a6d6583f04 Mon Sep 17 00:00:00 2001 From: Anis Date: Thu, 18 Feb 2016 23:33:46 +0100 Subject: [PATCH 04/12] Update guiTypes.cpp --- Engine/source/gui/core/guiTypes.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Engine/source/gui/core/guiTypes.cpp b/Engine/source/gui/core/guiTypes.cpp index dbf96c517..08c647f36 100644 --- a/Engine/source/gui/core/guiTypes.cpp +++ b/Engine/source/gui/core/guiTypes.cpp @@ -269,6 +269,7 @@ GuiControlProfile::GuiControlProfile(void) : mFillColor(255,0,255,255), mFillColorHL(255,0,255,255), mFillColorNA(255,0,255,255), + mFillColorERR(255,0,0,255), mFillColorSEL(255,0,255,255), mBorderColor(255,0,255,255), mBorderColorHL(255,0,255,255), @@ -334,6 +335,7 @@ GuiControlProfile::GuiControlProfile(void) : mFillColor = def->mFillColor; mFillColorHL = def->mFillColorHL; mFillColorNA = def->mFillColorNA; + mFillColorERR = def->mFillColorERR; mFillColorSEL = def->mFillColorSEL; mBorder = def->mBorder; @@ -398,6 +400,7 @@ void GuiControlProfile::initPersistFields() addField("fillColor", TypeColorI, Offset(mFillColor, GuiControlProfile)); addField("fillColorHL", TypeColorI, Offset(mFillColorHL, GuiControlProfile)); addField("fillColorNA", TypeColorI, Offset(mFillColorNA, GuiControlProfile)); + addField("fillColorERR", TypeColorI, Offset(mFillColorERR, GuiControlProfile)); addField("fillColorSEL", TypeColorI, Offset(mFillColorSEL, GuiControlProfile)); addField("border", TypeS32, Offset(mBorder, GuiControlProfile), "Border type (0=no border)." ); From 494922d9ed066f0a8117dacceb7ca3ca4fb56924 Mon Sep 17 00:00:00 2001 From: Anis Date: Sun, 21 Feb 2016 18:14:41 +0100 Subject: [PATCH 05/12] fixed the not working text edit RGB field on color picker. --- Engine/source/console/consoleFunctions.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index 1e72f05b8..3a79a99e1 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -879,9 +879,11 @@ DefineConsoleFunction(ColorHEXToRGB, ColorI, (const char* hex), , "@endtsexample\n" "@ingroup Strings") { - ColorI color; - color.set(hex); - return color; + S32 rgb = dAtoui(hex, 16); + + ColorI color; + color.set(rgb & 0x000000FF, (rgb & 0x0000FF00) >> 8, (rgb & 0x00FF0000) >> 16); + return color; } DefineConsoleFunction(ColorHSBToRGB, ColorI, (Point3I hsb), , From aed2e0b5b63d5dfc46a23fb692b712910bae32ae Mon Sep 17 00:00:00 2001 From: Anis Date: Sun, 21 Feb 2016 22:09:14 +0100 Subject: [PATCH 06/12] Update guiColorPicker.cpp --- Engine/source/gui/controls/guiColorPicker.cpp | 480 +++++++++--------- 1 file changed, 228 insertions(+), 252 deletions(-) diff --git a/Engine/source/gui/controls/guiColorPicker.cpp b/Engine/source/gui/controls/guiColorPicker.cpp index 39c140434..97a8470d8 100644 --- a/Engine/source/gui/controls/guiColorPicker.cpp +++ b/Engine/source/gui/controls/guiColorPicker.cpp @@ -39,13 +39,13 @@ ColorF colorAlpha(0.0f, 0.0f, 0.0f, 0.0f); ColorF colorAlphaW(1.0f, 1.0f, 1.0f, 0.0f); ColorI GuiColorPickerCtrl::mColorRange[7] = { - ColorI(255,0,0), // Red - ColorI(255,0,255), // Pink - ColorI(0,0,255), // Blue - ColorI(0,255,255), // Light blue - ColorI(0,255,0), // Green - ColorI(255,255,0), // Yellow - ColorI(255,0,0), // Red + ColorI(255,0,0), // Red + ColorI(255,0,255), // Pink + ColorI(0,0,255), // Blue + ColorI(0,255,255), // Light blue + ColorI(0,255,0), // Green + ColorI(255,255,0), // Yellow + ColorI(255,0,0), // Red }; /// @} @@ -57,7 +57,6 @@ ConsoleDocClass( GuiColorPickerCtrl, "@internal" ); -//-------------------------------------------------------------------------- GuiColorPickerCtrl::GuiColorPickerCtrl() { setExtent(140, 30); @@ -70,56 +69,50 @@ GuiColorPickerCtrl::GuiColorPickerCtrl() mPositionChanged = false; mSelectorGap = 1; mActionOnMove = false; - mShowReticle = true; - mSelectColor = false; - mSetColor = mSetColor.BLACK; - mBitmap = NULL; + mShowReticle = true; + mSelectColor = false; + mSetColor = mSetColor.BLACK; + mBitmap = NULL; } GuiColorPickerCtrl::~GuiColorPickerCtrl() { - if (mBitmap) - { - delete mBitmap; - mBitmap = NULL; - } + if (mBitmap) + { + delete mBitmap; + mBitmap = NULL; + } } -//-------------------------------------------------------------------------- - ImplementEnumType( GuiColorPickMode, "\n\n" "@ingroup GuiUtil" "@internal" ) - { GuiColorPickerCtrl::pPallet, "Pallete" }, - { GuiColorPickerCtrl::pHorizColorRange, "HorizColor"}, - { GuiColorPickerCtrl::pVertColorRange, "VertColor" }, - { GuiColorPickerCtrl::pHorizColorBrightnessRange, "HorizBrightnessColor"}, - { GuiColorPickerCtrl::pVertColorBrightnessRange, "VertBrightnessColor" }, - { GuiColorPickerCtrl::pBlendColorRange, "BlendColor"}, - { GuiColorPickerCtrl::pHorizAlphaRange, "HorizAlpha"}, - { GuiColorPickerCtrl::pVertAlphaRange, "VertAlpha" }, - { GuiColorPickerCtrl::pDropperBackground, "Dropper" }, + { GuiColorPickerCtrl::pPallet, "Pallete" }, + { GuiColorPickerCtrl::pHorizColorRange, "HorizColor"}, + { GuiColorPickerCtrl::pVertColorRange, "VertColor" }, + { GuiColorPickerCtrl::pHorizColorBrightnessRange, "HorizBrightnessColor" }, + { GuiColorPickerCtrl::pVertColorBrightnessRange, "VertBrightnessColor" }, + { GuiColorPickerCtrl::pBlendColorRange, "BlendColor" }, + { GuiColorPickerCtrl::pHorizAlphaRange, "HorizAlpha" }, + { GuiColorPickerCtrl::pVertAlphaRange, "VertAlpha" }, + { GuiColorPickerCtrl::pDropperBackground, "Dropper" }, EndImplementEnumType; -//-------------------------------------------------------------------------- void GuiColorPickerCtrl::initPersistFields() { addGroup("ColorPicker"); - addField("baseColor", TypeColorF, Offset(mBaseColor, GuiColorPickerCtrl)); addField("pickColor", TypeColorF, Offset(mPickColor, GuiColorPickerCtrl)); addField("selectorGap", TypeS32, Offset(mSelectorGap, GuiColorPickerCtrl)); addField("displayMode", TYPEID< PickMode >(), Offset(mDisplayMode, GuiColorPickerCtrl) ); addField("actionOnMove", TypeBool,Offset(mActionOnMove, GuiColorPickerCtrl)); addField("showReticle", TypeBool, Offset(mShowReticle, GuiColorPickerCtrl)); - endGroup("ColorPicker"); Parent::initPersistFields(); } -//-------------------------------------------------------------------------- // Function to draw a box which can have 4 different colors in each corner blended together void GuiColorPickerCtrl::drawBlendBox(RectI &bounds, ColorF &c1, ColorF &c2, ColorF &c3, ColorF &c4) { @@ -131,54 +124,54 @@ void GuiColorPickerCtrl::drawBlendBox(RectI &bounds, ColorF &c1, ColorF &c2, Col //A couple of checks to determine if color blend if(c1 == colorWhite && c3 == colorAlpha && c4 == colorBlack) { - //Color - PrimBuild::begin( GFXTriangleFan, 4 ); - PrimBuild::color( c2 ); - PrimBuild::vertex2i( r, t ); + //Color + PrimBuild::begin(GFXTriangleFan, 4); + PrimBuild::color( c2 ); + PrimBuild::vertex2i( r, t ); - PrimBuild::color( c2 ); - PrimBuild::vertex2i( r, b ); + PrimBuild::color( c2 ); + PrimBuild::vertex2i( r, b ); - PrimBuild::color( c2 ); - PrimBuild::vertex2i( l, b ); + PrimBuild::color( c2 ); + PrimBuild::vertex2i( l, b ); - PrimBuild::color( c2 ); - PrimBuild::vertex2i( l, t ); - PrimBuild::end(); + PrimBuild::color( c2 ); + PrimBuild::vertex2i( l, t ); + PrimBuild::end(); - //White - PrimBuild::begin( GFXTriangleFan, 4 ); - PrimBuild::color( colorAlphaW ); - PrimBuild::vertex2i( r, t ); + //White + PrimBuild::begin( GFXTriangleFan, 4 ); + PrimBuild::color( colorAlphaW ); + PrimBuild::vertex2i( r, t ); - PrimBuild::color( colorAlphaW ); - PrimBuild::vertex2i( r, b ); + PrimBuild::color( colorAlphaW ); + PrimBuild::vertex2i( r, b ); - PrimBuild::color( c1 ); - PrimBuild::vertex2i( l, b ); + PrimBuild::color( c1 ); + PrimBuild::vertex2i( l, b ); - PrimBuild::color( c1 ); - PrimBuild::vertex2i( l, t ); - PrimBuild::end(); + PrimBuild::color( c1 ); + PrimBuild::vertex2i( l, t ); + PrimBuild::end(); - //Black - PrimBuild::begin( GFXTriangleFan, 4 ); - PrimBuild::color( c3 ); - PrimBuild::vertex2i( r, t ); + //Black + PrimBuild::begin( GFXTriangleFan, 4 ); + PrimBuild::color( c3 ); + PrimBuild::vertex2i( r, t ); - PrimBuild::color( c4 ); - PrimBuild::vertex2i( r, b ); + PrimBuild::color( c4 ); + PrimBuild::vertex2i( r, b ); - PrimBuild::color( c4 ); - PrimBuild::vertex2i( l, b ); + PrimBuild::color( c4 ); + PrimBuild::vertex2i( l, b ); - PrimBuild::color( c3 ); - PrimBuild::vertex2i( l, t ); - PrimBuild::end(); + PrimBuild::color( c3 ); + PrimBuild::vertex2i( l, t ); + PrimBuild::end(); } else { - PrimBuild::begin( GFXTriangleFan, 4 ); + PrimBuild::begin( GFXTriangleFan, 4 ); PrimBuild::color( c1 ); PrimBuild::vertex2i( l, t ); @@ -245,31 +238,29 @@ void GuiColorPickerCtrl::drawBlendRangeBox(RectI &bounds, bool vertical, U8 numC void GuiColorPickerCtrl::drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode) { - if( !mShowReticle ) - return; + if( !mShowReticle ) + return; - U16 sMax = mSelectorGap*2; - switch (mode) - { - case sVertical: - // Now draw the vertical selector - // Up -> Pos - if (selectorPos.y != bounds.point.y+1) - GFX->getDrawUtil()->drawLine(selectorPos.x, bounds.point.y, selectorPos.x, selectorPos.y-sMax-1, colorWhiteBlend); - // Down -> Pos - if (selectorPos.y != bounds.point.y+bounds.extent.y) - GFX->getDrawUtil()->drawLine(selectorPos.x, selectorPos.y + sMax, selectorPos.x, bounds.point.y + bounds.extent.y, colorWhiteBlend); - break; - case sHorizontal: - // Now draw the horizontal selector - // Left -> Pos - if (selectorPos.x != bounds.point.x) + U16 sMax = mSelectorGap*2; + switch (mode) + { + case sVertical: + // Now draw the vertical selector Up -> Pos + if (selectorPos.y != bounds.point.y+1) + GFX->getDrawUtil()->drawLine(selectorPos.x, bounds.point.y, selectorPos.x, selectorPos.y-sMax-1, colorWhiteBlend); + // Down -> Pos + if (selectorPos.y != bounds.point.y+bounds.extent.y) + GFX->getDrawUtil()->drawLine(selectorPos.x, selectorPos.y + sMax, selectorPos.x, bounds.point.y + bounds.extent.y, colorWhiteBlend); + break; + case sHorizontal: + // Now draw the horizontal selector Left -> Pos + if (selectorPos.x != bounds.point.x) GFX->getDrawUtil()->drawLine(bounds.point.x, selectorPos.y-1, selectorPos.x-sMax, selectorPos.y-1, colorWhiteBlend); - // Right -> Pos - if (selectorPos.x != bounds.point.x) + // Right -> Pos + if (selectorPos.x != bounds.point.x) GFX->getDrawUtil()->drawLine(bounds.point.x+mSelectorPos.x+sMax, selectorPos.y-1, bounds.point.x + bounds.extent.x, selectorPos.y-1, colorWhiteBlend); - break; - } + break; + } } //-------------------------------------------------------------------------- @@ -281,10 +272,10 @@ void GuiColorPickerCtrl::renderColorBox(RectI &bounds) pickerBounds.point.y = bounds.point.y+1; pickerBounds.extent.x = bounds.extent.x-1; pickerBounds.extent.y = bounds.extent.y-1; - + if (mProfile->mBorder) GFX->getDrawUtil()->drawRect(bounds, mProfile->mBorderColor); - + Point2I selectorPos = Point2I(bounds.point.x+mSelectorPos.x+1, bounds.point.y+mSelectorPos.y+1); // Draw color box differently depending on mode @@ -343,183 +334,176 @@ 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 || mBitmap == NULL) - { - bool nullBitmap = false; + if (mPositionChanged || mBitmap == NULL) + { + bool nullBitmap = false; - if (mPositionChanged == false && mBitmap == NULL) - nullBitmap = true; + if (mPositionChanged == false && mBitmap == NULL) + nullBitmap = true; - mPositionChanged = false; - Point2I extent = getRoot()->getExtent(); - // If we are anything but a pallete, change the pick color - if (mDisplayMode != pPallet) - { - Point2I resolution = getRoot()->getExtent(); + mPositionChanged = false; + Point2I extent = getRoot()->getExtent(); - U32 buf_x = offset.x + mSelectorPos.x + 1; - U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1)); + // If we are anything but a pallete, change the pick color + if (mDisplayMode != pPallet) + { + Point2I resolution = getRoot()->getExtent(); - GFXTexHandle bb(resolution.x, - resolution.y, - GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__)); + U32 buf_x = offset.x + mSelectorPos.x + 1; + U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1)); - Point2I tmpPt(buf_x, buf_y); + GFXTexHandle bb( resolution.x, resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) ); - GFXTarget *targ = GFX->getActiveRenderTarget(); - targ->resolveTo(bb); + Point2I tmpPt(buf_x, buf_y); - if (mBitmap) - { - delete mBitmap; - mBitmap = NULL; - } + GFXTarget *targ = GFX->getActiveRenderTarget(); + targ->resolveTo(bb); - mBitmap = new GBitmap(bb.getWidth(), bb.getHeight()); + if (mBitmap) + { + delete mBitmap; + mBitmap = NULL; + } - bb.copyToBmp(mBitmap); + mBitmap = new GBitmap(bb.getWidth(), bb.getHeight()); - //bmp.writePNGDebug( "foo.png" ); + bb.copyToBmp(mBitmap); - if (!nullBitmap) - { - if (mSelectColor) - { - Point2I pos = findColor(mSetColor, offset, resolution, *mBitmap); - mSetColor = mSetColor.BLACK; - mSelectColor = false; + 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); - setSelectorPos(pos); - } - else - { - ColorI tmp; - mBitmap->getColor(buf_x, buf_y, tmp); + mPickColor = (ColorF)tmp; - mPickColor = (ColorF)tmp; + // Now do onAction() if we are allowed + if (mActionOnMove) + onAction(); + } + } + } + } - // Now do onAction() if we are allowed - if (mActionOnMove) - onAction(); - } - } - } - - } - - //render the children - renderChildControls(offset, updateRect); + //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; + 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; - } + 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); - } + 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); + Point2I closestPos(-1, -1); - /* Debugging - char filename[256]; - dSprintf( filename, 256, "%s.%s", "colorPickerTest", "png" ); + /* 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 ); + // 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(); - } - */ + fs.close(); + } + */ - ColorI tmp; - U32 buf_x; - U32 buf_y; - ColorF curColor; - F32 val(10000.0f); - F32 closestVal(10000.0f); - bool closestSet = false; + 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; + 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)); + buf_y = resolution.y - buf_y; - //Get the color at that position - bmp.getColor(buf_x, buf_y, tmp); - curColor = (ColorF)tmp; + //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); + //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); - } - } - } + if (!closestSet) + { + closestVal = val; + closestPos.set(x, y); + closestSet = true; + } + else if (val < closestVal) + { + closestVal = val; + closestPos.set(x, y); + } + } + } - return closestPos; + return closestPos; } -//-------------------------------------------------------------------------- void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos) { Point2I extent = getExtent(); @@ -564,7 +548,6 @@ void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos) } } -//-------------------------------------------------------------------------- void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event) { if (!mActive) @@ -577,14 +560,14 @@ void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event) if (mProfile->mCanKeyFocus) setFirstResponder(); - - if (mActive && (mDisplayMode != pDropperBackground)) + + if (mActive && (mDisplayMode != pDropperBackground)) onAction(); // Update the picker cross position if (mDisplayMode != pPallet) - setSelectorPos(globalToLocalCoord(event.mousePoint)); - + setSelectorPos(globalToLocalCoord(event.mousePoint)); + mMouseDown = true; } @@ -600,10 +583,8 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event) if( !mActionOnMove ) execAltConsoleCallback(); - } -//-------------------------------------------------------------------------- void GuiColorPickerCtrl::onMouseMove(const GuiEvent &event) { // Only for dropper mode @@ -611,45 +592,40 @@ void GuiColorPickerCtrl::onMouseMove(const GuiEvent &event) setSelectorPos(globalToLocalCoord(event.mousePoint)); } -//-------------------------------------------------------------------------- void GuiColorPickerCtrl::onMouseEnter(const GuiEvent &event) { mMouseOver = true; } -//-------------------------------------------------------------------------- void GuiColorPickerCtrl::onMouseLeave(const GuiEvent &) { // Reset state mMouseOver = false; } -//-------------------------------------------------------------------------- void GuiColorPickerCtrl::onMouseUp(const GuiEvent &) { //if we released the mouse within this control, perform the action - if (mActive && mMouseDown && (mDisplayMode != pDropperBackground)) + if (mActive && mMouseDown && (mDisplayMode != pDropperBackground)) mMouseDown = false; - if (mActive && (mDisplayMode == pDropperBackground)) + if (mActive && (mDisplayMode == pDropperBackground)) { // In a dropper, the alt command executes the mouse up action (to signal stopping) execAltConsoleCallback(); } - + mouseUnlock(); } -//-------------------------------------------------------------------------- const char *GuiColorPickerCtrl::getScriptValue() { static char temp[256]; ColorF color = getValue(); - dSprintf(temp,256,"%f %f %f %f",color.red, color.green, color.blue, color.alpha); - return temp; + dSprintf( temp, 256, "%f %f %f %f", color.red, color.green, color.blue, color.alpha ); + return temp; } -//-------------------------------------------------------------------------- void GuiColorPickerCtrl::setScriptValue(const char *value) { ColorF newValue; @@ -669,12 +645,12 @@ DefineConsoleMethod(GuiColorPickerCtrl, setSelectorPos, void, (Point2I newPos), DefineConsoleMethod(GuiColorPickerCtrl, updateColor, void, (), , "Forces update of pick color") { - object->updateColor(); + 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") + "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 + object->setSelectorPos(color); +} From 5c2bfbf82eaec500f2e2b7138a6697d762205240 Mon Sep 17 00:00:00 2001 From: Anis Date: Sun, 21 Feb 2016 22:10:17 +0100 Subject: [PATCH 07/12] Update guiColorPicker.h --- Engine/source/gui/controls/guiColorPicker.h | 37 ++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Engine/source/gui/controls/guiColorPicker.h b/Engine/source/gui/controls/guiColorPicker.h index 202a2b5ca..42531c3bb 100644 --- a/Engine/source/gui/controls/guiColorPicker.h +++ b/Engine/source/gui/controls/guiColorPicker.h @@ -59,29 +59,28 @@ class GuiColorPickerCtrl : public GuiControl public: enum PickMode { - pPallet = 0, ///< We just have a solid color; We just act like a pallet - pHorizColorRange, ///< We have a range of base colors going horizontally - pVertColorRange, ///< We have a range of base colors going vertically + pPallet = 0, ///< We just have a solid color; We just act like a pallet + pHorizColorRange, ///< We have a range of base colors going horizontally + pVertColorRange, ///< We have a range of base colors going vertically pHorizColorBrightnessRange, ///< HorizColorRange with brightness - pVertColorBrightnessRange, ///< VertColorRange with brightness - pBlendColorRange, ///< We have a box which shows a range in brightness of the color - pHorizAlphaRange, ///< We have a box which shows a range in alpha going horizontally - pVertAlphaRange, ///< We have a box which shows a range in alpha going vertically - pDropperBackground ///< The control does not draw anything; Only does something when you click, or move the mouse (when active) + pVertColorBrightnessRange, ///< VertColorRange with brightness + pBlendColorRange, ///< We have a box which shows a range in brightness of the color + pHorizAlphaRange, ///< We have a box which shows a range in alpha going horizontally + pVertAlphaRange, ///< We have a box which shows a range in alpha going vertically + pDropperBackground ///< The control does not draw anything; Only does something when you click, or move the mouse (when active) }; enum SelectorMode { - sHorizontal = 0, ///< Horizontal selector with small gap - sVertical, ///< Vertical selector with small gap + sHorizontal = 0, ///< Horizontal selector with small gap + sVertical, ///< Vertical selector with small gap }; - + protected: - /// @name Core Rendering functions /// @{ - void renderColorBox(RectI &bounds); ///< Function that draws the actual color box - void drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode); ///< Function that draws the selection indicator + void renderColorBox(RectI &bounds); ///< Function that draws the actual color box + void drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode); /// < Function that draws the selection indicator void drawBlendBox(RectI &bounds, ColorF &c1, ColorF &c2, ColorF &c3, ColorF &c4); void drawBlendRangeBox(RectI &bounds, bool vertical, U8 numColors, ColorI *colors); /// @} @@ -111,8 +110,8 @@ class GuiColorPickerCtrl : public GuiControl static ColorI mColorRange[7]; ///< Color range for pHorizColorRange and pVertColorRange /// @} - public: - + public: + DECLARE_CONOBJECT(GuiColorPickerCtrl); DECLARE_CATEGORY( "Gui Editor" ); @@ -127,19 +126,19 @@ class GuiColorPickerCtrl : public GuiControl /// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful void setValue(ColorF &value) {mBaseColor = value;} /// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves) - ColorF getValue() {return mDisplayMode == pPallet ? mBaseColor : mPickColor;} + ColorF getValue() { return mDisplayMode == pPallet ? mBaseColor : mPickColor; } const char *getScriptValue(); void setScriptValue(const char *value); void updateColor() {mPositionChanged = true;} /// @} - + /// @name Selector Functions /// @{ void setSelectorPos(const Point2I &pos); ///< Set new pos (in local coords) void setSelectorPos(const ColorF & color); Point2I getSelectorPos() {return mSelectorPos;} /// @} - + /// @name Input Events /// @{ void onMouseDown(const GuiEvent &); From 8ec2e534dc1c617a0b350179d948adba539236f5 Mon Sep 17 00:00:00 2001 From: Anis Date: Sun, 21 Feb 2016 22:36:27 +0100 Subject: [PATCH 08/12] removed tabs --- Engine/source/console/consoleFunctions.cpp | 86 +++++++++++----------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index 3a79a99e1..3e9466a16 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -833,51 +833,51 @@ DefineConsoleFunction(ColorFloatToInt, ColorI, (ColorF 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") + "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; + 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") + "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()); + 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") + "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); + 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") + "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") { S32 rgb = dAtoui(hex, 16); @@ -887,17 +887,17 @@ DefineConsoleFunction(ColorHEXToRGB, ColorI, (const char* hex), , } 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") + "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; + ColorI color; + color.set(ColorI::Hsb(hsb.x, hsb.y, hsb.z)); + return color; } //============================================================================= From 4c0d3bbc3492b699b2f6d11e6c0c7858fa2bed8d Mon Sep 17 00:00:00 2001 From: Anis Date: Sun, 21 Feb 2016 22:41:35 +0100 Subject: [PATCH 09/12] removed tabs --- Engine/source/core/color.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Engine/source/core/color.h b/Engine/source/core/color.h index ddb98c8a8..63e69921b 100644 --- a/Engine/source/core/color.h +++ b/Engine/source/core/color.h @@ -127,12 +127,12 @@ class ColorI struct Hsb { - Hsb() :hue(0), sat(0), brightness(0){}; - Hsb(U32 h, U32 s, U32 b) :hue(h), sat(s), brightness(b){}; + 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 + U32 hue; ///Hue + U32 sat; ///Saturation + U32 brightness; //Brightness/Value/Lightness }; public: From 2a1f81d3aaaab268f2129d69da274273a4f3c185 Mon Sep 17 00:00:00 2001 From: Anis Date: Sun, 21 Feb 2016 22:48:10 +0100 Subject: [PATCH 10/12] removed tabs --- Engine/source/math/mConsoleFunctions.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Engine/source/math/mConsoleFunctions.cpp b/Engine/source/math/mConsoleFunctions.cpp index df380da1b..1d57743e6 100644 --- a/Engine/source/math/mConsoleFunctions.cpp +++ b/Engine/source/math/mConsoleFunctions.cpp @@ -104,16 +104,16 @@ DefineConsoleFunction( mRound, S32, ( F32 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") + "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); + if (n <= 0) + return mRound(v); + else + return mRound(v, n); } DefineConsoleFunction( mCeil, S32, ( F32 v ),, From 304c33e525947c4aebd72d2bb515a2584817a76d Mon Sep 17 00:00:00 2001 From: Anis Date: Sun, 21 Feb 2016 22:55:45 +0100 Subject: [PATCH 11/12] removed tabs --- .../source/gui/controls/guiTextEditCtrl.cpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Engine/source/gui/controls/guiTextEditCtrl.cpp b/Engine/source/gui/controls/guiTextEditCtrl.cpp index 6c1935bb1..0cdf7ade6 100644 --- a/Engine/source/gui/controls/guiTextEditCtrl.cpp +++ b/Engine/source/gui/controls/guiTextEditCtrl.cpp @@ -1252,27 +1252,27 @@ void GuiTextEditCtrl::onLoseFirstResponder() Parent::onLoseFirstResponder(); } -void GuiTextEditCtrl::onRender(Point2I offset, const RectI &updateRect) +void GuiTextEditCtrl::onRender( Point2I offset, const RectI &updateRect ) { RectI ctrlRect( offset, getExtent() ); //if opaque, fill the update rect with the fill color if ( mProfile->mOpaque ) { - if (!mTextValid) - GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorERR); - else if (isFirstResponder()) - GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorHL); - else - GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColor); + if ( !mTextValid ) + GFX->getDrawUtil()->drawRectFill( ctrlRect, mProfile->mFillColorERR ); + 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) + if ( mProfile->mBorder ) { - renderBorder(ctrlRect, mProfile); - if (!mTextValid) - GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorERR); + renderBorder( ctrlRect, mProfile ); + if ( !mTextValid ) + GFX->getDrawUtil()->drawRectFill( ctrlRect, mProfile->mFillColorERR ); } drawText( ctrlRect, isFirstResponder() ); @@ -1496,25 +1496,25 @@ void GuiTextEditCtrl::drawText( const RectI &drawRect, bool isFocused ) bool GuiTextEditCtrl::hasText() { - return (mTextBuffer.length()); + return ( mTextBuffer.length() ); } void GuiTextEditCtrl::invalidText(bool playSound) { - mTextValid = false; + mTextValid = false; - if (playSound) - playDeniedSound(); + if ( playSound ) + playDeniedSound(); } void GuiTextEditCtrl::validText() { - mTextValid = true; + mTextValid = true; } bool GuiTextEditCtrl::isValidText() { - return mTextValid; + return mTextValid; } void GuiTextEditCtrl::playDeniedSound() From 973e5a6c0209502ec036dc6bcf7fb64f470dc3f6 Mon Sep 17 00:00:00 2001 From: Anis Date: Fri, 26 Feb 2016 20:11:27 +0100 Subject: [PATCH 12/12] Update consoleFunctions.cpp --- Engine/source/console/consoleFunctions.cpp | 472 +++++++++++++++++++++ 1 file changed, 472 insertions(+) diff --git a/Engine/source/console/consoleFunctions.cpp b/Engine/source/console/consoleFunctions.cpp index c03c68046..be265add8 100644 --- a/Engine/source/console/consoleFunctions.cpp +++ b/Engine/source/console/consoleFunctions.cpp @@ -25,6 +25,11 @@ #include "console/consoleInternal.h" #include "console/engineAPI.h" #include "console/ast.h" + +#ifndef _CONSOLFUNCTIONS_H_ +#include "console/consoleFunctions.h" +#endif + #include "core/strings/findMatch.h" #include "core/strings/stringUnit.h" #include "core/strings/unicode.h" @@ -32,6 +37,7 @@ #include "console/compiler.h" #include "platform/platformInput.h" #include "core/util/journal/journal.h" +#include "gfx/gfxEnums.h" #include "core/util/uuid.h" #include "core/color.h" #include "math/mPoint3.h" @@ -44,6 +50,132 @@ bool LinkConsoleFunctions = false; // Buffer for expanding script filenames. static char scriptFilenameBuffer[1024]; +bool isInt(const char* str) +{ + int len = dStrlen(str); + if(len <= 0) + return false; + + // Ignore whitespace + int start = 0; + for(int i = start; i < len; i++) + if(str[i] != ' ') + { + start = i; + break; + } + + for(int i = start; i < len; i++) + switch(str[i]) + { + case '+': case '-': + if(i != 0) + return false; + break; + case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': + break; + case ' ': // ignore whitespace + for(int j = i+1; j < len; j++) + if(str[j] != ' ') + return false; + return true; + break; + default: + return false; + } + return true; +} + +bool isFloat(const char* str, bool sciOk = false) +{ + int len = dStrlen(str); + if(len <= 0) + return false; + + // Ingore whitespace + int start = 0; + for(int i = start; i < len; i++) + if(str[i] != ' ') + { + start = i; + break; + } + + bool seenDot = false; + int eLoc = -1; + for(int i = 0; i < len; i++) + switch(str[i]) + { + case '+': case '-': + if(sciOk) + { + //Haven't found e or scientific notation symbol + if(eLoc == -1) + { + //only allowed in beginning + if(i != 0) + return false; + } + else + { + //if not right after the e + if(i != (eLoc + 1)) + return false; + } + } + else + { + //only allowed in beginning + if(i != 0) + return false; + } + break; + case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': + break; + case 'e': case 'E': + if(!sciOk) + return false; + else + { + //already saw it so can't have 2 + if(eLoc != -1) + return false; + + eLoc = i; + } + break; + case '.': + if(seenDot | (sciOk && eLoc != -1)) + return false; + seenDot = true; + break; + case ' ': // ignore whitespace + for(int j = i+1; j < len; j++) + if(str[j] != ' ') + return false; + return true; + break; + default: + return false; + } + return true; +} + +bool isValidIP(const char* ip) +{ + unsigned b1, b2, b3, b4; + unsigned char c; + int rc = dSscanf(ip, "%3u.%3u.%3u.%3u%c", &b1, &b2, &b3, &b4, &c); + if (rc != 4 && rc != 5) return false; + if ((b1 | b2 | b3 | b4) > 255) return false; + if (dStrspn(ip, "0123456789.") < dStrlen(ip)) return false; + return true; +} + +bool isValidPort(U16 port) +{ + return (port >= 0 && port <=65535); +} //============================================================================= // String Functions. @@ -238,6 +370,40 @@ DefineConsoleFunction( strlen, S32, ( const char* str ),, return dStrlen( str ); } +//----------------------------------------------------------------------------- +DefineConsoleFunction( strlenskip, S32, ( const char* str, const char* first, const char* last ),, + "Calculate the length of a string in characters, skipping everything between and including first and last.\n" + "@param str A string.\n" + "@param first First character to look for to skip block of text.\n" + "@param last Second character to look for to skip block of text.\n" + "@return The length of the given string skipping blocks of text between characters.\n" + "@ingroup Strings" ) +{ + const UTF8* pos = str; + U32 size = 0; + U32 length = dStrlen(str); + bool count = true; + + //loop through each character counting each character, skipping tags (anything with < followed by >) + for(U32 i = 0; i < length; i++, pos++) + { + if(count) + { + if(*pos == first[0]) + count = false; + else + size++; + } + else + { + if(*pos == last[0]) + count = true; + } + } + + return S32(size); +} + //----------------------------------------------------------------------------- DefineConsoleFunction( strstr, S32, ( const char* string, const char* substring ),, @@ -284,6 +450,33 @@ DefineConsoleFunction( strpos, S32, ( const char* haystack, const char* needle, //----------------------------------------------------------------------------- +DefineConsoleFunction( strposr, S32, ( const char* haystack, const char* needle, S32 offset ), ( 0 ), + "Find the start of @a needle in @a haystack searching from right to left beginning at the given offset.\n" + "@param haystack The string to search.\n" + "@param needle The string to search for.\n" + "@return The index at which the first occurrence of @a needle was found in @a heystack or -1 if no match was found.\n\n" + "@tsexample\n" + "strposr( \"b ab\", \"b\", 1 ) // Returns 2.\n" + "@endtsexample\n" + "@ingroup Strings" ) +{ + U32 sublen = dStrlen( needle ); + U32 strlen = dStrlen( haystack ); + S32 start = strlen - offset; + + if(start < 0 || start > strlen) + return -1; + + if (start + sublen > strlen) + start = strlen - sublen; + for(; start >= 0; start--) + if(!dStrncmp(haystack + start, needle, sublen)) + return start; + return -1; +} + +//----------------------------------------------------------------------------- + DefineConsoleFunction( ltrim, const char*, ( const char* str ),, "Remove leading whitespace from the string.\n" "@param str A string.\n" @@ -630,6 +823,18 @@ DefineConsoleFunction( stripTrailingNumber, String, ( const char* str ),, return String::GetTrailingNumber( str, suffix ); } +//----------------------------------------------------------------------------- + +DefineConsoleFunction( getFirstNumber, String, ( const char* str ),, + "Get the first occuring number from @a str.\n" + "@param str The string from which to read out the first number.\n" + "@return String representation of the number or "" if no number.\n\n") +{ + U32 start; + U32 end; + return String::GetFirstNumber(str, start, end); +} + //---------------------------------------------------------------- DefineConsoleFunction( isspace, bool, ( const char* str, S32 index ),, @@ -896,6 +1101,110 @@ DefineConsoleFunction(ColorHSBToRGB, ColorI, (Point3I hsb), , return color; } +//---------------------------------------------------------------- + +DefineConsoleFunction( strToggleCaseToWords, const char*, ( const char* str ),, + "Parse a Toggle Case word into separate words.\n" + "@param str The string to parse.\n" + "@return new string space separated.\n\n" + "@tsexample\n" + "strToggleCaseToWords( \"HelloWorld\" ) // Returns \"Hello World\".\n" + "@endtsexample\n" + "@ingroup Strings" ) +{ + String newStr; + for(S32 i = 0; str[i]; i++) + { + //If capitol add a space + if(i != 0 && str[i] >= 65 && str[i] <= 90) + newStr += " "; + + newStr += str[i]; + } + + return Con::getReturnBuffer(newStr); +} + +//---------------------------------------------------------------- + +// Warning: isInt and isFloat are very 'strict' and might need to be adjusted to allow other values. //seanmc +DefineConsoleFunction( isInt, bool, ( const char* str),, + "Returns true if the string is an integer.\n" + "@param str The string to test.\n" + "@return true if @a str is an integer and false if not\n\n" + "@tsexample\n" + "isInt( \"13\" ) // Returns true.\n" + "@endtsexample\n" + "@ingroup Strings" ) +{ + return isInt(str); +} + +//---------------------------------------------------------------- + +DefineConsoleFunction( isFloat, bool, ( const char* str, bool sciOk), (false), + "Returns true if the string is a float.\n" + "@param str The string to test.\n" + "@param sciOk Test for correct scientific notation and accept it (ex. 1.2e+14)" + "@return true if @a str is a float and false if not\n\n" + "@tsexample\n" + "isFloat( \"13.5\" ) // Returns true.\n" + "@endtsexample\n" + "@ingroup Strings" ) +{ + return isFloat(str, sciOk); +} + +//---------------------------------------------------------------- + +DefineConsoleFunction( isValidPort, bool, ( const char* str),, + "Returns true if the string is a valid port number.\n" + "@param str The string to test.\n" + "@return true if @a str is a port and false if not\n\n" + "@tsexample\n" + "isValidPort( \"8080\" ) // Returns true.\n" + "@endtsexample\n" + "@ingroup Strings" ) +{ + if(isInt(str)) + { + U16 port = dAtous(str); + return isValidPort(port); + } + else + return false; +} + +//---------------------------------------------------------------- + +DefineConsoleFunction( isValidIP, bool, ( const char* str),, + "Returns true if the string is a valid ip address, excepts localhost.\n" + "@param str The string to test.\n" + "@return true if @a str is a valid ip address and false if not\n\n" + "@tsexample\n" + "isValidIP( \"localhost\" ) // Returns true.\n" + "@endtsexample\n" + "@ingroup Strings" ) +{ + if(dStrcmp(str, "localhost") == 0) + { + return true; + } + else + return isValidIP(str); +} + +//---------------------------------------------------------------- + +// Torque won't normally add another string if it already exists with another casing, +// so this forces the addition. It should be called once near the start, such as in main.cs. +ConsoleFunction(addCaseSensitiveStrings,void,2,0,"[string1, string2, ...]" + "Adds case sensitive strings to the StringTable.") +{ + for(int i = 1; i < argc; i++) + StringTable->insert(argv[i], true); +} + //============================================================================= // Field Manipulators. //============================================================================= @@ -914,6 +1223,7 @@ DefineConsoleFunction( getWord, const char*, ( const char* text, S32 index ),, "@endtsexample\n\n" "@see getWords\n" "@see getWordCount\n" + "@see getToken\n" "@see getField\n" "@see getRecord\n" "@ingroup FieldManip" ) @@ -937,6 +1247,7 @@ DefineConsoleFunction( getWords, const char*, ( const char* text, S32 startIndex "@endtsexample\n\n" "@see getWord\n" "@see getWordCount\n" + "@see getTokens\n" "@see getFields\n" "@see getRecords\n" "@ingroup FieldManip" ) @@ -961,6 +1272,7 @@ DefineConsoleFunction( setWord, const char*, ( const char* text, S32 index, cons "setWord( \"a b c d\", 2, \"f\" ) // Returns \"a b f d\"\n" "@endtsexample\n\n" "@see getWord\n" + "@see setToken\n" "@see setField\n" "@see setRecord\n" "@ingroup FieldManip" ) @@ -980,6 +1292,7 @@ DefineConsoleFunction( removeWord, const char*, ( const char* text, S32 index ), "@tsexample\n" "removeWord( \"a b c d\", 2 ) // Returns \"a b d\"\n" "@endtsexample\n\n" + "@see removeToken\n" "@see removeField\n" "@see removeRecord\n" "@ingroup FieldManip" ) @@ -997,6 +1310,7 @@ DefineConsoleFunction( getWordCount, S32, ( const char* text ),, "@tsexample\n" "getWordCount( \"a b c d e\" ) // Returns 5\n" "@endtsexample\n\n" + "@see getTokenCount\n" "@see getFieldCount\n" "@see getRecordCount\n" "@ingroup FieldManip" ) @@ -1006,6 +1320,49 @@ DefineConsoleFunction( getWordCount, S32, ( const char* text ),, //----------------------------------------------------------------------------- +DefineEngineFunction( monthNumToStr, String, ( S32 num, bool abbreviate ), (false), + "@brief returns month as a word given a number or \"\" if number is bad" + "@return month as a word given a number or \"\" if number is bad" + "@ingroup FileSystem") +{ + switch(num) + { + case 1: return abbreviate ? "Jan" : "January"; break; + case 2: return abbreviate ? "Feb" : "February"; break; + case 3: return abbreviate ? "Mar" : "March"; break; + case 4: return abbreviate ? "Apr" : "April"; break; + case 5: return "May"; break; + case 6: return abbreviate ? "Jun" : "June"; break; + case 7: return abbreviate ? "Jul" : "July"; break; + case 8: return abbreviate ? "Aug" : "August"; break; + case 9: return abbreviate ? "Sep" : "September"; break; + case 10: return abbreviate ? "Oct" : "October"; break; + case 11: return abbreviate ? "Nov" : "November"; break; + case 12: return abbreviate ? "Dec" : "December"; break; + default: return ""; + } +} + +DefineEngineFunction( weekdayNumToStr, String, ( S32 num, bool abbreviate ), (false), + "@brief returns weekday as a word given a number or \"\" if number is bad" + "@return weekday as a word given a number or \"\" if number is bad" + "@ingroup FileSystem") +{ + switch(num) + { + case 0: return abbreviate ? "Sun" : "Sunday"; break; + case 1: return abbreviate ? "Mon" : "Monday"; break; + case 2: return abbreviate ? "Tue" : "Tuesday"; break; + case 3: return abbreviate ? "Wed" : "Wednesday"; break; + case 4: return abbreviate ? "Thu" : "Thursday"; break; + case 5: return abbreviate ? "Fri" : "Friday"; break; + case 6: return abbreviate ? "Sat" : "Saturday"; break; + default: return ""; + } +} + +//----------------------------------------------------------------------------- + DefineConsoleFunction( getField, const char*, ( const char* text, S32 index ),, "Extract the field at the given @a index in the newline and/or tab separated list in @a text.\n" "Fields in @a text must be separated by newlines and/or tabs.\n" @@ -1327,6 +1684,114 @@ DefineConsoleFunction( nextToken, const char*, ( const char* str1, const char* t return ret; } +//----------------------------------------------------------------------------- + +DefineConsoleFunction( getToken, const char*, ( const char* text, const char* delimiters, S32 index ),, + "Extract the substring at the given @a index in the @a delimiters separated list in @a text.\n" + "@param text A @a delimiters list of substrings.\n" + "@param delimiters Character or characters that separate the list of substrings in @a text.\n" + "@param index The zero-based index of the substring to extract.\n" + "@return The substring at the given index or \"\" if the index is out of range.\n\n" + "@tsexample\n" + "getToken( \"a b c d\", \" \", 2 ) // Returns \"c\"\n" + "@endtsexample\n\n" + "@see getTokens\n" + "@see getTokenCount\n" + "@see getWord\n" + "@see getField\n" + "@see getRecord\n" + "@ingroup FieldManip" ) +{ + return Con::getReturnBuffer( StringUnit::getUnit(text, index, delimiters)); +} + +//----------------------------------------------------------------------------- + +DefineConsoleFunction( getTokens, const char*, ( const char* text, const char* delimiters, S32 startIndex, S32 endIndex ), ( -1 ), + "Extract a range of substrings separated by @a delimiters at the given @a startIndex onwards thru @a endIndex.\n" + "@param text A @a delimiters list of substrings.\n" + "@param delimiters Character or characters that separate the list of substrings in @a text.\n" + "@param startIndex The zero-based index of the first substring to extract from @a text.\n" + "@param endIndex The zero-based index of the last substring to extract from @a text. If this is -1, all words beginning " + "with @a startIndex are extracted from @a text.\n" + "@return A string containing the specified range of substrings from @a text or \"\" if @a startIndex " + "is out of range or greater than @a endIndex.\n\n" + "@tsexample\n" + "getTokens( \"a b c d\", \" \", 1, 2, ) // Returns \"b c\"\n" + "@endtsexample\n\n" + "@see getToken\n" + "@see getTokenCount\n" + "@see getWords\n" + "@see getFields\n" + "@see getRecords\n" + "@ingroup FieldManip" ) +{ + if( endIndex < 0 ) + endIndex = 1000000; + + return Con::getReturnBuffer( StringUnit::getUnits( text, startIndex, endIndex, delimiters ) ); +} + +//----------------------------------------------------------------------------- + +DefineConsoleFunction( setToken, const char*, ( const char* text, const char* delimiters, S32 index, const char* replacement ),, + "Replace the substring in @a text separated by @a delimiters at the given @a index with @a replacement.\n" + "@param text A @a delimiters list of substrings.\n" + "@param delimiters Character or characters that separate the list of substrings in @a text.\n" + "@param index The zero-based index of the substring to replace.\n" + "@param replacement The string with which to replace the substring.\n" + "@return A new string with the substring at the given @a index replaced by @a replacement or the original " + "string if @a index is out of range.\n\n" + "@tsexample\n" + "setToken( \"a b c d\", \" \", 2, \"f\" ) // Returns \"a b f d\"\n" + "@endtsexample\n\n" + "@see getToken\n" + "@see setWord\n" + "@see setField\n" + "@see setRecord\n" + "@ingroup FieldManip" ) +{ + return Con::getReturnBuffer( StringUnit::setUnit( text, index, replacement, delimiters) ); +} + +//----------------------------------------------------------------------------- + +DefineConsoleFunction( removeToken, const char*, ( const char* text, const char* delimiters, S32 index ),, + "Remove the substring in @a text separated by @a delimiters at the given @a index.\n" + "@param text A @a delimiters list of substrings.\n" + "@param delimiters Character or characters that separate the list of substrings in @a text.\n" + "@param index The zero-based index of the word in @a text.\n" + "@return A new string with the substring at the given index removed or the original string if @a index is " + "out of range.\n\n" + "@tsexample\n" + "removeToken( \"a b c d\", \" \", 2 ) // Returns \"a b d\"\n" + "@endtsexample\n\n" + "@see removeWord\n" + "@see removeField\n" + "@see removeRecord\n" + "@ingroup FieldManip" ) +{ + return Con::getReturnBuffer( StringUnit::removeUnit( text, index, delimiters ) ); +} + +//----------------------------------------------------------------------------- + +DefineConsoleFunction( getTokenCount, S32, ( const char* text, const char* delimiters),, + "Return the number of @a delimiters substrings in @a text.\n" + "@param text A @a delimiters list of substrings.\n" + "@param delimiters Character or characters that separate the list of substrings in @a text.\n" + "@return The number of @a delimiters substrings in @a text.\n\n" + "@tsexample\n" + "getTokenCount( \"a b c d e\", \" \" ) // Returns 5\n" + "@endtsexample\n\n" + "@see getWordCount\n" + "@see getFieldCount\n" + "@see getRecordCount\n" + "@ingroup FieldManip" ) +{ + return StringUnit::getUnitCount( text, delimiters ); +} + //============================================================================= // Tagged Strings. //============================================================================= @@ -2682,3 +3147,10 @@ DefineEngineFunction( isToolBuild, bool, (),, return false; #endif } + +DefineEngineFunction( getMaxDynamicVerts, S32, (),, + "Get max number of allowable dynamic vertices in a single vertex buffer.\n\n" + "@return the max number of allowable dynamic vertices in a single vertex buffer" ) +{ + return MAX_DYNAMIC_VERTS / 2; +}