Useful utility to set Brush content from a sprite without using a UImage

This commit is contained in:
Steve Streeting 2020-11-23 11:50:40 +00:00
parent b5bdc5141c
commit 183a601170
2 changed files with 34 additions and 0 deletions

View File

@ -191,6 +191,31 @@ UPaperSprite* UStevesGameSubsystem::GetImageSpriteFromTable(const FKey& InKey,
return nullptr;
}
void UStevesGameSubsystem::SetBrushFromAtlas(FSlateBrush* Brush, TScriptInterface<ISlateTextureAtlasInterface> AtlasRegion, bool bMatchSize)
{
if(Brush->GetResourceObject() != AtlasRegion.GetObject())
{
Brush->SetResourceObject(AtlasRegion.GetObject());
if (bMatchSize)
{
if (AtlasRegion)
{
const FSlateAtlasData AtlasData = AtlasRegion->GetSlateAtlasData();
Brush->ImageSize = AtlasData.GetSourceDimensions();
}
else
{
Brush->ImageSize = FVector2D(0, 0);
}
}
}
}
UStevesGameSubsystem::FInputModeDetector::FInputModeDetector()
{
// 4 local players should be plenty usually (will expand if necessary)

View File

@ -166,4 +166,13 @@ public:
*/
UPaperSprite* GetInputImageSpriteFromKey(const FKey& Key, const UUiTheme* Theme = nullptr);
/**
* @brief Set the content of a slate brush from an atlas (e.g. sprite)
* @param Brush The brush to update
* @param AtlasRegion Atlas to use as source e.g. a Sprite
* @param bMatchSize Whether to resize the brush to match the atlas entry
*/
void SetBrushFromAtlas(FSlateBrush* Brush, TScriptInterface<ISlateTextureAtlasInterface> AtlasRegion,
bool bMatchSize);
};