diff --git a/Resources/Color.png b/Resources/Color.png new file mode 100644 index 0000000..3ebe67d Binary files /dev/null and b/Resources/Color.png differ diff --git a/Resources/ColorPanelBackGround.png b/Resources/ColorPanelBackGround.png new file mode 100644 index 0000000..1a7e5a8 Binary files /dev/null and b/Resources/ColorPanelBackGround.png differ diff --git a/Resources/ColorPanelClose.png b/Resources/ColorPanelClose.png new file mode 100644 index 0000000..7fe7857 Binary files /dev/null and b/Resources/ColorPanelClose.png differ diff --git a/Resources/ColorSelectCircle.png b/Resources/ColorSelectCircle.png new file mode 100644 index 0000000..8d18aaa Binary files /dev/null and b/Resources/ColorSelectCircle.png differ diff --git a/Resources/CustomPreset.png b/Resources/CustomPreset.png new file mode 100644 index 0000000..a3cd7f2 Binary files /dev/null and b/Resources/CustomPreset.png differ diff --git a/Resources/SaveCustomPreset.png b/Resources/SaveCustomPreset.png new file mode 100644 index 0000000..4b9eda6 Binary files /dev/null and b/Resources/SaveCustomPreset.png differ diff --git a/Source/Cut5/Interface/CutMainWidgetInterface.h b/Source/Cut5/Interface/CutMainWidgetInterface.h index ce56891..8c744be 100644 --- a/Source/Cut5/Interface/CutMainWidgetInterface.h +++ b/Source/Cut5/Interface/CutMainWidgetInterface.h @@ -48,8 +48,8 @@ public: virtual void SaveProject() {}; virtual FString GetGroupName(TSharedPtr WidgetInterface) { return FString(); }; virtual FTimelinePropertyData* GetResourcePropertyDataPtr(FGuid GUID) { return nullptr; }; - - + virtual void OpenColorPanel(FLinearColor* ColorPtr) {}; + virtual void AddNewCustomPreset(const FString& Name, const FPresetsCustomData CustomData) {}; virtual void OnSelectCard(const FGuid& SelectedCard) {}; virtual void OnRemoveCard(const FGuid& SelectedCard) {}; diff --git a/Source/Cut5/Widgets/DefineGlobal.h b/Source/Cut5/Widgets/DefineGlobal.h index 496106c..c12e3be 100644 --- a/Source/Cut5/Widgets/DefineGlobal.h +++ b/Source/Cut5/Widgets/DefineGlobal.h @@ -165,7 +165,7 @@ struct CUT5_API FPresetsData struct CUT5_API FPresetsCustomData { - TArray Colors; + TArray Colors = { FLinearColor::White }; int32 Times; float Angle; int32 Time; @@ -333,6 +333,10 @@ struct CUT5_API FTimelinePropertyData int32 MovieFrameLength = 0; TArray AudioData; + + bool bIsCustomPresetData = false; + FPresetsCustomData PresetsCustomData = FPresetsCustomData(); + friend FArchive& operator<<(FArchive& Ar, FTimelinePropertyData& PropertyData) { Ar << PropertyData.Guid; @@ -345,6 +349,8 @@ struct CUT5_API FTimelinePropertyData Ar << PropertyData.AudioStream; Ar << PropertyData.MoviePath; Ar << PropertyData.MovieFrameLength; + Ar << PropertyData.bIsCustomPresetData; + Ar << PropertyData.PresetsCustomData; return Ar; } @@ -370,6 +376,9 @@ public: Device, PresetDrag, CursorDrag, + ColorDragH, + ColorDragS, + ColorDragV, }; FCutDragDropBase() {}; FCutDragDropBase(EType InType) @@ -402,6 +411,12 @@ public: FPresetsData PresetData = FPresetsData(); }; +class CUT5_API FColorDragOperation final : public FCutDragDropBase +{ +public: + +}; + class CUT5_API FClip2ClipDragDropOperation final : public FCutDragDropBase { public: diff --git a/Source/Cut5/Widgets/DragDropOperator/DragDropOperator.cpp b/Source/Cut5/Widgets/DragDropOperator/DragDropOperator.cpp index e19ef5c..969ce15 100644 --- a/Source/Cut5/Widgets/DragDropOperator/DragDropOperator.cpp +++ b/Source/Cut5/Widgets/DragDropOperator/DragDropOperator.cpp @@ -5,6 +5,8 @@ #include "Cut5/Widgets/SCutMainWindow.h" #include "Cut5/Widgets/STimelineClip.h" #include "Cut5/Widgets/STrackBody.h" +#include "Cut5/Widgets/MicroWidgets/SColorBar.h" +#include "Cut5/Widgets/MicroWidgets/SColorPanel.h" DragDropOperator* DragDropOperator::Operator = nullptr; @@ -19,6 +21,65 @@ DragDropOperator* DragDropOperator::GetDragDropOperator() void DragDropOperator::OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) { + if (TSharedPtr DragDropBase = DragDropEvent.GetOperationAs()) + { + if (DragDropBase->DragDropType == FCutDragDropBase::EType::ColorDragH || DragDropBase->DragDropType == FCutDragDropBase::EType::ColorDragV) + { + TSharedPtr ColorBar = StaticCastSharedPtr(DragDropBase->DraggingWidget); + float Local = ColorBar->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition()).X / ColorBar->GetCachedGeometry().Size.X; + switch (ColorBar->ColorType) + { + case SColorBar::EColorType::H: + { + if (Local < 1.0 && Local >= 0) + { + + GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Local: %f"), Local)); + ColorBar->ColorPtr->R = (ColorBar->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition()).X / ColorBar->GetCachedGeometry().Size.X) * 360.0; + ColorBar->OnColorCallback.ExecuteIfBound(ColorBar->ColorPtr->R); + } + + break; + } + case SColorBar::EColorType::S: + { + if (Local < 1.0 && Local >= 0) + { + + GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Local: %f"), Local)); + ColorBar->ColorPtr->G = (ColorBar->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition()).X / ColorBar->GetCachedGeometry().Size.X) * 360.0; + ColorBar->OnColorCallback.ExecuteIfBound(ColorBar->ColorPtr->G); + } + } + case SColorBar::EColorType::V: + { + if (Local < 1.0 && Local >= 0) + { + ColorBar->ColorPtr->B = (ColorBar->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition()).X / ColorBar->GetCachedGeometry().Size.X); + ColorBar->OnColorCallback.ExecuteIfBound(ColorBar->ColorPtr->B); + } + break; + } + default: + break; + } + } + if (DragDropBase->DragDropType == FCutDragDropBase::EType::ColorDragS) + { + TSharedPtr ColorPanel = StaticCastSharedPtr(DragDropBase->DraggingWidget); + float Local = ColorPanel->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition()).X / ColorPanel->GetCachedGeometry().Size.X; + if (ColorPanel) + { + if (Local < 1.0 && Local >= 0) + { + ColorPanel->ColorS = (ColorPanel->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition()).X / ColorPanel->GetCachedGeometry().Size.X); + } + } + } + + + } + if (TSharedPtr DragDrop = DragDropEvent.GetOperationAs()) { if (DragDrop->DragDropType == FCutDragDropBase::EType::CursorDrag) diff --git a/Source/Cut5/Widgets/MicroWidgets/SColorBar.cpp b/Source/Cut5/Widgets/MicroWidgets/SColorBar.cpp new file mode 100644 index 0000000..ca71297 --- /dev/null +++ b/Source/Cut5/Widgets/MicroWidgets/SColorBar.cpp @@ -0,0 +1,115 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "SColorBar.h" + +#include "SlateOptMacros.h" +#include "Cut5/Widgets/DefineGlobal.h" +#include "Cut5/Widgets/DragDropOperator/DragDropOperator.h" +#include "Rendering/DrawElementPayloads.h" + +BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION + +void SColorBar::Construct(const FArguments& InArgs) +{ + ColorType = InArgs._ColorType; + OnColorCallback = InArgs._OnColorCallBack; + ColorPtr = InArgs._ColorPtr; + ChildSlot + [ + SNew(SBox) + .HAlign(HAlign_Fill) + .VAlign(VAlign_Fill) + .WidthOverride(286) + .HeightOverride(8) + [ + SAssignNew(Bar, SImage) + .DesiredSizeOverride(FVector2D(286, 8)) + .OnMouseButtonDown_Lambda([this](const FGeometry& Geometry, const FPointerEvent& Event) + { + + TSharedPtr ColorDragOperation = MakeShared(); + ColorDragOperation->DragDropType = ColorType == EColorType::H ? FCutDragDropBase::EType::ColorDragH : FCutDragDropBase::EType::ColorDragV; + ColorDragOperation->DraggingWidget = SharedThis(this); + return FReply::Handled().DetectDrag(SharedThis(this), EKeys::LeftMouseButton).BeginDragDrop(ColorDragOperation.ToSharedRef()); + }) + ] + ]; +} + +int32 SColorBar::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, + FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, + bool bParentEnabled) const +{ + switch (ColorType) + { + case EColorType::H: + { + FLinearColor Color = FLinearColor(0, 1, 1, 1); + TArray GradientStops; + for (int32 i = 0; i < 50; i++) + { + Color.R = i / 50.0f * 360.0; + FLinearColor RGB = Color.HSVToLinearRGB(); + float Loc = i / 50.0f * Bar->GetCachedGeometry().Size.X; + GradientStops.Add(FSlateGradientStop(FVector2D(Loc, 0), RGB)); + } + + FSlateDrawElement::MakeGradient(OutDrawElements, LayerId + 10, Bar->GetPaintSpaceGeometry().ToPaintGeometry(FVector2D(286, 8), FSlateLayoutTransform(FVector2D(0))), + GradientStops, EOrientation::Orient_Vertical, ESlateDrawEffect::None); + } + break; + case EColorType::V: + { + FLinearColor Color = FLinearColor(0, 1, 1, 1); + TArray GradientStops; + for (int32 i = 0; i < 50; i++) + { + Color.B = i / 50.0f; + FLinearColor RGB = Color.HSVToLinearRGB(); + float Loc = i / 50.0f * Bar->GetCachedGeometry().Size.X; + GradientStops.Add(FSlateGradientStop(FVector2D(Loc, 0), RGB)); + } + FSlateDrawElement::MakeGradient(OutDrawElements, LayerId + 10, Bar->GetPaintSpaceGeometry().ToPaintGeometry(FVector2D(286, 8), FSlateLayoutTransform(FVector2D(0))), + GradientStops, EOrientation::Orient_Vertical, ESlateDrawEffect::None); + } + break; + default: + break; + } + + return SCompoundWidget::OnPaint(Args, AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, + bParentEnabled); +} + +FReply SColorBar::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) +{ + + return SCompoundWidget::OnMouseMove(MyGeometry, MouseEvent); +} + +FReply SColorBar::OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) +{ + DragDropOperator::GetDragDropOperator()->OnDragOver(MyGeometry, DragDropEvent); + return SCompoundWidget::OnDragOver(MyGeometry, DragDropEvent); + switch (ColorType) + { + case EColorType::H: + { + ColorPtr->R = (MyGeometry.AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition()).X / MyGeometry.Size.X) * 360.0; + OnColorCallback.ExecuteIfBound(ColorPtr->R); + break; + } + case EColorType::V: + { + ColorPtr->B = (MyGeometry.AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition()).X / MyGeometry.Size.X); + OnColorCallback.ExecuteIfBound(ColorPtr->B); + break; + } + default: + return SCompoundWidget::OnDragOver(MyGeometry, DragDropEvent); + break; + } + return SCompoundWidget::OnDragOver(MyGeometry, DragDropEvent); +} +END_SLATE_FUNCTION_BUILD_OPTIMIZATION diff --git a/Source/Cut5/Widgets/MicroWidgets/SColorBar.h b/Source/Cut5/Widgets/MicroWidgets/SColorBar.h new file mode 100644 index 0000000..75c79ac --- /dev/null +++ b/Source/Cut5/Widgets/MicroWidgets/SColorBar.h @@ -0,0 +1,41 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Widgets/SCompoundWidget.h" + +/** + * + */ + +DECLARE_DELEGATE_OneParam(FOnColorCallback, float) +class CUT5_API SColorBar : public SCompoundWidget +{ +public: + enum class EColorType + { + H, + S, + V, + }; + SLATE_BEGIN_ARGS(SColorBar) + { + } + SLATE_ARGUMENT(EColorType, ColorType) + SLATE_ARGUMENT(FLinearColor*, ColorPtr) + SLATE_EVENT(FOnColorCallback, OnColorCallBack) + SLATE_END_ARGS() + + /** Constructs this widget with InArgs */ + void Construct(const FArguments& InArgs); + + TSharedPtr Bar; + FOnColorCallback OnColorCallback; + EColorType ColorType; + FLinearColor* ColorPtr; + virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; + virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; + virtual FReply OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override; +}; + diff --git a/Source/Cut5/Widgets/MicroWidgets/SColorPanel.cpp b/Source/Cut5/Widgets/MicroWidgets/SColorPanel.cpp index 3469f73..8353bdf 100644 --- a/Source/Cut5/Widgets/MicroWidgets/SColorPanel.cpp +++ b/Source/Cut5/Widgets/MicroWidgets/SColorPanel.cpp @@ -3,21 +3,40 @@ #include "SColorPanel.h" +#include "SColorBar.h" #include "SlateOptMacros.h" +#include "Cut5/Utils/Utils.h" +#include "Cut5/Widgets/DragDropOperator/DragDropOperator.h" +#include "Rendering/DrawElementPayloads.h" +#include "Widgets/Input/SSlider.h" #include "Widgets/Layout/SConstraintCanvas.h" BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION void SColorPanel::Construct(const FArguments& InArgs) { + ColorPtr = InArgs._ColorPtr; FTextBlockStyle TextBlockStyle = FAppStyle::GetWidgetStyle("NormalText"); TextBlockStyle.SetFontSize(16); ChildSlot [ - SNew(SConstraintCanvas) - + SConstraintCanvas::Slot() - .Anchors(FAnchors(0, 0, 0, 0)) - .Offset(FMargin(0, 0, 320, 445)) + SNew(SOverlay) + + SOverlay::Slot() + .HAlign(HAlign_Center) + .VAlign(VAlign_Center) + [ + SNew(SBox) + .WidthOverride(320) + .HeightOverride(445) + [ + SNew(SImage) + .Image(FUtils::GetBrushFromImage(FUtils::GetResourcesPath("ColorPanelBackGround.png"), {320, 445})) + ] + + ] + + SOverlay::Slot() + .HAlign(HAlign_Center) + .VAlign(VAlign_Center) [ SNew(SBox) .WidthOverride(320) @@ -29,7 +48,7 @@ void SColorPanel::Construct(const FArguments& InArgs) SNew(SBox) .HAlign(HAlign_Left) .VAlign(VAlign_Top) - .Padding(21, 16, 267, 405) + .Padding(21, 16, 0, 0) .WidthOverride(32) .HeightOverride(24) [ @@ -38,9 +57,223 @@ void SColorPanel::Construct(const FArguments& InArgs) .Font(TextBlockStyle.Font) ] ] + + SOverlay::Slot() + [ + SNew(SBox) + .HAlign(HAlign_Left) + .VAlign(VAlign_Top) + .Padding(18, 272, 0, 0) + .WidthOverride(286) + .HeightOverride(8) + [ + SNew(SColorBar) + .ColorPtr(&CurrentSelectColor) + .ColorType(SColorBar::EColorType::V) + .OnColorCallBack_Lambda([this](float A) + { + + }) + + ] + ] + + SOverlay::Slot() + [ + SNew(SBox) + .HAlign(HAlign_Left) + .VAlign(VAlign_Top) + .Padding(18, 246, 0, 0) + .WidthOverride(286) + .HeightOverride(8) + [ + SNew(SColorBar) + .ColorPtr(&CurrentSelectColor) + .ColorType(SColorBar::EColorType::H) + .OnColorCallBack_Lambda([this](float A) + { + + }) + ] + ] + + SOverlay::Slot() + [ + SNew(SBox) + .HAlign(HAlign_Left) + .VAlign(VAlign_Top) + .Padding(17, 56, 0, 0) + .WidthOverride(287) + .HeightOverride(176) + [ + SAssignNew(ColorBox, SImage) + .DesiredSizeOverride(FVector2D(287, 176)) + .OnMouseButtonDown_Lambda([this](const FGeometry&, const FPointerEvent&) + { + TSharedPtr ColorDragOperation = MakeShared(); + ColorDragOperation->DragDropType = FCutDragDropBase::EType::ColorDragS; + ColorDragOperation->DraggingWidget = SharedThis(this); + return FReply::Handled().DetectDrag(SharedThis(this), EKeys::LeftMouseButton).BeginDragDrop(ColorDragOperation.ToSharedRef()); + return FReply::Handled(); + }) + + ] + ] + + SOverlay::Slot() + [ + SNew(SBox) + .HAlign(HAlign_Left) + .VAlign(VAlign_Top) + .Padding(61, 17, 0, 0) + .WidthOverride(40) + .HeightOverride(21.5) + [ + SAssignNew(ColorImage, SImage) + .DesiredSizeOverride(FVector2D(40, 21.5)) + .Image(FUtils::GetBrushFromImage(FUtils::GetResourcesPath("Color.png"), {40, 21.5})) + .ColorAndOpacity(GetColor()) + ] + ] + + SOverlay::Slot() + .HAlign(HAlign_Right) + .VAlign(VAlign_Top) + [ + SNew(SBox) + .HAlign(HAlign_Left) + .VAlign(VAlign_Top) + .Padding(0, 0, 16, 16) + .WidthOverride(24) + .HeightOverride(24) + [ + SNew(SImage) + .DesiredSizeOverride(FVector2D(24, 24)) + .Image(FUtils::GetBrushFromImage(FUtils::GetResourcesPath("ColorPanelClose.png"), {24, 24})) + .OnMouseButtonDown_Lambda([this](const FGeometry&, const FPointerEvent&) + { + GEngine->GameViewport->RemoveViewportWidgetContent(SharedThis(this)); + return FReply::Handled(); + }) + ] + ] + + SOverlay::Slot() + .HAlign(HAlign_Left) + .VAlign(VAlign_Top) + [ + SNew(SBox) + .WidthOverride(12) + .HeightOverride(12) + [ + SAssignNew(ColorBarHCircle, SImage) + .Image(FUtils::GetBrushFromImage(FUtils::GetResourcesPath("ColorSelectCircle.png"), {16, 16})) + ] + + ] + + SOverlay::Slot() + .HAlign(HAlign_Left) + .VAlign(VAlign_Top) + [ + SNew(SBox) + .WidthOverride(12) + .HeightOverride(12) + [ + SAssignNew(ColorBarVCircle, SImage) + .Image(FUtils::GetBrushFromImage(FUtils::GetResourcesPath("ColorSelectCircle.png"), {16, 16})) + ] + ] + + SOverlay::Slot() + .HAlign(HAlign_Left) + .VAlign(VAlign_Top) + [ + SNew(SBox) + .WidthOverride(12) + .HeightOverride(12) + [ + SAssignNew(ColorBarSCircle, SImage) + .Image(FUtils::GetBrushFromImage(FUtils::GetResourcesPath("ColorSelectCircle.png"), {16, 16})) + ] + ] ] ] + ]; } +int32 SColorPanel::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, + FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, + bool bParentEnabled) const +{ + // { + // FLinearColor Color = FLinearColor(0, 1, 1, 1); + // TArray GradientStops; + // for (int32 i = 0; i < 50; i++) + // { + // Color.R = i / 50.0f * 360.0; + // FLinearColor RGB = Color.HSVToLinearRGB(); + // float Loc = i / 50.0f * ColorBar->GetCachedGeometry().Size.X; + // GradientStops.Add(FSlateGradientStop(FVector2D(Loc, 0), RGB)); + // } + // + // FSlateDrawElement::MakeGradient(OutDrawElements, LayerId + 10000, ColorBar->GetPaintSpaceGeometry().ToPaintGeometry(FVector2D(286, 8), FSlateLayoutTransform(FVector2D(0))), + // GradientStops, EOrientation::Orient_Vertical, ESlateDrawEffect::None); + // } + // + // + // { + // FLinearColor Color = FLinearColor(0, 1, 1, 1); + // TArray GradientStops; + // for (int32 i = 0; i < 50; i++) + // { + // Color.B = i / 50.0f; + // FLinearColor RGB = Color.HSVToLinearRGB(); + // float Loc = i / 50.0f * SBar->GetCachedGeometry().Size.X; + // GradientStops.Add(FSlateGradientStop(FVector2D(Loc, 0), RGB)); + // } + // + // FSlateDrawElement::MakeGradient(OutDrawElements, LayerId + 10000, SBar->GetPaintSpaceGeometry().ToPaintGeometry(FVector2D(286, 8), FSlateLayoutTransform(FVector2D(0))), + // GradientStops, EOrientation::Orient_Vertical, ESlateDrawEffect::None); + // + // } + + + TArray ColorBoxGradientStops; + ColorBoxGradientStops.Add(FSlateGradientStop(FVector2D(0, 0), FLinearColor(1, 1, 1, 1))); + ColorBoxGradientStops.Add(FSlateGradientStop(FVector2D(ColorBox->GetCachedGeometry().Size.X, 0), CurrentSelectColor.HSVToLinearRGB())); + FSlateDrawElement::MakeGradient(OutDrawElements, LayerId + 10000, ColorBox->GetPaintSpaceGeometry().ToPaintGeometry(FVector2D(287, 176), FSlateLayoutTransform(FVector2D(0))), + ColorBoxGradientStops, EOrientation::Orient_Vertical, ESlateDrawEffect::NoGamma); + + return SCompoundWidget::OnPaint(Args, AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle, + bParentEnabled); +} + +FReply SColorPanel::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) +{ + + return FReply::Handled(); +} + +void SColorPanel::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) +{ + ColorBarHCircle->SetRenderTransform(FVector2D(18 + (CurrentSelectColor.R / 360.0f * 286), 246)); + ColorBarSCircle->SetRenderTransform(FVector2D(18 + (CurrentSelectColor.G * 286), 246)); + ColorBarVCircle->SetRenderTransform(FVector2D(18 + (CurrentSelectColor.B * 286), 272)); + + ColorImage->SetColorAndOpacity(GetColor()); + *ColorPtr = GetColor(); +} + +FReply SColorPanel::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) +{ + + return SCompoundWidget::OnDrop(MyGeometry, DragDropEvent); +} + +FReply SColorPanel::OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) +{ + DragDropOperator::GetDragDropOperator()->OnDragOver(MyGeometry, DragDropEvent); + return SCompoundWidget::OnDragOver(MyGeometry, DragDropEvent); +} + +FLinearColor SColorPanel::GetColor() +{ + FLinearColor RGB = FLinearColor(CurrentSelectColor.R, ColorS, CurrentSelectColor.B, 1).HSVToLinearRGB(); + return RGB; +} + END_SLATE_FUNCTION_BUILD_OPTIMIZATION diff --git a/Source/Cut5/Widgets/MicroWidgets/SColorPanel.h b/Source/Cut5/Widgets/MicroWidgets/SColorPanel.h index 56e3b66..afd37fe 100644 --- a/Source/Cut5/Widgets/MicroWidgets/SColorPanel.h +++ b/Source/Cut5/Widgets/MicroWidgets/SColorPanel.h @@ -14,9 +14,26 @@ public: SLATE_BEGIN_ARGS(SColorPanel) { } - + SLATE_ARGUMENT(FLinearColor*, ColorPtr) SLATE_END_ARGS() /** Constructs this widget with InArgs */ void Construct(const FArguments& InArgs); + virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; + virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; + virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override; + virtual FReply OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override; + virtual FReply OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override; + FLinearColor GetColor(); + TSharedPtr ColorBar; + TSharedPtr SBar; + TSharedPtr ColorBox; + TSharedPtr ColorImage; + FLinearColor CurrentSelectColor = FLinearColor(1, 1, 0, 1); + float ColorS = 0; + + FLinearColor* ColorPtr; + TSharedPtr ColorBarHCircle; + TSharedPtr ColorBarSCircle; + TSharedPtr ColorBarVCircle; }; diff --git a/Source/Cut5/Widgets/Presets/SEffectPreset.cpp b/Source/Cut5/Widgets/Presets/SEffectPreset.cpp index 9475cf4..0070426 100644 --- a/Source/Cut5/Widgets/Presets/SEffectPreset.cpp +++ b/Source/Cut5/Widgets/Presets/SEffectPreset.cpp @@ -5,6 +5,7 @@ #include "SlateOptMacros.h" #include "Cut5/Utils/Utils.h" +#include "Cut5/Widgets/MicroWidgets/SNewProjectTips.h" #include "Cut5/Widgets/Style/CutButtonWidgetStyle.h" #include "Math/UnitConversion.h" #include "Widgets/Input/SComboBox.h" @@ -107,14 +108,16 @@ TSharedPtr SEffectPreset::GetPropertiesWidget() .WidthOverride(136) .HeightOverride(32) [ - SNew(SEditableTextBox) - .OnVerifyTextChanged_Lambda([this](const FText& InText, FText& OutErrorMessage) + SNew(SImage) + .Image(FUtils::GetBrushFromImage(FUtils::GetResourcesPath("Color.png"), {})) + .ColorAndOpacity_Lambda([this]() { - return true; + return CustomData.Colors[0]; }) - .OnTextCommitted_Lambda([this](const FText& InText, ETextCommit::Type InCommitType) + .OnMouseButtonDown_Lambda([this](const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { - + MainInterface->OpenColorPanel(&CustomData.Colors[0]); + return FReply::Handled(); }) ] ] @@ -183,6 +186,10 @@ TSharedPtr SEffectPreset::GetPropertiesWidget() [ SNew(SSpinBox) .MinValue(0) + .OnValueChanged_Lambda([this](const int32& Value) + { + CustomData.Times = Value; + }) ] ] ] @@ -218,6 +225,10 @@ TSharedPtr SEffectPreset::GetPropertiesWidget() SNew(SSpinBox) .MinValue(0.0) .MaxValue(360.0) + .OnValueChanged_Lambda([this](const float& Value) + { + CustomData.Angle = Value; + }) // .TypeInterface(MakeShared>(EUnit::Degrees)) ] ] @@ -253,12 +264,53 @@ TSharedPtr SEffectPreset::GetPropertiesWidget() [ SNew(SSpinBox) .MinValue(0.0) + .OnValueChanged_Lambda([this](const int32& Value) + { + CustomData.Time = Value; + }) // .TypeInterface(MakeShared>(EUnit::Seconds)) ] ] ] + ] + + SVerticalBox::Slot() + .HAlign(HAlign_Center) + .VAlign(VAlign_Bottom) + .Padding(0, 0, 0, 24) + [ + SNew(SBox).HeightOverride(40).WidthOverride(144) + [ + SNew(SOverlay) + + SOverlay::Slot() + .HAlign(HAlign_Fill) + .VAlign(VAlign_Fill) + [ + SNew(SImage) + .Image(FUtils::GetBrushFromImage(FUtils::GetResourcesPath("SaveCustomPreset.png"), {144, 40})) + .OnMouseButtonDown_Lambda([this](const FGeometry&, const FPointerEvent&) + { + TSharedPtr NewProjectTips = SNew(SNewProjectTips).Title(TEXT("保存自定义效果名称")); + NewProjectTips->OnEnsure.BindLambda([this, NewProjectTips](const FString& String) + { + MainInterface->AddNewCustomPreset(String, CustomData); + GEngine->GameViewport->RemoveViewportWidgetContent(NewProjectTips.ToSharedRef()); + }); + GEngine->GameViewport->AddViewportWidgetContent(NewProjectTips.ToSharedRef() + , 1); + return FReply::Handled(); + }) + ] + + SOverlay::Slot() + [ + SNew(STextBlock) + .Visibility(EVisibility::HitTestInvisible) + .Text(FText::FromString((TEXT("保存自定义效果")))) + .Font(NormalText.Font) + ] + ] ]; - + // TODO: 配置文件保存自定义效果 + // TODO: 自定义效果拖拽到轨道 return PropertiesWidget; } diff --git a/Source/Cut5/Widgets/Presets/SEffectPreset.h b/Source/Cut5/Widgets/Presets/SEffectPreset.h index 7a586a5..4124fcd 100644 --- a/Source/Cut5/Widgets/Presets/SEffectPreset.h +++ b/Source/Cut5/Widgets/Presets/SEffectPreset.h @@ -34,5 +34,6 @@ public: TSharedPtr>> GroupComboBox; virtual TSharedPtr GetPropertiesWidget() override; + FPresetsCustomData CustomData; virtual FReply OnDragDetected(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; }; diff --git a/Source/Cut5/Widgets/SCustomInputResource.cpp b/Source/Cut5/Widgets/SCustomInputResource.cpp index 744a13e..c9a9b21 100644 --- a/Source/Cut5/Widgets/SCustomInputResource.cpp +++ b/Source/Cut5/Widgets/SCustomInputResource.cpp @@ -14,7 +14,7 @@ void SCustomInputResource::Construct(const FArguments& InArgs) PropertyData = InArgs._PropertyData; VideoCapture = InArgs._VideoCapture; OnCheckBoxChecked = InArgs._OnCheckBoxChecked; - + CustomPresetName = InArgs._CustomPresetName; ChildSlot [ SNew(SBox) @@ -34,7 +34,15 @@ void SCustomInputResource::Construct(const FArguments& InArgs) .VAlign(VAlign_Fill) [ SNew(SImage) - .Image(FUtils::GetBrushFromImage(PropertyData.IconPath, {})) + .Image(PropertyData.bIsCustomPresetData == false ? FUtils::GetBrushFromImage(PropertyData.IconPath, {}) : FUtils::GetBrushFromImage(FUtils::GetResourcesPath("CustomPreset.png"), {})) + ] + + SOverlay::Slot() + .HAlign(HAlign_Center) + .VAlign(VAlign_Center) + [ + SNew(STextBlock) + .Text(FText::FromString(CustomPresetName)) + .Visibility(PropertyData.bIsCustomPresetData == true ? EVisibility::Visible : EVisibility::Collapsed) ] ] diff --git a/Source/Cut5/Widgets/SCustomInputResource.h b/Source/Cut5/Widgets/SCustomInputResource.h index 3cc3c9a..2177f40 100644 --- a/Source/Cut5/Widgets/SCustomInputResource.h +++ b/Source/Cut5/Widgets/SCustomInputResource.h @@ -18,6 +18,7 @@ public: } SLATE_ARGUMENT(FTimelinePropertyData, PropertyData) SLATE_ARGUMENT(cv::VideoCapture, VideoCapture) + SLATE_ARGUMENT(FString, CustomPresetName) SLATE_EVENT(FOnCheckBoxChecked, OnCheckBoxChecked) SLATE_END_ARGS() @@ -33,4 +34,6 @@ public: cv::VideoCapture VideoCapture; TSharedPtr CheckBox; TSharedPtr Box; + + FString CustomPresetName; }; diff --git a/Source/Cut5/Widgets/SCutMainWindow.cpp b/Source/Cut5/Widgets/SCutMainWindow.cpp index 042e70e..25703a9 100644 --- a/Source/Cut5/Widgets/SCutMainWindow.cpp +++ b/Source/Cut5/Widgets/SCutMainWindow.cpp @@ -352,7 +352,6 @@ void SCutMainWindow::Construct(const FArguments& InArgs) CommandList->MapAction(FMainMenuCommands::Get().NewProject, FExecuteAction::CreateLambda([this]() { - OpenColorPanel(); PreNewProject(); })); CommandList->MapAction(FMainMenuCommands::Get().OpenProject, FExecuteAction::CreateLambda([this]() @@ -1007,26 +1006,25 @@ void SCutMainWindow::PreSettingBeforeSeek() OnUpdateVideo(FGuid::NewGuid(), 1920, 1080, nullptr); } -void SCutMainWindow::OpenColorPanel() +void SCutMainWindow::OpenColorPanel(FLinearColor* ColorPtr) { - TSharedPtr ColorPanel = SNew(SColorPanel); - // GEngine->GameViewport->AddViewportWidgetContent( - // ColorPanel.ToSharedRef()); - TSharedPtr Window = SNew(SWindow) - .CreateTitleBar(false) - .SupportsMaximize(false) - .SupportsMinimize(false) - .bDragAnywhere(true) - .MinHeight(445) - .MinWidth(320) - .MaxHeight(445) - .Content() + TSharedPtr ColorPanel = SNew(SColorPanel).ColorPtr(ColorPtr); + GEngine->GameViewport->AddViewportWidgetContent( + ColorPanel.ToSharedRef()); + + +} + +void SCutMainWindow::AddNewCustomPreset(const FString& Name, const FPresetsCustomData CustomData) +{ + FTimelinePropertyData NewPropertyData; + NewPropertyData.bIsCustomPresetData = true; + NewPropertyData.PresetsCustomData = CustomData; + + CustomInputPanel->GridPanel->AddSlot(CustomInputPanel->GridPanel->GetChildren()->Num() % 2, CustomInputPanel->GridPanel->GetChildren()->Num() / 2) [ - ColorPanel.ToSharedRef() + SNew(SCustomInputResource).PropertyData(NewPropertyData).CustomPresetName(Name) ]; - - FSlateApplication::Get().AddWindow(Window.ToSharedRef()); - } tinyxml2::XMLElement* SCutMainWindow::GetDeviceElement(tinyxml2::XMLElement* Parent) diff --git a/Source/Cut5/Widgets/SCutMainWindow.h b/Source/Cut5/Widgets/SCutMainWindow.h index a171974..ea7a7c3 100644 --- a/Source/Cut5/Widgets/SCutMainWindow.h +++ b/Source/Cut5/Widgets/SCutMainWindow.h @@ -78,7 +78,8 @@ public: virtual void DeleteAllAssetsInTimeline() override; virtual SCutTimeline* GetCutTimeline() override { return CutTimeline.Get(); }; virtual void PreSettingBeforeSeek() override; - void OpenColorPanel(); + virtual void OpenColorPanel(FLinearColor* ColorPtr); + virtual void AddNewCustomPreset(const FString& Name, const FPresetsCustomData CustomData) override; tinyxml2::XMLElement* GetDeviceElement(tinyxml2::XMLElement* Parent); tinyxml2::XMLElement* GetVideoElement(tinyxml2::XMLElement* Parent, FEncodeVideoInfo EncodeVideoInfo); diff --git a/Source/Cut5/Widgets/STimelineClip.cpp b/Source/Cut5/Widgets/STimelineClip.cpp index c1f70c1..061253a 100644 --- a/Source/Cut5/Widgets/STimelineClip.cpp +++ b/Source/Cut5/Widgets/STimelineClip.cpp @@ -535,7 +535,7 @@ int32 STimelineClip::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGe GradientStops.Add(FSlateGradientStop(FVector2D(ClipData->Cursors[i].CursorFrameOffset * FGlobalData::DefaultTimeTickSpace, 0), ClipData->Cursors[i].Color)); } - FSlateDrawElement::MakeGradient(OutDrawElements, LayerId, AllottedGeometry.ToPaintGeometry(), + FSlateDrawElement::MakeGradient(OutDrawElements, LayerId + 10000, AllottedGeometry.ToPaintGeometry(), GradientStops, EOrientation::Orient_Vertical, ESlateDrawEffect::None); }