Skip to content

Commit

Permalink
4.x UI tweaks TorqueGameEngines#6: Source side -> guiIconButton changed
Browse files Browse the repository at this point in the history
  • Loading branch information
StudioDimSum committed Dec 2, 2022
1 parent e3d0a17 commit 37ad3e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
29 changes: 22 additions & 7 deletions Engine/source/gui/buttons/guiIconButtonCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ ConsoleDocClass( GuiIconButtonCtrl,
" makeIconSquare = \"1\";\n"
" textLocation = \"Bottom\";\n"
" textMargin = \"-2\";\n"
" autoSize = \"0\";\n"
" text = \"Lag Icon\";\n"
" textID = \"\"STR_LAG\"\";\n"
" buttonType = \"PushButton\";\n"
" profile = \"GuiIconButtonProfile\";\n"
" bitmapMargin = \"0\";\n"
" autoSize = \"0\";\n"
" text = \"Lag Icon\";\n"
" textID = \"\"STR_LAG\"\";\n"
" buttonType = \"PushButton\";\n"
" profile = \"GuiIconButtonProfile\";\n"
"};\n"
"@endtsexample\n\n"

Expand All @@ -96,6 +97,8 @@ GuiIconButtonCtrl::GuiIconButtonCtrl()

mAutoSize = false;

mBitmapMargin = 0;

setExtent(140, 30);
}

Expand Down Expand Up @@ -133,6 +136,8 @@ void GuiIconButtonCtrl::initPersistFields()
"Options are 0 (None), 1 (Bottom), 2 (Right), 3 (Top), 4 (Left), 5 (Center).\n");
addField( "textMargin", TypeS32, Offset( mTextMargin, GuiIconButtonCtrl ),"Margin between the icon and the text.\n");
addField( "autoSize", TypeBool, Offset( mAutoSize, GuiIconButtonCtrl ),"If true, the text and icon will be automatically sized to the size of the control.\n");
addField( "bitmapMargin", TypeS32, Offset( mBitmapMargin, GuiIconButtonCtrl), "Margin between the icon and the border.\n");

Parent::initPersistFields();
}

Expand Down Expand Up @@ -288,10 +293,16 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
// Render the normal bitmap
drawer->clearBitmapModulation();

// Size of the bitmap
Point2I textureSize(mBitmap->getWidth(), mBitmap->getHeight());

// Reduce the size with the margin (if set)
textureSize.x = textureSize.x - (mBitmapMargin * 2);
textureSize.y = textureSize.y - (mBitmapMargin * 2);

// Maintain the bitmap size or fill the button?
if ( !mFitBitmapToButton )
{
Point2I textureSize(mBitmap->getWidth(), mBitmap->getHeight() );
iconRect.set( offset + mButtonMargin, textureSize );

if ( mIconLocation == IconLocRight )
Expand All @@ -315,7 +326,11 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
}
else
{
iconRect.set( offset + mButtonMargin, getExtent() - (Point2I(mAbs(mButtonMargin.x), mAbs(mButtonMargin.y)) * 2) );
// adding offset with the bitmap margin next to the button margin
Point2I bitMapOffset(mBitmapMargin, mBitmapMargin);

// set the offset
iconRect.set( offset + mButtonMargin + bitMapOffset, getExtent() - (Point2I(mAbs(mButtonMargin.x - (mBitmapMargin * 2)), mAbs(mButtonMargin.y - (mBitmapMargin * 2))) * 2) );

if ( mMakeIconSquare )
{
Expand Down
3 changes: 3 additions & 0 deletions Engine/source/gui/buttons/guiIconButtonCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class GuiIconButtonCtrl : public GuiButtonCtrl
S32 mTextLocation;
S32 mTextMargin;
Point2I mButtonMargin;

/// Margin between the icon and the button border
S32 mBitmapMargin;

/// Make the bitmap fill the button extent.
bool mFitBitmapToButton;
Expand Down

0 comments on commit 37ad3e0

Please sign in to comment.