colorpicker cleanups

largely focuses on removing extraneous code and mangled math
This commit is contained in:
AzaezelX 2024-09-16 13:24:41 -05:00
parent 9712a8b1c9
commit ead06b845e
2 changed files with 22 additions and 71 deletions

View file

@ -272,18 +272,18 @@ void GuiColorPickerCtrl::drawSelector(RectI &bounds, Point2I &selectorPos, Selec
{ {
case sVertical: case sVertical:
// Now draw the vertical selector Up -> Pos // Now draw the vertical selector Up -> Pos
if (selectorPos.y != bounds.point.y+1) if (selectorPos.y > bounds.point.y)
GFX->getDrawUtil()->drawLine(selectorPos.x, bounds.point.y, selectorPos.x, selectorPos.y-sMax-1, color); GFX->getDrawUtil()->drawLine(selectorPos.x, bounds.point.y, selectorPos.x, selectorPos.y-sMax-1, color);
// 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, color); GFX->getDrawUtil()->drawLine(selectorPos.x, selectorPos.y + sMax, selectorPos.x, bounds.point.y + bounds.extent.y, color);
break; break;
case sHorizontal: case sHorizontal:
// Now draw the horizontal selector Left -> Pos // Now draw the horizontal selector Left -> Pos
if (selectorPos.x != bounds.point.x) if (selectorPos.x > bounds.point.x)
GFX->getDrawUtil()->drawLine(bounds.point.x, selectorPos.y-1, selectorPos.x-sMax, selectorPos.y-1, color); GFX->getDrawUtil()->drawLine(bounds.point.x, selectorPos.y-1, selectorPos.x-sMax, selectorPos.y-1, color);
// Right -> Pos // Right -> Pos
if (selectorPos.x != bounds.point.x) if (selectorPos.x < bounds.point.x + bounds.extent.x)
GFX->getDrawUtil()->drawLine(bounds.point.x+mSelectorPos.x+sMax, selectorPos.y-1, bounds.point.x + bounds.extent.x, selectorPos.y-1, color); GFX->getDrawUtil()->drawLine(bounds.point.x+mSelectorPos.x+sMax, selectorPos.y-1, bounds.point.x + bounds.extent.x, selectorPos.y-1, color);
break; break;
} }
@ -388,13 +388,11 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect)
{ {
Point2I resolution = getRoot()->getExtent(); Point2I resolution = getRoot()->getExtent();
U32 buf_x = offset.x + mSelectorPos.x + 1; U32 buf_x = offset.x + mSelectorPos.x;
U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1)); U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y));
GFXTexHandle bb(resolution.x, resolution.y, GFXFormatR8G8B8A8_SRGB, &GFXRenderTargetSRGBProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__)); GFXTexHandle bb(resolution.x, resolution.y, GFXFormatR8G8B8A8_SRGB, &GFXRenderTargetSRGBProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__));
Point2I tmpPt(buf_x, buf_y);
GFXTarget *targ = GFX->getActiveRenderTarget(); GFXTarget *targ = GFX->getActiveRenderTarget();
targ->resolveTo(bb); targ->resolveTo(bb);
@ -458,19 +456,7 @@ void GuiColorPickerCtrl::setSelectorPos(const LinearColorF & color)
Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp) Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I& offset, const Point2I& resolution, GBitmap& bmp)
{ {
RectI rect;
Point2I ext = getExtent(); 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 /* Debugging
@ -498,12 +484,12 @@ Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I&
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 = 0; x < ext.x; x++)
{ {
for (S32 y = rect.point.y; y <= rect.extent.y; y++) for (S32 y = 0; y < ext.y; y++)
{ {
buf_x = offset.x + x + 1; buf_x = offset.x + x;
buf_y = (resolution.y - (offset.y + y + 1)); buf_y = (resolution.y - (offset.y + y));
buf_y = resolution.y - buf_y; buf_y = resolution.y - buf_y;
//Get the color at that position //Get the color at that position
@ -532,46 +518,11 @@ Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I&
void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos) void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos)
{ {
Point2I extent = getExtent(); Point2I ext = getExtent();
RectI rect; mSelectorPos.x = mClamp(pos.x, 1, ext.x - 1);
if (mDisplayMode != pDropperBackground) mSelectorPos.y = mClamp(pos.y, 1, ext.y - 1);
{ mPositionChanged = true;
extent.x -= 3; setUpdate();
extent.y -= 2;
rect = RectI(Point2I(1,1), extent);
}
else
{
rect = RectI(Point2I(0,0), extent);
}
if (rect.pointInRect(pos))
{
mSelectorPos = pos;
mPositionChanged = true;
// We now need to update
setUpdate();
}
else
{
if ((pos.x > rect.point.x) && (pos.x < (rect.point.x + rect.extent.x)))
mSelectorPos.x = pos.x;
else if (pos.x <= rect.point.x)
mSelectorPos.x = rect.point.x;
else if (pos.x >= (rect.point.x + rect.extent.x))
mSelectorPos.x = rect.point.x + rect.extent.x - 1;
if ((pos.y > rect.point.y) && (pos.y < (rect.point.y + rect.extent.y)))
mSelectorPos.y = pos.y;
else if (pos.y <= rect.point.y)
mSelectorPos.y = rect.point.y;
else if (pos.y >= (rect.point.y + rect.extent.y))
mSelectorPos.y = rect.point.y + rect.extent.y - 1;
mPositionChanged = true;
setUpdate();
}
} }
void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event) void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event)

View file

@ -45,8 +45,8 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) {
canSaveDynamicFields = "0"; canSaveDynamicFields = "0";
new GuiBitmapBorderCtrl(){ // color blend new GuiBitmapBorderCtrl(){ // color blend
position = "3 24"; position = "3 25";
extent = "255 258"; extent = "260 260";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "right"; horizSizing = "right";
vertSizing = "bottom"; vertSizing = "bottom";
@ -67,8 +67,8 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) {
selectorGap = "1"; selectorGap = "1";
displayMode = "BlendColor"; displayMode = "BlendColor";
actionOnMove = "1"; actionOnMove = "1";
position = "1 0"; position = "1 1";
extent = "255 258"; extent = "255 255";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "right"; horizSizing = "right";
vertSizing = "bottom"; vertSizing = "bottom";
@ -86,8 +86,8 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) {
}; };
}; };
new GuiBitmapBorderCtrl(){ // Hue new GuiBitmapBorderCtrl(){ // Hue
position = "263 23"; position = "265 25";
extent = "25 261"; extent = "25 260";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "right"; horizSizing = "right";
vertSizing = "bottom"; vertSizing = "bottom";
@ -109,7 +109,7 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) {
displayMode = "VertColor"; displayMode = "VertColor";
actionOnMove = "1"; actionOnMove = "1";
position = "1 1"; position = "1 1";
extent = "21 257"; extent = "20 255";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "right"; horizSizing = "right";
vertSizing = "bottom"; vertSizing = "bottom";