41 lines
956 B
C++
41 lines
956 B
C++
//
|
|
|
|
|
|
#include "Synty_IconFrame.h"
|
|
|
|
#include "Components/Image.h"
|
|
#include "Kismet/KismetMaterialLibrary.h"
|
|
|
|
void USynty_IconFrame::UpdateIconImage(TSoftObjectPtr<UTexture2D> NewTexture)
|
|
{
|
|
IconTexture = NewTexture;
|
|
if (IconImage && !IconTexture.IsNull())
|
|
{
|
|
if (IconMaterialInstance)
|
|
{
|
|
IconMaterialInstance->SetTextureParameterValue(FName("InputTexture"), IconTexture.LoadSynchronous());
|
|
FSlateBrush Brush;
|
|
Brush.SetResourceObject(IconMaterialInstance);
|
|
Brush.DrawAs = ESlateBrushDrawType::Box;
|
|
Brush.SetImageSize(IconSize);
|
|
Brush.Margin = IconPadding;
|
|
IconImage->SetBrush(Brush);
|
|
}
|
|
else
|
|
{
|
|
IconImage->SetBrushFromTexture(IconTexture.LoadSynchronous());
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void USynty_IconFrame::NativePreConstruct()
|
|
{
|
|
Super::NativePreConstruct();
|
|
if (IconMaterialInterface)
|
|
{
|
|
IconMaterialInstance = UKismetMaterialLibrary::CreateDynamicMaterialInstance(this, IconMaterialInterface);
|
|
}
|
|
UpdateIconImage(IconTexture);
|
|
}
|