|
@@ -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,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"
|
|
"@internal"
|
|
);
|
|
);
|
|
|
|
|
|
-//--------------------------------------------------------------------------
|
|
|
|
GuiColorPickerCtrl::GuiColorPickerCtrl()
|
|
GuiColorPickerCtrl::GuiColorPickerCtrl()
|
|
{
|
|
{
|
|
setExtent(140, 30);
|
|
setExtent(140, 30);
|
|
@@ -70,44 +69,50 @@ GuiColorPickerCtrl::GuiColorPickerCtrl()
|
|
mPositionChanged = false;
|
|
mPositionChanged = false;
|
|
mSelectorGap = 1;
|
|
mSelectorGap = 1;
|
|
mActionOnMove = false;
|
|
mActionOnMove = false;
|
|
- mShowReticle = true;
|
|
|
|
|
|
+ mShowReticle = true;
|
|
|
|
+ mSelectColor = false;
|
|
|
|
+ mSetColor = mSetColor.BLACK;
|
|
|
|
+ mBitmap = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
-//--------------------------------------------------------------------------
|
|
|
|
|
|
+GuiColorPickerCtrl::~GuiColorPickerCtrl()
|
|
|
|
+{
|
|
|
|
+ if (mBitmap)
|
|
|
|
+ {
|
|
|
|
+ delete mBitmap;
|
|
|
|
+ mBitmap = NULL;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
ImplementEnumType( GuiColorPickMode,
|
|
ImplementEnumType( GuiColorPickMode,
|
|
"\n\n"
|
|
"\n\n"
|
|
"@ingroup GuiUtil"
|
|
"@ingroup GuiUtil"
|
|
"@internal" )
|
|
"@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;
|
|
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)
|
|
{
|
|
{
|
|
@@ -119,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
|
|
|
|
- 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
|
|
else
|
|
{
|
|
{
|
|
- PrimBuild::begin( GFXTriangleFan, 4 );
|
|
|
|
|
|
+ PrimBuild::begin( GFXTriangleFan, 4 );
|
|
PrimBuild::color( c1 );
|
|
PrimBuild::color( c1 );
|
|
PrimBuild::vertex2i( l, t );
|
|
PrimBuild::vertex2i( l, t );
|
|
|
|
|
|
@@ -233,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 )
|
|
|
|
- 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)
|
|
|
|
|
|
+ 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)
|
|
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
|
|
|
|
- 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);
|
|
GFX->getDrawUtil()->drawLine(bounds.point.x+mSelectorPos.x+sMax, selectorPos.y-1, bounds.point.x + bounds.extent.x, selectorPos.y-1, colorWhiteBlend);
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
//--------------------------------------------------------------------------
|
|
@@ -269,10 +272,10 @@ void GuiColorPickerCtrl::renderColorBox(RectI &bounds)
|
|
pickerBounds.point.y = bounds.point.y+1;
|
|
pickerBounds.point.y = bounds.point.y+1;
|
|
pickerBounds.extent.x = bounds.extent.x-1;
|
|
pickerBounds.extent.x = bounds.extent.x-1;
|
|
pickerBounds.extent.y = bounds.extent.y-1;
|
|
pickerBounds.extent.y = bounds.extent.y-1;
|
|
-
|
|
|
|
|
|
+
|
|
if (mProfile->mBorder)
|
|
if (mProfile->mBorder)
|
|
GFX->getDrawUtil()->drawRect(bounds, mProfile->mBorderColor);
|
|
GFX->getDrawUtil()->drawRect(bounds, mProfile->mBorderColor);
|
|
-
|
|
|
|
|
|
+
|
|
Point2I selectorPos = Point2I(bounds.point.x+mSelectorPos.x+1, bounds.point.y+mSelectorPos.y+1);
|
|
Point2I selectorPos = Point2I(bounds.point.x+mSelectorPos.x+1, bounds.point.y+mSelectorPos.y+1);
|
|
|
|
|
|
// Draw color box differently depending on mode
|
|
// Draw color box differently depending on mode
|
|
@@ -338,56 +341,169 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
|
|
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)
|
|
|
|
|
|
+ if (mPositionChanged || mBitmap == NULL)
|
|
{
|
|
{
|
|
|
|
+ bool nullBitmap = false;
|
|
|
|
+
|
|
|
|
+ if (mPositionChanged == false && mBitmap == NULL)
|
|
|
|
+ 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 we are anything but a pallete, change the pick color
|
|
if (mDisplayMode != pPallet)
|
|
if (mDisplayMode != pPallet)
|
|
{
|
|
{
|
|
Point2I resolution = getRoot()->getExtent();
|
|
Point2I resolution = getRoot()->getExtent();
|
|
|
|
|
|
U32 buf_x = offset.x + mSelectorPos.x + 1;
|
|
U32 buf_x = offset.x + mSelectorPos.x + 1;
|
|
- U32 buf_y = resolution.y - ( extent.y - ( offset.y + mSelectorPos.y + 1 ) );
|
|
|
|
|
|
+ U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1));
|
|
|
|
|
|
- GFXTexHandle bb( resolution.x,
|
|
|
|
- resolution.y,
|
|
|
|
- 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__) );
|
|
|
|
+
|
|
|
|
+ Point2I tmpPt(buf_x, buf_y);
|
|
|
|
|
|
GFXTarget *targ = GFX->getActiveRenderTarget();
|
|
GFXTarget *targ = GFX->getActiveRenderTarget();
|
|
- targ->resolveTo( bb );
|
|
|
|
-
|
|
|
|
- GBitmap bmp( bb.getWidth(), bb.getHeight() );
|
|
|
|
|
|
+ targ->resolveTo(bb);
|
|
|
|
+
|
|
|
|
+ if (mBitmap)
|
|
|
|
+ {
|
|
|
|
+ delete mBitmap;
|
|
|
|
+ mBitmap = NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mBitmap = new GBitmap(bb.getWidth(), bb.getHeight());
|
|
|
|
+
|
|
|
|
+ bb.copyToBmp(mBitmap);
|
|
|
|
+
|
|
|
|
+ if (!nullBitmap)
|
|
|
|
+ {
|
|
|
|
+ if (mSelectColor)
|
|
|
|
+ {
|
|
|
|
+ Point2I pos = findColor(mSetColor, offset, resolution, *mBitmap);
|
|
|
|
+ mSetColor = mSetColor.BLACK;
|
|
|
|
+ mSelectColor = false;
|
|
|
|
+ setSelectorPos(pos);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ColorI tmp;
|
|
|
|
+ mBitmap->getColor(buf_x, buf_y, tmp);
|
|
|
|
+
|
|
|
|
+ mPickColor = (ColorF)tmp;
|
|
|
|
+
|
|
|
|
+ // Now do onAction() if we are allowed
|
|
|
|
+ if (mActionOnMove)
|
|
|
|
+ onAction();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- bb.copyToBmp( &bmp );
|
|
|
|
-
|
|
|
|
- //bmp.writePNGDebug( "foo.png" );
|
|
|
|
|
|
+ //render the children
|
|
|
|
+ renderChildControls(offset, updateRect);
|
|
|
|
+}
|
|
|
|
|
|
- ColorI tmp;
|
|
|
|
- bmp.getColor( buf_x, buf_y, tmp );
|
|
|
|
|
|
+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;
|
|
|
|
|
|
- mPickColor = (ColorF)tmp;
|
|
|
|
|
|
+ setSelectorPos(pos);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ mSetColor = color;
|
|
|
|
+ mSelectColor = true;
|
|
|
|
+ mPositionChanged = true;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Point2I GuiColorPickerCtrl::findColor(const ColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp)
|
|
|
|
+{
|
|
|
|
+ RectI rect;
|
|
|
|
+ Point2I ext = getExtent();
|
|
|
|
+ if (mDisplayMode != pDropperBackground)
|
|
|
|
+ {
|
|
|
|
+ ext.x -= 3;
|
|
|
|
+ ext.y -= 2;
|
|
|
|
+ rect = RectI(Point2I(1, 1), ext);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ rect = RectI(Point2I(0, 0), ext);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Point2I closestPos(-1, -1);
|
|
|
|
+
|
|
|
|
+ /* Debugging
|
|
|
|
+ char filename[256];
|
|
|
|
+ dSprintf( filename, 256, "%s.%s", "colorPickerTest", "png" );
|
|
|
|
+
|
|
|
|
+ // Open up the file on disk.
|
|
|
|
+ FileStream fs;
|
|
|
|
+ if ( !fs.open( filename, Torque::FS::File::Write ) )
|
|
|
|
+ Con::errorf( "GuiObjectView::saveAsImage() - Failed to open output file '%s'!", filename );
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ // Write it and close.
|
|
|
|
+ bmp.writeBitmap( "png", fs );
|
|
|
|
+
|
|
|
|
+ fs.close();
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
|
|
- // Now do onAction() if we are allowed
|
|
|
|
- if (mActionOnMove)
|
|
|
|
- onAction();
|
|
|
|
|
|
+ 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));
|
|
|
|
+ buf_y = resolution.y - buf_y;
|
|
|
|
+
|
|
|
|
+ //Get the color at that position
|
|
|
|
+ bmp.getColor(buf_x, buf_y, tmp);
|
|
|
|
+ curColor = (ColorF)tmp;
|
|
|
|
+
|
|
|
|
+ //Evaluate how close the color is to our desired color
|
|
|
|
+ val = mFabs(color.red - curColor.red) + mFabs(color.green - curColor.green) + mFabs(color.blue - curColor.blue);
|
|
|
|
+
|
|
|
|
+ if (!closestSet)
|
|
|
|
+ {
|
|
|
|
+ closestVal = val;
|
|
|
|
+ closestPos.set(x, y);
|
|
|
|
+ closestSet = true;
|
|
|
|
+ }
|
|
|
|
+ else if (val < closestVal)
|
|
|
|
+ {
|
|
|
|
+ closestVal = val;
|
|
|
|
+ closestPos.set(x, y);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- //render the children
|
|
|
|
- renderChildControls( offset, updateRect);
|
|
|
|
|
|
+
|
|
|
|
+ return closestPos;
|
|
}
|
|
}
|
|
|
|
|
|
-//--------------------------------------------------------------------------
|
|
|
|
void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos)
|
|
void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos)
|
|
{
|
|
{
|
|
Point2I extent = getExtent();
|
|
Point2I extent = getExtent();
|
|
@@ -432,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)
|
|
@@ -445,14 +560,14 @@ 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
|
|
if (mDisplayMode != pPallet)
|
|
if (mDisplayMode != pPallet)
|
|
- setSelectorPos(globalToLocalCoord(event.mousePoint));
|
|
|
|
-
|
|
|
|
|
|
+ setSelectorPos(globalToLocalCoord(event.mousePoint));
|
|
|
|
+
|
|
mMouseDown = true;
|
|
mMouseDown = true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -468,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
|
|
@@ -479,45 +592,40 @@ 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))
|
|
{
|
|
{
|
|
// In a dropper, the alt command executes the mouse up action (to signal stopping)
|
|
// In a dropper, the alt command executes the mouse up action (to signal stopping)
|
|
execAltConsoleCallback();
|
|
execAltConsoleCallback();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
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);
|
|
|
|
- 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)
|
|
void GuiColorPickerCtrl::setScriptValue(const char *value)
|
|
{
|
|
{
|
|
ColorF newValue;
|
|
ColorF newValue;
|
|
@@ -537,5 +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), ,
|
|
|
|
+ "Sets the current position of the selector based on a color.n"
|
|
|
|
+ "@param color Color to look for.n")
|
|
|
|
+{
|
|
|
|
+ object->setSelectorPos(color);
|
|
}
|
|
}
|