Cut5/Source/Cut5/Widgets/DefineGlobal.h
2023-07-31 03:24:35 +08:00

388 lines
8.0 KiB
C++

#pragma once
#include "Cut5/WidgetInterface.h"
extern "C"{
#include "libavformat/avformat.h"
}
#include "DragAndDrop/DecoratedDragDropOp.h"
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/core/mat.hpp>
struct FTimelinePropertyData;
class CUT5_API FGlobalData
{
public:
inline static int32 DefaultTrackHeight = 50;
inline static int32 TrackLength = 1000;
inline static double DefaultTimeTickSpace = 9.0;
inline static int32 LightArrayX = 70;
inline static int32 LightArrayY = 42;
inline static float CurrentTimeScroll = 0.0f;
inline static float GlobalFPS = 30.0f;
inline static FString CurrentProjectName = "DefaultProject";
static int32 GetAlignOfTickSpace(double Align, bool bCeil = false)
{
return bCeil ? FMath::CeilToInt(Align / FGlobalData::DefaultTimeTickSpace) * FGlobalData::DefaultTimeTickSpace :
FMath::TruncToInt(Align / FGlobalData::DefaultTimeTickSpace) * FGlobalData::DefaultTimeTickSpace;
}
};
enum class ETrackType
{
VideoTrack,
AudioTrack,
AudioTrackR,
PlayerTrack,
AtomSphereLightTrack,
SpotLightTrack,
ProjectorTrack,
LightArrayTrack,
LightBarTrack,
};
struct FClipData;
struct CUT5_API FTrackData
{
FTrackData()
{
};
FTrackData(const FString& Name, ETrackType Type)
{
TrackName = Name;
TrackType = Type;
};
friend FArchive& operator<<(FArchive& Ar, FTrackData& TrackData)
{
Ar << TrackData.Guid;
Ar << TrackData.TrackName;
Ar << TrackData.TrackType;
Ar << TrackData.TrackNum;
Ar << TrackData.ClipData;
return Ar;
};
FGuid Guid = FGuid::NewGuid();
FString TrackName = "None";
ETrackType TrackType = ETrackType::VideoTrack;
FSlateBrush Brush;
int32 TrackNum = 1;
TArray<FClipData> ClipData;
};
struct CUT5_API FClipData
{
friend FArchive& operator<<(FArchive& Ar, FClipData& ClipData)
{
Ar << ClipData.ClipGuid;
Ar << ClipData.ClipType;
Ar << ClipData.ClipStartFrame;
Ar << ClipData.ClipEndFrame;
Ar << ClipData.ClipColors;
Ar << ClipData.MoviePath;
Ar << ClipData.VideoStartFrame;
Ar << ClipData.VideoEndFrame;
Ar << ClipData.LightArrayData;
Ar << ClipData.PlayerName;
Ar << ClipData.PlayerLightData;
Ar << ClipData.ResourcePropertyGuid;
return Ar;
};
FGuid ClipGuid;
ETrackType ClipType;
UE_DEPRECATED(0.0, "Use int32 instead of float")
double ClipStartTime = 0;
UE_DEPRECATED(0.0, "Use int32 instead of float")
double ClipEndTime = 10;
int32 ClipStartFrame = 0;
int32 ClipEndFrame = 10;
TArray<FLinearColor> ClipColors;
UE_DEPRECATED(0.0, "Use int32 instead of float, Please just use ClipStartFrame and ClipEndFrame")
int32 GetClipStartFrame() const { return ClipStartTime / FGlobalData::DefaultTimeTickSpace; };
UE_DEPRECATED(0.0, "Use int32 instead of float, Please just use ClipStartFrame and ClipEndFrame")
int32 GetClipEndFrame() const { return ClipEndTime / FGlobalData::DefaultTimeTickSpace; };
int32 GetClipRelativeEndFrame() const { return ClipEndFrame - ClipStartFrame; }
enum class ECropMethod
{
FromFront,
FromBack,
};
void CropClip(ECropMethod CropMethod, int32 CropFrame)
{
if (CropMethod == ECropMethod::FromFront)
{
ClipStartFrame += CropFrame;
if (ClipType == ETrackType::VideoTrack || ClipType == ETrackType::AudioTrack)
{
VideoStartFrame += CropFrame;
}
}
else
{
ClipEndFrame -= CropFrame;
if (ClipType == ETrackType::VideoTrack || ClipType == ETrackType::AudioTrack)
{
VideoEndFrame -= CropFrame;
}
}
}
// A Ptr to Input Resource;
FTimelinePropertyData* ResourcePropertyDataPtr = nullptr;
FGuid ResourcePropertyGuid;
// Movies
FString MoviePath;
int32 VideoStartFrame = 0;
int32 VideoEndFrame = 0;
cv::VideoCapture* VideoCapture;
// Light Array
TArray<TArray<FColor>> LightArrayData;
// Player
FString PlayerName;
TArray<FColor> PlayerLightData;
};
struct CUT5_API FTimelinePropertyData
{
FTimelinePropertyData() {};
FTimelinePropertyData(FString InName, ETrackType InType)
{
Name = InName;
Type = InType;
}
FTimelinePropertyData(FString InName, ETrackType InType, FString InIconPath)
{
Name = InName;
Type = InType;
IconPath = InIconPath;
}
FString Name = "";
ETrackType Type = ETrackType::VideoTrack;
FString IconPath = "";
FGuid Guid = FGuid::NewGuid();
AVFormatContext* Context = nullptr;
AVCodecContext* CodecContext = nullptr;
AVCodec* Codec = nullptr;
// Movie Data
FString MoviePath = "";
int32 MovieFrameLength = 0;
TObjectPtr<USoundWave> Sound;
// Audio Data
TArray<uint8> AudioData;
};
class CUT5_API FCutDragDropBase : public FDecoratedDragDropOp
{
public:
// TODO: I Decide to use type to Main Widget to handle all drag over event
enum class EType
{
TrackClip,
Clip2Clip,
TickDrag,
};
FCutDragDropBase() {};
FCutDragDropBase(EType InType)
{
Type = InType;
}
TSharedPtr<SWidget> DraggingWidget;
TSharedPtr<IWidgetInterface> OverrideWidget;
TSharedPtr<IWidgetInterface> MoveAboutWidget;
float DragOffset = 0.0f;
EType Type = EType::TrackClip;
};
class CUT5_API FTrackClipDragOperation final : public FCutDragDropBase
{
public:
// It's a Ptr to Resource;
FTimelinePropertyData* TimelinePropertyData = nullptr;
cv::VideoCapture* VideoCapture;
};
class CUT5_API FClip2ClipDragDropOperation final : public FCutDragDropBase
{
public:
enum class EDragType
{
DragLeft,
DragRight,
Move,
};
EDragType DragType;
};
struct FTimelineInfo;
struct CUT5_API FTimelineInfo
{
enum class ETimelineType
{
Main,
FX,
};
FString CurrentOpenFullPath = "";
FTimelineInfo::ETimelineType CurrentOpenType = ETimelineType::Main;
friend FArchive& operator<<(FArchive& Ar, FTimelineInfo& TimelineInfo)
{
Ar << TimelineInfo.CurrentOpenFullPath;
Ar << TimelineInfo.CurrentOpenType;
return Ar;
};
FString GetSavePath()
{
return CurrentOpenFullPath;
}
};
struct CUT5_API FEffectCardProperty
{
FEffectCardProperty() {};
FGuid Guid = FGuid::NewGuid();
FString Name = "";
FTimelineInfo TimelineInfo;
friend FArchive& operator<<(FArchive& Ar, FEffectCardProperty& EffectCardProperty)
{
Ar << EffectCardProperty.Guid;
Ar << EffectCardProperty.Name;
Ar << EffectCardProperty.TimelineInfo;
return Ar;
};
};
struct CUT5_API FEffectCardGroup
{
FString GroupName;
TArray<FEffectCardProperty> Cards;
bool bIsDedicated = false;
bool bCanEditName = false;
bool bIsExpanded = true;
friend FArchive& operator<<(FArchive& Ar, FEffectCardGroup& EffectCard)
{
Ar << EffectCard.GroupName;
Ar << EffectCard.Cards;
Ar << EffectCard.bIsDedicated;
Ar << EffectCard.bCanEditName;
Ar << EffectCard.bIsExpanded;
return Ar;
};
};
class FCurtain
{
public:
FString CurtainName = TEXT("新建幕");
FGuid CurtainUUID;
TSharedPtr<FCurtain> ParentCurtain;
TArray<TSharedPtr<FCurtain>> ChildrenCurtain;
};
struct FGeneralPropertyBase
{
FString PropertyName;
TSharedPtr<SWidget> BaseWidget = nullptr;
FGeneralPropertyBase()
{
BaseWidget = SNew(SBox)
.WidthOverride(214)
.HeightOverride(32)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.SizeParam(FAuto())
[
SNew(STextBlock)
.Text(FText::FromString(PropertyName))
]
];
}
};
struct FColorProperty : public FGeneralPropertyBase
{
FColorProperty() : FGeneralPropertyBase()
{
}
};
struct FAngleProperty : public FGeneralPropertyBase
{
FAngleProperty() : FGeneralPropertyBase()
{
}
};
struct FTimesProperty : public FGeneralPropertyBase
{
FTimesProperty() : FGeneralPropertyBase()
{
}
};
struct FTimeProperty : public FGeneralPropertyBase
{
FTimeProperty() : FGeneralPropertyBase()
{
}
};
struct FProperties
{
FProperties* AddColorProperties(const FString& Name, FLinearColor* ColorPtr)
{
this->Properties.Add(FColorProperty());
return this;
};
FProperties* AddAngleProperties(const FString& Name, float* AnglePtr)
{
this->Properties.Add(FAngleProperty());
return this;
};
FProperties* AddTimesProperties(const FString& Name, float* TimesPtr)
{
this->Properties.Add(FTimesProperty());
return this;
};
FProperties* AddTimeProperties(const FString& Name, float* TimePtr)
{
this->Properties.Add(FTimeProperty());
return this;
};
TArray<FGeneralPropertyBase> Properties;
};