Browse Source

ColorPopup Improvements

This further improves the color popup in the inspector by adding text boxes for the four color values. The inspector can now also take dedicated color picker profiles.
Peter Robinson 2 years ago
parent
commit
07f012f4e5

+ 4 - 0
editor/AssetAdmin/AssetInspector.cs

@@ -187,6 +187,10 @@ function AssetInspector::createInspector(%this)
 	ThemeManager.setProfile(%inspector, "checkboxProfile", "checkboxProfile");
 	ThemeManager.setProfile(%inspector, "buttonProfile", "buttonProfile");
 	ThemeManager.setProfile(%inspector, "tipProfile", "tooltipProfile");
+	ThemeManager.setProfile(%inspector, "colorPickerProfile", "colorPopupProfile");
+	ThemeManager.setProfile(%inspector, "colorPopupProfile", "colorPopupPanelProfile");
+	ThemeManager.setProfile(%inspector, "emptyProfile", "colorPopupPickerProfile");
+	ThemeManager.setProfile(%inspector, "colorPickerSelectorProfile", "colorPopupSelectorProfile");
 
 	return %inspector;
 }

+ 4 - 0
editor/GuiEditor/scripts/GuiEditorInspectorWindow.cs

@@ -48,6 +48,10 @@ function GuiEditorInspectorWindow::onAdd(%this)
 	ThemeManager.setProfile(%this.inspector, "checkboxProfile", "checkboxProfile");
 	ThemeManager.setProfile(%this.inspector, "buttonProfile", "buttonProfile");
 	ThemeManager.setProfile(%this.inspector, "tipProfile", "tooltipProfile");
+	ThemeManager.setProfile(%this.inspector, "colorPickerProfile", "colorPopupProfile");
+	ThemeManager.setProfile(%this.inspector, "colorPopupProfile", "colorPopupPanelProfile");
+	ThemeManager.setProfile(%this.inspector, "emptyProfile", "colorPopupPickerProfile");
+	ThemeManager.setProfile(%this.inspector, "colorPickerSelectorProfile", "colorPopupSelectorProfile");
 	%this.scroller.add(%this.inspector);
 
     %this.inspectList = new SimSet();

+ 28 - 0
engine/source/gui/editor/guiInspector.cc

@@ -103,6 +103,10 @@ void GuiInspector::initPersistFields()
 	addField("arrowProfile", TypeGuiProfile, Offset(mArrowProfile, GuiInspector));
 	addField("CheckboxProfile", TypeGuiProfile, Offset(mCheckboxProfile, GuiInspector));
 	addField("ButtonProfile", TypeGuiProfile, Offset(mButtonProfile, GuiInspector));
+	addField("ColorPopupProfile", TypeGuiProfile, Offset(mColorPopupProfile, GuiInspector));
+	addField("ColorPopupPanelProfile", TypeGuiProfile, Offset(mColorPopupPanelProfile, GuiInspector));
+	addField("ColorPopupPickerProfile", TypeGuiProfile, Offset(mColorPopupPickerProfile, GuiInspector));
+	addField("ColorPopupSelectorProfile", TypeGuiProfile, Offset(mColorPopupSelectorProfile, GuiInspector));
 
 	addField("constantThumbHeight", TypeBool, Offset(mUseConstantHeightThumb, GuiInspector));
 	addField("scrollBarThickness", TypeS32, Offset(mScrollBarThickness, GuiInspector));
@@ -156,6 +160,18 @@ bool GuiInspector::onWake()
 	if (mButtonProfile != NULL)
 		mButtonProfile->incRefCount();
 
+	if (mColorPopupProfile != NULL)
+		mColorPopupProfile->incRefCount();
+
+	if (mColorPopupPanelProfile != NULL)
+		mColorPopupPanelProfile->incRefCount();
+
+	if (mColorPopupPickerProfile != NULL)
+		mColorPopupPickerProfile->incRefCount();
+
+	if (mColorPopupSelectorProfile != NULL)
+		mColorPopupSelectorProfile->incRefCount();
+
 	return true;
 }
 
@@ -201,6 +217,18 @@ void GuiInspector::onSleep()
 
 	if (mButtonProfile != NULL)
 		mButtonProfile->decRefCount();
+
+	if (mColorPopupProfile != NULL)
+		mColorPopupProfile->decRefCount();
+
+	if (mColorPopupPanelProfile != NULL)
+		mColorPopupPanelProfile->decRefCount();
+
+	if (mColorPopupPickerProfile != NULL)
+		mColorPopupPickerProfile->decRefCount();
+
+	if (mColorPopupSelectorProfile != NULL)
+		mColorPopupSelectorProfile->decRefCount();
 }
 
 void GuiInspector::inspectPostApply()

+ 17 - 13
engine/source/gui/editor/guiInspector.h

@@ -105,19 +105,23 @@ public:
    inline void clearHiddenField() { mHiddenFieldList.clear(); };
    inline void addHiddenField(const char* fieldName) { mHiddenFieldList.push_back(fieldName); };
 
-   GuiControlProfile *mGroupPanelProfile;
-   GuiControlProfile *mGroupGridProfile;
-   GuiControlProfile *mLabelProfile;
-   GuiControlProfile *mTextEditProfile;
-   GuiControlProfile *mDropDownProfile;
-   GuiControlProfile *mDropDownItemProfile;
-   GuiControlProfile *mScrollProfile;
-   GuiControlProfile *mBackgroundProfile;
-   GuiControlProfile *mThumbProfile;
-   GuiControlProfile *mArrowProfile;
-   GuiControlProfile *mTrackProfile;
-   GuiControlProfile *mCheckboxProfile;
-   GuiControlProfile *mButtonProfile;
+   GuiControlProfile* mGroupPanelProfile;
+   GuiControlProfile* mGroupGridProfile;
+   GuiControlProfile* mLabelProfile;
+   GuiControlProfile* mTextEditProfile;
+   GuiControlProfile* mDropDownProfile;
+   GuiControlProfile* mDropDownItemProfile;
+   GuiControlProfile* mScrollProfile;
+   GuiControlProfile* mBackgroundProfile;
+   GuiControlProfile* mThumbProfile;
+   GuiControlProfile* mArrowProfile;
+   GuiControlProfile* mTrackProfile;
+   GuiControlProfile* mCheckboxProfile;
+   GuiControlProfile* mButtonProfile;
+   GuiControlProfile* mColorPopupProfile;
+   GuiControlProfile* mColorPopupPanelProfile;
+   GuiControlProfile* mColorPopupPickerProfile;
+   GuiControlProfile* mColorPopupSelectorProfile;
 
    bool onWake();
    void onSleep();

+ 150 - 19
engine/source/gui/editor/guiInspectorTypes.cc

@@ -339,34 +339,96 @@ void GuiInspectorTypeFileName::resize( const Point2I &newPosition, const Point2I
 //////////////////////////////////////////////////////////////////////////
 // GuiInspectorTypeColor (Base for ColorI/ColorF) 
 //////////////////////////////////////////////////////////////////////////
-IMPLEMENT_CONOBJECT(GuiInspectorTypeColor);
-
 GuiControl* GuiInspectorTypeColor::constructEditControl(S32 width)
 {
-	GuiColorPopupCtrl* retCtrl = new GuiColorPopupCtrl();
+	GuiControl* retCtrl = new GuiControl();
 
-   // If we couldn't construct the control, bail!
-   if( retCtrl == NULL )
-      return retCtrl;
+	// If we couldn't construct the control, bail!
+	if (retCtrl == NULL)
+		return retCtrl;
 
-   // Don't forget to register ourselves
-   registerEditControl( retCtrl );
+	// Let's make it look pretty.
+	retCtrl->setControlProfile(mGroup->mInspector->mBackgroundProfile);
+	retCtrl->mBounds.set(mGroup->mInspector->mControlOffset, Point2I(width - mGroup->mInspector->mControlOffset.x, 52));
 
-   const char* mCol = getData();
-   retCtrl->setField("BaseColor", mCol);
-   char szBuffer[512];
-   dSprintf(szBuffer, 512, "%d.apply(%d.%s());", getId(), retCtrl->getId(), mColorFunction);
-   retCtrl->setField("Command", szBuffer);
-   retCtrl->mBounds.set(mGroup->mInspector->mControlOffset, Point2I(32, 32));
+	// Don't forget to register ourselves
+	registerEditControl(retCtrl);
 
-   return retCtrl;
+	constructColorPopup(retCtrl);
+	constructColorEditBoxes(retCtrl, (width - 32) - mGroup->mInspector->mControlOffset.x);
+	finishControlConstruction();
+
+	const char* color = getData();
+	updateValue(color);
+
+	return retCtrl;
+}
+
+void GuiInspectorTypeColor::constructColorPopup(GuiControl* retCtrl)
+{
+	mColorPopup = new GuiColorPopupCtrl();
+	if (mColorPopup == NULL)
+		return;
+
+	mColorPopup->setControlProfile(mGroup->mInspector->mColorPopupProfile);
+	mColorPopup->setControlBackgroundProfile(mGroup->mInspector->mBackgroundProfile);
+	mColorPopup->setControlPopupProfile(mGroup->mInspector->mColorPopupPanelProfile);
+	mColorPopup->setControlPickerProfile(mGroup->mInspector->mColorPopupPickerProfile);
+	mColorPopup->setControlSelectorProfile(mGroup->mInspector->mColorPopupSelectorProfile);
+	registerEditControl(mColorPopup);
+
+	const char* mCol = getData();
+	mColorPopup->setField("BaseColor", mCol);
+	char szBuffer[512];
+	dSprintf(szBuffer, 512, "%d.apply(%d.%s());", getId(), mColorPopup->getId(), mColorFunction);
+	mColorPopup->setField("Command", szBuffer);
+	mColorPopup->mBounds.set(Point2I(0, 0), Point2I(32, 32));
+
+	retCtrl->addObject(mColorPopup);
 }
 
-void GuiInspectorTypeColor::updateValue(StringTableEntry newValue)
+void GuiInspectorTypeColor::constructColorEditBoxes(GuiControl* retCtrl, S32 width)
 {
-	GuiColorPopupCtrl*ctrl = dynamic_cast<GuiColorPopupCtrl*>(mEdit);
-   if (ctrl != NULL)
-      ctrl->setField("BaseColor", newValue);
+	const S32 w = mFloor(width / 4);
+	const S32 x = 32;
+	mRedEdit = constructColorEditBox(retCtrl, x, w, StringTable->insert("R", true));
+	mGreenEdit = constructColorEditBox(retCtrl, x + w, w, StringTable->insert("G", true));
+	mBlueEdit = constructColorEditBox(retCtrl, x + (2 * w), w, StringTable->insert("B", true));
+	mAlphaEdit = constructColorEditBox(retCtrl, x + (3 * w), w, StringTable->insert("A", true));
+
+	char szCommand[512];
+	dSprintf(szCommand, 512, "%d.apply(%d.getText() SPC %d.getText() SPC %d.getText() SPC %d.getText());",
+		getId(), mRedEdit->getId(), mGreenEdit->getId(), mBlueEdit->getId(), mAlphaEdit->getId());
+	mRedEdit->setField("AltCommand", szCommand);
+	mGreenEdit->setField("AltCommand", szCommand);
+	mBlueEdit->setField("AltCommand", szCommand);
+	mAlphaEdit->setField("AltCommand", szCommand);
+}
+
+GuiTextEditCtrl* GuiInspectorTypeColor::constructColorEditBox(GuiControl* retCtrl, S32 posX, S32 width, StringTableEntry text)
+{
+	GuiTextEditCtrl* textEdit = new GuiTextEditCtrl();
+	registerEditControl(textEdit);
+
+	GuiControl* label = new GuiControl();
+	registerEditControl(label);
+
+	textEdit->setControlProfile(mGroup->mInspector->mTextEditProfile);
+	label->setControlProfile(mGroup->mInspector->mLabelProfile);
+
+	label->resize(Point2I(posX, 32), Point2I(width, 20));
+	label->setField("text", text);
+	label->setField("align", "center");
+	label->setField("fontSizeAdjust", "0.8");
+
+	textEdit->resize(Point2I(posX, 0), Point2I(width, 30));
+	textEdit->setInputMode(GuiTextEditCtrl::InputMode::Number);
+	textEdit->setField("align", "center");
+
+	retCtrl->addObject(label);
+	retCtrl->addObject(textEdit);
+
+	return textEdit;
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -386,6 +448,31 @@ GuiInspectorTypeColorI::GuiInspectorTypeColorI()
    mColorFunction = StringTable->insert("getColorI");
 }
 
+void GuiInspectorTypeColorI::updateValue(StringTableEntry newValue)
+{
+	if (Utility::mGetStringElementCount(newValue) != 4)
+	{
+		return;
+	}
+
+	S32 red = dAtoi(Utility::mGetStringElement(newValue, 0));
+	S32 green = dAtoi(Utility::mGetStringElement(newValue, 1));
+	S32 blue = dAtoi(Utility::mGetStringElement(newValue, 2));
+	S32 alpha = dAtoi(Utility::mGetStringElement(newValue, 3));
+
+	ColorF color = ColorI(red, green, blue, alpha);
+	mColorPopup->setColor(color);
+
+	mRedEdit->setText(Utility::mGetStringElement(newValue, 0));
+	mGreenEdit->setText(Utility::mGetStringElement(newValue, 1));
+	mBlueEdit->setText(Utility::mGetStringElement(newValue, 2));
+	mAlphaEdit->setText(Utility::mGetStringElement(newValue, 3));
+}
+
+void GuiInspectorTypeColorI::finishControlConstruction()
+{
+}
+
 //////////////////////////////////////////////////////////////////////////
 // GuiInspectorTypeColorF
 //////////////////////////////////////////////////////////////////////////
@@ -403,6 +490,46 @@ GuiInspectorTypeColorF::GuiInspectorTypeColorF()
    mColorFunction = StringTable->insert("getColorF");
 }
 
+void GuiInspectorTypeColorF::updateValue(StringTableEntry newValue)
+{
+	if (Utility::mGetStringElementCount(newValue) != 4)
+	{
+		return;
+	}
+
+	F32 red = mFabs(mRound(100 * dAtof(Utility::mGetStringElement(newValue, 0))) / 100.0f);
+	F32 green = mFabs(mRound(100 * dAtof(Utility::mGetStringElement(newValue, 1))) / 100.0f);
+	F32 blue = mFabs(mRound(100 * dAtof(Utility::mGetStringElement(newValue, 2))) / 100.0f);
+	F32 alpha = mFabs(mRound(100 * dAtof(Utility::mGetStringElement(newValue, 3))) / 100.0f);
+
+	ColorF color = ColorF(red, green, blue, alpha);
+	mColorPopup->setColor(color);
+
+	char redText[10];
+	dSprintf(redText, 10, "%.2f", red);
+	mRedEdit->setText(redText);
+
+	char greenText[10];
+	dSprintf(greenText, 10, "%.2f", green);
+	mGreenEdit->setText(greenText);
+
+	char blueText[10];
+	dSprintf(blueText, 10, "%.2f", blue);
+	mBlueEdit->setText(blueText);
+
+	char alphaText[10];
+	dSprintf(alphaText, 10, "%.2f", alpha);
+	mAlphaEdit->setText(alphaText);
+}
+
+void GuiInspectorTypeColorF::finishControlConstruction()
+{
+	mRedEdit->setInputMode(GuiTextEditCtrl::InputMode::Decimal);
+	mGreenEdit->setInputMode(GuiTextEditCtrl::InputMode::Decimal);
+	mBlueEdit->setInputMode(GuiTextEditCtrl::InputMode::Decimal);
+	mAlphaEdit->setInputMode(GuiTextEditCtrl::InputMode::Decimal);
+}
+
 
 //////////////////////////////////////////////////////////////////////////
 // TypeSimObjectPtr GuiInspectorField Class
@@ -596,6 +723,10 @@ void GuiInspectorTypeDualValue::constructEditControlChildren(GuiControl* retCtrl
 	S32 labelWidth = 20;
 	mLabelX->setExtent(Point2I(labelWidth, 30));
 	mLabelY->setExtent(Point2I(labelWidth, 30));
+	mLabelX->setField("align", "center");
+	mLabelX->setField("vAlign", "middle");
+	mLabelY->setField("align", "center");
+	mLabelY->setField("vAlign", "middle");
 	mLabelX->setField("text", "X");
 	mLabelY->setField("text", "Y");
 

+ 15 - 3
engine/source/gui/editor/guiInspectorTypes.h

@@ -176,16 +176,24 @@ class GuiInspectorTypeColor : public GuiInspectorField
 {
 private:
    typedef GuiInspectorField Parent;
+protected:
+	GuiColorPopupCtrl* mColorPopup;
+	GuiTextEditCtrl* mRedEdit;
+	GuiTextEditCtrl* mGreenEdit;
+	GuiTextEditCtrl* mBlueEdit;
+	GuiTextEditCtrl* mAlphaEdit;
+
+	void constructColorPopup(GuiControl* retCtrl);
+	void constructColorEditBoxes(GuiControl* retCtrl, S32 width);
+	GuiTextEditCtrl* constructColorEditBox(GuiControl* retCtrl, S32 posX, S32 width, StringTableEntry text);
 public:
-   DECLARE_CONOBJECT(GuiInspectorTypeColor);
-
    StringTableEntry  mColorFunction;
 
    //////////////////////////////////////////////////////////////////////////
    // Override able methods for custom edit fields
    //////////////////////////////////////////////////////////////////////////
    virtual GuiControl*        constructEditControl(S32 width);
-   virtual void               updateValue(StringTableEntry newValue);
+   virtual void               finishControlConstruction() = 0;
 };
 
 //////////////////////////////////////////////////////////////////////////
@@ -200,6 +208,8 @@ public:
 
    DECLARE_CONOBJECT(GuiInspectorTypeColorI);
    static void consoleInit();
+   void updateValue(StringTableEntry newValue);
+   void finishControlConstruction();
 };
 
 //////////////////////////////////////////////////////////////////////////
@@ -214,6 +224,8 @@ public:
 
    DECLARE_CONOBJECT(GuiInspectorTypeColorF);
    static void consoleInit();
+   void updateValue(StringTableEntry newValue);
+   void finishControlConstruction();
 };
 
 //////////////////////////////////////////////////////////////////////////

+ 2 - 1
engine/source/gui/guiColorPopupCtrl.cc

@@ -129,7 +129,7 @@ GuiColorPopupCtrl::GuiColorPopupCtrl()
 
 	mContent = new GuiColorPopupContentCtrl();
 	AssertFatal(mContent, "GuiColorPopupCtrl: Failed to initialize GuiControl!");
-	mContent->setField("profile", "GuiDefaultProfile");
+	mContent->setField("profile", "GuiPanelProfile");
 	mPopupProfile = mContent->mProfile;
 	mPopupProfile->incRefCount();
 	mContent->setExtent(mPopupSize);
@@ -479,6 +479,7 @@ void GuiColorPopupCtrl::setColor(const ColorF& theColor)
 	mBaseColor.red = theColor.red;
 	mBaseColor.green = theColor.green;
 	mBaseColor.blue = theColor.blue;
+	mBaseColor.alpha = theColor.alpha;
 }
 
 const char* GuiColorPopupCtrl::getScriptValue()

+ 1 - 1
engine/source/gui/guiControl.cc

@@ -250,8 +250,8 @@ void GuiControl::initPersistFields()
    addField("align", TypeEnum, Offset(mAlignment, GuiControl), 1, &gAlignCtrlTable);
    addField("vAlign", TypeEnum, Offset(mVAlignment, GuiControl), 1, &gVAlignCtrlTable);
    addField("fontSizeAdjust", TypeF32, Offset(mFontSizeAdjust, GuiControl), "A decimal value that is multiplied with the profile's fontSize to determine the control's actual font size.");
-   addField("fontColor", TypeColorI, Offset(mFontColor, GuiControl), "A color to override the font color of the control's profile. OverrideFontColor must be set to true for this to work.");
    addField("overrideFontColor", TypeBool, Offset(mOverrideFontColor, GuiControl), "If true, the control's fontColor will override the profile's font color.");
+   addField("fontColor", TypeColorI, Offset(mFontColor, GuiControl), "A color to override the font color of the control's profile. OverrideFontColor must be set to true for this to work.");
    endGroup("Text");
 }