Skip to content
Permalink
Browse files

CSS Box Model

This adds margin and padding to the GuiBorderProfile. With these fields in place, the profiles now mimic the CSS Box Model.
  • Loading branch information...
greenfire27 committed Feb 11, 2019
1 parent 8fe3d0a commit 66b8d4045535abeb77c0d0f3230ad26854ea1a3d
Showing with 291 additions and 256 deletions.
  1. +1 −1 engine/source/2d/core/ImageFrameProviderCore.cc
  2. +1 −1 engine/source/2d/gui/SceneWindow.cc
  3. +1 −1 engine/source/2d/gui/guiImageButtonCtrl.cc
  4. +1 −1 engine/source/2d/gui/guiSceneObjectCtrl.cc
  5. +24 −35 engine/source/gui/buttons/guiButtonCtrl.cc
  6. +37 −22 engine/source/gui/buttons/guiCheckBoxCtrl.cc
  7. +1 −0 engine/source/gui/buttons/guiCheckBoxCtrl.h
  8. +7 −70 engine/source/gui/buttons/guiRadioCtrl.cc
  9. +1 −1 engine/source/gui/buttons/guiRadioCtrl.h
  10. +1 −1 engine/source/gui/containers/guiFormCtrl.cc
  11. +1 −1 engine/source/gui/containers/guiFrameCtrl.cc
  12. +1 −1 engine/source/gui/containers/guiPaneCtrl.cc
  13. +1 −1 engine/source/gui/containers/guiRolloutCtrl.cc
  14. +1 −1 engine/source/gui/containers/guiScrollCtrl.cc
  15. +2 −1 engine/source/gui/containers/guiTabBookCtrl.cc
  16. +13 −13 engine/source/gui/containers/guiTabBookCtrl.h
  17. +1 −1 engine/source/gui/containers/guiWindowCtrl.cc
  18. +1 −1 engine/source/gui/editor/guiEditCtrl.cc
  19. +1 −1 engine/source/gui/editor/guiFilterCtrl.cc
  20. +1 −1 engine/source/gui/editor/guiMenuBar.cc
  21. +1 −1 engine/source/gui/editor/guiSeparatorCtrl.cc
  22. +1 −1 engine/source/gui/guiArrayCtrl.cc
  23. +1 −1 engine/source/gui/guiBackgroundCtrl.cc
  24. +1 −1 engine/source/gui/guiBitmapBorderCtrl.cc
  25. +2 −2 engine/source/gui/guiBitmapCtrl.cc
  26. +2 −2 engine/source/gui/guiColorPicker.cc
  27. +1 −1 engine/source/gui/guiConsoleTextCtrl.cc
  28. +96 −9 engine/source/gui/guiControl.cc
  29. +15 −3 engine/source/gui/guiControl.h
  30. +6 −6 engine/source/gui/guiDefaultControlRender.cc
  31. +1 −1 engine/source/gui/guiMLTextCtrl.h
  32. +2 −2 engine/source/gui/guiProgressCtrl.cc
  33. +1 −1 engine/source/gui/guiSliderCtrl.cc
  34. +2 −2 engine/source/gui/guiTabPageCtrl.cc
  35. +3 −3 engine/source/gui/guiTabPageCtrl.h
  36. +1 −1 engine/source/gui/guiTextCtrl.cc
  37. +1 −1 engine/source/gui/guiTextEditCtrl.cc
  38. +40 −50 engine/source/gui/guiTypes.cc
  39. +16 −13 engine/source/gui/guiTypes.h
@@ -290,7 +290,7 @@ void ImageFrameProviderCore::renderGui( GuiControl& owner, Point2I offset, const
}

// Render child controls.
owner.renderChildControls(offset, updateRect);
owner.renderChildControls(offset, updateRect, updateRect);
}

//------------------------------------------------------------------------------
@@ -1720,7 +1720,7 @@ void SceneWindow::onRender( Point2I offset, const RectI& updateRect )
renderMetricsOverlay( offset, updateRect );

// Render Children.
renderChildControls( offset, updateRect );
renderChildControls( offset, mBounds, updateRect );

// Update Window.
setUpdate();
@@ -272,7 +272,7 @@ void GuiImageButtonCtrl::renderButton( ImageAsset* pImageAsset, const U32 frame,
dglSetBitmapModulation( mProfile->mFillColor );
dglDrawBitmapStretchSR( pImageAsset->getImageTexture(), destinationRegion, sourceRegion );
dglClearBitmapModulation();
renderChildControls( offset, updateRect);
renderChildControls( offset, mBounds, updateRect);
}
else
{
@@ -476,5 +476,5 @@ void GuiSceneObjectCtrl::onRender(Point2I offset, const RectI& updateRect)


// Render Child Controls.
renderChildControls(offset, updateRect);
renderChildControls(offset, mBounds, updateRect);
}
@@ -238,6 +238,7 @@ void GuiButtonCtrl::onAction()

void GuiButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
{

GuiControlState currentState = GuiControlState::NormalState;
if (!mActive)
{
@@ -252,46 +253,34 @@ void GuiButtonCtrl::onRender(Point2I offset, const RectI& updateRect)
currentState = GuiControlState::HighlightState;
}

RectI ctrlRect = applyMargins(offset, mBounds.extent, currentState);
RectI boundsRect(offset, mBounds.extent);

if(mProfile->mBitmapName != NULL && mProfile->constructBitmapArray() >= 36)
{
S32 indexMultiplier = 1;
if ( currentState == HighlightState)
indexMultiplier = 2;
else if ( currentState == SelectedState )
indexMultiplier = 3;
else if ( currentState == DisabledState )
indexMultiplier = 4;

renderSizableBitmapBordersFilled( boundsRect, indexMultiplier, mProfile );
}
if(mProfile->mBitmapName != NULL && mProfile->constructBitmapArray() >= 36)
{
S32 indexMultiplier = 1;
if ( currentState == HighlightState)
indexMultiplier = 2;
else if ( currentState == SelectedState )
indexMultiplier = 3;
else if ( currentState == DisabledState )
indexMultiplier = 4;

renderSizableBitmapBordersFilled(ctrlRect, indexMultiplier, mProfile );
}
else
{
renderBorderedRect(boundsRect, mProfile, currentState);
}

//Get the border profiles
GuiBorderProfile *leftProfile = (mProfile->mBorderLeft) ? mProfile->mBorderLeft : mProfile->mBorderDefault;
GuiBorderProfile *rightProfile = (mProfile->mBorderRight) ? mProfile->mBorderRight : mProfile->mBorderDefault;
GuiBorderProfile *topProfile = (mProfile->mBorderTop) ? mProfile->mBorderTop : mProfile->mBorderDefault;
GuiBorderProfile *bottomProfile = (mProfile->mBorderBottom) ? mProfile->mBorderBottom : mProfile->mBorderDefault;

S32 leftSize = (leftProfile) ? leftProfile->getBorder(currentState) : 0;
S32 rightSize = (rightProfile) ? rightProfile->getBorder(currentState) : 0;
S32 topSize = (topProfile) ? topProfile->getBorder(currentState) : 0;
S32 bottomSize = (bottomProfile) ? bottomProfile->getBorder(currentState) : 0;

//Get the inner rect
RectI innerRect = RectI(offset.x + leftSize, offset.y + topSize, (mBounds.extent.x - leftSize) - rightSize, (mBounds.extent.y - topSize) - bottomSize);

ColorI fontColor = mProfile->getFontColor(currentState);
{
renderBorderedRect(ctrlRect, mProfile, currentState);
}

dglSetBitmapModulation( fontColor );
renderJustifiedText(innerRect.point, innerRect.extent, mText);
//Render Text
dglSetBitmapModulation(mProfile->getFontColor(currentState));
RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState);
RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState);
renderJustifiedText(contentRect.point, contentRect.extent, mText);

//render the children
renderChildControls( offset, updateRect);
//Render the childen
renderChildControls(contentRect.point, contentRect, updateRect);
}

void GuiButtonCtrl::setScriptValue(const char *value)
@@ -78,8 +78,20 @@ void GuiCheckBoxCtrl::onRender(Point2I offset, const RectI &updateRect)
currentState = GuiControlState::HighlightState;
}

RectI boundsRect(offset, mBounds.extent);
RectI boxRect(offset + mBoxOffset, mBoxExtent);
RectI ctrlRect = applyMargins(offset, mBounds.extent, currentState);
RectI fillRect = applyBorders(ctrlRect.point, ctrlRect.extent, currentState);
RectI contentRect = applyPadding(fillRect.point, fillRect.extent, currentState);
RectI boxRect(contentRect.point + mBoxOffset, mBoxExtent);

//Contrain the Box Rect. It must fit in the content Rect.
if ((boxRect.point.x + boxRect.extent.x) > (contentRect.point.x + contentRect.extent.x))
{
boxRect.extent.x = contentRect.point.x + contentRect.extent.x - boxRect.point.x;
}
if ((boxRect.point.y + boxRect.extent.y) > (contentRect.point.y + contentRect.extent.y))
{
boxRect.extent.y = contentRect.point.y + contentRect.extent.y - boxRect.point.y;
}

if(mProfile->mBitmapName != NULL && mProfile->constructBitmapArray() >= 6)
{
@@ -105,29 +117,32 @@ void GuiCheckBoxCtrl::onRender(Point2I offset, const RectI &updateRect)
else
{
//Draw the checkbox
renderBorderedRect(boxRect, mProfile, currentState);
renderInnerControl(boxRect, currentState);
}

if(mText[0] != '\0')
{
ColorI fontColor = mProfile->getFontColor(currentState);
dglSetBitmapModulation( fontColor );

Point2I textArea = mTextExtent;
if ((textArea.x + mTextOffset.x) > mBounds.extent.x)
{
textArea.x = mBounds.extent.x;
}
if ((textArea.y + mTextOffset.y) > mBounds.extent.y)
{
textArea.y = mBounds.extent.y;
}

renderJustifiedText(Point2I(offset.x + mTextOffset.x, offset.y + mTextOffset.y), textArea, mText);
}
RectI textRect(contentRect.point + mTextOffset, mTextExtent);

//render the children
renderChildControls(offset, updateRect);
//Contrain the Text Rect. It must fit in the content Rect.
if ((textRect.point.x + textRect.extent.x) > (contentRect.point.x + contentRect.extent.x))
{
textRect.extent.x = contentRect.point.x + contentRect.extent.x - textRect.point.x;
}
if ((textRect.point.y + textRect.extent.y) > (contentRect.point.y + contentRect.extent.y))
{
textRect.extent.y = contentRect.point.y + contentRect.extent.y - textRect.point.y;
}

//Render Text
dglSetBitmapModulation(mProfile->getFontColor(currentState));
renderJustifiedText(textRect.point, textRect.extent, mText);

//Render the childen
renderChildControls(offset, contentRect, updateRect);
}

void GuiCheckBoxCtrl::renderInnerControl(RectI &boxRect, const GuiControlState currentState)
{
renderBorderedRect(boxRect, mProfile, currentState);
}

void GuiCheckBoxCtrl::onAction()
@@ -61,6 +61,7 @@ class GuiCheckBoxCtrl : public GuiButtonCtrl
void setTextExtent(const Point2I &newExtent) { mTextExtent = newExtent; }

void onRender(Point2I offset, const RectI &updateRect);
virtual void renderInnerControl(RectI &boxRect, const GuiControlState currentState);
void setScriptValue(const char *value);
const char *getScriptValue();

@@ -41,79 +41,16 @@ void GuiRadioCtrl::initPersistFields()
addField("groupNum", TypeS32, Offset(mRadioGroup, GuiRadioCtrl));
}

void GuiRadioCtrl::onRender(Point2I offset, const RectI &updateRect)
void GuiRadioCtrl::renderInnerControl(RectI &boxRect, const GuiControlState currentState)
{
GuiControlState currentState = GuiControlState::NormalState;
if (!mActive)
{
currentState = GuiControlState::DisabledState;
}
else if (mDepressed || mStateOn)
{
currentState = GuiControlState::SelectedState;
}
else if (mMouseOver)
{
currentState = GuiControlState::HighlightState;
}

RectI boundsRect(offset, mBounds.extent);
RectI boxRect(offset + mBoxOffset, mBoxExtent);

if (mProfile->mBitmapName != NULL && mProfile->constructBitmapArray() >= 6)
S32 radius = boxRect.extent.x;
if (boxRect.extent.y < radius)
{
//Use the bitmap to create the radio button
S32 index = 1;
if (mStateOn || mDepressed)
{
index = 2;
}
if (mMouseOver)
{
index += 2;
}
else if (!mActive)
{
index += 4;
}

RectI dest = RectI(offset + mBoxOffset, mBoxExtent);
dglClearBitmapModulation();
dglDrawBitmapStretchSR(mProfile->mTextureHandle, dest, mProfile->mBitmapArrayRects[index - 1]);
}
else
{
//Draw the radio button
S32 radius = mBoxExtent.x;
if (mBoxExtent.y < radius)
{
radius = mBoxExtent.y;
}
radius = (S32)round(radius/2);
Point2I center = Point2I(offset.x + mBoxOffset.x + (mBoxExtent.x/2), offset.y + mBoxOffset.y + (mBoxExtent.y / 2));
renderBorderedCircle(center, radius, mProfile, currentState);
radius = boxRect.extent.y;
}

if (mText[0] != '\0')
{
ColorI fontColor = mProfile->getFontColor(currentState);
dglSetBitmapModulation(fontColor);

Point2I textArea = mTextExtent;
if ((textArea.x + mTextOffset.x) > mBounds.extent.x)
{
textArea.x = mBounds.extent.x;
}
if ((textArea.y + mTextOffset.y) > mBounds.extent.y)
{
textArea.y = mBounds.extent.y;
}

renderJustifiedText(Point2I(offset.x + mTextOffset.x, offset.y + mTextOffset.y), textArea, mText);
}

//render the children
renderChildControls(offset, updateRect);
radius = (S32)round(radius / 2);
Point2I center = Point2I(boxRect.point.x + (boxRect.extent.x / 2), boxRect.point.y + (boxRect.extent.y / 2));
renderBorderedCircle(center, radius, mProfile, currentState);
}

void GuiRadioCtrl::onAction()
@@ -38,7 +38,7 @@ class GuiRadioCtrl : public GuiCheckBoxCtrl
DECLARE_CONOBJECT(GuiRadioCtrl);
GuiRadioCtrl();
static void initPersistFields();
void onRender(Point2I offset, const RectI &updateRect);
void renderInnerControl(RectI &boxRect, const GuiControlState currentState);
void setStateOn(bool bStateOn);
void onAction();
void onMessage(GuiControl *, S32 msg);
@@ -291,7 +291,7 @@ void GuiFormCtrl::onRender(Point2I offset, const RectI &updateRect)
}

// Render the children
renderChildControls(offset, updateRect);
renderChildControls(offset, mBounds, updateRect);
}

void GuiFormCtrl::onMouseDragged(const GuiEvent &event)
@@ -498,7 +498,7 @@ void GuiFrameSetCtrl::onRender(Point2I offset, const RectI &updateRect )
// dglDrawRect(r, mProfile->mBorderColor);

// draw the frame contents
renderChildControls(offset, updateRect);
renderChildControls(offset, mBounds, updateRect);
}

//-----------------------------------------------------------------------------
@@ -220,7 +220,7 @@ void GuiPaneControl::onRender(Point2I offset, const RectI &updateRect)

// Draw child controls if appropriate
if(!mCollapsed)
renderChildControls(offset, updateRect);
renderChildControls(offset, mBounds, updateRect);
}

ConsoleMethod(GuiPaneControl, setCollapsed, void, 3, 3, "(bool collapsed) Sets the controls \"collapsed\" property\n"
@@ -367,7 +367,7 @@ void GuiRolloutCtrl::onRender(Point2I offset, const RectI &updateRect)
else if( mIsExpanded && !pChild->isVisible())
pChild->setVisible( true );
}
renderChildControls(offset, updateRect);
renderChildControls(offset, mBounds, updateRect);
}
}

@@ -813,7 +813,7 @@ void GuiScrollCtrl::onRender(Point2I offset, const RectI &updateRect)
// create a rect to intersect with the updateRect
RectI contentRect(mContentPos.x + offset.x, mContentPos.y + offset.y, mContentExt.x, mContentExt.y);
if(contentRect.intersect(updateRect))
renderChildControls(offset, contentRect);
renderChildControls(offset, mBounds, contentRect);

// Finally draw the last vis rect (debug aid, BJG)
//RectI renderRect = lastVisRect;
@@ -64,6 +64,7 @@ GuiTabBookCtrl::GuiTabBookCtrl()
mPages.reserve(12);
mTabMargin = 7;
mMinTabWidth = 64;
mTabWidth = 64;
mIsContainer = true;


@@ -309,7 +310,7 @@ void GuiTabBookCtrl::onRender(Point2I offset, const RectI &updateRect)
renderTabs( offset );

// Render Children
renderChildControls( offset, updateRect );
renderChildControls( offset, mBounds, updateRect );

// Restore old modulation
dglSetBitmapModulation( oldModulation );
Oops, something went wrong.

0 comments on commit 66b8d40

Please sign in to comment.
You can’t perform that action at this time.