You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb vincent.gauthier #preflight 621cc32a9a5676d19a301114 #ROBOMERGE-OWNER: patrick.boutot #ROBOMERGE-AUTHOR: patrick.boutot #ROBOMERGE-SOURCE: CL 19172743 via CL 19172838 via CL 19172865 via CL 19173039 via CL 19173047 via CL 19173891 #ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v921-19075845) [CL 19174092 by patrick boutot in ue5-main branch]
259 lines
5.4 KiB
C++
259 lines
5.4 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "Components/Button.h"
|
|
#include "Widgets/SNullWidget.h"
|
|
#include "Widgets/DeclarativeSyntaxSupport.h"
|
|
#include "Widgets/Input/SButton.h"
|
|
#include "Components/ButtonSlot.h"
|
|
#include "Styling/UMGCoreStyle.h"
|
|
#include "Blueprint/WidgetTree.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "UMG"
|
|
|
|
/////////////////////////////////////////////////////
|
|
// UButton
|
|
|
|
static FButtonStyle* DefaultButtonStyle = nullptr;
|
|
|
|
#if WITH_EDITOR
|
|
static FButtonStyle* EditorButtonStyle = nullptr;
|
|
#endif
|
|
|
|
UButton::UButton(const FObjectInitializer& ObjectInitializer)
|
|
: Super(ObjectInitializer)
|
|
{
|
|
if (DefaultButtonStyle == nullptr)
|
|
{
|
|
DefaultButtonStyle = new FButtonStyle(FUMGCoreStyle::Get().GetWidgetStyle<FButtonStyle>("Button"));
|
|
|
|
// Unlink UMG default colors.
|
|
DefaultButtonStyle->UnlinkColors();
|
|
}
|
|
|
|
WidgetStyle = *DefaultButtonStyle;
|
|
|
|
#if WITH_EDITOR
|
|
if (EditorButtonStyle == nullptr)
|
|
{
|
|
EditorButtonStyle = new FButtonStyle(FCoreStyle::Get().GetWidgetStyle<FButtonStyle>("EditorUtilityButton"));
|
|
|
|
// Unlink UMG Editor colors from the editor settings colors.
|
|
EditorButtonStyle->UnlinkColors();
|
|
}
|
|
|
|
if (IsEditorWidget())
|
|
{
|
|
WidgetStyle = *EditorButtonStyle;
|
|
|
|
// The CDO isn't an editor widget and thus won't use the editor style, call post edit change to mark difference from CDO
|
|
PostEditChange();
|
|
}
|
|
#endif // WITH_EDITOR
|
|
|
|
ColorAndOpacity = FLinearColor::White;
|
|
BackgroundColor = FLinearColor::White;
|
|
|
|
ClickMethod = EButtonClickMethod::DownAndUp;
|
|
TouchMethod = EButtonTouchMethod::DownAndUp;
|
|
|
|
IsFocusable = true;
|
|
|
|
#if WITH_EDITORONLY_DATA
|
|
AccessibleBehavior = ESlateAccessibleBehavior::Summary;
|
|
bCanChildrenBeAccessible = false;
|
|
#endif
|
|
}
|
|
|
|
void UButton::ReleaseSlateResources(bool bReleaseChildren)
|
|
{
|
|
Super::ReleaseSlateResources(bReleaseChildren);
|
|
|
|
MyButton.Reset();
|
|
}
|
|
|
|
TSharedRef<SWidget> UButton::RebuildWidget()
|
|
{
|
|
MyButton = SNew(SButton)
|
|
.OnClicked(BIND_UOBJECT_DELEGATE(FOnClicked, SlateHandleClicked))
|
|
.OnPressed(BIND_UOBJECT_DELEGATE(FSimpleDelegate, SlateHandlePressed))
|
|
.OnReleased(BIND_UOBJECT_DELEGATE(FSimpleDelegate, SlateHandleReleased))
|
|
.OnHovered_UObject( this, &ThisClass::SlateHandleHovered )
|
|
.OnUnhovered_UObject( this, &ThisClass::SlateHandleUnhovered )
|
|
.ButtonStyle(&WidgetStyle)
|
|
.ClickMethod(ClickMethod)
|
|
.TouchMethod(TouchMethod)
|
|
.PressMethod(PressMethod)
|
|
.IsFocusable(IsFocusable)
|
|
;
|
|
|
|
if ( GetChildrenCount() > 0 )
|
|
{
|
|
Cast<UButtonSlot>(GetContentSlot())->BuildSlot(MyButton.ToSharedRef());
|
|
}
|
|
|
|
return MyButton.ToSharedRef();
|
|
}
|
|
|
|
void UButton::SynchronizeProperties()
|
|
{
|
|
Super::SynchronizeProperties();
|
|
|
|
MyButton->SetColorAndOpacity( ColorAndOpacity );
|
|
MyButton->SetBorderBackgroundColor( BackgroundColor );
|
|
}
|
|
|
|
UClass* UButton::GetSlotClass() const
|
|
{
|
|
return UButtonSlot::StaticClass();
|
|
}
|
|
|
|
void UButton::OnSlotAdded(UPanelSlot* InSlot)
|
|
{
|
|
// Add the child to the live slot if it already exists
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
CastChecked<UButtonSlot>(InSlot)->BuildSlot(MyButton.ToSharedRef());
|
|
}
|
|
}
|
|
|
|
void UButton::OnSlotRemoved(UPanelSlot* InSlot)
|
|
{
|
|
// Remove the widget from the live slot if it exists.
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
MyButton->SetContent(SNullWidget::NullWidget);
|
|
}
|
|
}
|
|
|
|
void UButton::SetStyle(const FButtonStyle& InStyle)
|
|
{
|
|
WidgetStyle = InStyle;
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
MyButton->SetButtonStyle(&WidgetStyle);
|
|
}
|
|
}
|
|
|
|
void UButton::SetColorAndOpacity(FLinearColor InColorAndOpacity)
|
|
{
|
|
ColorAndOpacity = InColorAndOpacity;
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
MyButton->SetColorAndOpacity(InColorAndOpacity);
|
|
}
|
|
}
|
|
|
|
void UButton::SetBackgroundColor(FLinearColor InBackgroundColor)
|
|
{
|
|
BackgroundColor = InBackgroundColor;
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
MyButton->SetBorderBackgroundColor(InBackgroundColor);
|
|
}
|
|
}
|
|
|
|
bool UButton::IsPressed() const
|
|
{
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
return MyButton->IsPressed();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void UButton::SetClickMethod(EButtonClickMethod::Type InClickMethod)
|
|
{
|
|
ClickMethod = InClickMethod;
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
MyButton->SetClickMethod(ClickMethod);
|
|
}
|
|
}
|
|
|
|
void UButton::SetTouchMethod(EButtonTouchMethod::Type InTouchMethod)
|
|
{
|
|
TouchMethod = InTouchMethod;
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
MyButton->SetTouchMethod(TouchMethod);
|
|
}
|
|
}
|
|
|
|
void UButton::SetPressMethod(EButtonPressMethod::Type InPressMethod)
|
|
{
|
|
PressMethod = InPressMethod;
|
|
if ( MyButton.IsValid() )
|
|
{
|
|
MyButton->SetPressMethod(PressMethod);
|
|
}
|
|
}
|
|
|
|
void UButton::PostLoad()
|
|
{
|
|
Super::PostLoad();
|
|
|
|
if ( GetChildrenCount() > 0 )
|
|
{
|
|
//TODO UMG Pre-Release Upgrade, now buttons have slots of their own. Convert existing slot to new slot.
|
|
if ( UPanelSlot* PanelSlot = GetContentSlot() )
|
|
{
|
|
UButtonSlot* ButtonSlot = Cast<UButtonSlot>(PanelSlot);
|
|
if ( ButtonSlot == NULL )
|
|
{
|
|
ButtonSlot = NewObject<UButtonSlot>(this);
|
|
ButtonSlot->Content = GetContentSlot()->Content;
|
|
ButtonSlot->Content->Slot = ButtonSlot;
|
|
Slots[0] = ButtonSlot;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
FReply UButton::SlateHandleClicked()
|
|
{
|
|
OnClicked.Broadcast();
|
|
|
|
return FReply::Handled();
|
|
}
|
|
|
|
void UButton::SlateHandlePressed()
|
|
{
|
|
OnPressed.Broadcast();
|
|
}
|
|
|
|
void UButton::SlateHandleReleased()
|
|
{
|
|
OnReleased.Broadcast();
|
|
}
|
|
|
|
void UButton::SlateHandleHovered()
|
|
{
|
|
OnHovered.Broadcast();
|
|
}
|
|
|
|
void UButton::SlateHandleUnhovered()
|
|
{
|
|
OnUnhovered.Broadcast();
|
|
}
|
|
|
|
#if WITH_ACCESSIBILITY
|
|
TSharedPtr<SWidget> UButton::GetAccessibleWidget() const
|
|
{
|
|
return MyButton;
|
|
}
|
|
#endif
|
|
|
|
#if WITH_EDITOR
|
|
|
|
const FText UButton::GetPaletteCategory()
|
|
{
|
|
return LOCTEXT("Common", "Common");
|
|
}
|
|
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////
|
|
|
|
#undef LOCTEXT_NAMESPACE
|