Skip to content

Commit

Permalink
Changes to guiColorPopupCtrl
Browse files Browse the repository at this point in the history
This includes a few bug fixes for the GuiColorPopupCtrl. I've removed mBlendHeight. The blend height is now calculated to fill in available space. I fixed a bug that shows the alpha bar when it is turned off using mShowAlphaBar. I've added two methods also: setColorF and setColorI.
  • Loading branch information
greenfire27 committed Jan 24, 2024
1 parent 1e4562a commit 67dff45
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
17 changes: 8 additions & 9 deletions engine/source/gui/guiColorPopupCtrl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ GuiColorPopupCtrl::GuiColorPopupCtrl()
mIsContainer = false;
mBaseColor = ColorF(0.5f, 0.5f, 0.5f);
mPopupSize = Point2I(240, 208);
mBlendHeight = 150;
mBarHeight = 20;
mShowAlphaBar = true;
mBounds.extent.set(40, 40);
Expand Down Expand Up @@ -152,7 +151,7 @@ GuiColorPopupCtrl::GuiColorPopupCtrl()
AssertFatal(mColorBlendPicker, "GuiColorPopupCtrl: Failed to initialize GuiColorPopupBlendCtrl!");
mColorBlendPicker->setField("profile", "GuiColorPickerProfile");
mColorBlendPicker->setField("displayMode", "blendColor");
mColorBlendPicker->setExtent(Point2I(contentRect.extent.x, mBlendHeight));
mColorBlendPicker->setExtent(Point2I(contentRect.extent.x, 100));
mColorBlendPicker->showSelector();
mPickerProfile = mColorBlendPicker->mProfile;
mPickerProfile->incRefCount();
Expand Down Expand Up @@ -305,21 +304,21 @@ void GuiColorPopupCtrl::openColorPopup()
mContent->setExtent(mPopupSize);
RectI contentRect = mContent->getInnerRect();
mColorBlendPicker->setWidth(contentRect.extent.x);
S32 blendHeight = getMin(contentRect.extent.y, mBlendHeight);
mColorBlendPicker->setHeight(blendHeight);
S32 remainingHeight = contentRect.extent.y - blendHeight;

U8 barCount = mShowAlphaBar ? 2 : 1;
S32 barSpace = remainingHeight / barCount;
mColorHuePicker->resize(Point2I(0, blendHeight + barSpace - mBarHeight), Point2I(contentRect.extent.x, mBarHeight));
if (mShowAlphaBar)
{
mColorAlphaPicker->setActive(true);
mColorAlphaPicker->resize(Point2I(0, blendHeight + (barSpace * 2) - mBarHeight), Point2I(contentRect.extent.x, mBarHeight));
mColorAlphaPicker->setVisible(true);
mColorAlphaPicker->resize(Point2I(0, contentRect.extent.y - mBarHeight), Point2I(contentRect.extent.x, mBarHeight));
mColorHuePicker->resize(Point2I(0, contentRect.extent.y - (2 * mBarHeight)), Point2I(contentRect.extent.x, mBarHeight));
mColorBlendPicker->setHeight(contentRect.extent.y - (2 * mBarHeight));
}
else
{
mColorAlphaPicker->setActive(false);
mColorAlphaPicker->setVisible(false);
mColorHuePicker->resize(Point2I(0, contentRect.extent.y - mBarHeight), Point2I(contentRect.extent.x, mBarHeight));
mColorBlendPicker->setHeight(contentRect.extent.y - mBarHeight);
}

Point2I huePos = mColorHuePicker->getSelectorPositionForColor(mBaseColor);
Expand Down
1 change: 0 additions & 1 deletion engine/source/gui/guiColorPopupCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class GuiColorPopupCtrl : public GuiButtonCtrl
ColorF mBaseColor;
bool mIsOpen;
Point2I mPopupSize;
S32 mBlendHeight;
S32 mBarHeight;
bool mShowAlphaBar;

Expand Down
62 changes: 62 additions & 0 deletions engine/source/gui/guiColorPopupCtrl_ScriptBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,66 @@ ConsoleMethodWithDocs(GuiColorPopupCtrl, getColorI, ConsoleString, 2, 2, ())
return(returnBuffer);
}

/*! Sets the base color displayed using floating point values.
@param color The color to display as values between 0 and 1.0.
@return No return value.
*/
ConsoleMethodWithDocs(GuiColorPopupCtrl, setColorF, ConsoleVoid, 3, 3, "(color red / green / blue / [alpha])")
{
if (argc == 3)
{
const U32 colorCount = Utility::mGetStringElementCount(argv[2]);
if (colorCount != 4 && colorCount != 3)
{
Con::warnf("GuiColorPopupCtrl::setColorF() - Invalid color! Colors require three or four values (red / green / blue / [alpha])!");
return;
}

F32 red, green, blue, alpha;

red = dAtof(Utility::mGetStringElement(argv[2], 0));
green = dAtof(Utility::mGetStringElement(argv[2], 1));
blue = dAtof(Utility::mGetStringElement(argv[2], 2));
alpha = colorCount > 3 ? dAtof(Utility::mGetStringElement(argv[2], 3)) : 1.0;

ColorF color = ColorF(red, green, blue, alpha);
object->setColor(color);
}
else
{
Con::warnf("GuiColorPopupCtrl::setColorF() - Invalid number of parameters!");
}
}

/*! Sets the base color displayed using integer values.
@param color The color to display as values between 0 and 255.
@return No return value.
*/
ConsoleMethodWithDocs(GuiColorPopupCtrl, setColorI, ConsoleVoid, 3, 3, "(color red / green / blue / [alpha])")
{
if (argc == 3)
{
const U32 colorCount = Utility::mGetStringElementCount(argv[2]);
if (colorCount != 4 && colorCount != 3)
{
Con::warnf("GuiColorPopupCtrl::setColorI() - Invalid color! Colors require three or four values (red / green / blue / [alpha])!");
return;
}

S32 red, green, blue, alpha;

red = dAtoi(Utility::mGetStringElement(argv[2], 0));
green = dAtoi(Utility::mGetStringElement(argv[2], 1));
blue = dAtoi(Utility::mGetStringElement(argv[2], 2));
alpha = colorCount > 3 ? dAtoi(Utility::mGetStringElement(argv[2], 3)) : 255;

ColorF color = ColorI(red, green, blue, alpha);
object->setColor(color);
}
else
{
Con::warnf("GuiColorPopupCtrl::setColorI() - Invalid number of parameters!");
}
}

ConsoleMethodGroupEndWithDocs(GuiColorPopupCtrl)

0 comments on commit 67dff45

Please sign in to comment.