Merge branch 'ColorPickerAdvanced' of https://github.com/Azaezel/Torque3D into ColorPickerAdvanced

This commit is contained in:
Azaezel 2016-02-21 15:31:09 -06:00
commit bc433e7c30
6 changed files with 257 additions and 276 deletions

View file

@ -875,9 +875,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), ,

View file

@ -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);
}
object->setSelectorPos(color);
}

View file

@ -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 &);

View file

@ -1262,7 +1262,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
@ -1274,7 +1274,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() );

View file

@ -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)." );

View file

@ -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