#include "MainWindow.h" #include "IChildWindow.h" #include "SBackgroundBlur.h" #include "SChildWindow.h" #include "SMainWindowHeader.h" #include "SConstraintCanvas.h" #include "SlateApplication.h" #include "SMainWindow.h" #include "SWindow.h" #include "SWindowTitleBar.h" #include "WaveformViewer.h" #include "ChannelRack/ChannelRack.h" #include "Thread/MainThreadEventList.h" #include "Thread/ThreadMessage.h" #include "Mixer/SMixer.h" #include "PlayList/SPlayList.h" #define LOCTEXT_NAMESPACE "Arona" DECLARE_THREAD_MESSAGE(FMainThreadEventList, PostCreateChildWindow, FMainWindow* Window; TSharedPtr ChildWindow; ) { Args.Window->FrontChildWindow(Args.ChildWindow); } void FMainWindow::Init() { auto NewTab = SNew(SDockTab); TabManager = FGlobalTabmanager::Get()->NewTabManager(NewTab); TArray TabNames = {"Tab0", "Tab1", "Tab2"}; auto Layout = FTabManager::NewLayout(TEXT("TestLayout")) ->AddArea( FTabManager::NewPrimaryArea() ->SetOrientation(Orient_Horizontal) ->Split( FTabManager::NewStack() ->AddTab(TabNames[0], ETabState::Type::OpenedTab) ) ->Split( FTabManager::NewStack() ->AddTab(TabNames[1], ETabState::Type::OpenedTab) ) ); TabManager->RegisterTabSpawner(TabNames[0], FOnSpawnTab::CreateLambda([](const FSpawnTabArgs& Args) -> TSharedRef { return SNew(SDockTab) .TabRole(ETabRole::NomadTab) [ SNew(SButton) ]; })); TabManager->RegisterTabSpawner(TabNames[1], FOnSpawnTab::CreateRaw(this, &FMainWindow::CreatePlayListTab)); MainWindow = SNew(SMainWindow) .CreateTitleBar(false) .AutoCenter(EAutoCenter::PrimaryWorkArea) .ClientSize(FVector2D(1270, 720)); const auto WindowTitleBar = SNew(SWindowTitleBar, MainWindow.ToSharedRef(), nullptr, EHorizontalAlignment::HAlign_Fill) .ShowAppIcon(false); MainWindow->SetTitleBar(WindowTitleBar); MainWindow->SetContent( SNew(SVerticalBox) +SVerticalBox::Slot() .AutoHeight() [ WindowTitleBar ] +SVerticalBox::Slot() .AutoHeight() [ SNew(SMainWindowHeader) .OnChannelRackClicked_Raw(this, &FMainWindow::ToggleChannelRack) .OnMixerClicked_Raw(this, &FMainWindow::ToggleMixer) ] +SVerticalBox::Slot() [ SNew(SOverlay) +SOverlay::Slot() [ TabManager->RestoreFrom(Layout, MainWindow).ToSharedRef() ] +SOverlay::Slot() [ SAssignNew(MainWindowCanvas, SConstraintCanvas) ] ] ); FSlateApplication::Get().AddWindow(MainWindow.ToSharedRef()); InitChildWindow(); } TSharedPtr FMainWindow::CreateChildWindow(FVector2D Size, FString Title, TSharedPtr Content, bool IsSingletonWindow) { auto* PanelChildren = static_cast*>(MainWindowCanvas->GetChildren()); TSharedPtr Out; auto Slot = MainWindowCanvas->AddSlot(); Slot.ZOrder(PanelChildren->Num() + 2); Slot.AttachWidget(SAssignNew(Out, SChildWindow, Slot.GetSlot()) .IsSingletonWindow(IsSingletonWindow) .Title(Title) .ResizeHandleSize(FVector2D(16, 16)) .Content(Content) ); Slot.Offset(FMargin(0, 0, Size.X, Size.Y)); PUSH_THREAD_EVENT(PostCreateChildWindow, this, Out); return Out; } void FMainWindow::FrontChildWindow(TSharedPtr ChildWindow) { const auto& PanelChildren = MainWindowCanvas->GetPanelChildren(); const TArray>& Children = PanelChildren.GetAllChildren(); for (auto& Slot : Children) { Slot->SetZOrder(Slot->GetZOrder() - 1); } ChildWindow->GetSlot()->SetZOrder(PanelChildren.Num()); FWidgetPath WidgetPath; const TSharedPtr FocusWidget = ChildWindow->Content->GetFocusWidget(); if (FocusWidget.IsValid()) { FSlateApplication::Get().SetAllUserFocus(FocusWidget); FSlateApplication::Get().SetKeyboardFocus(FocusWidget); } else { FSlateApplication::Get().SetAllUserFocus(ChildWindow->Content->GetWidget()); FSlateApplication::Get().SetKeyboardFocus(ChildWindow->Content->GetWidget()); } } TSharedPtr FMainWindow::GetChannelRack() { return ChannelRack; } TSharedRef FMainWindow::CreatePlayListTab(const FSpawnTabArgs& Args) { return SNew(SDockTab) .TabRole(ETabRole::NomadTab) .Label(LOCTEXT("PlayListTabTitle", "PlayList")) [ SNew(SPlayList) ]; } void FMainWindow::InitChildWindow() { ChannelRackWindow = CreateChildWindow(FVector2D(300, 600), "ChannelRack", SAssignNew(ChannelRack, SChannelRack), true); MixerWindow = CreateChildWindow(FVector2D(600, 400), "Mixer", SNew(SMixer), true); } void FMainWindow::ToggleChildWindow(TSharedPtr ChildWindow) { if (ChildWindow->GetVisibility() != EVisibility::Visible) ChildWindow->SetVisibility(EVisibility::Visible); else ChildWindow->SetVisibility(EVisibility::Collapsed); } void FMainWindow::ToggleChannelRack() { ToggleChildWindow(ChannelRackWindow); } void FMainWindow::ToggleMixer() { ToggleChildWindow(MixerWindow); } #undef LOCTEXT_NAMESPACE