Ver Fonte

Center Positioning Improvements

Peter Robinson há 3 anos atrás
pai
commit
2b0efd494f

+ 9 - 0
engine/source/gui/containers/guiChainCtrl.cc

@@ -81,6 +81,15 @@ void GuiChainCtrl::resize(const Point2I &newPosition, const Point2I &newExtent)
 
 
 void GuiChainCtrl::onChildAdded(GuiControl *child)
 void GuiChainCtrl::onChildAdded(GuiControl *child)
 {
 {
+	//Ensure the child isn't positioned to the center
+	if (child->getHorizSizing() == horizResizeCenter && !mIsVertical)
+	{
+		child->setHorizSizing(horizResizeLeft);
+	}
+	if (child->getVertSizing() == vertResizeCenter && mIsVertical)
+	{
+		child->setVertSizing(vertResizeTop);
+	}
 	Parent::onChildAdded(child);
 	Parent::onChildAdded(child);
 	calculateExtent();
 	calculateExtent();
 }
 }

+ 9 - 0
engine/source/gui/containers/guiGridCtrl.cc

@@ -321,6 +321,15 @@ Point2F GuiGridCtrl::GetGridItemHeight(const S32 totalArea, const S32 maxChainLe
 
 
 void GuiGridCtrl::onChildAdded(GuiControl *child)
 void GuiGridCtrl::onChildAdded(GuiControl *child)
 {
 {
+	//Ensure the child isn't positioned to the center
+	if (child->getHorizSizing() == horizResizeCenter)
+	{
+		child->setHorizSizing(horizResizeLeft);
+	}
+	if (child->getVertSizing() == vertResizeCenter)
+	{
+		child->setVertSizing(vertResizeTop);
+	}
 	resize(getPosition(), getExtent());
 	resize(getPosition(), getExtent());
 }
 }
 
 

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

@@ -416,13 +416,28 @@ void GuiControl::resize(const Point2I &newPosition, const Point2I &newExtent)
 
 
 	Point2I oldExtent = mBounds.extent;
 	Point2I oldExtent = mBounds.extent;
 
 
+    //force center if using center positioning
+    Point2I actualNewPosition = Point2I(newPosition);
+    GuiControl* parent = getParent();
+    if (parent)
+    {
+        if (mHorizSizing == horizResizeCenter)
+        {
+            actualNewPosition.x = (parent->mBounds.extent.x - actualNewExtent.x) / 2;
+        }
+        if (mVertSizing == vertResizeCenter)
+        {
+            actualNewPosition.y = (parent->mBounds.extent.y - actualNewExtent.y) / 2;
+        }
+    }
+
    // only do the child control resizing stuff if you really need to.
    // only do the child control resizing stuff if you really need to.
    bool extentChanged = (actualNewExtent != oldExtent);
    bool extentChanged = (actualNewExtent != oldExtent);
 
 
    if (extentChanged) {
    if (extentChanged) {
       //call set update both before and after
       //call set update both before and after
       setUpdate();
       setUpdate();
-      mBounds.set(newPosition, actualNewExtent);
+      mBounds.set(actualNewPosition, actualNewExtent);
       iterator i;
       iterator i;
       for(i = begin(); i != end(); i++)
       for(i = begin(); i != end(); i++)
       {
       {
@@ -430,7 +445,6 @@ void GuiControl::resize(const Point2I &newPosition, const Point2I &newExtent)
          ctrl->parentResized(oldExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB), actualNewExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB));
          ctrl->parentResized(oldExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB), actualNewExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB));
       }
       }
 
 
-      GuiControl *parent = getParent();
       if (parent)
       if (parent)
          parent->childResized(this);
          parent->childResized(this);
       setUpdate();
       setUpdate();
@@ -441,7 +455,7 @@ void GuiControl::resize(const Point2I &newPosition, const Point2I &newExtent)
 	  }
 	  }
    }
    }
    else {
    else {
-      mBounds.point = newPosition;
+      mBounds.point = actualNewPosition;
    }
    }
 }
 }
 void GuiControl::setPosition( const Point2I &newPosition )
 void GuiControl::setPosition( const Point2I &newPosition )

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

@@ -327,6 +327,12 @@ public:
     inline void				 setTextExtend(const bool extend) { mTextExtend = extend; }
     inline void				 setTextExtend(const bool extend) { mTextExtend = extend; }
     inline bool				 getTextExtend() { return mTextExtend; }
     inline bool				 getTextExtend() { return mTextExtend; }
 
 
+    const horizSizingOptions getHorizSizing() { return static_cast<horizSizingOptions>(mHorizSizing); }
+    const vertSizingOptions  getVertSizing() { return static_cast<vertSizingOptions>(mVertSizing); }
+
+    void                     setHorizSizing(const horizSizingOptions sizing) { mHorizSizing = sizing; }
+    void                     setVertSizing(const vertSizingOptions sizing) { mVertSizing = sizing; }
+
 	// Text Property Accessors
 	// Text Property Accessors
 	static bool setTextProperty(void* obj, const char* data) { static_cast<GuiControl*>(obj)->setText(data); return false; }
 	static bool setTextProperty(void* obj, const char* data) { static_cast<GuiControl*>(obj)->setText(data); return false; }
 	static const char* getTextProperty(void* obj, const char* data) { return static_cast<GuiControl*>(obj)->getText(); }
 	static const char* getTextProperty(void* obj, const char* data) { return static_cast<GuiControl*>(obj)->getText(); }