diff --git a/Source/StevesUEHelpers/Private/StevesGameSubsystem.cpp b/Source/StevesUEHelpers/Private/StevesGameSubsystem.cpp index 0ae5ee8..a57c9b0 100644 --- a/Source/StevesUEHelpers/Private/StevesGameSubsystem.cpp +++ b/Source/StevesUEHelpers/Private/StevesGameSubsystem.cpp @@ -191,6 +191,31 @@ UPaperSprite* UStevesGameSubsystem::GetImageSpriteFromTable(const FKey& InKey, return nullptr; } +void UStevesGameSubsystem::SetBrushFromAtlas(FSlateBrush* Brush, TScriptInterface 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) diff --git a/Source/StevesUEHelpers/Public/StevesGameSubsystem.h b/Source/StevesUEHelpers/Public/StevesGameSubsystem.h index adf44e8..a638f36 100644 --- a/Source/StevesUEHelpers/Public/StevesGameSubsystem.h +++ b/Source/StevesUEHelpers/Public/StevesGameSubsystem.h @@ -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 AtlasRegion, + bool bMatchSize); + };