mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 00:24:40 +00:00
Merge branch 'ColorPickerAdvanced' of https://github.com/Azaezel/Torque3D into ColorPickerAdvanced
This commit is contained in:
commit
bc433e7c30
6 changed files with 257 additions and 276 deletions
|
|
@ -875,9 +875,11 @@ DefineConsoleFunction(ColorHEXToRGB, ColorI, (const char* hex), ,
|
||||||
"@endtsexample\n"
|
"@endtsexample\n"
|
||||||
"@ingroup Strings")
|
"@ingroup Strings")
|
||||||
{
|
{
|
||||||
ColorI color;
|
S32 rgb = dAtoui(hex, 16);
|
||||||
color.set(hex);
|
|
||||||
return color;
|
ColorI color;
|
||||||
|
color.set(rgb & 0x000000FF, (rgb & 0x0000FF00) >> 8, (rgb & 0x00FF0000) >> 16);
|
||||||
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineConsoleFunction(ColorHSBToRGB, ColorI, (Point3I hsb), ,
|
DefineConsoleFunction(ColorHSBToRGB, ColorI, (Point3I hsb), ,
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,13 @@ ColorF colorAlpha(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
ColorF colorAlphaW(1.0f, 1.0f, 1.0f, 0.0f);
|
ColorF colorAlphaW(1.0f, 1.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
ColorI GuiColorPickerCtrl::mColorRange[7] = {
|
ColorI GuiColorPickerCtrl::mColorRange[7] = {
|
||||||
ColorI(255,0,0), // Red
|
ColorI(255,0,0), // Red
|
||||||
ColorI(255,0,255), // Pink
|
ColorI(255,0,255), // Pink
|
||||||
ColorI(0,0,255), // Blue
|
ColorI(0,0,255), // Blue
|
||||||
ColorI(0,255,255), // Light blue
|
ColorI(0,255,255), // Light blue
|
||||||
ColorI(0,255,0), // Green
|
ColorI(0,255,0), // Green
|
||||||
ColorI(255,255,0), // Yellow
|
ColorI(255,255,0), // Yellow
|
||||||
ColorI(255,0,0), // Red
|
ColorI(255,0,0), // Red
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,6 @@ ConsoleDocClass( GuiColorPickerCtrl,
|
||||||
"@internal"
|
"@internal"
|
||||||
);
|
);
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
GuiColorPickerCtrl::GuiColorPickerCtrl()
|
GuiColorPickerCtrl::GuiColorPickerCtrl()
|
||||||
{
|
{
|
||||||
setExtent(140, 30);
|
setExtent(140, 30);
|
||||||
|
|
@ -70,56 +69,50 @@ GuiColorPickerCtrl::GuiColorPickerCtrl()
|
||||||
mPositionChanged = false;
|
mPositionChanged = false;
|
||||||
mSelectorGap = 1;
|
mSelectorGap = 1;
|
||||||
mActionOnMove = false;
|
mActionOnMove = false;
|
||||||
mShowReticle = true;
|
mShowReticle = true;
|
||||||
mSelectColor = false;
|
mSelectColor = false;
|
||||||
mSetColor = mSetColor.BLACK;
|
mSetColor = mSetColor.BLACK;
|
||||||
mBitmap = NULL;
|
mBitmap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiColorPickerCtrl::~GuiColorPickerCtrl()
|
GuiColorPickerCtrl::~GuiColorPickerCtrl()
|
||||||
{
|
{
|
||||||
if (mBitmap)
|
if (mBitmap)
|
||||||
{
|
{
|
||||||
delete mBitmap;
|
delete mBitmap;
|
||||||
mBitmap = NULL;
|
mBitmap = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
ImplementEnumType( GuiColorPickMode,
|
ImplementEnumType( GuiColorPickMode,
|
||||||
"\n\n"
|
"\n\n"
|
||||||
"@ingroup GuiUtil"
|
"@ingroup GuiUtil"
|
||||||
"@internal" )
|
"@internal" )
|
||||||
{ GuiColorPickerCtrl::pPallet, "Pallete" },
|
{ GuiColorPickerCtrl::pPallet, "Pallete" },
|
||||||
{ GuiColorPickerCtrl::pHorizColorRange, "HorizColor"},
|
{ GuiColorPickerCtrl::pHorizColorRange, "HorizColor"},
|
||||||
{ GuiColorPickerCtrl::pVertColorRange, "VertColor" },
|
{ GuiColorPickerCtrl::pVertColorRange, "VertColor" },
|
||||||
{ GuiColorPickerCtrl::pHorizColorBrightnessRange, "HorizBrightnessColor"},
|
{ GuiColorPickerCtrl::pHorizColorBrightnessRange, "HorizBrightnessColor" },
|
||||||
{ GuiColorPickerCtrl::pVertColorBrightnessRange, "VertBrightnessColor" },
|
{ GuiColorPickerCtrl::pVertColorBrightnessRange, "VertBrightnessColor" },
|
||||||
{ GuiColorPickerCtrl::pBlendColorRange, "BlendColor"},
|
{ GuiColorPickerCtrl::pBlendColorRange, "BlendColor" },
|
||||||
{ GuiColorPickerCtrl::pHorizAlphaRange, "HorizAlpha"},
|
{ GuiColorPickerCtrl::pHorizAlphaRange, "HorizAlpha" },
|
||||||
{ GuiColorPickerCtrl::pVertAlphaRange, "VertAlpha" },
|
{ GuiColorPickerCtrl::pVertAlphaRange, "VertAlpha" },
|
||||||
{ GuiColorPickerCtrl::pDropperBackground, "Dropper" },
|
{ GuiColorPickerCtrl::pDropperBackground, "Dropper" },
|
||||||
EndImplementEnumType;
|
EndImplementEnumType;
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void GuiColorPickerCtrl::initPersistFields()
|
void GuiColorPickerCtrl::initPersistFields()
|
||||||
{
|
{
|
||||||
addGroup("ColorPicker");
|
addGroup("ColorPicker");
|
||||||
|
|
||||||
addField("baseColor", TypeColorF, Offset(mBaseColor, GuiColorPickerCtrl));
|
addField("baseColor", TypeColorF, Offset(mBaseColor, GuiColorPickerCtrl));
|
||||||
addField("pickColor", TypeColorF, Offset(mPickColor, GuiColorPickerCtrl));
|
addField("pickColor", TypeColorF, Offset(mPickColor, GuiColorPickerCtrl));
|
||||||
addField("selectorGap", TypeS32, Offset(mSelectorGap, GuiColorPickerCtrl));
|
addField("selectorGap", TypeS32, Offset(mSelectorGap, GuiColorPickerCtrl));
|
||||||
addField("displayMode", TYPEID< PickMode >(), Offset(mDisplayMode, GuiColorPickerCtrl) );
|
addField("displayMode", TYPEID< PickMode >(), Offset(mDisplayMode, GuiColorPickerCtrl) );
|
||||||
addField("actionOnMove", TypeBool,Offset(mActionOnMove, GuiColorPickerCtrl));
|
addField("actionOnMove", TypeBool,Offset(mActionOnMove, GuiColorPickerCtrl));
|
||||||
addField("showReticle", TypeBool, Offset(mShowReticle, GuiColorPickerCtrl));
|
addField("showReticle", TypeBool, Offset(mShowReticle, GuiColorPickerCtrl));
|
||||||
|
|
||||||
endGroup("ColorPicker");
|
endGroup("ColorPicker");
|
||||||
|
|
||||||
Parent::initPersistFields();
|
Parent::initPersistFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
// Function to draw a box which can have 4 different colors in each corner blended together
|
// 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)
|
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
|
//A couple of checks to determine if color blend
|
||||||
if(c1 == colorWhite && c3 == colorAlpha && c4 == colorBlack)
|
if(c1 == colorWhite && c3 == colorAlpha && c4 == colorBlack)
|
||||||
{
|
{
|
||||||
//Color
|
//Color
|
||||||
PrimBuild::begin( GFXTriangleFan, 4 );
|
PrimBuild::begin(GFXTriangleFan, 4);
|
||||||
PrimBuild::color( c2 );
|
PrimBuild::color( c2 );
|
||||||
PrimBuild::vertex2i( r, t );
|
PrimBuild::vertex2i( r, t );
|
||||||
|
|
||||||
PrimBuild::color( c2 );
|
PrimBuild::color( c2 );
|
||||||
PrimBuild::vertex2i( r, b );
|
PrimBuild::vertex2i( r, b );
|
||||||
|
|
||||||
PrimBuild::color( c2 );
|
PrimBuild::color( c2 );
|
||||||
PrimBuild::vertex2i( l, b );
|
PrimBuild::vertex2i( l, b );
|
||||||
|
|
||||||
PrimBuild::color( c2 );
|
PrimBuild::color( c2 );
|
||||||
PrimBuild::vertex2i( l, t );
|
PrimBuild::vertex2i( l, t );
|
||||||
PrimBuild::end();
|
PrimBuild::end();
|
||||||
|
|
||||||
//White
|
//White
|
||||||
PrimBuild::begin( GFXTriangleFan, 4 );
|
PrimBuild::begin( GFXTriangleFan, 4 );
|
||||||
PrimBuild::color( colorAlphaW );
|
PrimBuild::color( colorAlphaW );
|
||||||
PrimBuild::vertex2i( r, t );
|
PrimBuild::vertex2i( r, t );
|
||||||
|
|
||||||
PrimBuild::color( colorAlphaW );
|
PrimBuild::color( colorAlphaW );
|
||||||
PrimBuild::vertex2i( r, b );
|
PrimBuild::vertex2i( r, b );
|
||||||
|
|
||||||
PrimBuild::color( c1 );
|
PrimBuild::color( c1 );
|
||||||
PrimBuild::vertex2i( l, b );
|
PrimBuild::vertex2i( l, b );
|
||||||
|
|
||||||
PrimBuild::color( c1 );
|
PrimBuild::color( c1 );
|
||||||
PrimBuild::vertex2i( l, t );
|
PrimBuild::vertex2i( l, t );
|
||||||
PrimBuild::end();
|
PrimBuild::end();
|
||||||
|
|
||||||
//Black
|
//Black
|
||||||
PrimBuild::begin( GFXTriangleFan, 4 );
|
PrimBuild::begin( GFXTriangleFan, 4 );
|
||||||
PrimBuild::color( c3 );
|
PrimBuild::color( c3 );
|
||||||
PrimBuild::vertex2i( r, t );
|
PrimBuild::vertex2i( r, t );
|
||||||
|
|
||||||
PrimBuild::color( c4 );
|
PrimBuild::color( c4 );
|
||||||
PrimBuild::vertex2i( r, b );
|
PrimBuild::vertex2i( r, b );
|
||||||
|
|
||||||
PrimBuild::color( c4 );
|
PrimBuild::color( c4 );
|
||||||
PrimBuild::vertex2i( l, b );
|
PrimBuild::vertex2i( l, b );
|
||||||
|
|
||||||
PrimBuild::color( c3 );
|
PrimBuild::color( c3 );
|
||||||
PrimBuild::vertex2i( l, t );
|
PrimBuild::vertex2i( l, t );
|
||||||
PrimBuild::end();
|
PrimBuild::end();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PrimBuild::begin( GFXTriangleFan, 4 );
|
PrimBuild::begin( GFXTriangleFan, 4 );
|
||||||
PrimBuild::color( c1 );
|
PrimBuild::color( c1 );
|
||||||
PrimBuild::vertex2i( l, t );
|
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)
|
void GuiColorPickerCtrl::drawSelector(RectI &bounds, Point2I &selectorPos, SelectorMode mode)
|
||||||
{
|
{
|
||||||
if( !mShowReticle )
|
if( !mShowReticle )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
U16 sMax = mSelectorGap*2;
|
U16 sMax = mSelectorGap*2;
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case sVertical:
|
case sVertical:
|
||||||
// Now draw the vertical selector
|
// Now draw the vertical selector Up -> Pos
|
||||||
// Up -> Pos
|
if (selectorPos.y != bounds.point.y+1)
|
||||||
if (selectorPos.y != bounds.point.y+1)
|
GFX->getDrawUtil()->drawLine(selectorPos.x, bounds.point.y, selectorPos.x, selectorPos.y-sMax-1, colorWhiteBlend);
|
||||||
GFX->getDrawUtil()->drawLine(selectorPos.x, bounds.point.y, selectorPos.x, selectorPos.y-sMax-1, colorWhiteBlend);
|
// Down -> Pos
|
||||||
// Down -> Pos
|
if (selectorPos.y != bounds.point.y+bounds.extent.y)
|
||||||
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);
|
||||||
GFX->getDrawUtil()->drawLine(selectorPos.x, selectorPos.y + sMax, selectorPos.x, bounds.point.y + bounds.extent.y, colorWhiteBlend);
|
break;
|
||||||
break;
|
case sHorizontal:
|
||||||
case sHorizontal:
|
// Now draw the horizontal selector Left -> Pos
|
||||||
// Now draw the horizontal selector
|
if (selectorPos.x != bounds.point.x)
|
||||||
// Left -> Pos
|
|
||||||
if (selectorPos.x != bounds.point.x)
|
|
||||||
GFX->getDrawUtil()->drawLine(bounds.point.x, selectorPos.y-1, selectorPos.x-sMax, selectorPos.y-1, colorWhiteBlend);
|
GFX->getDrawUtil()->drawLine(bounds.point.x, selectorPos.y-1, selectorPos.x-sMax, selectorPos.y-1, colorWhiteBlend);
|
||||||
// Right -> Pos
|
// Right -> Pos
|
||||||
if (selectorPos.x != bounds.point.x)
|
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);
|
GFX->getDrawUtil()->drawLine(bounds.point.x+mSelectorPos.x+sMax, selectorPos.y-1, bounds.point.x + bounds.extent.x, selectorPos.y-1, colorWhiteBlend);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
|
@ -343,183 +334,176 @@ void GuiColorPickerCtrl::renderColorBox(RectI &bounds)
|
||||||
|
|
||||||
void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
|
void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
|
||||||
{
|
{
|
||||||
if (mStateBlock.isNull())
|
if (mStateBlock.isNull())
|
||||||
{
|
{
|
||||||
GFXStateBlockDesc desc;
|
GFXStateBlockDesc desc;
|
||||||
desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
|
desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha);
|
||||||
desc.setZReadWrite(false);
|
desc.setZReadWrite(false);
|
||||||
desc.zWriteEnable = false;
|
desc.zWriteEnable = false;
|
||||||
desc.setCullMode(GFXCullNone);
|
desc.setCullMode(GFXCullNone);
|
||||||
mStateBlock = GFX->createStateBlock(desc);
|
mStateBlock = GFX->createStateBlock(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
RectI boundsRect(offset, getExtent());
|
RectI boundsRect(offset, getExtent());
|
||||||
renderColorBox(boundsRect);
|
renderColorBox(boundsRect);
|
||||||
|
|
||||||
if (mPositionChanged || mBitmap == NULL)
|
if (mPositionChanged || mBitmap == NULL)
|
||||||
{
|
{
|
||||||
bool nullBitmap = false;
|
bool nullBitmap = false;
|
||||||
|
|
||||||
if (mPositionChanged == false && mBitmap == NULL)
|
if (mPositionChanged == false && mBitmap == NULL)
|
||||||
nullBitmap = true;
|
nullBitmap = true;
|
||||||
|
|
||||||
mPositionChanged = false;
|
mPositionChanged = false;
|
||||||
Point2I extent = getRoot()->getExtent();
|
Point2I extent = getRoot()->getExtent();
|
||||||
// If we are anything but a pallete, change the pick color
|
|
||||||
if (mDisplayMode != pPallet)
|
|
||||||
{
|
|
||||||
Point2I resolution = getRoot()->getExtent();
|
|
||||||
|
|
||||||
U32 buf_x = offset.x + mSelectorPos.x + 1;
|
// If we are anything but a pallete, change the pick color
|
||||||
U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1));
|
if (mDisplayMode != pPallet)
|
||||||
|
{
|
||||||
|
Point2I resolution = getRoot()->getExtent();
|
||||||
|
|
||||||
GFXTexHandle bb(resolution.x,
|
U32 buf_x = offset.x + mSelectorPos.x + 1;
|
||||||
resolution.y,
|
U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1));
|
||||||
GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__));
|
|
||||||
|
|
||||||
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();
|
Point2I tmpPt(buf_x, buf_y);
|
||||||
targ->resolveTo(bb);
|
|
||||||
|
|
||||||
if (mBitmap)
|
GFXTarget *targ = GFX->getActiveRenderTarget();
|
||||||
{
|
targ->resolveTo(bb);
|
||||||
delete mBitmap;
|
|
||||||
mBitmap = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (!nullBitmap)
|
||||||
{
|
{
|
||||||
if (mSelectColor)
|
if (mSelectColor)
|
||||||
{
|
{
|
||||||
Point2I pos = findColor(mSetColor, offset, resolution, *mBitmap);
|
Point2I pos = findColor(mSetColor, offset, resolution, *mBitmap);
|
||||||
mSetColor = mSetColor.BLACK;
|
mSetColor = mSetColor.BLACK;
|
||||||
mSelectColor = false;
|
mSelectColor = false;
|
||||||
|
setSelectorPos(pos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ColorI tmp;
|
||||||
|
mBitmap->getColor(buf_x, buf_y, tmp);
|
||||||
|
|
||||||
setSelectorPos(pos);
|
mPickColor = (ColorF)tmp;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ColorI tmp;
|
|
||||||
mBitmap->getColor(buf_x, buf_y, tmp);
|
|
||||||
|
|
||||||
mPickColor = (ColorF)tmp;
|
// Now do onAction() if we are allowed
|
||||||
|
if (mActionOnMove)
|
||||||
|
onAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now do onAction() if we are allowed
|
//render the children
|
||||||
if (mActionOnMove)
|
renderChildControls(offset, updateRect);
|
||||||
onAction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//render the children
|
|
||||||
renderChildControls(offset, updateRect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiColorPickerCtrl::setSelectorPos(const ColorF & color)
|
void GuiColorPickerCtrl::setSelectorPos(const ColorF & color)
|
||||||
{
|
{
|
||||||
if (mBitmap && !mPositionChanged)
|
if (mBitmap && !mPositionChanged)
|
||||||
{
|
{
|
||||||
Point2I resolution = getRoot() ? getRoot()->getExtent() : Point2I(1024, 768);
|
Point2I resolution = getRoot() ? getRoot()->getExtent() : Point2I(1024, 768);
|
||||||
RectI rect(getGlobalBounds());
|
RectI rect(getGlobalBounds());
|
||||||
Point2I pos = findColor(color, rect.point, resolution, *mBitmap);
|
Point2I pos = findColor(color, rect.point, resolution, *mBitmap);
|
||||||
mSetColor = mSetColor.BLACK;
|
mSetColor = mSetColor.BLACK;
|
||||||
mSelectColor = false;
|
mSelectColor = false;
|
||||||
|
|
||||||
setSelectorPos(pos);
|
setSelectorPos(pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mSetColor = color;
|
mSetColor = color;
|
||||||
mSelectColor = true;
|
mSelectColor = true;
|
||||||
mPositionChanged = true;
|
mPositionChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2I GuiColorPickerCtrl::findColor(const ColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp)
|
Point2I GuiColorPickerCtrl::findColor(const ColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp)
|
||||||
{
|
{
|
||||||
RectI rect;
|
RectI rect;
|
||||||
Point2I ext = getExtent();
|
Point2I ext = getExtent();
|
||||||
if (mDisplayMode != pDropperBackground)
|
if (mDisplayMode != pDropperBackground)
|
||||||
{
|
{
|
||||||
ext.x -= 3;
|
ext.x -= 3;
|
||||||
ext.y -= 2;
|
ext.y -= 2;
|
||||||
rect = RectI(Point2I(1, 1), ext);
|
rect = RectI(Point2I(1, 1), ext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rect = RectI(Point2I(0, 0), ext);
|
rect = RectI(Point2I(0, 0), ext);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point2I closestPos(-1, -1);
|
Point2I closestPos(-1, -1);
|
||||||
|
|
||||||
/* Debugging
|
/* Debugging
|
||||||
char filename[256];
|
char filename[256];
|
||||||
dSprintf( filename, 256, "%s.%s", "colorPickerTest", "png" );
|
dSprintf( filename, 256, "%s.%s", "colorPickerTest", "png" );
|
||||||
|
|
||||||
// Open up the file on disk.
|
// Open up the file on disk.
|
||||||
FileStream fs;
|
FileStream fs;
|
||||||
if ( !fs.open( filename, Torque::FS::File::Write ) )
|
if ( !fs.open( filename, Torque::FS::File::Write ) )
|
||||||
Con::errorf( "GuiObjectView::saveAsImage() - Failed to open output file '%s'!", filename );
|
Con::errorf( "GuiObjectView::saveAsImage() - Failed to open output file '%s'!", filename );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Write it and close.
|
// Write it and close.
|
||||||
bmp.writeBitmap( "png", fs );
|
bmp.writeBitmap( "png", fs );
|
||||||
|
|
||||||
fs.close();
|
fs.close();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ColorI tmp;
|
ColorI tmp;
|
||||||
U32 buf_x;
|
U32 buf_x;
|
||||||
U32 buf_y;
|
U32 buf_y;
|
||||||
ColorF curColor;
|
ColorF curColor;
|
||||||
F32 val(10000.0f);
|
F32 val(10000.0f);
|
||||||
F32 closestVal(10000.0f);
|
F32 closestVal(10000.0f);
|
||||||
bool closestSet = false;
|
bool closestSet = false;
|
||||||
|
|
||||||
for (S32 x = rect.point.x; x <= rect.extent.x; x++)
|
for (S32 x = rect.point.x; x <= rect.extent.x; x++)
|
||||||
{
|
{
|
||||||
for (S32 y = rect.point.y; y <= rect.extent.y; y++)
|
for (S32 y = rect.point.y; y <= rect.extent.y; y++)
|
||||||
{
|
{
|
||||||
buf_x = offset.x + x + 1;
|
buf_x = offset.x + x + 1;
|
||||||
buf_y = (resolution.y - (offset.y + y + 1));
|
buf_y = (resolution.y - (offset.y + y + 1));
|
||||||
if (GFX->getAdapterType() != OpenGL)
|
buf_y = resolution.y - buf_y;
|
||||||
buf_y = resolution.y - buf_y;
|
|
||||||
|
|
||||||
//Get the color at that position
|
//Get the color at that position
|
||||||
bmp.getColor(buf_x, buf_y, tmp);
|
bmp.getColor(buf_x, buf_y, tmp);
|
||||||
curColor = (ColorF)tmp;
|
curColor = (ColorF)tmp;
|
||||||
|
|
||||||
//Evaluate how close the color is to our desired color
|
//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);
|
val = mFabs(color.red - curColor.red) + mFabs(color.green - curColor.green) + mFabs(color.blue - curColor.blue);
|
||||||
|
|
||||||
if (!closestSet)
|
if (!closestSet)
|
||||||
{
|
{
|
||||||
closestVal = val;
|
closestVal = val;
|
||||||
closestPos.set(x, y);
|
closestPos.set(x, y);
|
||||||
closestSet = true;
|
closestSet = true;
|
||||||
}
|
}
|
||||||
else if (val < closestVal)
|
else if (val < closestVal)
|
||||||
{
|
{
|
||||||
closestVal = val;
|
closestVal = val;
|
||||||
closestPos.set(x, y);
|
closestPos.set(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return closestPos;
|
return closestPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos)
|
void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos)
|
||||||
{
|
{
|
||||||
Point2I extent = getExtent();
|
Point2I extent = getExtent();
|
||||||
|
|
@ -564,7 +548,6 @@ void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)
|
void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)
|
||||||
{
|
{
|
||||||
if (!mActive)
|
if (!mActive)
|
||||||
|
|
@ -578,7 +561,7 @@ void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)
|
||||||
if (mProfile->mCanKeyFocus)
|
if (mProfile->mCanKeyFocus)
|
||||||
setFirstResponder();
|
setFirstResponder();
|
||||||
|
|
||||||
if (mActive && (mDisplayMode != pDropperBackground))
|
if (mActive && (mDisplayMode != pDropperBackground))
|
||||||
onAction();
|
onAction();
|
||||||
|
|
||||||
// Update the picker cross position
|
// Update the picker cross position
|
||||||
|
|
@ -600,10 +583,8 @@ void GuiColorPickerCtrl::onMouseDragged(const GuiEvent &event)
|
||||||
|
|
||||||
if( !mActionOnMove )
|
if( !mActionOnMove )
|
||||||
execAltConsoleCallback();
|
execAltConsoleCallback();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void GuiColorPickerCtrl::onMouseMove(const GuiEvent &event)
|
void GuiColorPickerCtrl::onMouseMove(const GuiEvent &event)
|
||||||
{
|
{
|
||||||
// Only for dropper mode
|
// Only for dropper mode
|
||||||
|
|
@ -611,24 +592,21 @@ void GuiColorPickerCtrl::onMouseMove(const GuiEvent &event)
|
||||||
setSelectorPos(globalToLocalCoord(event.mousePoint));
|
setSelectorPos(globalToLocalCoord(event.mousePoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void GuiColorPickerCtrl::onMouseEnter(const GuiEvent &event)
|
void GuiColorPickerCtrl::onMouseEnter(const GuiEvent &event)
|
||||||
{
|
{
|
||||||
mMouseOver = true;
|
mMouseOver = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void GuiColorPickerCtrl::onMouseLeave(const GuiEvent &)
|
void GuiColorPickerCtrl::onMouseLeave(const GuiEvent &)
|
||||||
{
|
{
|
||||||
// Reset state
|
// Reset state
|
||||||
mMouseOver = false;
|
mMouseOver = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void GuiColorPickerCtrl::onMouseUp(const GuiEvent &)
|
void GuiColorPickerCtrl::onMouseUp(const GuiEvent &)
|
||||||
{
|
{
|
||||||
//if we released the mouse within this control, perform the action
|
//if we released the mouse within this control, perform the action
|
||||||
if (mActive && mMouseDown && (mDisplayMode != pDropperBackground))
|
if (mActive && mMouseDown && (mDisplayMode != pDropperBackground))
|
||||||
mMouseDown = false;
|
mMouseDown = false;
|
||||||
|
|
||||||
if (mActive && (mDisplayMode == pDropperBackground))
|
if (mActive && (mDisplayMode == pDropperBackground))
|
||||||
|
|
@ -640,16 +618,14 @@ void GuiColorPickerCtrl::onMouseUp(const GuiEvent &)
|
||||||
mouseUnlock();
|
mouseUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
const char *GuiColorPickerCtrl::getScriptValue()
|
const char *GuiColorPickerCtrl::getScriptValue()
|
||||||
{
|
{
|
||||||
static char temp[256];
|
static char temp[256];
|
||||||
ColorF color = getValue();
|
ColorF color = getValue();
|
||||||
dSprintf(temp,256,"%f %f %f %f",color.red, color.green, color.blue, color.alpha);
|
dSprintf( temp, 256, "%f %f %f %f", color.red, color.green, color.blue, color.alpha );
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
void GuiColorPickerCtrl::setScriptValue(const char *value)
|
void GuiColorPickerCtrl::setScriptValue(const char *value)
|
||||||
{
|
{
|
||||||
ColorF newValue;
|
ColorF newValue;
|
||||||
|
|
@ -669,12 +645,12 @@ DefineConsoleMethod(GuiColorPickerCtrl, setSelectorPos, void, (Point2I newPos),
|
||||||
|
|
||||||
DefineConsoleMethod(GuiColorPickerCtrl, updateColor, void, (), , "Forces update of pick color")
|
DefineConsoleMethod(GuiColorPickerCtrl, updateColor, void, (), , "Forces update of pick color")
|
||||||
{
|
{
|
||||||
object->updateColor();
|
object->updateColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineMethod(GuiColorPickerCtrl, setSelectorColor, void, (ColorF color), ,
|
DefineEngineMethod(GuiColorPickerCtrl, setSelectorColor, void, (ColorF color), ,
|
||||||
"Sets the current position of the selector based on a color.n"
|
"Sets the current position of the selector based on a color.n"
|
||||||
"@param color Color to look for.n")
|
"@param color Color to look for.n")
|
||||||
{
|
{
|
||||||
object->setSelectorPos(color);
|
object->setSelectorPos(color);
|
||||||
}
|
}
|
||||||
|
|
@ -59,29 +59,28 @@ class GuiColorPickerCtrl : public GuiControl
|
||||||
public:
|
public:
|
||||||
enum PickMode
|
enum PickMode
|
||||||
{
|
{
|
||||||
pPallet = 0, ///< We just have a solid color; We just act like a pallet
|
pPallet = 0, ///< We just have a solid color; We just act like a pallet
|
||||||
pHorizColorRange, ///< We have a range of base colors going horizontally
|
pHorizColorRange, ///< We have a range of base colors going horizontally
|
||||||
pVertColorRange, ///< We have a range of base colors going vertically
|
pVertColorRange, ///< We have a range of base colors going vertically
|
||||||
pHorizColorBrightnessRange, ///< HorizColorRange with brightness
|
pHorizColorBrightnessRange, ///< HorizColorRange with brightness
|
||||||
pVertColorBrightnessRange, ///< VertColorRange with brightness
|
pVertColorBrightnessRange, ///< VertColorRange with brightness
|
||||||
pBlendColorRange, ///< We have a box which shows a range in brightness of the color
|
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
|
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
|
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)
|
pDropperBackground ///< The control does not draw anything; Only does something when you click, or move the mouse (when active)
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SelectorMode
|
enum SelectorMode
|
||||||
{
|
{
|
||||||
sHorizontal = 0, ///< Horizontal selector with small gap
|
sHorizontal = 0, ///< Horizontal selector with small gap
|
||||||
sVertical, ///< Vertical selector with small gap
|
sVertical, ///< Vertical selector with small gap
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/// @name Core Rendering functions
|
/// @name Core Rendering functions
|
||||||
/// @{
|
/// @{
|
||||||
void renderColorBox(RectI &bounds); ///< Function that draws the actual color box
|
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 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 drawBlendBox(RectI &bounds, ColorF &c1, ColorF &c2, ColorF &c3, ColorF &c4);
|
||||||
void drawBlendRangeBox(RectI &bounds, bool vertical, U8 numColors, ColorI *colors);
|
void drawBlendRangeBox(RectI &bounds, bool vertical, U8 numColors, ColorI *colors);
|
||||||
/// @}
|
/// @}
|
||||||
|
|
@ -127,7 +126,7 @@ class GuiColorPickerCtrl : public GuiControl
|
||||||
/// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful
|
/// NOTE: setValue only sets baseColor, since setting pickColor wouldn't be useful
|
||||||
void setValue(ColorF &value) {mBaseColor = value;}
|
void setValue(ColorF &value) {mBaseColor = value;}
|
||||||
/// NOTE: getValue() returns baseColor if pallet (since pallet controls can't "pick" colours themselves)
|
/// 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();
|
const char *getScriptValue();
|
||||||
void setScriptValue(const char *value);
|
void setScriptValue(const char *value);
|
||||||
void updateColor() {mPositionChanged = true;}
|
void updateColor() {mPositionChanged = true;}
|
||||||
|
|
|
||||||
|
|
@ -1262,7 +1262,7 @@ void GuiTextEditCtrl::onRender(Point2I offset, const RectI &updateRect)
|
||||||
if ( mProfile->mOpaque )
|
if ( mProfile->mOpaque )
|
||||||
{
|
{
|
||||||
if (!mTextValid)
|
if (!mTextValid)
|
||||||
GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorNA);
|
GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorERR);
|
||||||
else if (isFirstResponder())
|
else if (isFirstResponder())
|
||||||
GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorHL);
|
GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorHL);
|
||||||
else
|
else
|
||||||
|
|
@ -1274,7 +1274,7 @@ void GuiTextEditCtrl::onRender(Point2I offset, const RectI &updateRect)
|
||||||
{
|
{
|
||||||
renderBorder(ctrlRect, mProfile);
|
renderBorder(ctrlRect, mProfile);
|
||||||
if (!mTextValid)
|
if (!mTextValid)
|
||||||
GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorNA);
|
GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColorERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawText( ctrlRect, isFirstResponder() );
|
drawText( ctrlRect, isFirstResponder() );
|
||||||
|
|
|
||||||
|
|
@ -269,6 +269,7 @@ GuiControlProfile::GuiControlProfile(void) :
|
||||||
mFillColor(255,0,255,255),
|
mFillColor(255,0,255,255),
|
||||||
mFillColorHL(255,0,255,255),
|
mFillColorHL(255,0,255,255),
|
||||||
mFillColorNA(255,0,255,255),
|
mFillColorNA(255,0,255,255),
|
||||||
|
mFillColorERR(255,0,0,255),
|
||||||
mFillColorSEL(255,0,255,255),
|
mFillColorSEL(255,0,255,255),
|
||||||
mBorderColor(255,0,255,255),
|
mBorderColor(255,0,255,255),
|
||||||
mBorderColorHL(255,0,255,255),
|
mBorderColorHL(255,0,255,255),
|
||||||
|
|
@ -334,6 +335,7 @@ GuiControlProfile::GuiControlProfile(void) :
|
||||||
mFillColor = def->mFillColor;
|
mFillColor = def->mFillColor;
|
||||||
mFillColorHL = def->mFillColorHL;
|
mFillColorHL = def->mFillColorHL;
|
||||||
mFillColorNA = def->mFillColorNA;
|
mFillColorNA = def->mFillColorNA;
|
||||||
|
mFillColorERR = def->mFillColorERR;
|
||||||
mFillColorSEL = def->mFillColorSEL;
|
mFillColorSEL = def->mFillColorSEL;
|
||||||
|
|
||||||
mBorder = def->mBorder;
|
mBorder = def->mBorder;
|
||||||
|
|
@ -398,6 +400,7 @@ void GuiControlProfile::initPersistFields()
|
||||||
addField("fillColor", TypeColorI, Offset(mFillColor, GuiControlProfile));
|
addField("fillColor", TypeColorI, Offset(mFillColor, GuiControlProfile));
|
||||||
addField("fillColorHL", TypeColorI, Offset(mFillColorHL, GuiControlProfile));
|
addField("fillColorHL", TypeColorI, Offset(mFillColorHL, GuiControlProfile));
|
||||||
addField("fillColorNA", TypeColorI, Offset(mFillColorNA, GuiControlProfile));
|
addField("fillColorNA", TypeColorI, Offset(mFillColorNA, GuiControlProfile));
|
||||||
|
addField("fillColorERR", TypeColorI, Offset(mFillColorERR, GuiControlProfile));
|
||||||
addField("fillColorSEL", TypeColorI, Offset(mFillColorSEL, GuiControlProfile));
|
addField("fillColorSEL", TypeColorI, Offset(mFillColorSEL, GuiControlProfile));
|
||||||
addField("border", TypeS32, Offset(mBorder, GuiControlProfile),
|
addField("border", TypeS32, Offset(mBorder, GuiControlProfile),
|
||||||
"Border type (0=no border)." );
|
"Border type (0=no border)." );
|
||||||
|
|
|
||||||
|
|
@ -385,6 +385,7 @@ public:
|
||||||
ColorI mFillColor; ///< Fill color, this is used to fill the bounds of the control if it is opaque
|
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 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 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
|
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
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue