From ead06b845e682e6f3ac85e57f10561947c79c76f Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 16 Sep 2024 13:24:41 -0500 Subject: [PATCH] colorpicker cleanups largely focuses on removing extraneous code and mangled math --- Engine/source/gui/controls/guiColorPicker.cpp | 79 ++++--------------- .../game/tools/gui/colorPicker.ed.gui | 14 ++-- 2 files changed, 22 insertions(+), 71 deletions(-) diff --git a/Engine/source/gui/controls/guiColorPicker.cpp b/Engine/source/gui/controls/guiColorPicker.cpp index bed80df84c..09e47a97ef 100644 --- a/Engine/source/gui/controls/guiColorPicker.cpp +++ b/Engine/source/gui/controls/guiColorPicker.cpp @@ -272,18 +272,18 @@ void GuiColorPickerCtrl::drawSelector(RectI &bounds, Point2I &selectorPos, Selec { case sVertical: // 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); // 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); break; case sHorizontal: // 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); // 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); break; } @@ -388,13 +388,11 @@ void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) { Point2I resolution = getRoot()->getExtent(); - U32 buf_x = offset.x + mSelectorPos.x + 1; - U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1)); + U32 buf_x = offset.x + mSelectorPos.x; + 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__)); - Point2I tmpPt(buf_x, buf_y); - GFXTarget *targ = GFX->getActiveRenderTarget(); 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) { - 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 @@ -498,12 +484,12 @@ Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I& F32 closestVal(10000.0f); 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_y = (resolution.y - (offset.y + y + 1)); + buf_x = offset.x + x; + buf_y = (resolution.y - (offset.y + y)); buf_y = resolution.y - buf_y; //Get the color at that position @@ -532,46 +518,11 @@ Point2I GuiColorPickerCtrl::findColor(const LinearColorF & color, const Point2I& void GuiColorPickerCtrl::setSelectorPos(const Point2I &pos) { - Point2I extent = getExtent(); - RectI rect; - if (mDisplayMode != pDropperBackground) - { - extent.x -= 3; - 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(); - } + Point2I ext = getExtent(); + mSelectorPos.x = mClamp(pos.x, 1, ext.x - 1); + mSelectorPos.y = mClamp(pos.y, 1, ext.y - 1); + mPositionChanged = true; + setUpdate(); } void GuiColorPickerCtrl::onMouseDown(const GuiEvent &event) diff --git a/Templates/BaseGame/game/tools/gui/colorPicker.ed.gui b/Templates/BaseGame/game/tools/gui/colorPicker.ed.gui index 56ced8850c..d99ce01eb5 100644 --- a/Templates/BaseGame/game/tools/gui/colorPicker.ed.gui +++ b/Templates/BaseGame/game/tools/gui/colorPicker.ed.gui @@ -45,8 +45,8 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) { canSaveDynamicFields = "0"; new GuiBitmapBorderCtrl(){ // color blend - position = "3 24"; - extent = "255 258"; + position = "3 25"; + extent = "260 260"; minExtent = "8 2"; horizSizing = "right"; vertSizing = "bottom"; @@ -67,8 +67,8 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) { selectorGap = "1"; displayMode = "BlendColor"; actionOnMove = "1"; - position = "1 0"; - extent = "255 258"; + position = "1 1"; + extent = "255 255"; minExtent = "8 2"; horizSizing = "right"; vertSizing = "bottom"; @@ -86,8 +86,8 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) { }; }; new GuiBitmapBorderCtrl(){ // Hue - position = "263 23"; - extent = "25 261"; + position = "265 25"; + extent = "25 260"; minExtent = "8 2"; horizSizing = "right"; vertSizing = "bottom"; @@ -109,7 +109,7 @@ $guiContent = new GuiColorPickerCtrl(ColorPickerDlg,EditorGuiGroup) { displayMode = "VertColor"; actionOnMove = "1"; position = "1 1"; - extent = "21 257"; + extent = "20 255"; minExtent = "8 2"; horizSizing = "right"; vertSizing = "bottom";