Merge pull request #1363 from marauder2k9-torque/ColorPicker-refactor

Color picker refactor rev2
This commit is contained in:
Brian Roberts 2025-01-27 11:31:17 -06:00 committed by GitHub
commit fdbac265b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 595 additions and 207 deletions

View file

@ -1104,7 +1104,21 @@ DefineEngineFunction(ColorRGBToHSB, const char*, (ColorI color), ,
"@endtsexample\n" "@endtsexample\n"
"@ingroup Strings") "@ingroup Strings")
{ {
ColorI::Hsb hsb(color.getHSB()); Hsb hsb(color.getHSB());
String s(String::ToString(hsb.hue) + " " + String::ToString(hsb.sat) + " " + String::ToString(hsb.brightness));
return Con::getReturnBuffer(s);
}
DefineEngineFunction(ColorLinearRGBToHSB, const char*, (LinearColorF 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")
{
Hsb hsb(color.getHSB());
String s(String::ToString(hsb.hue) + " " + String::ToString(hsb.sat) + " " + String::ToString(hsb.brightness)); String s(String::ToString(hsb.hue) + " " + String::ToString(hsb.sat) + " " + String::ToString(hsb.brightness));
return Con::getReturnBuffer(s); return Con::getReturnBuffer(s);
} }
@ -1133,7 +1147,7 @@ DefineEngineFunction(ColorHSBToRGB, ColorI, (Point3I hsb), ,
"@ingroup Strings") "@ingroup Strings")
{ {
ColorI color; ColorI color;
color.set(ColorI::Hsb(hsb.x, hsb.y, hsb.z)); color.set(Hsb(hsb.x, hsb.y, hsb.z));
return color; return color;
} }

View file

@ -419,7 +419,7 @@ ConsoleGetType(TypeF64)
{ {
static const U32 bufSize = 256; static const U32 bufSize = 256;
char* returnBuffer = Con::getReturnBuffer(bufSize); char* returnBuffer = Con::getReturnBuffer(bufSize);
dSprintf(returnBuffer, bufSize, "%Lg", *((F64*)dptr)); dSprintf(returnBuffer, bufSize, "%g", *((F64*)dptr));
return returnBuffer; return returnBuffer;
} }
ConsoleSetType(TypeF64) ConsoleSetType(TypeF64)

View file

@ -34,9 +34,24 @@
#include "console/engineAPI.h" #include "console/engineAPI.h"
#endif #endif
#ifdef TORQUE_USE_LEGACY_GAMMA
const F32 gGamma = 2.2f; const F32 gGamma = 2.2f;
const F32 gOneOverGamma = 1.f / 2.2f; const F32 gOneOverGamma = 1.f / 2.2f;
#else
const F32 gGamma = 2.4f;
const F32 gOneOverGamma = 1.f / 2.4f;
const F32 gOneOver255 = 1.f / 255.f; const F32 gOneOver255 = 1.f / 255.f;
#endif
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
};
class ColorI; class ColorI;
@ -55,9 +70,14 @@ public:
LinearColorF(const F32 in_r, const F32 in_g, const F32 in_b, const F32 in_a = 1.0f); LinearColorF(const F32 in_r, const F32 in_g, const F32 in_b, const F32 in_a = 1.0f);
LinearColorF(const ColorI &color); LinearColorF(const ColorI &color);
LinearColorF(const char* pStockColorName); LinearColorF(const char* pStockColorName);
LinearColorF(const Hsb& color);
F32 srgbToLinearChannel(const F32 chan_col);
F32 linearChannelToSrgb(const F32 chan_col);
void set( const F32 in_r, const F32 in_g, const F32 in_b, const F32 in_a = 1.0f ); void set( const F32 in_r, const F32 in_g, const F32 in_b, const F32 in_a = 1.0f );
void set( const char* pStockColorName ); void set( const char* pStockColorName );
void set(const Hsb& color);
static const LinearColorF& StockColor( const char* pStockColorName ); static const LinearColorF& StockColor( const char* pStockColorName );
StringTableEntry StockColor( void ); StringTableEntry StockColor( void );
@ -88,6 +108,7 @@ public:
U32 getARGBPack() const; U32 getARGBPack() const;
U32 getRGBAPack() const; U32 getRGBAPack() const;
U32 getABGRPack() const; U32 getABGRPack() const;
Hsb getHSB();
void interpolate(const LinearColorF& in_rC1, void interpolate(const LinearColorF& in_rC1,
const LinearColorF& in_rC2, const LinearColorF& in_rC2,
@ -126,16 +147,6 @@ public:
U8 blue; U8 blue;
U8 alpha; U8 alpha;
struct Hsb
{
Hsb() :hue(0), sat(0), brightness(0){};
Hsb(F64 h, F64 s, F64 b) :hue(h), sat(s), brightness(b){};
F64 hue; ///Hue
F64 sat; ///Saturation
F64 brightness; //Brightness/Value/Lightness
};
public: public:
ColorI() : red(0), green(0), blue(0), alpha(0) {} ColorI() : red(0), green(0), blue(0), alpha(0) {}
ColorI(const ColorI& in_rCopy); ColorI(const ColorI& in_rCopy);
@ -247,6 +258,27 @@ public:
static void destroy( void ); static void destroy( void );
}; };
inline F32 LinearColorF::srgbToLinearChannel(const F32 chan_col)
{
if (chan_col < 0.0405f) {
return chan_col / 12.92f;
}
else {
return mPow((chan_col + 0.055f) / 1.055f, gGamma);
}
}
inline F32 LinearColorF::linearChannelToSrgb(const F32 chan_col)
{
if (chan_col <= 0.0031308f) {
return chan_col * 12.92f;
}
else {
return 1.055f * mPow(chan_col, gOneOverGamma) - 0.055f;
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
//-------------------------------------- INLINES (LinearColorF) //-------------------------------------- INLINES (LinearColorF)
// //
@ -441,6 +473,80 @@ inline F32 LinearColorF::luminance()
return red * 0.3f + green * 0.59f + blue * 0.11f; return red * 0.3f + green * 0.59f + blue * 0.11f;
} }
inline LinearColorF::LinearColorF(const Hsb& color)
{
set(color);
}
inline void LinearColorF::set(const Hsb& color)
{
F64 c = (color.brightness / 100.0) * (color.sat / 100.0);
F64 x = c * (1.0 - fabs(fmod(color.hue / 60.0, 2.0) - 1.0));
F64 m = (color.brightness / 100.0) - c;
F64 r = 0.0, g = 0.0, b = 0.0;
if (color.hue < 60.0) {
r = c; g = x; b = 0.0;
}
else if (color.hue < 120.0) {
r = x; g = c; b = 0.0;
}
else if (color.hue < 180.0) {
r = 0.0; g = c; b = x;
}
else if (color.hue < 240.0) {
r = 0.0; g = x; b = c;
}
else if (color.hue < 300.0) {
r = x; g = 0.0; b = c;
}
else {
r = c; g = 0.0; b = x;
}
r += m;
g += m;
b += m;
red = static_cast<F32>(srgbToLinearChannel(r));
green = static_cast<F32>(srgbToLinearChannel(g));
blue = static_cast<F32>(srgbToLinearChannel(b));
alpha = 1.0f; // Default alpha to 1.0
}
inline Hsb LinearColorF::getHSB()
{
F32 r = linearChannelToSrgb(red);
F32 g = linearChannelToSrgb(green);
F32 b = linearChannelToSrgb(blue);
F32 maxVal = mMax(r, mMax(g, b));
F32 minVal = mMin(r, mMin(g, b));
F32 delta = maxVal - minVal;
Hsb hsb;
hsb.brightness = maxVal * 100.0; // Convert to percentage
hsb.sat = (maxVal > 0.0f) ? (delta / maxVal) * 100.0 : 0.0;
if (delta > 0.0f) {
if (r == maxVal)
hsb.hue = 60.0 * mFmod(((g - b) / delta), 6.0);
else if (g == maxVal)
hsb.hue = 60.0 * (((b - r) / delta) + 2.0);
else
hsb.hue = 60.0 * (((r - g) / delta) + 4.0);
if (hsb.hue < 0.0)
hsb.hue += 360.0;
}
else {
hsb.hue = 0.0;
}
return hsb;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
//-------------------------------------- INLINES (ColorI) //-------------------------------------- INLINES (ColorI)
// //
@ -550,6 +656,7 @@ inline void ColorI::set(const String& hex)
red = (U8)(convertFromHex(redString)); red = (U8)(convertFromHex(redString));
green = (U8)(convertFromHex(greenString)); green = (U8)(convertFromHex(greenString));
blue = (U8)(convertFromHex(blueString)); blue = (U8)(convertFromHex(blueString));
alpha = 255;
} }
inline S32 ColorI::convertFromHex(const String& hex) const inline S32 ColorI::convertFromHex(const String& hex) const
@ -718,7 +825,7 @@ inline U16 ColorI::get4444() const
U16(U16(blue >> 4) << 0)); U16(U16(blue >> 4) << 0));
} }
inline ColorI::Hsb ColorI::getHSB() const inline Hsb ColorI::getHSB() const
{ {
// Normalize RGB values to [0, 1] // Normalize RGB values to [0, 1]
F64 rPercent = (F64)red / 255.0; F64 rPercent = (F64)red / 255.0;
@ -739,22 +846,22 @@ inline ColorI::Hsb ColorI::getHSB() const
S = delta / maxColor; // Saturation S = delta / maxColor; // Saturation
// Compute hue // Compute hue
if (fabs(maxColor - rPercent) < 1e-6) if (mFabsD(maxColor - rPercent) < 1e-6)
{ {
H = 60.0 * ((gPercent - bPercent) / delta); H = 60.0 * ((gPercent - bPercent) / delta);
} }
else if (fabs(maxColor - gPercent) < 1e-6) else if (mFabsD(maxColor - gPercent) < 1e-6)
{ {
H = 60.0 * (((bPercent - rPercent) / delta) + 2.0); H = 60.0 * (((bPercent - rPercent) / delta) + 2.0);
} }
else if (fabs(maxColor - bPercent) < 1e-6) else if (mFabsD(maxColor - bPercent) < 1e-6)
{ {
H = 60.0 * (((rPercent - gPercent) / delta) + 4.0); H = 60.0 * (((rPercent - gPercent) / delta) + 4.0);
} }
} }
// Prepare the output HSB struct // Prepare the output HSB struct
ColorI::Hsb val; Hsb val;
val.hue = H; // Round to nearest integer val.hue = H; // Round to nearest integer
val.sat = S * 100.0; // Convert to percentage val.sat = S * 100.0; // Convert to percentage
val.brightness = B * 100.0; // Convert to percentage val.brightness = B * 100.0; // Convert to percentage
@ -781,9 +888,9 @@ inline String ColorI::getHex() const
inline LinearColorF::LinearColorF( const ColorI &color) inline LinearColorF::LinearColorF( const ColorI &color)
{ {
red = sSrgbToLinear[color.red], red = srgbToLinearChannel(color.red * gOneOver255),
green = sSrgbToLinear[color.green], green = srgbToLinearChannel(color.green * gOneOver255),
blue = sSrgbToLinear[color.blue], blue = srgbToLinearChannel(color.blue * gOneOver255),
alpha = F32(color.alpha * gOneOver255); alpha = F32(color.alpha * gOneOver255);
} }
@ -798,14 +905,14 @@ inline ColorI LinearColorF::toColorI(const bool keepAsLinear)
else else
{ {
#ifdef TORQUE_USE_LEGACY_GAMMA #ifdef TORQUE_USE_LEGACY_GAMMA
float r = mPow(red, gOneOverGamma); F32 r = mPow(red, gOneOverGamma);
float g = mPow(green, gOneOverGamma); F32 g = mPow(green, gOneOverGamma);
float b = mPow(blue, gOneOverGamma); F32 b = mPow(blue, gOneOverGamma);
return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5)); return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5));
#else #else
float r = red < 0.0031308f ? 12.92f * red : 1.055f * mPow(red, 1.0f / 2.4f) - 0.055f; F32 r = linearChannelToSrgb(red);
float g = green < 0.0031308f ? 12.92f * green : 1.055f * mPow(green, 1.0f / 2.4f) - 0.055f; F32 g = linearChannelToSrgb(green);
float b = blue < 0.0031308f ? 12.92f * blue : 1.055f * mPow(blue, 1.0f / 2.4f) - 0.055f; F32 b = linearChannelToSrgb(blue);
return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5f)); return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5f));
#endif #endif
} }
@ -822,14 +929,14 @@ inline ColorI LinearColorF::toColorI(const bool keepAsLinear)
else else
{ {
#ifdef TORQUE_USE_LEGACY_GAMMA #ifdef TORQUE_USE_LEGACY_GAMMA
float r = mPow(red, gOneOverGamma); F32 r = mPow(red, gOneOverGamma);
float g = mPow(green, gOneOverGamma); F32 g = mPow(green, gOneOverGamma);
float b = mPow(blue, gOneOverGamma); F32 b = mPow(blue, gOneOverGamma);
return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5)); return ColorI(U8(r * 255.0f + 0.5), U8(g * 255.0f + 0.5), U8(b * 255.0f + 0.5), U8(alpha * 255.0f + 0.5));
#else #else
float r = red < 0.0031308f ? 12.92f * red : 1.055f * mPow(red, 1.0f / 2.4f) - 0.055f; F32 r = linearChannelToSrgb(red);
float g = green < 0.0031308f ? 12.92f * green : 1.055f * mPow(green, 1.0f / 2.4f) - 0.055f; F32 g = linearChannelToSrgb(green);
float b = blue < 0.0031308f ? 12.92f * blue : 1.055f * mPow(blue, 1.0f / 2.4f) - 0.055f; F32 b = linearChannelToSrgb(blue);
return ColorI(U8(r * 255.0f + 0.5f), U8(g * 255.0f + 0.5f), U8(b * 255.0f + 0.5f), U8(alpha * 255.0f + 0.5f)); return ColorI(U8(r * 255.0f + 0.5f), U8(g * 255.0f + 0.5f), U8(b * 255.0f + 0.5f), U8(alpha * 255.0f + 0.5f));
#endif #endif
} }

View file

@ -186,7 +186,7 @@ public:
static inline String ToString( U32 v ) { return ToString( "%u", v ); } static inline String ToString( U32 v ) { return ToString( "%u", v ); }
static inline String ToString( S32 v ) { return ToString( "%d", v ); } static inline String ToString( S32 v ) { return ToString( "%d", v ); }
static inline String ToString( F32 v ) { return ToString( "%g", v ); } static inline String ToString( F32 v ) { return ToString( "%g", v ); }
static inline String ToString( F64 v ) { return ToString( "%Lg", v ); } static inline String ToString( F64 v ) { return ToString( "%g", v ); }
inline operator const char* () { return c_str(); } inline operator const char* () { return c_str(); }
static String SpanToString(const char* start, const char* end); static String SpanToString(const char* start, const char* end);

View file

@ -29,7 +29,7 @@
//************************************************************************** //**************************************************************************
class ScreenShotD3D11 : public ScreenShot class ScreenShotD3D11 : public ScreenShot
{ {
protected: public:
GBitmap* _captureBackBuffer() override; GBitmap* _captureBackBuffer() override;

View file

@ -29,7 +29,7 @@
//************************************************************************** //**************************************************************************
class ScreenShotGL : public ScreenShot class ScreenShotGL : public ScreenShot
{ {
protected: public:
GBitmap* _captureBackBuffer() override; GBitmap* _captureBackBuffer() override;

View file

@ -40,10 +40,6 @@ class Frustum;
class ScreenShot class ScreenShot
{ {
/// This is overloaded to copy the current GFX
/// backbuffer to a new bitmap.
virtual GBitmap* _captureBackBuffer() { return NULL; }
/// This is set to toggle the capture. /// This is set to toggle the capture.
bool mPending; bool mPending;
@ -76,6 +72,9 @@ public:
ScreenShot(); ScreenShot();
virtual ~ScreenShot() { } virtual ~ScreenShot() { }
/// This is overloaded to copy the current GFX
/// backbuffer to a new bitmap.
virtual GBitmap* _captureBackBuffer() { return NULL; }
/// Used to start the screenshot capture. /// Used to start the screenshot capture.
void setPending( const char *filename, bool writeJPG, S32 tiles, F32 overlap ); void setPending( const char *filename, bool writeJPG, S32 tiles, F32 overlap );

View file

@ -29,6 +29,8 @@
#include "gui/controls/guiColorPicker.h" #include "gui/controls/guiColorPicker.h"
#include "gfx/primBuilder.h" #include "gfx/primBuilder.h"
#include "gfx/gfxDrawUtil.h" #include "gfx/gfxDrawUtil.h"
#include "postFx/postEffectManager.h"
#include "gfx/screenshot.h"
IMPLEMENT_CONOBJECT(GuiColorPickerCtrl); IMPLEMENT_CONOBJECT(GuiColorPickerCtrl);
@ -47,15 +49,23 @@ GuiColorPickerCtrl::GuiColorPickerCtrl()
mActive = true; mActive = true;
mSelectorGap = 1; mSelectorGap = 1;
mActionOnMove = false; mActionOnMove = false;
mDropperActive = false;
mShowReticle = true; mShowReticle = true;
mSelectedHue = 0; mSelectedHue = 0;
mSelectedAlpha = 255; mSelectedAlpha = 255;
mSelectedSaturation = 100; mSelectedSaturation = 100;
mSelectedBrightness = 100; mSelectedBrightness = 100;
eyeDropperPos = Point2I::Zero;
eyeDropperCap = NULL;
} }
GuiColorPickerCtrl::~GuiColorPickerCtrl() GuiColorPickerCtrl::~GuiColorPickerCtrl()
{ {
if (eyeDropperCap != NULL)
{
delete eyeDropperCap;
eyeDropperCap = NULL;
}
} }
ImplementEnumType( GuiColorPickMode, ImplementEnumType( GuiColorPickMode,
@ -94,7 +104,7 @@ void GuiColorPickerCtrl::initPersistFields()
void GuiColorPickerCtrl::renderBlendRange(RectI& bounds) void GuiColorPickerCtrl::renderBlendRange(RectI& bounds)
{ {
ColorI currentColor; ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100)); currentColor.set(Hsb(mSelectedHue, 100, 100));
GFX->getDrawUtil()->drawRectFill(bounds, currentColor, 0.0f, ColorI(0,0,0,0), true); GFX->getDrawUtil()->drawRectFill(bounds, currentColor, 0.0f, ColorI(0,0,0,0), true);
} }
@ -114,7 +124,7 @@ void GuiColorPickerCtrl::renderBlendSelector(RectI& bounds)
selectorRect.set(Point2I(selectorPos.x - mSelectorGap, selectorPos.y - mSelectorGap), Point2I(mSelectorGap * 2, mSelectorGap * 2)); selectorRect.set(Point2I(selectorPos.x - mSelectorGap, selectorPos.y - mSelectorGap), Point2I(mSelectorGap * 2, mSelectorGap * 2));
ColorI currentColor; ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness)); currentColor.set(Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness));
GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE); GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE);
} }
@ -136,8 +146,8 @@ void GuiColorPickerCtrl::renderHueGradient(RectI& bounds, U32 numColours)
U32 nextHue = static_cast<U32>((F32(i + 1) / F32(numColours)) * 360.0f); U32 nextHue = static_cast<U32>((F32(i + 1) / F32(numColours)) * 360.0f);
ColorI currentColor, nextColor; ColorI currentColor, nextColor;
currentColor.set(ColorI::Hsb(currentHue, 100, 100)); currentColor.set(Hsb(currentHue, 100, 100));
nextColor.set(ColorI::Hsb(nextHue, 100, 100)); nextColor.set(Hsb(nextHue, 100, 100));
switch (mSelectorMode) switch (mSelectorMode)
{ {
@ -217,7 +227,7 @@ void GuiColorPickerCtrl::renderHueSelector(RectI& bounds)
} }
ColorI currentColor; ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100)); currentColor.set(Hsb(mSelectedHue, 100, 100));
GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE); GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE);
} }
@ -232,7 +242,7 @@ void GuiColorPickerCtrl::renderAlphaGradient(RectI& bounds)
S32 b = bounds.point.y + bounds.extent.y; S32 b = bounds.point.y + bounds.extent.y;
ColorI currentColor; ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100)); currentColor.set(Hsb(mSelectedHue, 100, 100));
ColorI alphaCol = ColorI::BLACK; ColorI alphaCol = ColorI::BLACK;
alphaCol.alpha = 0; alphaCol.alpha = 0;
@ -308,12 +318,38 @@ void GuiColorPickerCtrl::renderAlphaSelector(RectI& bounds)
} }
ColorI currentColor; ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, 100, 100)); currentColor.set(Hsb(mSelectedHue, 100, 100));
currentColor.alpha = mSelectedAlpha; currentColor.alpha = mSelectedAlpha;
GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE); GFX->getDrawUtil()->drawRectFill(selectorRect, currentColor, 2.0f, ColorI::WHITE);
} }
void GuiColorPickerCtrl::renderEyeDropper()
{
if (eyeDropperCap != NULL)
{
GFX->getDrawUtil()->drawBitmap(eyeHandle, getRoot()->getPosition());
Point2I resolution = getRoot()->getExtent();
Point2I magnifierSize(100, 100);
Point2I magnifierPosition = eyeDropperPos + Point2I(20, 20);
// Adjust position to ensure magnifier stays on screen
if (magnifierPosition.x + magnifierSize.x > resolution.x)
magnifierPosition.x = eyeDropperPos.x - magnifierSize.x - 20;
if (magnifierPosition.y + magnifierSize.y > resolution.y)
magnifierPosition.y = eyeDropperPos.y - magnifierSize.y - 20;
RectI magnifierBounds(magnifierPosition, magnifierSize);
ColorI currentColor;
currentColor.set(Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness));
currentColor.alpha = mSelectedAlpha;
GFX->getDrawUtil()->drawRectFill(magnifierBounds, currentColor, 2.0f, ColorI::BLACK);
}
}
void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
{ {
if (mStateBlock.isNull()) if (mStateBlock.isNull())
@ -333,7 +369,7 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
case GuiColorPickerCtrl::pPalette: case GuiColorPickerCtrl::pPalette:
{ {
ColorI currentColor; ColorI currentColor;
currentColor.set(ColorI::Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness)); currentColor.set(Hsb(mSelectedHue, mSelectedSaturation, mSelectedBrightness));
currentColor.alpha = mSelectedAlpha; currentColor.alpha = mSelectedAlpha;
GFX->getDrawUtil()->drawRectFill(boundsRect, currentColor); GFX->getDrawUtil()->drawRectFill(boundsRect, currentColor);
break; break;
@ -356,6 +392,15 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
if (mShowReticle) renderAlphaSelector(boundsRect); if (mShowReticle) renderAlphaSelector(boundsRect);
break; break;
} }
case GuiColorPickerCtrl::pDropperBackground:
{
if (mDropperActive)
{
// Render the magnified view of our currently selected color.
renderEyeDropper();
}
break;
}
default: default:
break; break;
} }
@ -364,72 +409,31 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
renderChildControls(offset, updateRect); renderChildControls(offset, updateRect);
} }
Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp)
{
Point2I ext = getExtent();
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;
LinearColorF curColor;
F32 val(10000.0f);
F32 closestVal(10000.0f);
bool closestSet = false;
for (S32 x = 0; x < ext.x; x++)
{
for (S32 y = 0; y < ext.y; y++)
{
buf_x = offset.x + x;
buf_y = (resolution.y - (offset.y + y));
buf_y = resolution.y - buf_y;
//Get the color at that position
bmp.getColor(buf_x, buf_y, tmp);
curColor = (LinearColorF)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;
}
void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event) void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)
{ {
if (!mActive) if (!mActive)
return; return;
// we need to do this first.
if (mDisplayMode == GuiColorPickerCtrl::pDropperBackground) {
if (mDropperActive)
{
mDropperActive = false;
//getRoot()->pushObjectToBack(this);
onAction();
mouseUnlock();
if (eyeDropperCap != NULL)
{
delete eyeDropperCap;
eyeDropperCap = NULL;
}
}
return;
}
mouseLock(this); mouseLock(this);
@ -510,14 +514,15 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
Point2I ext = getExtent(); Point2I ext = getExtent();
Point2I mousePoint = globalToLocalCoord(event.mousePoint); Point2I mousePoint = globalToLocalCoord(event.mousePoint);
F32 relX = mClampF(F32(mousePoint.x) / F32(ext.x), 0.0, 1.0);
F32 relY = mClampF(F32(mousePoint.y) / F32(ext.y), 0.0, 1.0);
switch (mDisplayMode) switch (mDisplayMode)
{ {
case GuiColorPickerCtrl::pPalette: case GuiColorPickerCtrl::pPalette:
return; return;
case GuiColorPickerCtrl::pBlendRange: case GuiColorPickerCtrl::pBlendRange:
{ {
F32 relX = F32(mousePoint.x) / F32(ext.x); relY = 1.0f - relY;
F32 relY = 1.0f - F32(mousePoint.y) / F32(ext.y);
setSelectedSaturation(relX * 100.0); setSelectedSaturation(relX * 100.0);
setSelectedBrightness(relY * 100.0); setSelectedBrightness(relY * 100.0);
break; break;
@ -528,13 +533,11 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
{ {
case GuiColorPickerCtrl::sHorizontal: case GuiColorPickerCtrl::sHorizontal:
{ {
F32 relX = F32(mousePoint.x) / F32(ext.x);
setSelectedHue(relX * 360.0); setSelectedHue(relX * 360.0);
break; break;
} }
case GuiColorPickerCtrl::sVertical: case GuiColorPickerCtrl::sVertical:
{ {
F32 relY = F32(mousePoint.y) / F32(ext.y);
setSelectedHue(relY * 360.0); setSelectedHue(relY * 360.0);
break; break;
} }
@ -549,13 +552,11 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
{ {
case GuiColorPickerCtrl::sHorizontal: case GuiColorPickerCtrl::sHorizontal:
{ {
F32 relX = F32(mousePoint.x) / F32(ext.x);
setSelectedAlpha(relX * 255.0); setSelectedAlpha(relX * 255.0);
break; break;
} }
case GuiColorPickerCtrl::sVertical: case GuiColorPickerCtrl::sVertical:
{ {
F32 relY = F32(mousePoint.y) / F32(ext.y);
setSelectedAlpha(relY * 255.0); setSelectedAlpha(relY * 255.0);
break; break;
} }
@ -574,6 +575,29 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
void GuiColorPickerCtrl::onMouseMove(const GuiEvent &event) void GuiColorPickerCtrl::onMouseMove(const GuiEvent &event)
{ {
if (mDisplayMode != pDropperBackground)
return;
if (!mDropperActive)
return;
// should not need globalToLocal as we are capturing the whole screen.
eyeDropperPos = globalToLocalCoord(event.mousePoint);
if (eyeDropperCap != NULL)
{
// Sample the pixel color at the mouse position. Mouse position should translate directly.
ColorI sampledColor;
eyeDropperCap->getColor(eyeDropperPos.x, eyeDropperPos.y, sampledColor);
// Convert the sampled color to HSB
Hsb hsb = sampledColor.getHSB();
mSelectedHue = hsb.hue;
mSelectedSaturation = hsb.sat;
mSelectedBrightness = hsb.brightness;
mSelectedAlpha = sampledColor.alpha;
}
} }
void GuiColorPickerCtrl::onMouseEnter(const GuiEvent &event) void GuiColorPickerCtrl::onMouseEnter(const GuiEvent &event)
@ -587,7 +611,16 @@ void GuiColorPickerCtrl::onMouseLeave(const GuiEvent &)
mMouseOver = false; mMouseOver = false;
} }
void GuiColorPickerCtrl::setSelectedHue(const F64& hueValue) void GuiColorPickerCtrl::onMouseUp(const GuiEvent&)
{
//if we released the mouse within this control, perform the action
if (mActive && mMouseDown)
mMouseDown = false;
mouseUnlock();
}
void GuiColorPickerCtrl::setSelectedHue(const U32& hueValue)
{ {
if (hueValue < 0) if (hueValue < 0)
{ {
@ -605,7 +638,7 @@ void GuiColorPickerCtrl::setSelectedHue(const F64& hueValue)
} }
void GuiColorPickerCtrl::setSelectedBrightness(const F64& brightValue) void GuiColorPickerCtrl::setSelectedBrightness(const U32& brightValue)
{ {
if (brightValue < 0) if (brightValue < 0)
{ {
@ -622,7 +655,7 @@ void GuiColorPickerCtrl::setSelectedBrightness(const F64& brightValue)
mSelectedBrightness = brightValue; mSelectedBrightness = brightValue;
} }
void GuiColorPickerCtrl::setSelectedSaturation(const F64& satValue) void GuiColorPickerCtrl::setSelectedSaturation(const U32& satValue)
{ {
if (satValue < 0) if (satValue < 0)
{ {
@ -639,7 +672,7 @@ void GuiColorPickerCtrl::setSelectedSaturation(const F64& satValue)
mSelectedSaturation = satValue; mSelectedSaturation = satValue;
} }
void GuiColorPickerCtrl::setSelectedAlpha(const F64& alphaValue) void GuiColorPickerCtrl::setSelectedAlpha(const U32& alphaValue)
{ {
if (alphaValue < 0) if (alphaValue < 0)
{ {
@ -656,13 +689,27 @@ void GuiColorPickerCtrl::setSelectedAlpha(const F64& alphaValue)
mSelectedAlpha = alphaValue; mSelectedAlpha = alphaValue;
} }
void GuiColorPickerCtrl::onMouseUp(const GuiEvent &) void GuiColorPickerCtrl::activateEyeDropper()
{ {
//if we released the mouse within this control, perform the action // Make sure we are a pDropperBackground
if (mActive && mMouseDown) if (mDisplayMode == GuiColorPickerCtrl::pDropperBackground)
mMouseDown = false; {
mouseLock(this); // take over!
mouseUnlock(); setFirstResponder(); // we need this to be first responder regardless.
//getRoot()->bringObjectToFront(this);
mDropperActive = true;
// Set up our resolution.
Point2I resolution = getRoot()->getExtent();
eyeDropperCap = gScreenShot->_captureBackBuffer();
// Texture handle to resolve the target to.
eyeHandle.set(eyeDropperCap, &GFXStaticTextureSRGBProfile, false, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__));
}
} }
/// <summary> /// <summary>
@ -673,49 +720,57 @@ DefineEngineMethod(GuiColorPickerCtrl, executeUpdate, void, (), , "Execute the o
object->onAction(); object->onAction();
} }
DefineEngineMethod(GuiColorPickerCtrl, setSelectedHue, void, (F64 hueValue), , "Sets the selected hue value should be 0-360.") /// <summary>
/// This command should only be used with guiColorPicker in pDropperBackground mode.
/// </summary>
DefineEngineMethod(GuiColorPickerCtrl, activateEyeDropper, void, (), , "Activate the dropper mode.")
{
object->activateEyeDropper();
}
DefineEngineMethod(GuiColorPickerCtrl, setSelectedHue, void, (S32 hueValue), , "Sets the selected hue value should be 0-360.")
{ {
object->setSelectedHue(hueValue); object->setSelectedHue(hueValue);
} }
DefineEngineMethod(GuiColorPickerCtrl, getSelectedHue, F64, (), , "Gets the current selected hue value.") DefineEngineMethod(GuiColorPickerCtrl, getSelectedHue, S32, (), , "Gets the current selected hue value.")
{ {
return object->getSelectedHue(); return object->getSelectedHue();
} }
DefineEngineMethod(GuiColorPickerCtrl, setSelectedBrightness, void, (F64 brightness), , "Sets the selected brightness value should be 0-100.") DefineEngineMethod(GuiColorPickerCtrl, setSelectedBrightness, void, (S32 brightness), , "Sets the selected brightness value should be 0-100.")
{ {
object->setSelectedBrightness(brightness); object->setSelectedBrightness(brightness);
} }
DefineEngineMethod(GuiColorPickerCtrl, getSelectedBrightness, F64, (), , "Gets the current selected brightness.") DefineEngineMethod(GuiColorPickerCtrl, getSelectedBrightness, S32, (), , "Gets the current selected brightness.")
{ {
return object->getSelectedBrightness(); return object->getSelectedBrightness();
} }
DefineEngineMethod(GuiColorPickerCtrl, setSelectedSaturation, void, (F64 saturation), , "Sets the selected saturation value should be 0-100.") DefineEngineMethod(GuiColorPickerCtrl, setSelectedSaturation, void, (S32 saturation), , "Sets the selected saturation value should be 0-100.")
{ {
object->setSelectedSaturation(saturation); object->setSelectedSaturation(saturation);
} }
DefineEngineMethod(GuiColorPickerCtrl, getSelectedSaturation, F64, (), , "Gets the current selected saturation value.") DefineEngineMethod(GuiColorPickerCtrl, getSelectedSaturation, S32, (), , "Gets the current selected saturation value.")
{ {
return object->getSelectedSaturation(); return object->getSelectedSaturation();
} }
DefineEngineMethod(GuiColorPickerCtrl, setSelectedAlpha, void, (F64 alpha), , "Sets the selected alpha value should be 0-255.") DefineEngineMethod(GuiColorPickerCtrl, setSelectedAlpha, void, (S32 alpha), , "Sets the selected alpha value should be 0-255.")
{ {
object->setSelectedAlpha(alpha); object->setSelectedAlpha(alpha);
} }
DefineEngineMethod(GuiColorPickerCtrl, getSelectedAlpha, F64, (), , "Gets the current selected alpha value.") DefineEngineMethod(GuiColorPickerCtrl, getSelectedAlpha, S32, (), , "Gets the current selected alpha value.")
{ {
return object->getSelectedAlpha(); return object->getSelectedAlpha();
} }
DefineEngineMethod(GuiColorPickerCtrl, setSelectedColorI, void, (ColorI col), , "Sets the current selected hsb from a colorI value.") DefineEngineMethod(GuiColorPickerCtrl, setSelectedColorI, void, (ColorI col), , "Sets the current selected hsb from a colorI value.")
{ {
ColorI::Hsb hsb(col.getHSB()); Hsb hsb(col.getHSB());
object->setSelectedHue(hsb.hue); object->setSelectedHue(hsb.hue);
object->setSelectedSaturation(hsb.sat); object->setSelectedSaturation(hsb.sat);
object->setSelectedBrightness(hsb.brightness); object->setSelectedBrightness(hsb.brightness);
@ -725,26 +780,25 @@ DefineEngineMethod(GuiColorPickerCtrl, setSelectedColorI, void, (ColorI col), ,
DefineEngineMethod(GuiColorPickerCtrl, getSelectedColorI, ColorI, (), , "Gets the current selected hsb as a colorI value.") DefineEngineMethod(GuiColorPickerCtrl, getSelectedColorI, ColorI, (), , "Gets the current selected hsb as a colorI value.")
{ {
ColorI col; ColorI col;
col.set(ColorI::Hsb(object->getSelectedHue(), object->getSelectedSaturation(), object->getSelectedBrightness())); col.set(Hsb(object->getSelectedHue(), object->getSelectedSaturation(), object->getSelectedBrightness()));
col.alpha = object->getSelectedAlpha(); col.alpha = object->getSelectedAlpha();
return col; return col;
} }
DefineEngineMethod(GuiColorPickerCtrl, setSelectedLinearColor, void, (LinearColorF colF), , "Sets the current selected hsb froma a LinearColorF value.") DefineEngineMethod(GuiColorPickerCtrl, setSelectedLinearColor, void, (LinearColorF colF), , "Sets the current selected hsb froma a LinearColorF value.")
{ {
ColorI col = colF.toColorI(); Hsb hsb = colF.getHSB();
ColorI::Hsb hsb(col.getHSB());
object->setSelectedHue(hsb.hue); object->setSelectedHue(hsb.hue);
object->setSelectedSaturation(hsb.sat); object->setSelectedSaturation(hsb.sat);
object->setSelectedBrightness(hsb.brightness); object->setSelectedBrightness(hsb.brightness);
object->setSelectedAlpha(col.alpha); object->setSelectedAlpha(colF.alpha * 255.0);
} }
DefineEngineMethod(GuiColorPickerCtrl, getSelectedLinearColor, LinearColorF, (), , "Gets the current selected hsb as a LinearColorF value.") DefineEngineMethod(GuiColorPickerCtrl, getSelectedLinearColor, LinearColorF, (), , "Gets the current selected hsb as a LinearColorF value.")
{ {
ColorI col; LinearColorF col;
col.set(ColorI::Hsb(object->getSelectedHue(), object->getSelectedSaturation(), object->getSelectedBrightness())); col.set(Hsb(object->getSelectedHue(), object->getSelectedSaturation(), object->getSelectedBrightness()));
col.alpha = object->getSelectedAlpha(); col.alpha = (F32)object->getSelectedAlpha() / 255.0f;
return LinearColorF(col); return col;
} }

View file

@ -108,23 +108,27 @@ class GuiColorPickerCtrl : public GuiControl
/// <param name="bounds">The bounds of the ctrl.</param> /// <param name="bounds">The bounds of the ctrl.</param>
void renderAlphaSelector(RectI& bounds); void renderAlphaSelector(RectI& bounds);
void renderEyeDropper();
/// @name Core Variables /// @name Core Variables
/// @{ /// @{
PickMode mDisplayMode; ///< Current color display mode of the selector PickMode mDisplayMode; ///< Current color display mode of the selector
SelectorMode mSelectorMode; ///< Current color display mode of the selector SelectorMode mSelectorMode; ///< Current color display mode of the selector
F64 mSelectedHue; U32 mSelectedHue;
F64 mSelectedSaturation; U32 mSelectedSaturation;
F64 mSelectedBrightness; U32 mSelectedBrightness;
F64 mSelectedAlpha; U32 mSelectedAlpha;
Point2I eyeDropperPos;
GBitmap* eyeDropperCap;
GFXTexHandle eyeHandle;
bool mMouseOver; ///< Mouse is over? bool mDropperActive; ///< Is the eye dropper active?
bool mMouseDown; ///< Mouse button down? bool mMouseOver; ///< Mouse is over?
bool mActionOnMove; ///< Perform onAction() when position has changed? bool mMouseDown; ///< Mouse button down?
bool mShowReticle; ///< Show reticle on render bool mActionOnMove; ///< Perform onAction() when position has changed?
bool mShowReticle; ///< Show reticle on render
Point2I findColor(const LinearColorF & 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.
S32 mSelectorGap; ///< The half-way "gap" between the selector pos and where the selector is allowed to draw.
GFXStateBlockRef mStateBlock; GFXStateBlockRef mStateBlock;
/// @} /// @}
@ -158,29 +162,32 @@ class GuiColorPickerCtrl : public GuiControl
/// Set the selected hue. /// Set the selected hue.
/// </summary> /// </summary>
/// <param name="hueValue">Hue value, 0 - 360.</param> /// <param name="hueValue">Hue value, 0 - 360.</param>
void setSelectedHue(const F64& hueValue); void setSelectedHue(const U32& hueValue);
F64 getSelectedHue() { return mSelectedHue; } U32 getSelectedHue() { return mSelectedHue; }
/// <summary> /// <summary>
/// Set the selected brightness. /// Set the selected brightness.
/// </summary> /// </summary>
/// <param name="brightValue">Brightness value, 0 - 100.</param> /// <param name="brightValue">Brightness value, 0 - 100.</param>
void setSelectedBrightness(const F64& brightValue); void setSelectedBrightness(const U32& brightValue);
F64 getSelectedBrightness() { return mSelectedBrightness; } U32 getSelectedBrightness() { return mSelectedBrightness; }
/// <summary> /// <summary>
/// Set the selected saturation. /// Set the selected saturation.
/// </summary> /// </summary>
/// <param name="satValue">Saturation value, 0 - 100.</param> /// <param name="satValue">Saturation value, 0 - 100.</param>
void setSelectedSaturation(const F64& satValue); void setSelectedSaturation(const U32& satValue);
F64 getSelectedSaturation() { return mSelectedSaturation; } U32 getSelectedSaturation() { return mSelectedSaturation; }
/// <summary> /// <summary>
/// Set the selected alpha. /// Set the selected alpha.
/// </summary> /// </summary>
/// <param name="alphaValue">Alpha value, 0 - 255.</param> /// <param name="alphaValue">Alpha value, 0 - 255.</param>
void setSelectedAlpha(const F64& alphaValue); void setSelectedAlpha(const U32& alphaValue);
F64 getSelectedAlpha() { return mSelectedAlpha; } U32 getSelectedAlpha() { return mSelectedAlpha; }
void activateEyeDropper();
}; };
typedef GuiColorPickerCtrl::PickMode GuiColorPickMode; typedef GuiColorPickerCtrl::PickMode GuiColorPickMode;

View file

@ -1,43 +1,32 @@
//--- OBJECT WRITE BEGIN --- //--- OBJECT WRITE BEGIN ---
$guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) { $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) {
displayMode = "Dropper"; // this makes the background visible displayMode = "Dropper";
actionOnMove = "1"; extent = "1024 768";
position = "0 0"; profile = "GuiDefaultProfile";
extent = "1024 768"; command = "%selHue = ColorPickerDlg.getSelectedHue();\n%selSat = ColorPickerDlg.getSelectedSaturation();\n%selBright = ColorPickerDlg.getSelectedBrightness();\n%selAlpha = ColorPickerDlg.getSelectedAlpha();\n\nColorHueRange.setSelectedHue(%selHue);\nColorHueRange.executeUpdate();\n\nColorBlendRange.setSelectedBrightness(%selBright);\nColorBlendRange.setSelectedSaturation(%selSat);\nColorBlendRange.executeUpdate();\n\nColorAlphaRange.setSelectedAlpha(%selAlpha);\nColorAlphaRange.executeUpdate();\n\nColorEyeDropperButton.setStateOn(false);";
minExtent = "8 2"; tooltipProfile = "GuiToolTipProfile";
horizSizing = "right"; isContainer = "1";
vertSizing = "bottom";
profile = "ToolsGuiDefaultProfile";
visible = "1";
active = "1";
Clickable = "1";
AffectChildren = "1";
tooltipProfile = "GuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
new GuiWindowCtrl() { new GuiWindowCtrl() {
text = " "; text = " ";
resizeWidth = "0"; resizeWidth = "0";
resizeHeight = "0"; resizeHeight = "0";
canMinimize = "0"; canMinimize = "0";
canMaximize = "0"; canMaximize = "0";
closeCommand = "DoColorPickerCancelCallback(); ColorPickerDlg.getRoot().popDialog(ColorPickerDlg);"; closeCommand = "DoColorPickerCancelCallback(); ColorPickerDlg.getRoot().popDialog(ColorPickerDlg);";
position = "33 33"; position = "33 33";
extent = "271 574"; extent = "271 574";
horizSizing = "windowRelative"; horizSizing = "windowRelative";
vertSizing = "windowRelative"; vertSizing = "windowRelative";
profile = "ToolsGuiWindowProfile"; profile = "ToolsGuiWindowProfile";
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
new GuiStackControl() { new GuiStackControl() {
padding = "5"; padding = "5";
changeChildSizeToFit = "0"; changeChildSizeToFit = "0";
changeChildPosition = "0"; changeChildPosition = "0";
position = "0 24"; position = "0 24";
extent = "271 481"; extent = "271 491";
profile = "GuiDefaultProfile"; profile = "GuiDefaultProfile";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
@ -120,7 +109,7 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) {
position = "213 3"; position = "213 3";
extent = "50 25"; extent = "50 25";
profile = "GuiDefaultProfile"; profile = "GuiDefaultProfile";
command = "%selHue = ColorNewSelected.getSelectedHue();\n%selSat = ColorNewSelected.getSelectedSaturation();\n%selBright = ColorNewSelected.getSelectedBrightness();\n\nHueTextEditor.setText(%selHue);\nSatTextEditor.setText(%selSat);\nBrightTextEditor.setText(%selBright);\n\n%color = ColorNewSelected.getSelectedColorI();\nRedTextEdit.setText(getWord(%color, 0));\nGreenTextEdit.setText(getWord(%color, 1));\nBlueTextEdit.setText(getWord(%color, 2));\nAlphaTextEdit.setText(getWord(%color, 3));\n\n%hex = ColorRGBToHEX(%color);\nHexTextEditor.setText(%hex);"; command = "%selHue = ColorNewSelected.getSelectedHue();\n%selSat = ColorNewSelected.getSelectedSaturation();\n%selBright = ColorNewSelected.getSelectedBrightness();\n\nHueTextEditor.setText(%selHue);\nSatTextEditor.setText(%selSat);\nBrightTextEditor.setText(%selBright);\n\n%color = $ColorCallbackType == 1 ? ColorNewSelected.getSelectedColorI() : ColorNewSelected.getSelectedLinearColor();\nRedTextEdit.setText(getWord(%color, 0));\nGreenTextEdit.setText(getWord(%color, 1));\nBlueTextEdit.setText(getWord(%color, 2));\nAlphaTextEdit.setText(getWord(%color, 3));\n\n%hex = ColorRGBToHEX(ColorNewSelected.getSelectedColorI());\nHexTextEditor.setText(%hex);";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
}; };
new GuiColorPickerCtrl(ColorOld) { new GuiColorPickerCtrl(ColorOld) {
@ -268,16 +257,25 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) {
text = "Apply"; text = "Apply";
position = "211 1"; position = "211 1";
extent = "52 20"; extent = "52 20";
command = "DoColorPickerCallback();";
profile = "ToolsGuiButtonProfile"; profile = "ToolsGuiButtonProfile";
command = "DoColorPickerCallback();";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
}; };
new GuiButtonCtrl() { new GuiButtonCtrl() {
text = "Cancel"; text = "Cancel";
position = "211 24"; position = "211 24";
extent = "52 20"; extent = "52 20";
command = "DoColorPickerCancelCallback();";
profile = "ToolsGuiButtonProfile"; profile = "ToolsGuiButtonProfile";
command = "DoColorPickerCancelCallback();";
tooltipProfile = "GuiToolTipProfile";
};
new GuiBitmapButtonCtrl(ColorEyeDropperButton) {
BitmapAsset = "ToolsModule:eyedropper_n_image";
buttonType = "ToggleButton";
position = "223 56";
extent = "25 25";
profile = "ToolsGuiCheckBoxProfile";
command = "ColorPickerDlg.activateEyeDropper();";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
}; };
}; };
@ -285,20 +283,26 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) {
}; };
new GuiRolloutCtrl() { new GuiRolloutCtrl() {
caption = ":: Color Palette"; caption = ":: Color Palette";
margin = "5 5 5 5";
position = "0 445"; position = "0 445";
extent = "271 36"; extent = "271 46";
profile = "GuiRolloutProfile"; profile = "GuiRolloutProfile";
tooltipProfile = "GuiToolTipProfile"; tooltipProfile = "GuiToolTipProfile";
new GuiStackControl() { new GuiDynamicCtrlArrayControl(ColorPaletteStack) {
stackingType = "Dynamic"; colCount = "12";
padding = "5"; colSize = "12";
changeChildSizeToFit = "0"; rowSize = "12";
position = "0 17"; rowCount = "3";
extent = "271 16"; rowSpacing = "1";
profile = "GuiDefaultProfile"; colSpacing = "1";
tooltipProfile = "GuiToolTipProfile"; dynamicSize = "1";
}; padding = "3 3 3 3";
position = "0 17";
extent = "271 47";
profile = "GuiDefaultProfile";
tooltipProfile = "GuiToolTipProfile";
};
}; };
}; };
}; };
@ -344,6 +348,87 @@ function GetColorF( %currentColor, %callback, %root, %updateCallback, %cancelCal
%root.pushDialog(ColorPickerDlg); %root.pushDialog(ColorPickerDlg);
} }
function ColorPaletteStack::onWake(%this)
{
if($Pref::ColorPicker::ColorPalette $= "")
{
$Pref::ColorPicker::ColorPalette = "#FFFFFF #FF0000 #00FF00 #0000FF";
}
%colorCount = getWordCount($Pref::ColorPicker::ColorPalette);
if(%colorCount > 63)
%colorCount = 63;
for(%i=0; %i < %colorCount; %i++)
{
%hex = getWord($Pref::ColorPicker::ColorPalette, %i);
%rgb = ColorHEXToRGB(%hex);
%rgb = ColorIntToFloat(%rgb);
%colorBox = new GuiSwatchButtonCtrl() {
extent = "16 16";
color = %rgb;
profile = "GuiDefaultProfile";
colorHex = %hex;
useMouseEvents = "1";
class = "ColorPaletteSwatch";
};
ColorPaletteStack.Add(%colorBox);
}
%button = new GuiButtonCtrl() {
text = "+";
extent = "16 16";
profile = "ToolsGuiButtonProfile";
tooltipProfile = "GuiToolTipProfile";
command = "ColorPaletteStack.addCurrentColorToStack();";
};
ColorPaletteStack.Add(%button);
}
function ColorPaletteStack::addCurrentColorToStack(%this)
{
%hex = HexTextEditor.getValue();
//Make sure we have 6 characters
while(strlen(%hex) < 6)
{
%hex = "0" @ %hex;
}
%hex = strupr(%hex);
$Pref::ColorPicker::ColorPalette = "#" @ %hex SPC $Pref::ColorPicker::ColorPalette;
ColorPaletteStack.clear();
ColorPaletteStack.onWake();
}
function ColorPaletteStack::onSleep(%this)
{
ColorPaletteStack.clear();
}
function ColorPaletteSwatch::onMouseDown(%this)
{
//Update all the other color fields
%rgb = ColorHEXToRGB(%this.colorHex);
%hsb = ColorRGBToHSB(%rgb);
// these automatically update our ColorNewSelected which
// updates all text fields including these.
ColorHueRange.setSelectedHue(getWord(%hsb, 0));
ColorHueRange.executeUpdate();
ColorBlendRange.setSelectedSaturation(getWord(%hsb, 1));
ColorBlendRange.setSelectedBrightness(getWord(%hsb, 2));
ColorBlendRange.executeUpdate();
// for now just set full alpha until we save out alpha as well
ColorAlphaRange.setSelectedAlpha(255);
ColorAlphaRange.executeUpdate();
}
function ColorPickerRGBClass::onValidate(%this) function ColorPickerRGBClass::onValidate(%this)
{ {
%red = RedTextEdit.getValue(); %red = RedTextEdit.getValue();
@ -352,8 +437,13 @@ function ColorPickerRGBClass::onValidate(%this)
%alpha = AlphaTextEdit.getValue(); %alpha = AlphaTextEdit.getValue();
//Update all the other color fields //Update all the other color fields
%hsb = ColorRGBToHSB(%red SPC %green SPC %blue); if( $ColorCallbackType == 1)
%hsb = ColorRGBToHSB(%red SPC %green SPC %blue);
else
{
%hsb = ColorLinearRGBToHSB(%red SPC %green SPC %blue);
%alpha *= 255.0;
}
// these automatically update our ColorNewSelected which // these automatically update our ColorNewSelected which
// updates all text fields including these. // updates all text fields including these.
ColorHueRange.setSelectedHue(getWord(%hsb, 0)); ColorHueRange.setSelectedHue(getWord(%hsb, 0));

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="add-simgroup-btn_ctrl_i_image"
imageFile="@assetFile=add-simgroup-btn_ctrl_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="add-simgroup-btn_i_image"
imageFile="@assetFile=add-simgroup-btn_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="camera-btn_i_image"
imageFile="@assetFile=camera-btn_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="clear-icon_i_image"
imageFile="@assetFile=clear-icon_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="delete_i_image"
imageFile="@assetFile=delete_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="dropdown-button-arrow_d_image"
imageFile="@assetFile=dropdown-button-arrow_d.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="dropdown-button-arrow_h_image"
imageFile="@assetFile=dropdown-button-arrow_h.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="dropdown-button-arrow_i_image"
imageFile="@assetFile=dropdown-button-arrow_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="dropdown-button-arrow_n_image"
imageFile="@assetFile=dropdown-button-arrow_n.png"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="eyedropper_d_image"
imageFile="@assetFile=eyedropper_d.png"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="eyedropper_h_image"
imageFile="@assetFile=eyedropper_h.png"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="eyedropper_i_image"
imageFile="@assetFile=eyedropper_i.png"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="eyedropper_n_image"
imageFile="@assetFile=eyedropper_n.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="folder_d_image"
imageFile="@assetFile=folder_d.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="folder_h_image"
imageFile="@assetFile=folder_h.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="folder_i_image"
imageFile="@assetFile=folder_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="folder_n_image"
imageFile="@assetFile=folder_n.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="images_menuGrid_d_image"
imageFile="@assetFile=menuGrid_d.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="images_menuGrid_h_image"
imageFile="@assetFile=menuGrid_h.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="images_menuGrid_image"
imageFile="@assetFile=menuGrid.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="images_menuGrid_n_image"
imageFile="@assetFile=menuGrid_n.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="layers-btn_i_image"
imageFile="@assetFile=layers-btn_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="lock_i_image"
imageFile="@assetFile=lock_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="new-folder-btn_i_image"
imageFile="@assetFile=new-folder-btn_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="new_i_image"
imageFile="@assetFile=new_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="numericslider_image"
imageFile="@assetFile=numericslider.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="open-file_i_image"
imageFile="@assetFile=open-file_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="reset-icon_i_image"
imageFile="@assetFile=reset-icon_i.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="selector-button_image"
imageFile="@assetFile=selector-button.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="tab-border_image"
imageFile="@assetFile=tab-border.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="textEdit_black_image"
imageFile="@assetFile=textEdit_black.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="textEdit_blue_image"
imageFile="@assetFile=textEdit_blue.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="textEdit_cyan_image"
imageFile="@assetFile=textEdit_cyan.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="textEdit_green_image"
imageFile="@assetFile=textEdit_green.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="textEdit_magenta_image"
imageFile="@assetFile=textEdit_magenta.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="textEdit_red_image"
imageFile="@assetFile=textEdit_red.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="textEdit_white_image"
imageFile="@assetFile=textEdit_white.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="textEdit_yellow_image"
imageFile="@assetFile=textEdit_yellow.png"/>

View file

@ -0,0 +1,3 @@
<ImageAsset
AssetName="uv-editor-btn_i_image"
imageFile="@assetFile=uv-editor-btn_i.png"/>