moar refactors

This commit is contained in:
marauder2k7 2024-12-25 20:23:22 +00:00
parent 4d893f51cf
commit 22037bf94f
10 changed files with 65 additions and 60 deletions

View file

@ -86,7 +86,6 @@ ConsoleDocClass( GuiIconButtonCtrl,
GuiIconButtonCtrl::GuiIconButtonCtrl()
{
INIT_ASSET(Bitmap);
mTextLocation = TextLocLeft;
mIconLocation = IconLocLeft;
mTextMargin = 4;
@ -127,8 +126,8 @@ void GuiIconButtonCtrl::initPersistFields()
docsURL;
addField( "buttonMargin", TypePoint2I, Offset( mButtonMargin, GuiIconButtonCtrl ),"Margin area around the button.\n");
addProtectedField( "iconBitmap", TypeImageFilename, Offset( mBitmapName, GuiIconButtonCtrl ), &_setBitmapData, &defaultProtectedGetFn, "Bitmap file for the icon to display on the button.\n", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET(Bitmap, GuiIconButtonCtrl, "Bitmap file for the icon to display on the button.\n");
addProtectedField( "iconBitmap", TypeImageFilename, Offset( mBitmapAsset, GuiIconButtonCtrl ), &_setBitmapData, &defaultProtectedGetFn, "Bitmap file for the icon to display on the button.\n", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_IMAGEASSET_REFACTOR(Bitmap, GuiIconButtonCtrl, "Bitmap file for the icon to display on the button.\n");
addField( "iconLocation", TYPEID< IconLocation >(), Offset( mIconLocation, GuiIconButtonCtrl ),"Where to place the icon on the control. Options are 0 (None), 1 (Left), 2 (Right), 3 (Center).\n");
addField( "sizeIconToButton", TypeBool, Offset( mFitBitmapToButton, GuiIconButtonCtrl ),"If true, the icon will be scaled to be the same size as the button.\n");
@ -148,8 +147,6 @@ bool GuiIconButtonCtrl::onWake()
return false;
setActive(true);
setBitmap(mBitmapName);
if( mProfile )
mProfile->constructBitmapArray();
@ -181,8 +178,8 @@ bool GuiIconButtonCtrl::resize(const Point2I &newPosition, const Point2I &newExt
if ( mIconLocation != IconLocNone )
{
autoExtent.y = mBitmap.getHeight() + mButtonMargin.y * 2;
autoExtent.x = mBitmap.getWidth() + mButtonMargin.x * 2;
autoExtent.y = getBitmap().getHeight() + mButtonMargin.y * 2;
autoExtent.x = getBitmap().getWidth() + mButtonMargin.x * 2;
}
if ( mTextLocation != TextLocNone && mButtonText && mButtonText[0] )
@ -209,7 +206,7 @@ void GuiIconButtonCtrl::setBitmap(const char *name)
if(!isAwake())
return;
_setBitmap(getBitmap());
_setBitmap(name);
// So that extent is recalculated if autoSize is set.
resize( getPosition(), getExtent() );
@ -299,13 +296,13 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
RectI iconRect( 0, 0, 0, 0 );
// Render the icon
if ( mBitmap && mIconLocation != GuiIconButtonCtrl::IconLocNone )
if ( mBitmapAsset.notNull() && mIconLocation != GuiIconButtonCtrl::IconLocNone)
{
// Render the normal bitmap
drawer->clearBitmapModulation();
// Size of the bitmap
Point2I textureSize(mBitmap->getWidth(), mBitmap->getHeight());
Point2I textureSize(getBitmap()->getWidth(), getBitmap()->getHeight());
// Reduce the size with the margin (if set)
textureSize.x = textureSize.x - (mBitmapMargin * 2);
@ -332,7 +329,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
iconRect.point.y = offset.y + ( getHeight() - textureSize.y ) / 2;
}
drawer->drawBitmapStretch(mBitmap, iconRect );
drawer->drawBitmapStretch(getBitmap(), iconRect );
}
else
@ -366,7 +363,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
iconRect.point.y = offset.y + (getHeight() / 2) - (iconRect.extent.y / 2) + mButtonMargin.y;
}
drawer->drawBitmapStretch( mBitmap, iconRect );
drawer->drawBitmapStretch(getBitmap(), iconRect );
}
}
@ -383,7 +380,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
if ( mTextLocation == TextLocRight )
{
Point2I start( mTextMargin, ( getHeight() - mProfile->mFont->getHeight() ) / 2 );
if (mBitmap && mIconLocation != IconLocNone )
if (mBitmapAsset.notNull() && mIconLocation != IconLocNone)
{
start.x = iconRect.extent.x + mButtonMargin.x + mTextMargin;
}
@ -403,7 +400,7 @@ void GuiIconButtonCtrl::renderButton( Point2I &offset, const RectI& updateRect )
if ( mTextLocation == TextLocCenter )
{
Point2I start;
if (mBitmap && mIconLocation == IconLocLeft )
if (mBitmapAsset.notNull() && mIconLocation == IconLocLeft )
{
start.set( ( getWidth() - textWidth - iconRect.extent.x ) / 2 + iconRect.extent.x,
( getHeight() - mProfile->mFont->getHeight() ) / 2 );
@ -468,4 +465,4 @@ void GuiIconButtonCtrl::renderBitmapArray(RectI &bounds, S32 state)
}
}
DEF_ASSET_BINDS(GuiIconButtonCtrl, Bitmap);
DEF_ASSET_BINDS_REFACTOR(GuiIconButtonCtrl, Bitmap)