Files
UnrealEngineUWP/Engine/Source/Runtime/UMG/Private/Components/RetainerBox.cpp
Ben Marsh 20bf0eb6a1 Updating copyright notices to 2017 (copying from //Tasks/UE4/Dev-Copyright-2017).
#rb none
#lockdown Nick.Penwarden

[CL 3226823 by Ben Marsh in Main branch]
2016-12-08 08:52:44 -05:00

130 lines
2.9 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "Components/RetainerBox.h"
#include "Widgets/SNullWidget.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Slate/SRetainerWidget.h"
#define LOCTEXT_NAMESPACE "UMG"
static FName DefaultTextureParameterName("Texture");
/////////////////////////////////////////////////////
// URetainerBox
URetainerBox::URetainerBox(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
Visibility = ESlateVisibility::Visible;
Phase = 0;
PhaseCount = 1;
TextureParameter = DefaultTextureParameterName;
}
UMaterialInstanceDynamic* URetainerBox::GetEffectMaterial() const
{
if ( MyRetainerWidget.IsValid() )
{
return MyRetainerWidget->GetEffectMaterial();
}
return nullptr;
}
void URetainerBox::SetEffectMaterial(UMaterialInterface* InEffectMaterial)
{
EffectMaterial = InEffectMaterial;
if ( MyRetainerWidget.IsValid() )
{
MyRetainerWidget->SetEffectMaterial(EffectMaterial);
}
}
void URetainerBox::SetTextureParameter(FName InTextureParameter)
{
TextureParameter = InTextureParameter;
if ( MyRetainerWidget.IsValid() )
{
MyRetainerWidget->SetTextureParameter(TextureParameter);
}
}
void URetainerBox::ReleaseSlateResources(bool bReleaseChildren)
{
Super::ReleaseSlateResources(bReleaseChildren);
MyRetainerWidget.Reset();
}
TSharedRef<SWidget> URetainerBox::RebuildWidget()
{
MyRetainerWidget =
SNew(SRetainerWidget)
.Phase(Phase)
.PhaseCount(PhaseCount)
#if STATS
.StatId( FName( *FString::Printf(TEXT("%s [%s]"), *GetFName().ToString(), *GetClass()->GetName() ) ) )
#endif//STATS
;
MyRetainerWidget->SetRetainedRendering(IsDesignTime() ? false : true);
if ( GetChildrenCount() > 0 )
{
MyRetainerWidget->SetContent(GetContentSlot()->Content ? GetContentSlot()->Content->TakeWidget() : SNullWidget::NullWidget);
}
return BuildDesignTimeWidget(MyRetainerWidget.ToSharedRef());
}
void URetainerBox::SynchronizeProperties()
{
Super::SynchronizeProperties();
MyRetainerWidget->SetEffectMaterial(EffectMaterial);
MyRetainerWidget->SetTextureParameter(TextureParameter);
}
void URetainerBox::OnSlotAdded(UPanelSlot* InSlot)
{
// Add the child to the live slot if it already exists
if ( MyRetainerWidget.IsValid() )
{
MyRetainerWidget->SetContent(InSlot->Content ? InSlot->Content->TakeWidget() : SNullWidget::NullWidget);
}
}
void URetainerBox::OnSlotRemoved(UPanelSlot* InSlot)
{
// Remove the widget from the live slot if it exists.
if ( MyRetainerWidget.IsValid() )
{
MyRetainerWidget->SetContent(SNullWidget::NullWidget);
}
}
#if WITH_EDITOR
const FText URetainerBox::GetPaletteCategory()
{
return LOCTEXT("Optimization", "Optimization");
}
#endif
const FGeometry& URetainerBox::GetCachedAllottedGeometry() const
{
if (MyRetainerWidget.IsValid())
{
return MyRetainerWidget->GetCachedAllottedGeometry();
}
static const FGeometry TempGeo;
return TempGeo;
}
/////////////////////////////////////////////////////
#undef LOCTEXT_NAMESPACE