Browse Source

Changes to guiColorPopupCtrl

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.
Peter Robinson 1 year ago
parent
commit
67dff451a3

+ 8 - 9
engine/source/gui/guiColorPopupCtrl.cc

@@ -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);
@@ -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();
@@ -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);

+ 0 - 1
engine/source/gui/guiColorPopupCtrl.h

@@ -82,7 +82,6 @@ private:
 	ColorF mBaseColor;
 	bool mIsOpen;
 	Point2I mPopupSize;
-	S32 mBlendHeight;
 	S32 mBarHeight;
 	bool mShowAlphaBar;
 

+ 62 - 0
engine/source/gui/guiColorPopupCtrl_ScriptBinding.h

@@ -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)