|
@@ -58,9 +58,10 @@ GuiControl::GuiControl()
|
|
{
|
|
{
|
|
mLayer = 0;
|
|
mLayer = 0;
|
|
mBounds.set(0, 0, 64, 64);
|
|
mBounds.set(0, 0, 64, 64);
|
|
|
|
+ mStoredExtent.set(0, 0);
|
|
mRenderInsetLT.set(0, 0);
|
|
mRenderInsetLT.set(0, 0);
|
|
mRenderInsetRB.set(0, 0);
|
|
mRenderInsetRB.set(0, 0);
|
|
- mMinExtent.set(8, 2); // Set to 8x2 so GuiControl can be used as a separator.
|
|
|
|
|
|
+ mMinExtent.set(0, 0);
|
|
|
|
|
|
mProfile = NULL;
|
|
mProfile = NULL;
|
|
|
|
|
|
@@ -164,8 +165,8 @@ void GuiControl::initPersistFields()
|
|
addField("VertSizing", TypeEnum, Offset(mVertSizing, GuiControl), 1, &gVertSizingTable);
|
|
addField("VertSizing", TypeEnum, Offset(mVertSizing, GuiControl), 1, &gVertSizingTable);
|
|
|
|
|
|
addField("Position", TypePoint2I, Offset(mBounds.point, GuiControl));
|
|
addField("Position", TypePoint2I, Offset(mBounds.point, GuiControl));
|
|
- addField("Extent", TypePoint2I, Offset(mBounds.extent, GuiControl));
|
|
|
|
- addField("MinExtent", TypePoint2I, Offset(mMinExtent, GuiControl));
|
|
|
|
|
|
+ addProtectedField("Extent", TypePoint2I, Offset(mBounds.extent, GuiControl), &setExtentFn, &defaultProtectedGetFn, "The size of the control writen as width and height.");
|
|
|
|
+ addProtectedField("MinExtent", TypePoint2I, Offset(mMinExtent, GuiControl), &setMinExtentFn, &defaultProtectedGetFn, &writeMinExtentFn, "The extent will not shrink below this size.");
|
|
addField("canSave", TypeBool, Offset(mCanSave, GuiControl));
|
|
addField("canSave", TypeBool, Offset(mCanSave, GuiControl));
|
|
addField("Visible", TypeBool, Offset(mVisible, GuiControl));
|
|
addField("Visible", TypeBool, Offset(mVisible, GuiControl));
|
|
addDepricatedField("Modal");
|
|
addDepricatedField("Modal");
|
|
@@ -353,13 +354,13 @@ void GuiControl::resize(const Point2I &newPosition, const Point2I &newExtent)
|
|
if (extentChanged) {
|
|
if (extentChanged) {
|
|
//call set update both before and after
|
|
//call set update both before and after
|
|
setUpdate();
|
|
setUpdate();
|
|
|
|
+ mBounds.set(newPosition, actualNewExtent);
|
|
iterator i;
|
|
iterator i;
|
|
for(i = begin(); i != end(); i++)
|
|
for(i = begin(); i != end(); i++)
|
|
{
|
|
{
|
|
GuiControl *ctrl = static_cast<GuiControl *>(*i);
|
|
GuiControl *ctrl = static_cast<GuiControl *>(*i);
|
|
ctrl->parentResized(oldExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB), actualNewExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB));
|
|
ctrl->parentResized(oldExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB), actualNewExtent - (ctrl->mRenderInsetLT + ctrl->mRenderInsetRB));
|
|
}
|
|
}
|
|
- mBounds.set(newPosition, actualNewExtent);
|
|
|
|
|
|
|
|
GuiControl *parent = getParent();
|
|
GuiControl *parent = getParent();
|
|
if (parent)
|
|
if (parent)
|
|
@@ -418,8 +419,17 @@ void GuiControl::parentResized(const Point2I &oldParentExtent, const Point2I &ne
|
|
S32 deltaX = newParentExtent.x - oldParentExtent.x;
|
|
S32 deltaX = newParentExtent.x - oldParentExtent.x;
|
|
S32 deltaY = newParentExtent.y - oldParentExtent.y;
|
|
S32 deltaY = newParentExtent.y - oldParentExtent.y;
|
|
|
|
|
|
|
|
+ //In the case of centering, we want to make doubly sure we are using the inner rect.
|
|
|
|
+ GuiControl* parent = getParent();
|
|
|
|
+ Point2I parentInnerExt = Point2I(newParentExtent);
|
|
|
|
+ if(mHorizSizing == horizResizeCenter || mVertSizing == vertResizeCenter)
|
|
|
|
+ {
|
|
|
|
+ //This is based on the "new" outer extent of the parent.
|
|
|
|
+ parentInnerExt = getInnerRect(Point2I(0, 0), parent->mBounds.extent, NormalState, parent->mProfile).extent;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (mHorizSizing == horizResizeCenter)
|
|
if (mHorizSizing == horizResizeCenter)
|
|
- newPosition.x = (newParentExtent.x - mBounds.extent.x) >> 1;
|
|
|
|
|
|
+ newPosition.x = (parentInnerExt.x - mBounds.extent.x) >> 1;
|
|
else if (mHorizSizing == horizResizeWidth)
|
|
else if (mHorizSizing == horizResizeWidth)
|
|
newExtent.x += deltaX;
|
|
newExtent.x += deltaX;
|
|
else if (mHorizSizing == horizResizeLeft)
|
|
else if (mHorizSizing == horizResizeLeft)
|
|
@@ -434,7 +444,7 @@ void GuiControl::parentResized(const Point2I &oldParentExtent, const Point2I &ne
|
|
}
|
|
}
|
|
|
|
|
|
if (mVertSizing == vertResizeCenter)
|
|
if (mVertSizing == vertResizeCenter)
|
|
- newPosition.y = (newParentExtent.y - mBounds.extent.y) >> 1;
|
|
|
|
|
|
+ newPosition.y = (parentInnerExt.y - mBounds.extent.y) >> 1;
|
|
else if (mVertSizing == vertResizeHeight)
|
|
else if (mVertSizing == vertResizeHeight)
|
|
newExtent.y += deltaY;
|
|
newExtent.y += deltaY;
|
|
else if (mVertSizing == vertResizeTop)
|
|
else if (mVertSizing == vertResizeTop)
|
|
@@ -448,9 +458,45 @@ void GuiControl::parentResized(const Point2I &oldParentExtent, const Point2I &ne
|
|
newExtent.y = newBottom - newTop;
|
|
newExtent.y = newBottom - newTop;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ newExtent = extentBattery(newExtent);
|
|
|
|
+
|
|
resize(newPosition, newExtent);
|
|
resize(newPosition, newExtent);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+Point2I GuiControl::extentBattery(Point2I &newExtent)
|
|
|
|
+{
|
|
|
|
+ if (mMinExtent.x == 0 && mMinExtent.y == 0)
|
|
|
|
+ {
|
|
|
|
+ return newExtent;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Point2I result = Point2I(newExtent);
|
|
|
|
+ if (newExtent.x < mBounds.extent.x && newExtent.x < mMinExtent.x)
|
|
|
|
+ {
|
|
|
|
+ mStoredExtent.x += mBounds.extent.x > mMinExtent.x ? (mMinExtent.x - newExtent.x) : (mBounds.extent.x - newExtent.x);
|
|
|
|
+ result.x = mMinExtent.x;
|
|
|
|
+ }
|
|
|
|
+ else if (newExtent.x > mBounds.extent.x && mStoredExtent.x > 0)
|
|
|
|
+ {
|
|
|
|
+ S32 charge = getMin(newExtent.x - mBounds.extent.x, mStoredExtent.x);
|
|
|
|
+ mStoredExtent.x -= charge;
|
|
|
|
+ result.x = newExtent.x - charge;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (newExtent.y < mBounds.extent.y && newExtent.y < mMinExtent.y)
|
|
|
|
+ {
|
|
|
|
+ mStoredExtent.y += mBounds.extent.y > mMinExtent.y ? (mMinExtent.y - newExtent.y) : (mBounds.extent.y - newExtent.y);
|
|
|
|
+ result.y = mMinExtent.y;
|
|
|
|
+ }
|
|
|
|
+ else if (newExtent.y > mBounds.extent.y && mStoredExtent.y > 0)
|
|
|
|
+ {
|
|
|
|
+ S32 charge = getMin(newExtent.y - mBounds.extent.y, mStoredExtent.y);
|
|
|
|
+ mStoredExtent.y -= charge;
|
|
|
|
+ result.y = newExtent.y - charge;
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
+
|
|
//----------------------------------------------------------------
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
void GuiControl::onRender(Point2I offset, const RectI &updateRect)
|
|
void GuiControl::onRender(Point2I offset, const RectI &updateRect)
|