Updates ImageAsset usage to utilize AssetRef, and standardizes the setter/getter functions and naming conventions, as well as the ability to use and bind named targets.

This commit is contained in:
JeffR 2026-06-16 17:39:30 -05:00
parent a858d8624e
commit 34e3f78a22
82 changed files with 1451 additions and 951 deletions

View file

@ -87,7 +87,8 @@ void GuiBitmapCtrl::initPersistFields()
docsURL;
addGroup("Bitmap");
INITPERSISTFIELD_IMAGEASSET(Bitmap, GuiBitmapCtrl, "The bitmap to render in this BitmapCtrl.")
ADD_FIELD("bitmapAsset", TypeImageAssetRef, Offset(mBitmapAssetRef, GuiBitmapCtrl))
.doc("The bitmap asset to render in this BitmapCtrl.");
addField("color", TypeColorI, Offset(mColor, GuiBitmapCtrl), "color mul");
addField("wrap", TypeBool, Offset(mWrap, GuiBitmapCtrl), "If true, the bitmap is tiled inside the control rather than stretched to fit.");
@ -127,6 +128,21 @@ void GuiBitmapCtrl::inspectPostApply()
}
}
void GuiBitmapCtrl::_setBitmap(StringTableEntry _in)
{
if (mBitmapAssetRef.assetId == _in)
return;
if (ImageAsset::isNamedTarget(_in))
{
mBitmapAssetRef.assetId = _in;
mBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
return;
}
mBitmapAssetRef = _in;
}
void GuiBitmapCtrl::setBitmap(const char* name, bool resize)
{
// coming in here we are probably getting a filename.
@ -144,9 +160,9 @@ void GuiBitmapCtrl::setBitmap(const char* name, bool resize)
_setBitmap(StringTable->EmptyString());
}
if (mBitmapAsset.notNull())
if (mBitmapAssetRef.notNull())
{
mBitmap = mBitmapAsset->getTexture(&GFXDefaultGUIProfile);
mBitmap = mBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile);
if (getBitmap() && resize)
{
@ -184,7 +200,7 @@ void GuiBitmapCtrl::updateSizing()
void GuiBitmapCtrl::onRender(Point2I offset, const RectI& updateRect)
{
if (mBitmap.isNull() && mBitmapAsset.notNull())
if (mBitmap.isNull() && mBitmapAssetRef.notNull())
mBitmap = getBitmap();
if (mBitmap)
@ -309,8 +325,8 @@ void GuiBitmapCtrl::setValue(S32 x, S32 y)
{
if (getBitmap())
{
x += mBitmapAsset->getTextureBitmapWidth() / 2;
y += mBitmapAsset->getTextureBitmapHeight() / 2;
x += mBitmapAssetRef.assetPtr->getTextureBitmapWidth() / 2;
y += mBitmapAssetRef.assetPtr->getTextureBitmapHeight() / 2;
}
while (x < 0)
x += 256;
@ -359,11 +375,11 @@ DefineEngineMethod(GuiBitmapCtrl, setBitmap, void, (const char* fileRoot, bool r
object->setBitmap(filename, resize);
}
DefineEngineMethod(GuiBitmapCtrl, getBitmap, const char*, (), ,
"Gets the current bitmap set for this control.\n\n"
DefineEngineMethod(GuiBitmapCtrl, getBitmapAsset, const char*, (), ,
"Gets the current asset Id of the bitmap set for this control.\n\n"
"@hide")
{
return object->_getBitmap();
return object->getBitmapAssetId();
}
DefineEngineMethod(GuiBitmapCtrl, setNamedTexture, bool, (String namedtexture), ,

View file

@ -48,7 +48,7 @@ protected:
/// Name of the bitmap file. If this is 'texhandle' the bitmap is not loaded
/// from a file but rather set explicitly on the control.
DECLARE_IMAGEASSET(GuiBitmapCtrl, Bitmap, GFXDefaultGUIProfile)
AssetRef<ImageAsset> mBitmapAssetRef;
Point2I mStartPoint;
ColorI mColor;
@ -74,6 +74,11 @@ public:
void setBitmap(const char* name, bool resize = true);
void setBitmapHandle(GFXTexHandle handle, bool resize = false);
void _setBitmap(StringTableEntry _in);
inline StringTableEntry getBitmapAssetId() const { return mBitmapAssetRef.getAssetId(); }
GFXTexHandle getBitmap() { return mBitmapAssetRef.notNull() ? mBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
AssetPtr<ImageAsset> getBitmapAsset() { return mBitmapAssetRef.assetPtr; }
void updateSizing();
void onRender(Point2I offset, const RectI& updateRect) override;

View file

@ -62,6 +62,51 @@ GuiGameSettingsCtrl::GuiGameSettingsCtrl() :
mCallbackOnY = mCallbackOnA;
}
void GuiGameSettingsCtrl::setKeybindBitmap(StringTableEntry _in)
{
if (mKeybindBitmapAssetRef.assetId == _in)
return;
if (ImageAsset::isNamedTarget(_in))
{
mKeybindBitmapAssetRef.assetId = _in;
mKeybindBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
return;
}
mKeybindBitmapAssetRef = _in;
}
void GuiGameSettingsCtrl::setPreviousBitmap(StringTableEntry _in)
{
if (mPreviousBitmapAssetRef.assetId == _in)
return;
if (ImageAsset::isNamedTarget(_in))
{
mPreviousBitmapAssetRef.assetId = _in;
mPreviousBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
return;
}
mPreviousBitmapAssetRef = _in;
}
void GuiGameSettingsCtrl::setNextBitmap(StringTableEntry _in)
{
if (mNextBitmapAssetRef.assetId == _in)
return;
if (ImageAsset::isNamedTarget(_in))
{
mNextBitmapAssetRef.assetId = _in;
mNextBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
return;
}
mNextBitmapAssetRef = _in;
}
GuiGameSettingsCtrl::~GuiGameSettingsCtrl()
{
mOptions.clear();
@ -430,7 +475,7 @@ void GuiGameSettingsCtrl::setKeybindSetting(const char* label, const char* bitma
{
static StringTableEntry DELIM = StringTable->insert("\t", true);
_setKeybindBitmap(StringTable->insert(bitmapName));
setKeybindBitmap(StringTable->insert(bitmapName));
//if(mBitmap != StringTable->EmptyString())
// mBitmapTex.set(mBitmap, &GFXDefaultGUIProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
@ -828,9 +873,12 @@ IMPLEMENT_CALLBACK(GuiGameSettingsCtrl, onAxisEvent, void, (const char* device,
void GuiGameSettingsCtrl::initPersistFields()
{
docsURL;
INITPERSISTFIELD_IMAGEASSET(KeybindBitmap, GuiGameSettingsCtrl, "Bitmap used to display the bound key for this keybind option.");
INITPERSISTFIELD_IMAGEASSET(PreviousBitmap, GuiGameSettingsCtrl, "Bitmap used for the previous button when in list mode.");
INITPERSISTFIELD_IMAGEASSET(NextBitmap, GuiGameSettingsCtrl, "Bitmap used for the next button when in list mode.");
ADD_FIELD("keybindBitmapAsset", TypeImageAssetRef, Offset(mKeybindBitmapAssetRef, GuiGameSettingsCtrl))
.doc("Bitmap asset used to display the bound key for this keybind option.");
ADD_FIELD("previousBitmapAsset", TypeImageAssetRef, Offset(mPreviousBitmapAssetRef, GuiGameSettingsCtrl))
.doc("Bitmap asset used for the previous button when in list mode.");
ADD_FIELD("nextBitmapAsset", TypeImageAssetRef, Offset(mNextBitmapAssetRef, GuiGameSettingsCtrl))
.doc("Bitmap asset used for the next button when in list mode.");
addFieldV("arrowSize", TypeRangedS32, Offset(mArrowSize, GuiGameSettingsCtrl), &CommonValidators::PositiveInt,
"Size of the arrow buttons' extents");

View file

@ -72,9 +72,9 @@ protected:
Point2F mRange; ///< When working as a slider, this sets our min/max range
//Keybind option
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, KeybindBitmap, GFXDefaultGUIProfile)
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, PreviousBitmap, GFXDefaultGUIProfile)
DECLARE_IMAGEASSET(GuiGameSettingsCtrl, NextBitmap, GFXDefaultGUIProfile)
AssetRef<ImageAsset> mKeybindBitmapAssetRef;
AssetRef<ImageAsset> mPreviousBitmapAssetRef;
AssetRef<ImageAsset> mNextBitmapAssetRef;
S32 mArrowSize;
S32 mColumnSplit; //Padding between the leftmost edge of the control, and the left side of the 'option'.
@ -84,7 +84,19 @@ protected:
bool mSelected;
public:
/// Sets the control as selected . Only controls that are enabled can be selected.
void setKeybindBitmap(StringTableEntry _in);
inline StringTableEntry getKeybindBitmapAssetId() const { return mKeybindBitmapAssetRef.getAssetId(); }
GFXTexHandle getKeybindBitmap() { return mKeybindBitmapAssetRef.notNull() ? mKeybindBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
void setPreviousBitmap(StringTableEntry _in);
inline StringTableEntry getPreviousBitmapAssetId() const { return mPreviousBitmapAssetRef.getAssetId(); }
GFXTexHandle getPreviousBitmap() { return mPreviousBitmapAssetRef.notNull() ? mPreviousBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
void setNextBitmap(StringTableEntry _in);
inline StringTableEntry getNextBitmapAssetId() const { return mNextBitmapAssetRef.getAssetId(); }
GFXTexHandle getNextBitmap() { return mNextBitmapAssetRef.notNull() ? mNextBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
/// Sets the control as selected . Only controls that are enabled can be selected.
virtual void setSelected();
/// Determines if the specified control is enabled or disabled.

View file

@ -299,7 +299,10 @@ void GuiPopUpMenuCtrl::initPersistFields(void)
addField("sbUsesNAColor", TypeBool, Offset(mRenderScrollInNA, GuiPopUpMenuCtrl));
addField("reverseTextList", TypeBool, Offset(mReverseTextList, GuiPopUpMenuCtrl));
addProtectedField("BitmapAsset", TypeImageAssetPtr, Offset(mBitmapAsset, GuiPopUpMenuCtrl), _setBitmaps, &defaultProtectedGetFn, "@brief ""Bitmap"" ""asset \"\".");
ADD_FIELD("bitmapAsset", TypeImageAssetRef, Offset(mBitmapAssetRef, GuiPopUpMenuCtrl))
.elements(NumBitmapModes)
.onSet(_setBitmaps)
.doc("@brief ""Bitmap"" ""asset \"\".");
addField("bitmapBounds", TypePoint2I, Offset(mBitmapBounds, GuiPopUpMenuCtrl));
@ -580,18 +583,18 @@ void GuiPopUpMenuCtrl::setBitmap( const char *name )
dStrcpy(p, "_n", pLen);
_setBitmap((StringTableEntry)buffer, Normal);
setBitmap((StringTableEntry)buffer, Normal);
dStrcpy(p, "_d", pLen);
_setBitmap((StringTableEntry)buffer, Depressed);
setBitmap((StringTableEntry)buffer, Depressed);
if ( mBitmapAsset[Depressed].isNull() )
mBitmapAsset[Depressed] = mBitmapAsset[Normal];
if ( mBitmapAssetRef[Depressed].isNull() )
mBitmapAssetRef[Depressed] = mBitmapAssetRef[Normal];
}
else
{
_setBitmap(StringTable->EmptyString(), Normal);
_setBitmap(StringTable->EmptyString(), Depressed);
setBitmap(StringTable->EmptyString(), Normal);
setBitmap(StringTable->EmptyString(), Depressed);
}
setUpdate();
}

View file

@ -126,7 +126,9 @@ protected:
NumBitmapModes = 2
};
DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrl, Bitmap, GFXDefaultGUIProfile, NumBitmapModes)
AssetRef<ImageAsset> mBitmapAssetRef[NumBitmapModes];
GFXTexHandle getBitmap(const U32& index) { return mBitmapAssetRef[index].notNull() ? mBitmapAssetRef[index].assetPtr->getTexture(&GFXDefaultGUIProfile) : GFXTexHandle(); }
void setBitmap(StringTableEntry assetId, const U32& index) { mBitmapAssetRef[index] = assetId; }
Point2I mBitmapBounds; // Added
S32 mIdMax;

View file

@ -354,7 +354,10 @@ void GuiPopUpMenuCtrlEx::initPersistFields(void)
addField("sbUsesNAColor", TypeBool, Offset(mRenderScrollInNA, GuiPopUpMenuCtrlEx), "Deprecated" "@internal");
addField("reverseTextList", TypeBool, Offset(mReverseTextList, GuiPopUpMenuCtrlEx), "Reverses text list if popup extends up, instead of down");
addProtectedField("BitmapAsset", TypeImageAssetPtr, Offset(mBitmapAsset, GuiPopUpMenuCtrlEx), _setBitmaps, &defaultProtectedGetFn, "@brief ""Bitmap"" ""asset \"Name of bitmap asset to use\".");
ADD_FIELD("bitmapAsset", TypeImageAssetRef, Offset(mBitmapAssetRef, GuiPopUpMenuCtrlEx))
.elements(NumBitmapModes)
.onSet(_setBitmaps)
.doc("@brief ""Bitmap"" ""asset \"Name of bitmap asset to use\".");
addField("bitmapBounds", TypePoint2I, Offset(mBitmapBounds, GuiPopUpMenuCtrlEx), "Boundaries of bitmap displayed");
addField("hotTrackCallback", TypeBool, Offset(mHotTrackItems, GuiPopUpMenuCtrlEx),
@ -807,18 +810,18 @@ void GuiPopUpMenuCtrlEx::setBitmap(const char *name)
dStrcpy(p, "_n", pLen);
_setBitmap((StringTableEntry)buffer, Normal);
setBitmap((StringTableEntry)buffer, Normal);
dStrcpy(p, "_d", pLen);
_setBitmap((StringTableEntry)buffer, Depressed);
setBitmap((StringTableEntry)buffer, Depressed);
if (mBitmapAsset[Depressed].isNull())
mBitmapAsset[Depressed] = mBitmapAsset[Normal];
if (mBitmapAssetRef[Depressed].isNull())
mBitmapAssetRef[Depressed] = mBitmapAssetRef[Normal];
}
else
{
_setBitmap(StringTable->EmptyString(), Normal);
_setBitmap(StringTable->EmptyString(), Depressed);
setBitmap(StringTable->EmptyString(), Normal);
setBitmap(StringTable->EmptyString(), Depressed);
}
setUpdate();
}

View file

@ -131,7 +131,9 @@ class GuiPopUpMenuCtrlEx : public GuiTextCtrl
NumBitmapModes = 2
};
DECLARE_IMAGEASSET_ARRAY(GuiPopUpMenuCtrlEx, Bitmap, GFXDefaultGUIProfile, NumBitmapModes)
AssetRef<ImageAsset> mBitmapAssetRef[NumBitmapModes];
GFXTexHandle getBitmap(const U32& index) { return mBitmapAssetRef[index].notNull() ? mBitmapAssetRef[index].assetPtr->getTexture(&GFXDefaultGUIProfile) : GFXTexHandle(); }
void setBitmap(StringTableEntry assetId, const U32& index) { mBitmapAssetRef[index] = assetId; }
Point2I mBitmapBounds; // Added