Browse Source

GuiChainCtrl Improved Editor Support

As a proof-of-concept, I've improved handling for the chain control so that it does some special rendering when in the editor state. I've also improved the ability for a control to test to see if it's actually inside the root object of the editor.
Peter Robinson 2 years ago
parent
commit
40c689d731

+ 7 - 0
editor/EditorCore/Themes/BaseTheme/BaseTheme.cs

@@ -2029,6 +2029,13 @@ function BaseTheme::makeGuiEditorProfile(%this)
 
 		tab = false;
 		canKeyFocus = true;
+
+		fontType = %this.font[3];
+		fontDirectory = %this.fontDirectory;
+		fontSize = 22;
+		fontColor = %this.color1;
+		align = "center";
+		vAlign = "middle";
 	};
 }
 

+ 2 - 3
editor/GuiEditor/scripts/GuiEditorBrain.cs

@@ -7,9 +7,8 @@ function GuiEditorBrain::onAdd(%this)
 
 function GuiEditorBrain::onControlDragged(%this, %payload, %position)
 {
-	%pos = VectorSub(%position, %this.root.getGlobalPosition());
-	%x = getWord(%pos, 0);
-	%y = getWord(%pos, 1);
+	%x = getWord(%position, 0);
+	%y = getWord(%position, 1);
 	%target = GuiEditor.content.findHitControl(%x, %y);
 
 	while(! %target.isContainer )

+ 43 - 7
engine/source/gui/containers/guiChainCtrl.cc

@@ -23,6 +23,7 @@
 #include "console/consoleTypes.h"
 #include "console/console.h"
 #include "gui/containers/guiChainCtrl.h"
+#include "gui/editor/guiEditCtrl.h"
 
 #include "guiChainCtrl_ScriptBinding.h"
 
@@ -35,6 +36,7 @@ GuiChainCtrl::GuiChainCtrl()
 	mIsContainer = true;
 	mChildSpacing = 0;
 	mIsVertical = true;
+	mBounds.extent.set(140, mEditOpenSpace);
 }
 
 //------------------------------------------------------------------------------
@@ -58,7 +60,7 @@ void GuiChainCtrl::inspectPreApply()
 
 void GuiChainCtrl::inspectPostApply()
 {
-	if (mPrevIsVertical != mIsVertical && smDesignTime)
+	if (mPrevIsVertical != mIsVertical && isEditMode())
 	{
 		//Since we're in the editor, we'll swap x and y, then calculateExtent will fix one of them.
 		iterator i;
@@ -81,19 +83,19 @@ void GuiChainCtrl::inspectPostApply()
 
 void GuiChainCtrl::childResized(GuiControl *child)
 {
-	calculateExtent(smDesignTime);
+	calculateExtent(isEditMode());
 	Parent::childResized(child);
 }
 
 void GuiChainCtrl::childMoved(GuiControl* child)
 {
-	calculateExtent(smDesignTime);
+	calculateExtent(isEditMode());
 	Parent::childMoved(child);
 }
 
 void GuiChainCtrl::childrenReordered()
 {
-	calculateExtent(smDesignTime);
+	calculateExtent(isEditMode());
 	Parent::childrenReordered();
 }
 
@@ -126,7 +128,7 @@ void GuiChainCtrl::onChildAdded(GuiControl *child)
 		child->setVertSizing(vertResizeTop);
 	}
 
-	if (smDesignTime)
+	if (isEditMode())
 	{
 		child->mBounds.point = Point2I::Zero;
 	}
@@ -149,9 +151,9 @@ void GuiChainCtrl::calculateExtent(bool holdLength)
 	S32 length = positionChildren(innerRect);
 	S32 oldLength = mIsVertical ? innerRect.extent.y : innerRect.extent.x;
 
-	if (smDesignTime)
+	if (isEditMode())
 	{
-		length += 20;//This gives some space to add new controls.
+		length += mEditOpenSpace;//This gives some space to add new controls.
 	}
 
 	if (holdLength && oldLength > length)
@@ -210,4 +212,38 @@ S32 GuiChainCtrl::positionChildren(RectI &innerRect)
 	}
 
 	return length;
+}
+
+void GuiChainCtrl::onRender(Point2I offset, const RectI& updateRect)
+{
+	Parent::onRender(offset, updateRect);
+
+	if (isEditMode())
+	{
+		GuiEditCtrl* edit = GuiControl::smEditorHandle;
+		const GuiControl* addSet = edit->getAddSet();
+		SimSet& selectSet = edit->getSelectedSet();
+		if(this == addSet || selectSet.isMember(this))
+		{
+			ColorI fill = edit->getEditorColor();
+			fill.alpha = 100;
+
+			RectI rect;
+			if (mIsVertical)
+			{
+				rect = RectI(0, mBounds.extent.y - mEditOpenSpace, mBounds.extent.x, mEditOpenSpace);
+			}
+			else 
+			{
+				rect = RectI(mBounds.extent.x - mEditOpenSpace, 0, mEditOpenSpace, mBounds.extent.y);
+			}
+			rect.point = localToGlobalCoord(rect.point);
+			dglDrawRectFill(rect, fill);
+			dglSetBitmapModulation(getFontColor(edit->mProfile, NormalState));
+			F32 tempAdjust = mFontSizeAdjust;
+			mFontSizeAdjust = 1.5f;
+			renderText(rect.point, rect.extent, "+", edit->mProfile);
+			mFontSizeAdjust = tempAdjust;
+		}
+	}
 }

+ 2 - 0
engine/source/gui/containers/guiChainCtrl.h

@@ -18,6 +18,7 @@ class GuiChainCtrl : public GuiControl
 private:
 	typedef GuiControl Parent;
 	bool mPrevIsVertical;
+	const S32 mEditOpenSpace = 30;
 
 protected:
 	S32 mChildSpacing;
@@ -37,6 +38,7 @@ public:
 	void inspectPostApply();
 	void onChildAdded(GuiControl *child);
 	void onChildRemoved(SimObject *child);
+	void onRender(Point2I offset, const RectI& updateRect);
 
 	inline void setChildSpacing(S32 space) { mChildSpacing = space; }
 	inline S32 getChildSpacing() { return mChildSpacing; }

+ 1 - 1
engine/source/gui/containers/guiGridCtrl.cc

@@ -149,7 +149,7 @@ void GuiGridCtrl::resize(const Point2I &newPosition, const Point2I &newExtent)
 	Point2I actualNewPosition = Point2I(newPosition);
 	if(mIsExtentDynamic)
 	{
-		if(smDesignTime)
+		if(isEditMode())
 		{
 			mRunningChainHeight += 20; 
 		}

+ 4 - 2
engine/source/gui/editor/guiEditCtrl.h

@@ -71,6 +71,7 @@ class GuiEditCtrl : public GuiControl
 
    void select(GuiControl *ctrl);
    void setRoot(GuiControl *ctrl);
+   GuiControl* getRoot() { return mContentControl; }
    void setEditMode(bool value);
    S32 getSizingHitKnobs(const Point2I &pt, const RectI &box);
    void getDragRect(RectI &b);
@@ -99,9 +100,9 @@ class GuiEditCtrl : public GuiControl
 
 
    const Vector<GuiControl *> *getSelected() const { return &mSelectedControls; }
-   const SimSet& getSelectedSet() { updateSelectedSet(); return mSelectedSet; }
+   SimSet& getSelectedSet() { updateSelectedSet(); return mSelectedSet; }
    const SimGroup& getTrash() { return mTrash; }
-   const GuiControl *getAddSet() const { return mCurrentAddSet; }; //JDD
+   const GuiControl* getAddSet() const { return mCurrentAddSet; };
 
    bool onKeyDown(const GuiEvent &event);
    void onTouchDown(const GuiEvent &event);
@@ -138,6 +139,7 @@ class GuiEditCtrl : public GuiControl
    bool hasSnapToGrid() { return mUseGridSnap; }
    S32 getGridSize() { return mGridSnap.x; }
    void moveSelectionToCtrl(GuiControl*);
+   ColorI getEditorColor() { return mProfile->getFillColor(DisabledState); }
 };
 
 #endif //_GUI_EDIT_CTRL_H

+ 7 - 0
engine/source/gui/guiCanvas.cc

@@ -1529,3 +1529,10 @@ void GuiCanvas::setFirstResponder( GuiControl* newResponder )
     if ( oldResponder && ( oldResponder != mFirstResponder ) )
         oldResponder->onLoseFirstResponder();
 }
+
+bool GuiCanvas::isEditMode()
+{
+	//If we've walked up the chain all the way to canvas and haven't found the 
+	//editor then we are not in edit mode.
+	return false;
+}

+ 2 - 0
engine/source/gui/guiCanvas.h

@@ -401,6 +401,8 @@ public:
    /// @param   firstResponder    Control to designate as first responder
    virtual void setFirstResponder(GuiControl *firstResponder);
    /// @}
+
+   virtual bool isEditMode();
 };
 
 extern GuiCanvas *Canvas;

+ 24 - 3
engine/source/gui/guiControl.cc

@@ -36,6 +36,7 @@
 #include "collection/vector.h"
 #include "2d/core/Utility.h"
 #include "gui/containers/guiScrollCtrl.h"
+#include "gui/editor/guiEditCtrl.h"
 
 #include <sstream>
 #include <iostream>
@@ -350,7 +351,7 @@ GuiCanvas *GuiControl::getRoot()
 
 void GuiControl::inspectPreApply()
 {
-   if(smDesignTime && smEditorHandle)
+   if(isEditMode())
       smEditorHandle->controlInspectPreApply(this);
    
    // The canvas never sleeps
@@ -371,7 +372,7 @@ void GuiControl::inspectPostApply()
       onWake();
    }
    
-   if(smDesignTime && smEditorHandle)
+   if(isEditMode())
       smEditorHandle->controlInspectPostApply(this);
 }
 
@@ -2056,7 +2057,7 @@ void GuiControl::renderLineList(const Point2I& offset, const Point2I& extent, co
 		}
 
 		Point2I start = Point2I(0, 0);
-		F32 rotation;
+		F32 rotation = 0.0f;
 		if (rot == tRotateNone)
 		{
             start.x += offsetX;
@@ -2303,4 +2304,24 @@ VertAlignmentType GuiControl::getVertAlignmentType(GuiControlProfile* profile)
 const ColorI& GuiControl::getFontColor(GuiControlProfile* profile, const GuiControlState state)
 {
     return mOverrideFontColor ? mFontColor : profile->getFontColor(state);
+}
+
+bool GuiControl::isEditMode()
+{
+	if (smDesignTime && smEditorHandle)
+	{
+		GuiEditCtrl* edit = GuiControl::smEditorHandle;
+		if (this == edit->getRoot())
+		{
+			return true;
+		}
+
+		//work up the parent chain to see if one of the parents is the edit root
+		GuiControl* parent = getParent();
+		if (parent)
+		{
+			return parent->isEditMode();
+		}
+		return false;
+	}
 }

+ 2 - 0
engine/source/gui/guiControl.h

@@ -159,6 +159,8 @@ public:
     static GuiEditCtrl *smEditorHandle; ///< static GuiEditCtrl pointer that gives controls access to editor-NULL if editor is closed
     /// @}
 
+	virtual bool isEditMode();
+
     /// @name Keyboard Input
     /// @{
     GuiControl* mFirstResponder;

+ 15 - 0
engine/source/sim/simSet.cc

@@ -107,6 +107,21 @@ void SimSet::callOnChildren( const char * method, S32 argc, const char *argv[],
    }
 }
 
+bool SimSet::isMember(SimObject* obj)
+{
+	lock();
+	for (SimSet::iterator i = begin(); i != end(); i++)
+	{
+		if (*i == obj)
+		{
+			unlock();
+			return true;
+		}
+	}
+	unlock();
+	return false;
+}
+
 bool SimSet::reOrder( SimObject *obj, SimObject *target )
 {
    MutexHandle handle;

+ 1 - 0
engine/source/sim/simSet.h

@@ -151,6 +151,7 @@ public:
        return false;
    }
 
+   bool isMember(SimObject* obj);
    virtual bool reOrder( SimObject *obj, SimObject *target=0 );
    SimObject* at(S32 index) const { return objectList.at(index); }
 

+ 1 - 12
engine/source/sim/simSet_ScriptBinding.h

@@ -367,18 +367,7 @@ ConsoleMethodWithDocs(SimSet, isMember, ConsoleBool, 3, 3, (object))
       return false;
    }
 
-   object->lock();
-   for(SimSet::iterator i = object->begin(); i != object->end(); i++)
-   {
-      if(*i == testObject)
-      {
-         object->unlock();
-         return true;
-      }
-   }
-   object->unlock();
-
-   return false;
+   return object->isMember(testObject);
 }
 
 /*! Returns the object with given internal name