Browse Source

Inspector Color Popup

This change causes the Inspector to use the color popup for colors.
Peter Robinson 2 years ago
parent
commit
c7a8dc6f20

+ 4 - 4
engine/source/gui/editor/guiInspectorTypes.cc

@@ -343,7 +343,7 @@ IMPLEMENT_CONOBJECT(GuiInspectorTypeColor);
 
 GuiControl* GuiInspectorTypeColor::constructEditControl(S32 width)
 {
-	GuiColorPickerCtrl* retCtrl = new GuiColorPickerCtrl();
+	GuiColorPopupCtrl* retCtrl = new GuiColorPopupCtrl();
 
    // If we couldn't construct the control, bail!
    if( retCtrl == NULL )
@@ -355,16 +355,16 @@ GuiControl* GuiInspectorTypeColor::constructEditControl(S32 width)
    const char* mCol = getData();
    retCtrl->setField("BaseColor", mCol);
    char szBuffer[512];
-   dSprintf(szBuffer, 512, "%s(\"%s\", \"%d.apply\");", mColorFunction, getData(), getId());
+   dSprintf(szBuffer, 512, "%d.apply(%d.%s());", getId(), retCtrl->getId(), mColorFunction);
    retCtrl->setField("Command", szBuffer);
-   retCtrl->mBounds.set(mGroup->mInspector->mControlOffset, Point2I(width - mGroup->mInspector->mControlOffset.x, 24));
+   retCtrl->mBounds.set(mGroup->mInspector->mControlOffset, Point2I(32, 32));
 
    return retCtrl;
 }
 
 void GuiInspectorTypeColor::updateValue(StringTableEntry newValue)
 {
-   GuiColorPickerCtrl *ctrl = dynamic_cast<GuiColorPickerCtrl*>(mEdit);
+	GuiColorPopupCtrl*ctrl = dynamic_cast<GuiColorPopupCtrl*>(mEdit);
    if (ctrl != NULL)
       ctrl->setField("BaseColor", newValue);
 }

+ 2 - 0
engine/source/gui/editor/guiInspectorTypes.h

@@ -71,6 +71,8 @@
 #include "gui/guiColorPickerCtrl.h"
 #endif // !_GUICOLORPICKERCTRL_H_
 
+#include "gui/guiColorPopupCtrl.h"
+
 
 
 //////////////////////////////////////////////////////////////////////////

+ 18 - 6
engine/source/gui/guiColorPopupCtrl.cc

@@ -283,12 +283,6 @@ void GuiColorPopupCtrl::onAction() //called when the button is clicked.
 	setUpdate();
 }
 
-void GuiColorPopupCtrl::itemSelected()
-{
-	if (mConsoleCommand[0])
-		Con::evaluate(mConsoleCommand, false);
-}
-
 void GuiColorPopupCtrl::openColorPopup()
 {
 	if (mIsOpen)
@@ -390,6 +384,9 @@ void GuiColorPopupCtrl::closeColorPopup()
 
 	if (isMethod("onClose"))
 		Con::executef(this, 1, "onClose");
+
+	if (mConsoleCommand[0])
+		Con::evaluate(mConsoleCommand, false);
 }
 
 bool GuiColorPopupCtrl::onWake()
@@ -482,4 +479,19 @@ void GuiColorPopupCtrl::setColor(const ColorF& theColor)
 	mBaseColor.red = theColor.red;
 	mBaseColor.green = theColor.green;
 	mBaseColor.blue = theColor.blue;
+}
+
+const char* GuiColorPopupCtrl::getScriptValue()
+{
+	static char temp[256];
+	ColorF color = getValue();
+	dSprintf(temp, 256, "%g %g %g %g", color.red, color.green, color.blue, color.alpha);
+	return temp;
+}
+  
+void GuiColorPopupCtrl::setScriptValue(const char* value)
+{
+	ColorF newValue;
+	dSscanf(value, "%g %g %g %g", &newValue.red, &newValue.green, &newValue.blue, &newValue.alpha);
+	setValue(newValue);
 }

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

@@ -110,7 +110,6 @@ public:
 
 	bool onKeyDown(const GuiEvent& event);
 	virtual void onAction();
-	void itemSelected();
 	void openColorPopup();
 	void closeColorPopup();
 
@@ -125,6 +124,8 @@ public:
 	void setAlpha(const F32 alpha) { mBaseColor.alpha = alpha; }
 	void setValue(ColorF& value) { mBaseColor = value; }
 	ColorF getValue() { return mBaseColor; }
+	const char* getScriptValue();
+	void setScriptValue(const char* value);
 
 	DECLARE_CONOBJECT(GuiColorPopupCtrl);
 };

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

@@ -86,4 +86,30 @@ ConsoleMethodWithDocs(GuiColorPopupCtrl, setSelectorProfile, ConsoleVoid, 3, 3,
 		object->setControlSelectorProfile(profile);
 }
 
+/*! Gets the selected color as floating point values.
+	@return The selected color as four floating point values between 0 and 1.
+*/
+ConsoleMethodWithDocs(GuiColorPopupCtrl, getColorF, ConsoleString, 2, 2, ())
+{
+	ColorF color = object->getValue();
+
+	// Format stock color.
+	char* returnBuffer = Con::getReturnBuffer(256);
+	dSprintf(returnBuffer, 256, "%g %g %g %g", color.red, color.green, color.blue, color.alpha);
+	return(returnBuffer);
+}
+
+/*! Gets the selected color as integer values.
+	@return The selected color as four integer values between 0 and 255.
+*/
+ConsoleMethodWithDocs(GuiColorPopupCtrl, getColorI, ConsoleString, 2, 2, ())
+{
+	const ColorI& color = object->getValue();
+
+	// Format stock color.
+	char* returnBuffer = Con::getReturnBuffer(256);
+	dSprintf(returnBuffer, 256, "%d %d %d %d", color.red, color.green, color.blue, color.alpha);
+	return(returnBuffer);
+}
+
 ConsoleMethodGroupEndWithDocs(GuiColorPopupCtrl)