105 lines
2.5 KiB
C++
105 lines
2.5 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "SChildWindowTitleBar.h"
|
|
|
|
#include "UI/Style/AronaStyle.h"
|
|
#include "SButton.h"
|
|
#include "SImage.h"
|
|
#include "SlateApplication.h"
|
|
#include "SlateOptMacros.h"
|
|
#include "STextBlock.h"
|
|
|
|
#include "Widgets/SBoxPanel.h"
|
|
|
|
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
|
|
|
void SChildWindowTitleBar::Construct(const FArguments& InArgs)
|
|
{
|
|
OnClose = InArgs._OnClose;
|
|
OnWindowMoveDelta = InArgs._OnWindowMoveDelta;
|
|
OnMaximize = InArgs._OnMaximize;
|
|
|
|
ChildSlot
|
|
[
|
|
SNew(SHorizontalBox)
|
|
+SHorizontalBox::Slot()
|
|
.VAlign(VAlign_Center)
|
|
.Padding(5, 0, 0, 0)
|
|
[
|
|
SNew(STextBlock)
|
|
.Text(FText::FromString(InArgs._Title))
|
|
]
|
|
+SHorizontalBox::Slot()
|
|
.HAlign(HAlign_Right)
|
|
.VAlign(VAlign_Center)
|
|
.AutoWidth()
|
|
[
|
|
SNew(SButton)
|
|
.DesiredSizeScale(FVector2D(16))
|
|
.ButtonStyle(FAronaStyle::GetButtonStyle(CloseButtonStyleName))
|
|
.OnClicked_Raw(this, &SChildWindowTitleBar::OnCloseClicked)
|
|
]
|
|
];
|
|
}
|
|
|
|
FReply SChildWindowTitleBar::OnMouseButtonDoubleClick(const FGeometry& InMyGeometry, const FPointerEvent& InMouseEvent)
|
|
{
|
|
if (InMouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
|
|
{
|
|
ToggleMaximize();
|
|
return FReply::Handled();
|
|
}
|
|
return FReply::Unhandled();
|
|
}
|
|
|
|
FReply SChildWindowTitleBar::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
|
{
|
|
if (bIsMaximized)
|
|
return FReply::Unhandled();
|
|
if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
|
|
{
|
|
OnMouseLeftButtonDown = true;
|
|
return FReply::Unhandled().CaptureMouse(AsShared());
|
|
}
|
|
return FReply::Unhandled();
|
|
}
|
|
|
|
FReply SChildWindowTitleBar::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
|
{
|
|
if (bIsMaximized)
|
|
return FReply::Unhandled().ReleaseMouseCapture();
|
|
if (MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
|
|
{
|
|
OnMouseLeftButtonDown = false;
|
|
return FReply::Unhandled().ReleaseMouseCapture();
|
|
}
|
|
return FReply::Unhandled().ReleaseMouseCapture();
|
|
}
|
|
|
|
FReply SChildWindowTitleBar::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
|
|
{
|
|
if (bIsMaximized)
|
|
return FReply::Unhandled();
|
|
if (OnMouseLeftButtonDown)
|
|
{
|
|
OnWindowMoveDelta.ExecuteIfBound(MouseEvent.GetCursorDelta() / MyGeometry.Scale);
|
|
return FReply::Handled();
|
|
}
|
|
return FReply::Unhandled();
|
|
}
|
|
|
|
void SChildWindowTitleBar::ToggleMaximize()
|
|
{
|
|
bIsMaximized = !bIsMaximized;
|
|
OnMaximize.ExecuteIfBound(bIsMaximized);
|
|
}
|
|
|
|
FReply SChildWindowTitleBar::OnCloseClicked()
|
|
{
|
|
OnClose.ExecuteIfBound();
|
|
return FReply::Handled();
|
|
}
|
|
|
|
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|