mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 07:04:36 +00:00
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:
parent
a858d8624e
commit
34e3f78a22
82 changed files with 1451 additions and 951 deletions
|
|
@ -120,6 +120,22 @@ IMPLEMENT_CALLBACK( GuiBitmapButtonCtrl, onShiftClick, void, (), (),
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void GuiBitmapButtonCtrl::_setBitmap(StringTableEntry _in)
|
||||
{
|
||||
if (mBitmapAssetRef.assetId == _in)
|
||||
return;
|
||||
|
||||
if (ImageAsset::isNamedTarget(_in))
|
||||
{
|
||||
mBitmapAssetRef.assetId = _in;
|
||||
mBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
|
||||
}
|
||||
else
|
||||
{
|
||||
mBitmapAssetRef = _in;
|
||||
}
|
||||
}
|
||||
|
||||
GuiBitmapButtonCtrl::GuiBitmapButtonCtrl()
|
||||
{
|
||||
mBitmapMode = BitmapStretched;
|
||||
|
|
@ -129,10 +145,7 @@ GuiBitmapButtonCtrl::GuiBitmapButtonCtrl()
|
|||
setExtent( 140, 30 );
|
||||
mMasked = false;
|
||||
mColor = ColorI::WHITE;
|
||||
mBitmapName = StringTable->EmptyString();
|
||||
mBitmap = NULL;
|
||||
mBitmapAsset.registerRefreshNotify(this);
|
||||
mBitmapFile = String::EmptyString;
|
||||
mBitmapAssetRef.assetPtr.registerRefreshNotify(this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -142,10 +155,11 @@ void GuiBitmapButtonCtrl::initPersistFields()
|
|||
docsURL;
|
||||
addGroup( "Bitmap" );
|
||||
|
||||
INITPERSISTFIELD_IMAGEASSET(Bitmap, GuiBitmapButtonCtrl,"Texture file to display on this button.\n"
|
||||
ADD_FIELD("bitmapAsset", TypeImageAssetRef, Offset(mBitmapAssetRef, GuiBitmapButtonCtrl))
|
||||
.doc("Texture asset to display on this button.\n"
|
||||
"If useStates is false, this will be the file that renders on the control. Otherwise, this will "
|
||||
"specify the default texture name to which the various state and modifier suffixes are appended "
|
||||
"to find the per-state and per-modifier (if enabled) textures.")
|
||||
"to find the per-state and per-modifier (if enabled) textures.");
|
||||
|
||||
addField("color", TypeColorI, Offset(mColor, GuiBitmapButtonCtrl), "color mul");
|
||||
|
||||
|
|
@ -183,7 +197,7 @@ bool GuiBitmapButtonCtrl::onWake()
|
|||
return false;
|
||||
|
||||
setActive( true );
|
||||
setBitmap( mBitmapName );
|
||||
setBitmap(mBitmapAssetRef.assetId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -192,17 +206,13 @@ bool GuiBitmapButtonCtrl::onWake()
|
|||
|
||||
void GuiBitmapButtonCtrl::onSleep()
|
||||
{
|
||||
if( dStricmp(mBitmapName, "texhandle") != 0 )
|
||||
for( U32 i = 0; i < NumModifiers; ++ i )
|
||||
{
|
||||
mTextures[ i ].mTextureNormal = NULL;
|
||||
mTextures[ i ].mTextureHilight = NULL;
|
||||
mTextures[ i ].mTextureDepressed = NULL;
|
||||
mTextures[ i ].mTextureInactive = NULL;
|
||||
}
|
||||
|
||||
if (mBitmapAsset.notNull())
|
||||
mBitmap = NULL;
|
||||
for( U32 i = 0; i < NumModifiers; ++ i )
|
||||
{
|
||||
mTextures[ i ].mTextureNormal = NULL;
|
||||
mTextures[ i ].mTextureHilight = NULL;
|
||||
mTextures[ i ].mTextureDepressed = NULL;
|
||||
mTextures[ i ].mTextureInactive = NULL;
|
||||
}
|
||||
|
||||
Parent::onSleep();
|
||||
}
|
||||
|
|
@ -241,7 +251,7 @@ void GuiBitmapButtonCtrl::inspectPostApply()
|
|||
{
|
||||
Parent::inspectPostApply();
|
||||
|
||||
setBitmap(mBitmapName);
|
||||
setBitmap(mBitmapAssetRef.assetId);
|
||||
|
||||
// if the extent is set to (0,0) in the gui editor and appy hit, this control will
|
||||
// set it's extent to be exactly the size of the normal bitmap (if present)
|
||||
|
|
@ -258,7 +268,7 @@ void GuiBitmapButtonCtrl::setAutoFitExtents( bool state )
|
|||
{
|
||||
mAutoFitExtents = state;
|
||||
if( mAutoFitExtents )
|
||||
setBitmap( mBitmapName );
|
||||
setBitmap(mBitmapAssetRef.assetId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
@ -271,143 +281,140 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
|
|||
if( !isAwake() )
|
||||
return;
|
||||
|
||||
if( mBitmapAsset.notNull())
|
||||
if( mBitmapAssetRef.notNull())
|
||||
{
|
||||
if( dStricmp( mBitmapName, "texhandle" ) != 0 )
|
||||
const U32 count = mUseModifiers ? NumModifiers : 1;
|
||||
for( U32 i = 0; i < count; ++ i )
|
||||
{
|
||||
const U32 count = mUseModifiers ? NumModifiers : 1;
|
||||
for( U32 i = 0; i < count; ++ i )
|
||||
static String modifiers[] =
|
||||
{
|
||||
static String modifiers[] =
|
||||
"",
|
||||
"_ctrl",
|
||||
"_alt",
|
||||
"_shift"
|
||||
};
|
||||
|
||||
static String s_n[2] = { "_n", "_n_image" };
|
||||
static String s_d[2] = { "_d", "_d_image" };
|
||||
static String s_h[2] = { "_h", "_h_image" };
|
||||
static String s_i[2] = { "_i", "_i_image" };
|
||||
|
||||
String baseName = mBitmapAssetRef.getAssetId();
|
||||
|
||||
//strip any pre-assigned suffix, just in case
|
||||
baseName = baseName.replace("_n_image", "");
|
||||
baseName = baseName.replace("_n", "");
|
||||
|
||||
if( mUseModifiers )
|
||||
baseName += modifiers[ i ];
|
||||
|
||||
mTextures[i].mTextureNormal = getBitmap();
|
||||
|
||||
if( mUseStates )
|
||||
{
|
||||
//normal lookup
|
||||
StringTableEntry lookupName;
|
||||
for (U32 s = 0; s < 2; s++)
|
||||
{
|
||||
"",
|
||||
"_ctrl",
|
||||
"_alt",
|
||||
"_shift"
|
||||
};
|
||||
|
||||
static String s_n[2] = { "_n", "_n_image" };
|
||||
static String s_d[2] = { "_d", "_d_image" };
|
||||
static String s_h[2] = { "_h", "_h_image" };
|
||||
static String s_i[2] = { "_i", "_i_image" };
|
||||
|
||||
String baseName = mBitmapAsset.getAssetId();
|
||||
|
||||
//strip any pre-assigned suffix, just in case
|
||||
baseName = baseName.replace("_n_image", "");
|
||||
baseName = baseName.replace("_n", "");
|
||||
|
||||
if( mUseModifiers )
|
||||
baseName += modifiers[ i ];
|
||||
|
||||
mTextures[i].mTextureNormal = getBitmap();
|
||||
|
||||
if( mUseStates )
|
||||
{
|
||||
//normal lookup
|
||||
StringTableEntry lookupName;
|
||||
for (U32 s = 0; s < 2; s++)
|
||||
if (!mTextures[i].mTextureNormal)
|
||||
{
|
||||
if (!mTextures[i].mTextureNormal)
|
||||
{
|
||||
lookupName = StringTable->insert(String(baseName + s_n[s]).c_str());
|
||||
if (AssetDatabase.isDeclaredAsset(lookupName))
|
||||
{
|
||||
mTextures[i].mTextureNormalAssetId = lookupName;
|
||||
mTextures[i].mTextureNormalAsset = mTextures[i].mTextureNormalAssetId;
|
||||
}
|
||||
|
||||
if (mTextures[i].mTextureNormalAsset.notNull())
|
||||
{
|
||||
mTextures[i].mTextureNormalAsset->load();
|
||||
if (mTextures[i].mTextureNormalAsset->getStatus() == AssetBase::Ok)
|
||||
{
|
||||
mTextures[i].mTextureNormal = mTextures[i].mTextureNormalAsset->getTexture(&GFXDefaultGUIProfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Hilight lookup
|
||||
for (U32 s = 0; s < 2; s++)
|
||||
{
|
||||
lookupName = StringTable->insert(String(baseName + s_h[s]).c_str());
|
||||
lookupName = StringTable->insert(String(baseName + s_n[s]).c_str());
|
||||
if (AssetDatabase.isDeclaredAsset(lookupName))
|
||||
{
|
||||
mTextures[i].mTextureHilightAssetId = lookupName;
|
||||
mTextures[i].mTextureHilightAsset = mTextures[i].mTextureHilightAssetId;
|
||||
mTextures[i].mTextureNormalAssetId = lookupName;
|
||||
mTextures[i].mTextureNormalAsset = mTextures[i].mTextureNormalAssetId;
|
||||
}
|
||||
|
||||
if (mTextures[i].mTextureHilightAsset.notNull())
|
||||
if (mTextures[i].mTextureNormalAsset.notNull())
|
||||
{
|
||||
mTextures[i].mTextureHilightAsset->load();
|
||||
if (mTextures[i].mTextureHilightAsset->getStatus() == AssetBase::Ok)
|
||||
mTextures[i].mTextureNormalAsset->load();
|
||||
if (mTextures[i].mTextureNormalAsset->getStatus() == AssetBase::Ok)
|
||||
{
|
||||
mTextures[i].mTextureHilight = mTextures[i].mTextureHilightAsset->getTexture(&GFXDefaultGUIProfile);
|
||||
mTextures[i].mTextureNormal = mTextures[i].mTextureNormalAsset->getTexture(&GFXDefaultGUIProfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !mTextures[ i ].mTextureHilight )
|
||||
mTextures[ i ].mTextureHilight = mTextures[ i ].mTextureNormal;
|
||||
|
||||
//Depressed lookup
|
||||
for (U32 s = 0; s < 2; s++)
|
||||
{
|
||||
lookupName = StringTable->insert(String(baseName + s_d[s]).c_str());
|
||||
if (AssetDatabase.isDeclaredAsset(lookupName))
|
||||
{
|
||||
mTextures[i].mTextureDepressedAssetId = lookupName;
|
||||
mTextures[i].mTextureDepressedAsset = mTextures[i].mTextureDepressedAssetId;
|
||||
}
|
||||
|
||||
if (mTextures[i].mTextureDepressedAsset.notNull())
|
||||
{
|
||||
mTextures[i].mTextureDepressedAsset->load();
|
||||
if (mTextures[i].mTextureDepressedAsset->getStatus() == AssetBase::Ok)
|
||||
{
|
||||
mTextures[i].mTextureDepressed = mTextures[i].mTextureDepressedAsset->getTexture(&GFXDefaultGUIProfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !mTextures[ i ].mTextureDepressed )
|
||||
mTextures[ i ].mTextureDepressed = mTextures[ i ].mTextureHilight;
|
||||
|
||||
//Depressed lookup
|
||||
for (U32 s = 0; s < 2; s++)
|
||||
{
|
||||
lookupName = StringTable->insert(String(baseName + s_i[s]).c_str());
|
||||
if (AssetDatabase.isDeclaredAsset(lookupName))
|
||||
{
|
||||
mTextures[i].mTextureInactiveAssetId = lookupName;
|
||||
mTextures[i].mTextureInactiveAsset = mTextures[i].mTextureInactiveAssetId;
|
||||
}
|
||||
|
||||
if (mTextures[i].mTextureInactiveAsset.notNull())
|
||||
{
|
||||
mTextures[i].mTextureInactiveAsset->load();
|
||||
if (mTextures[i].mTextureInactiveAsset->getStatus() == AssetBase::Ok)
|
||||
{
|
||||
mTextures[i].mTextureInactive = mTextures[i].mTextureInactiveAsset->getTexture(&GFXDefaultGUIProfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !mTextures[ i ].mTextureInactive )
|
||||
mTextures[ i ].mTextureInactive = mTextures[ i ].mTextureNormal;
|
||||
}
|
||||
|
||||
if( i == 0 && mTextures[ i ].mTextureNormal.isNull() && mTextures[ i ].mTextureHilight.isNull() && mTextures[ i ].mTextureDepressed.isNull() && mTextures[ i ].mTextureInactive.isNull() )
|
||||
//Hilight lookup
|
||||
for (U32 s = 0; s < 2; s++)
|
||||
{
|
||||
Con::warnf( "GuiBitmapButtonCtrl::setBitmap - Unable to load texture: %s", mBitmapName );
|
||||
this->setBitmap( StringTable->insert(GFXTextureManager::getUnavailableTexturePath().c_str()) );
|
||||
return;
|
||||
lookupName = StringTable->insert(String(baseName + s_h[s]).c_str());
|
||||
if (AssetDatabase.isDeclaredAsset(lookupName))
|
||||
{
|
||||
mTextures[i].mTextureHilightAssetId = lookupName;
|
||||
mTextures[i].mTextureHilightAsset = mTextures[i].mTextureHilightAssetId;
|
||||
}
|
||||
|
||||
if (mTextures[i].mTextureHilightAsset.notNull())
|
||||
{
|
||||
mTextures[i].mTextureHilightAsset->load();
|
||||
if (mTextures[i].mTextureHilightAsset->getStatus() == AssetBase::Ok)
|
||||
{
|
||||
mTextures[i].mTextureHilight = mTextures[i].mTextureHilightAsset->getTexture(&GFXDefaultGUIProfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !mTextures[ i ].mTextureHilight )
|
||||
mTextures[ i ].mTextureHilight = mTextures[ i ].mTextureNormal;
|
||||
|
||||
//Depressed lookup
|
||||
for (U32 s = 0; s < 2; s++)
|
||||
{
|
||||
lookupName = StringTable->insert(String(baseName + s_d[s]).c_str());
|
||||
if (AssetDatabase.isDeclaredAsset(lookupName))
|
||||
{
|
||||
mTextures[i].mTextureDepressedAssetId = lookupName;
|
||||
mTextures[i].mTextureDepressedAsset = mTextures[i].mTextureDepressedAssetId;
|
||||
}
|
||||
|
||||
if (mTextures[i].mTextureDepressedAsset.notNull())
|
||||
{
|
||||
mTextures[i].mTextureDepressedAsset->load();
|
||||
if (mTextures[i].mTextureDepressedAsset->getStatus() == AssetBase::Ok)
|
||||
{
|
||||
mTextures[i].mTextureDepressed = mTextures[i].mTextureDepressedAsset->getTexture(&GFXDefaultGUIProfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !mTextures[ i ].mTextureDepressed )
|
||||
mTextures[ i ].mTextureDepressed = mTextures[ i ].mTextureHilight;
|
||||
|
||||
//Depressed lookup
|
||||
for (U32 s = 0; s < 2; s++)
|
||||
{
|
||||
lookupName = StringTable->insert(String(baseName + s_i[s]).c_str());
|
||||
if (AssetDatabase.isDeclaredAsset(lookupName))
|
||||
{
|
||||
mTextures[i].mTextureInactiveAssetId = lookupName;
|
||||
mTextures[i].mTextureInactiveAsset = mTextures[i].mTextureInactiveAssetId;
|
||||
}
|
||||
|
||||
if (mTextures[i].mTextureInactiveAsset.notNull())
|
||||
{
|
||||
mTextures[i].mTextureInactiveAsset->load();
|
||||
if (mTextures[i].mTextureInactiveAsset->getStatus() == AssetBase::Ok)
|
||||
{
|
||||
mTextures[i].mTextureInactive = mTextures[i].mTextureInactiveAsset->getTexture(&GFXDefaultGUIProfile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !mTextures[ i ].mTextureInactive )
|
||||
mTextures[ i ].mTextureInactive = mTextures[ i ].mTextureNormal;
|
||||
}
|
||||
|
||||
if( i == 0 && mTextures[ i ].mTextureNormal.isNull() && mTextures[ i ].mTextureHilight.isNull() && mTextures[ i ].mTextureDepressed.isNull() && mTextures[ i ].mTextureInactive.isNull() )
|
||||
{
|
||||
Con::warnf( "GuiBitmapButtonCtrl::setBitmap - Unable to load texture: %s", mBitmapAssetRef.assetId);
|
||||
this->setBitmap( StringTable->insert(GFXTextureManager::getUnavailableTexturePath().c_str()) );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -428,37 +435,6 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
|
|||
setUpdate();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void GuiBitmapButtonCtrl::setBitmapHandles(GFXTexHandle normal, GFXTexHandle highlighted, GFXTexHandle depressed, GFXTexHandle inactive)
|
||||
{
|
||||
const U32 count = mUseModifiers ? NumModifiers : 1;
|
||||
for( U32 i = 0; i < count; ++ i )
|
||||
{
|
||||
mTextures[ i ].mTextureNormal = normal;
|
||||
mTextures[ i ].mTextureHilight = highlighted;
|
||||
mTextures[ i ].mTextureDepressed = depressed;
|
||||
mTextures[ i ].mTextureInactive = inactive;
|
||||
|
||||
if (!mTextures[ i ].mTextureHilight)
|
||||
mTextures[ i ].mTextureHilight = mTextures[ i ].mTextureNormal;
|
||||
if (!mTextures[ i ].mTextureDepressed)
|
||||
mTextures[ i ].mTextureDepressed = mTextures[ i ].mTextureHilight;
|
||||
if (!mTextures[ i ].mTextureInactive)
|
||||
mTextures[ i ].mTextureInactive = mTextures[ i ].mTextureNormal;
|
||||
|
||||
if (mTextures[ i ].mTextureNormal.isNull() && mTextures[ i ].mTextureHilight.isNull() && mTextures[ i ].mTextureDepressed.isNull() && mTextures[ i ].mTextureInactive.isNull())
|
||||
{
|
||||
Con::warnf("GuiBitmapButtonCtrl::setBitmapHandles() - Invalid texture handles");
|
||||
setBitmap( StringTable->insert(GFXTextureManager::getUnavailableTexturePath().c_str()) );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mBitmapName = "texhandle";
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
GuiBitmapButtonCtrl::Modifier GuiBitmapButtonCtrl::getCurrentModifier()
|
||||
|
|
@ -644,7 +620,7 @@ bool GuiBitmapButtonCtrl::pointInControl(const Point2I& parentCoordPoint)
|
|||
bmp = getTextureForCurrentState().getBitmap();
|
||||
if (!bmp)
|
||||
{
|
||||
setBitmap(mBitmapName);
|
||||
setBitmap(mBitmapAssetRef.assetId);
|
||||
bmp = getTextureForCurrentState().getBitmap();
|
||||
}
|
||||
|
||||
|
|
@ -669,10 +645,12 @@ bool GuiBitmapButtonCtrl::pointInControl(const Point2I& parentCoordPoint)
|
|||
return Parent::pointInControl(parentCoordPoint);
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiBitmapButtonCtrl, getBitmap, StringTableEntry, (), , "get name") {
|
||||
return object->getBitmapFile();
|
||||
}DefineEngineMethod(GuiBitmapButtonCtrl, getBitmapAsset, StringTableEntry, (), , assetText(Bitmap, asset reference)) {
|
||||
return object->_getBitmap();
|
||||
}DefineEngineMethod(GuiBitmapButtonCtrl, setBitmap, void, (const char* assetName), , assetText(Bitmap, assignment.first tries asset then flat file.)) {
|
||||
DefineEngineMethod(GuiBitmapButtonCtrl, getBitmapAsset, StringTableEntry, (), , "Get the Bitmap asset reference.")
|
||||
{
|
||||
return object->getBitmapAssetId();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiBitmapButtonCtrl, setBitmap, void, (const char* assetName), , "Bitmap assignment. First tries asset then flat file.")
|
||||
{
|
||||
object->setBitmap(StringTable->insert(assetName));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,46 +119,19 @@ class GuiBitmapButtonCtrl : public GuiButtonCtrl, protected AssetPtrCallback
|
|||
BitmapMode mBitmapMode;
|
||||
|
||||
private:
|
||||
AssetPtr<ImageAsset> mBitmapAsset;
|
||||
String mBitmapFile;
|
||||
AssetRef<ImageAsset> mBitmapAssetRef;
|
||||
public:
|
||||
void _setBitmap(StringTableEntry _in) {
|
||||
if (_in == NULL || _in == StringTable->EmptyString() || _in[0] == '\0')
|
||||
{
|
||||
mBitmapAsset = NULL;
|
||||
mBitmapFile = "";
|
||||
return;
|
||||
}
|
||||
if (mBitmapAsset.getAssetId() == _in) return; if (!AssetDatabase.isDeclaredAsset(_in)) {
|
||||
StringTableEntry imageAssetId = ImageAsset::smNoImageAssetFallback; AssetQuery query; S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, _in); if (foundAssetcount != 0) {
|
||||
imageAssetId = query.mAssetList[0];
|
||||
} mBitmapAsset = imageAssetId;
|
||||
}
|
||||
else {
|
||||
mBitmapAsset = _in;
|
||||
mBitmapName = _in;
|
||||
mBitmap = getBitmap();
|
||||
}
|
||||
}; inline StringTableEntry _getBitmap(void) const {
|
||||
return mBitmapAsset.getAssetId();
|
||||
} GFXTexHandle getBitmap() {
|
||||
return mBitmapAsset.notNull() ? mBitmapAsset->getTexture(&GFXDefaultGUIProfile) : 0;
|
||||
} AssetPtr<ImageAsset> getBitmapAsset(void) {
|
||||
return mBitmapAsset;
|
||||
} static bool _setBitmapData(void* obj, const char* index, const char* data) {
|
||||
static_cast<GuiBitmapButtonCtrl*>(obj)->_setBitmap(_getStringTable()->insert(data)); return false;
|
||||
}
|
||||
StringTableEntry getBitmapFile() { return mBitmapAsset.notNull() ? mBitmapAsset->getImageFile() : ""; }
|
||||
void _setBitmap(StringTableEntry _in);
|
||||
inline StringTableEntry getBitmapAssetId() const { return mBitmapAssetRef.getAssetId(); }
|
||||
GFXTexHandle getBitmap() { return mBitmapAssetRef.notNull() ? mBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
|
||||
|
||||
protected:
|
||||
|
||||
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
|
||||
{
|
||||
setBitmap(mBitmapName);
|
||||
setBitmap(mBitmapAssetRef.assetId);
|
||||
}
|
||||
|
||||
GFXTexHandle mBitmap;
|
||||
StringTableEntry mBitmapName;
|
||||
/// alpha masking
|
||||
bool mMasked;
|
||||
|
||||
|
|
@ -202,7 +175,6 @@ protected:
|
|||
|
||||
void setAutoFitExtents( bool state );
|
||||
void setBitmap( StringTableEntry name );
|
||||
void setBitmapHandles( GFXTexHandle normal, GFXTexHandle highlighted, GFXTexHandle depressed, GFXTexHandle inactive );
|
||||
|
||||
//Parent methods
|
||||
bool onWake() override;
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ void GuiIconButtonCtrl::initPersistFields()
|
|||
docsURL;
|
||||
addField( "buttonMargin", TypePoint2I, Offset( mButtonMargin, GuiIconButtonCtrl ),"Margin area around the button.\n");
|
||||
|
||||
INITPERSISTFIELD_IMAGEASSET(Bitmap, GuiIconButtonCtrl, "Bitmap file for the icon to display on the button.\n");
|
||||
ADD_FIELD("bitmapAsset", TypeImageAssetRef, Offset(mBitmapAssetRef, GuiIconButtonCtrl))
|
||||
.doc("Bitmap asset for the icon to display on the button.");
|
||||
|
||||
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");
|
||||
|
|
@ -200,6 +201,21 @@ bool GuiIconButtonCtrl::resize(const Point2I &newPosition, const Point2I &newExt
|
|||
return Parent::resize( newPosition, autoExtent );
|
||||
}
|
||||
|
||||
void GuiIconButtonCtrl::_setBitmap(StringTableEntry _in)
|
||||
{
|
||||
if (mBitmapAssetRef.assetId == _in)
|
||||
return;
|
||||
|
||||
if (ImageAsset::isNamedTarget(_in))
|
||||
{
|
||||
mBitmapAssetRef.assetId = _in;
|
||||
mBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
|
||||
return;
|
||||
}
|
||||
|
||||
mBitmapAssetRef = _in;
|
||||
}
|
||||
|
||||
void GuiIconButtonCtrl::setBitmap(const char *name)
|
||||
{
|
||||
_setBitmap(name);
|
||||
|
|
@ -463,10 +479,12 @@ void GuiIconButtonCtrl::renderBitmapArray(RectI &bounds, S32 state)
|
|||
}
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiIconButtonCtrl, getBitmap, StringTableEntry, (), , "get name") {
|
||||
return object->getBitmapFile();
|
||||
}DefineEngineMethod(GuiIconButtonCtrl, getBitmapAsset, StringTableEntry, (), , assetText(Bitmap, asset reference)) {
|
||||
return object->_getBitmap();
|
||||
}DefineEngineMethod(GuiIconButtonCtrl, setBitmap, void, (const char* assetName), , assetText(Bitmap, assignment.first tries asset then flat file.)) {
|
||||
DefineEngineMethod(GuiIconButtonCtrl, getBitmapAsset, StringTableEntry, (), , "Get the Bitmap asset reference.")
|
||||
{
|
||||
return object->getBitmapAssetId();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiIconButtonCtrl, setBitmap, void, (const char* assetName), , "Bitmap assignment. First tries asset then flat file.")
|
||||
{
|
||||
object->setBitmap(StringTable->insert(assetName));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ private:
|
|||
|
||||
protected:
|
||||
|
||||
DECLARE_IMAGEASSET(GuiIconButtonCtrl, Bitmap, GFXDefaultGUIProfile)
|
||||
AssetRef<ImageAsset> mBitmapAssetRef;
|
||||
|
||||
S32 mIconLocation;
|
||||
S32 mTextLocation;
|
||||
|
|
@ -113,9 +113,27 @@ public:
|
|||
// Used to set the optional error bitmap
|
||||
void setErrorBitmap(const char *name);
|
||||
|
||||
void _setBitmap(StringTableEntry _in);
|
||||
inline StringTableEntry getBitmapAssetId() const { return mBitmapAssetRef.getAssetId(); }
|
||||
GFXTexHandle getBitmap() { return mBitmapAssetRef.notNull() ? mBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
|
||||
|
||||
void onRender(Point2I offset, const RectI &updateRect) override;
|
||||
|
||||
void onImageChanged() {}
|
||||
|
||||
void setFitBitmapToButton(const bool& state) {
|
||||
mFitBitmapToButton = state;
|
||||
}
|
||||
bool getFitBitmapToButton() const {
|
||||
return mFitBitmapToButton;
|
||||
}
|
||||
|
||||
void setMakeIconSquare(const bool& state) {
|
||||
mMakeIconSquare = state;
|
||||
}
|
||||
bool getMakeIconSquare() const {
|
||||
return mMakeIconSquare;
|
||||
}
|
||||
};
|
||||
|
||||
typedef GuiIconButtonCtrl::TextLocation GuiIconButtonTextLocation;
|
||||
|
|
|
|||
|
|
@ -55,9 +55,12 @@ GuiToolboxButtonCtrl::GuiToolboxButtonCtrl()
|
|||
void GuiToolboxButtonCtrl::initPersistFields()
|
||||
{
|
||||
docsURL;
|
||||
INITPERSISTFIELD_IMAGEASSET(NormalBitmap, GuiToolboxButtonCtrl, "");
|
||||
INITPERSISTFIELD_IMAGEASSET(LoweredBitmap, GuiToolboxButtonCtrl, "");
|
||||
INITPERSISTFIELD_IMAGEASSET(HoverBitmap, GuiToolboxButtonCtrl, "");
|
||||
ADD_FIELD("normalBitmapAsset", TypeImageAssetRef, Offset(mNormalBitmapAssetRef, GuiToolboxButtonCtrl))
|
||||
.doc("Bitmap asset to display when the button is in its normal state.");
|
||||
ADD_FIELD("loweredBitmapAsset", TypeImageAssetRef, Offset(mLoweredBitmapAssetRef, GuiToolboxButtonCtrl))
|
||||
.doc("Bitmap asset to display when the button is pressed.");
|
||||
ADD_FIELD("hoverBitmapAsset", TypeImageAssetRef, Offset(mHoverBitmapAssetRef, GuiToolboxButtonCtrl))
|
||||
.doc("Bitmap asset to display when the button is hovered.");
|
||||
|
||||
Parent::initPersistFields();
|
||||
}
|
||||
|
|
@ -95,6 +98,52 @@ void GuiToolboxButtonCtrl::inspectPostApply()
|
|||
}
|
||||
|
||||
|
||||
//-------------------------------------
|
||||
void GuiToolboxButtonCtrl::_setNormalBitmap(StringTableEntry _in)
|
||||
{
|
||||
if (mNormalBitmapAssetRef.assetId == _in)
|
||||
return;
|
||||
|
||||
if (ImageAsset::isNamedTarget(_in))
|
||||
{
|
||||
mNormalBitmapAssetRef.assetId = _in;
|
||||
mNormalBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
|
||||
return;
|
||||
}
|
||||
|
||||
mNormalBitmapAssetRef = _in;
|
||||
}
|
||||
|
||||
void GuiToolboxButtonCtrl::_setLoweredBitmap(StringTableEntry _in)
|
||||
{
|
||||
if (mLoweredBitmapAssetRef.assetId == _in)
|
||||
return;
|
||||
|
||||
if (ImageAsset::isNamedTarget(_in))
|
||||
{
|
||||
mLoweredBitmapAssetRef.assetId = _in;
|
||||
mLoweredBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
|
||||
return;
|
||||
}
|
||||
|
||||
mLoweredBitmapAssetRef = _in;
|
||||
}
|
||||
|
||||
void GuiToolboxButtonCtrl::_setHoverBitmap(StringTableEntry _in)
|
||||
{
|
||||
if (mHoverBitmapAssetRef.assetId == _in)
|
||||
return;
|
||||
|
||||
if (ImageAsset::isNamedTarget(_in))
|
||||
{
|
||||
mHoverBitmapAssetRef.assetId = _in;
|
||||
mHoverBitmapAssetRef.assetPtr = ImageAsset::getNamedTargetAssetPtr(_in);
|
||||
return;
|
||||
}
|
||||
|
||||
mHoverBitmapAssetRef = _in;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void GuiToolboxButtonCtrl::setNormalBitmap( StringTableEntry bitmapName )
|
||||
{
|
||||
|
|
@ -186,6 +235,32 @@ void GuiToolboxButtonCtrl::renderButton(GFXTexHandle texture, Point2I &offset, c
|
|||
}
|
||||
}
|
||||
|
||||
DEF_ASSET_BINDS_REFACTOR(GuiToolboxButtonCtrl, NormalBitmap)
|
||||
DEF_ASSET_BINDS_REFACTOR(GuiToolboxButtonCtrl, LoweredBitmap)
|
||||
DEF_ASSET_BINDS_REFACTOR(GuiToolboxButtonCtrl, HoverBitmap)
|
||||
DefineEngineMethod(GuiToolboxButtonCtrl, getNormalBitmapAsset, StringTableEntry, (), , "Get the Normal Bitmap asset reference.")
|
||||
{
|
||||
return object->getNormalBitmapAssetId();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiToolboxButtonCtrl, setNormalBitmap, void, (const char* assetName), , "Normal Bitmap assignment. First tries asset then flat file.")
|
||||
{
|
||||
object->setNormalBitmap(StringTable->insert(assetName));
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiToolboxButtonCtrl, getLoweredBitmapAsset, StringTableEntry, (), , "Get the Lowered Bitmap asset reference.")
|
||||
{
|
||||
return object->getLoweredBitmapAssetId();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiToolboxButtonCtrl, setLoweredBitmap, void, (const char* assetName), , "Lowered Bitmap assignment. First tries asset then flat file.")
|
||||
{
|
||||
object->setLoweredBitmap(StringTable->insert(assetName));
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiToolboxButtonCtrl, getHoverBitmapAsset, StringTableEntry, (), , "Get the Hover Bitmap asset reference.")
|
||||
{
|
||||
return object->getHoverBitmapAssetId();
|
||||
}
|
||||
|
||||
DefineEngineMethod(GuiToolboxButtonCtrl, setHoverBitmap, void, (const char* assetName), , "Hover Bitmap assignment. First tries asset then flat file.")
|
||||
{
|
||||
object->setHoverBitmap(StringTable->insert(assetName));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ private:
|
|||
|
||||
protected:
|
||||
|
||||
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, NormalBitmap, GFXDefaultGUIProfile)
|
||||
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, LoweredBitmap, GFXDefaultGUIProfile)
|
||||
DECLARE_IMAGEASSET(GuiToolboxButtonCtrl, HoverBitmap, GFXDefaultGUIProfile)
|
||||
AssetRef<ImageAsset> mNormalBitmapAssetRef;
|
||||
AssetRef<ImageAsset> mLoweredBitmapAssetRef;
|
||||
AssetRef<ImageAsset> mHoverBitmapAssetRef;
|
||||
|
||||
void renderButton(GFXTexHandle texture, Point2I &offset, const RectI& updateRect);
|
||||
void renderStateRect( GFXTexHandle texture, const RectI& rect );
|
||||
|
|
@ -60,7 +60,19 @@ public:
|
|||
void setNormalBitmap( StringTableEntry bitmapName );
|
||||
void setLoweredBitmap( StringTableEntry bitmapName );
|
||||
void setHoverBitmap( StringTableEntry bitmapName );
|
||||
|
||||
|
||||
void _setNormalBitmap(StringTableEntry _in);
|
||||
inline StringTableEntry getNormalBitmapAssetId() const { return mNormalBitmapAssetRef.getAssetId(); }
|
||||
GFXTexHandle getNormalBitmap() { return mNormalBitmapAssetRef.notNull() ? mNormalBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
|
||||
|
||||
void _setLoweredBitmap(StringTableEntry _in);
|
||||
inline StringTableEntry getLoweredBitmapAssetId() const { return mLoweredBitmapAssetRef.getAssetId(); }
|
||||
GFXTexHandle getLoweredBitmap() { return mLoweredBitmapAssetRef.notNull() ? mLoweredBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
|
||||
|
||||
void _setHoverBitmap(StringTableEntry _in);
|
||||
inline StringTableEntry getHoverBitmapAssetId() const { return mHoverBitmapAssetRef.getAssetId(); }
|
||||
GFXTexHandle getHoverBitmap() { return mHoverBitmapAssetRef.notNull() ? mHoverBitmapAssetRef.assetPtr->getTexture(&GFXDefaultGUIProfile) : NULL; }
|
||||
|
||||
|
||||
void onRender(Point2I offset, const RectI &updateRect) override;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue