Files
UnrealEngineUWP/Engine/Source/Runtime/UMG/Private/Components/WindowTitleBarArea.cpp
patrick boutot e7fc3f9e55 UMG: Update UWidget::Visibility initialization from SetVisibility to SetVisibilityInternal.
[FYI] vincent.gauthier

#ROBOMERGE-AUTHOR: patrick.boutot
#ROBOMERGE-SOURCE: CL 20142060 via CL 20143142 via CL 20143633
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690)

[CL 20148091 by patrick boutot in ue5-main branch]
2022-05-11 15:55:37 -04:00

170 lines
4.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Components/WindowTitleBarArea.h"
#include "EngineGlobals.h"
#include "Widgets/SNullWidget.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Engine/GameViewportClient.h"
#include "Engine/Engine.h"
#include "Framework/Application/SlateApplication.h"
#include "Widgets/Layout/SWindowTitleBarArea.h"
#include "Components/WindowTitleBarAreaSlot.h"
#define LOCTEXT_NAMESPACE "UMG"
/////////////////////////////////////////////////////
// UWindowTitleBarArea
UWindowTitleBarArea::UWindowTitleBarArea(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bIsVariable = false;
SetVisibilityInternal(ESlateVisibility::Visible);
bDoubleClickTogglesFullscreen = false;
}
void UWindowTitleBarArea::ReleaseSlateResources(bool bReleaseChildren)
{
Super::ReleaseSlateResources(bReleaseChildren);
MyWindowTitleBarArea.Reset();
if (WindowActionNotificationHandle.IsValid())
{
FSlateApplication::Get().UnregisterOnWindowActionNotification(WindowActionNotificationHandle);
WindowActionNotificationHandle.Reset();
}
}
TSharedRef<SWidget> UWindowTitleBarArea::RebuildWidget()
{
MyWindowTitleBarArea = SNew(SWindowTitleBarArea);
if (bDoubleClickTogglesFullscreen)
{
WindowActionNotificationHandle = FSlateApplication::Get().RegisterOnWindowActionNotification(BIND_UOBJECT_DELEGATE(FOnWindowAction, HandleWindowAction));
}
else if (WindowActionNotificationHandle.IsValid())
{
FSlateApplication::Get().UnregisterOnWindowActionNotification(WindowActionNotificationHandle);
WindowActionNotificationHandle.Reset();
}
MyWindowTitleBarArea->SetRequestToggleFullscreenCallback(BIND_UOBJECT_DELEGATE(FSimpleDelegate, RequestToggleFullscreen));
if (GetChildrenCount() > 0)
{
Cast<UWindowTitleBarAreaSlot>(GetContentSlot())->BuildSlot(MyWindowTitleBarArea.ToSharedRef());
}
if (GEngine && GEngine->GameViewport && GEngine->GameViewport->GetWindow().IsValid())
{
MyWindowTitleBarArea->SetGameWindow(GEngine->GameViewport->GetWindow());
}
MyWindowTitleBarArea->SetWindowButtonsVisibility(bWindowButtonsEnabled);
return MyWindowTitleBarArea.ToSharedRef();
}
UClass* UWindowTitleBarArea::GetSlotClass() const
{
return UWindowTitleBarAreaSlot::StaticClass();
}
void UWindowTitleBarArea::OnSlotAdded(UPanelSlot* InSlot)
{
// Add the child to the live slot if it already exists
if (MyWindowTitleBarArea.IsValid())
{
// Construct the underlying slot.
UWindowTitleBarAreaSlot* WindowTitleBarAreaSlot = CastChecked<UWindowTitleBarAreaSlot>(InSlot);
WindowTitleBarAreaSlot->BuildSlot(MyWindowTitleBarArea.ToSharedRef());
}
}
void UWindowTitleBarArea::OnSlotRemoved(UPanelSlot* InSlot)
{
// Remove the widget from the live slot if it exists.
if (MyWindowTitleBarArea.IsValid())
{
MyWindowTitleBarArea->SetContent(SNullWidget::NullWidget);
}
}
void UWindowTitleBarArea::SetPadding(FMargin InPadding)
{
if (MyWindowTitleBarArea.IsValid())
{
MyWindowTitleBarArea->SetPadding(InPadding);
}
}
void UWindowTitleBarArea::SetHorizontalAlignment(EHorizontalAlignment InHorizontalAlignment)
{
if (MyWindowTitleBarArea.IsValid())
{
MyWindowTitleBarArea->SetHAlign(InHorizontalAlignment);
}
}
void UWindowTitleBarArea::SetVerticalAlignment(EVerticalAlignment InVerticalAlignment)
{
if (MyWindowTitleBarArea.IsValid())
{
MyWindowTitleBarArea->SetVAlign(InVerticalAlignment);
}
}
void UWindowTitleBarArea::PostLoad()
{
Super::PostLoad();
if (GetChildrenCount() > 0)
{
//TODO UMG Pre-Release Upgrade, now have slots of their own. Convert existing slot to new slot.
if (UPanelSlot* PanelSlot = GetContentSlot())
{
UWindowTitleBarAreaSlot* WindowTitleBarAreaSlot = Cast<UWindowTitleBarAreaSlot>(PanelSlot);
if (WindowTitleBarAreaSlot == NULL)
{
WindowTitleBarAreaSlot = NewObject<UWindowTitleBarAreaSlot>(this);
WindowTitleBarAreaSlot->Content = GetContentSlot()->Content;
WindowTitleBarAreaSlot->Content->Slot = WindowTitleBarAreaSlot;
Slots[0] = WindowTitleBarAreaSlot;
}
}
}
}
#if WITH_EDITOR
const FText UWindowTitleBarArea::GetPaletteCategory()
{
return LOCTEXT("Advanced", "Advanced");
}
#endif
bool UWindowTitleBarArea::HandleWindowAction(const TSharedRef<FGenericWindow>& PlatformWindow, EWindowAction::Type WindowAction)
{
if (GEngine && (WindowAction == EWindowAction::Maximize || WindowAction == EWindowAction::Restore))
{
GEngine->DeferredCommands.Add(TEXT("TOGGLE_FULLSCREEN"));
return true;
}
return false;
}
void UWindowTitleBarArea::RequestToggleFullscreen()
{
// This is only called in fullscreen mode when user double clicks the title bar or clicks the restore button.
if (GEngine)
{
GEngine->DeferredCommands.Add(TEXT("TOGGLE_FULLSCREEN"));
}
}
/////////////////////////////////////////////////////
#undef LOCTEXT_NAMESPACE