mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-09 07:20:40 +00:00
Update guiColorPicker.cpp
This commit is contained in:
parent
494922d9ed
commit
aed2e0b5b6
1 changed files with 228 additions and 252 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue