片段框选

This commit is contained in:
Sch 2023-08-17 19:25:05 +08:00
parent e414d7abf5
commit 7347bee2f3
9 changed files with 216 additions and 27 deletions

View File

@ -507,7 +507,7 @@ FString FUtils::GetMsFromString(FString TimeString)
// 将FTimespan对象转换为毫秒
int64 Milliseconds = Timespan.GetTotalMilliseconds();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s -> %s"), *TimeString, *FString::FromInt(Milliseconds)));
// GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s -> %s"), *TimeString, *FString::FromInt(Milliseconds)));
return FString::FromInt(Milliseconds);
}

View File

@ -28,7 +28,7 @@ public:
static TArray<FEncodeVideoInfo> TrackEncodeAudio(const FTrackData& TrackData, const FString& ExportPath);
static FString CurtainFullPath(const FString& GroupName)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FGlobalData::BasePath);
// GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FGlobalData::BasePath);
return FPaths::Combine(FGlobalData::BasePath, FGlobalData::CurrentProjectName, TEXT("Curtain"), GroupName + TEXT(".bin"));
};
static FString GroupFullPath(const FString& GroupName)

View File

@ -453,6 +453,7 @@ public:
ColorDragV,
MovePanel,
MoveTickCursor,
SelectClips,
};
FCutDragDropBase() {};
FCutDragDropBase(EType InType)
@ -534,6 +535,19 @@ public:
FClipData* ClipData;
};
class CUT5_API FClipSelectDragDrop final : public FCutDragDropBase
{
public:
FClipSelectDragDrop() { DragDropType = EType::SelectClips; }
FVector2D StartPosition;
FVector2D ScrollStartPosition;
FVector2D ScrollResultStartPosition;
FVector2D ScrollResultEndPosition;
};
struct FTimelineInfo;
struct CUT5_API FTimelineInfo
{

View File

@ -97,6 +97,57 @@ void DragDropOperator::OnDragOver(const FGeometry& MyGeometry, const FDragDropEv
{
if (TSharedPtr<FCutDragDropBase> DragDropBase = DragDropEvent.GetOperationAs<FCutDragDropBase>())
{
if (DragDropBase->DragDropType == FCutDragDropBase::EType::SelectClips)
{
TSharedPtr<FClipSelectDragDrop> ClipSelectDragDrop = DragDropEvent.GetOperationAs<FClipSelectDragDrop>();
TSharedPtr<SCutTimeline> Timeline = StaticCastSharedPtr<SCutTimeline>(ClipSelectDragDrop->DraggingWidget);
Timeline->bRenderBox = true;
const FVector2D StartPosition = ClipSelectDragDrop->StartPosition;
const FVector2D CurrentPosition = Timeline->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition());
const FVector2D ScrollStartPosition = ClipSelectDragDrop->ScrollStartPosition;
const FVector2D ScrollEndPosition = Timeline->TrackBodyScrollBox->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition());
// const FVector2D TestPos = Timeline->TrackBodyScrollBox->GetCachedGeometry().AbsoluteToLocal(DragDropEvent.GetScreenSpacePosition());
// GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::White, FString::Printf(TEXT("StartPos: %f, %f"), TestPos.X, TestPos.Y));
if (StartPosition.X < CurrentPosition.X && StartPosition.Y < CurrentPosition.Y)
{
Timeline->RenderBoxPos[0] = StartPosition;
Timeline->RenderBoxPos[1] = CurrentPosition;
ClipSelectDragDrop->ScrollResultStartPosition = ScrollStartPosition;
ClipSelectDragDrop->ScrollResultEndPosition = ScrollEndPosition;
}
else if (StartPosition.X > CurrentPosition.X && StartPosition.Y > CurrentPosition.Y)
{
Timeline->RenderBoxPos[0] = CurrentPosition;
Timeline->RenderBoxPos[1] = StartPosition;
ClipSelectDragDrop->ScrollResultStartPosition = ScrollEndPosition;
ClipSelectDragDrop->ScrollResultEndPosition = ScrollStartPosition;
}
else if (StartPosition.Y < CurrentPosition.Y && StartPosition.X > CurrentPosition.X)
{
Timeline->RenderBoxPos[0] = FVector2D(CurrentPosition.X, StartPosition.Y);
Timeline->RenderBoxPos[1] = FVector2D(StartPosition.X, CurrentPosition.Y);
ClipSelectDragDrop->ScrollResultStartPosition = FVector2D(ScrollEndPosition.X, ScrollStartPosition.Y);
ClipSelectDragDrop->ScrollResultEndPosition = FVector2D(ScrollStartPosition.X, ScrollEndPosition.Y);
}
else if (StartPosition.Y > CurrentPosition.Y && StartPosition.X < CurrentPosition.X)
{
Timeline->RenderBoxPos[0] = FVector2D(StartPosition.X, CurrentPosition.Y);
Timeline->RenderBoxPos[1] = FVector2D(CurrentPosition.X, StartPosition.Y);
ClipSelectDragDrop->ScrollResultStartPosition = FVector2D(ScrollStartPosition.X, ScrollEndPosition.Y);
ClipSelectDragDrop->ScrollResultEndPosition = FVector2D(ScrollEndPosition.X, ScrollStartPosition.Y);
}
}
if (DragDropBase->DragDropType == FCutDragDropBase::EType::TickDrag)
{
TSharedPtr<STimelineTick> TickTimeline = StaticCastSharedPtr<STimelineTick>(DragDropBase->DraggingWidget);
@ -174,7 +225,7 @@ void DragDropOperator::OnDragOver(const FGeometry& MyGeometry, const FDragDropEv
if (Local < 1.0 && Local >= 0)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Local: %f"), Local));
// 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);
}
@ -186,7 +237,7 @@ void DragDropOperator::OnDragOver(const FGeometry& MyGeometry, const FDragDropEv
if (Local < 1.0 && Local >= 0)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Local: %f"), Local));
// 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);
}
@ -318,6 +369,72 @@ void DragDropOperator::OnDragOver(const FGeometry& MyGeometry, const FDragDropEv
void DragDropOperator::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent, TSharedPtr<SWidget> DropWidget)
{
const auto& DragDropOperation = static_cast<FTrackClipDragOperation&>(DragDropEvent.GetOperation().ToSharedRef().Get());
if (DragDropOperation.DragDropType == FCutDragDropBase::EType::SelectClips)
{
TSharedPtr<FClipSelectDragDrop> ClipSelectDragDrop = DragDropEvent.GetOperationAs<FClipSelectDragDrop>();
TSharedPtr<SCutTimeline> Timeline = StaticCastSharedPtr<SCutTimeline>(ClipSelectDragDrop->DraggingWidget);
FVector2D StartPos = ClipSelectDragDrop->ScrollResultStartPosition;
FVector2D EndPos = ClipSelectDragDrop->ScrollResultEndPosition;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("StartPos : %f, %f"), StartPos.X, StartPos.Y));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("EndPos : %f, %f"), EndPos.X, EndPos.Y));
auto IsInRange = [this, StartPos, EndPos](FClipData& ClipData)
{
const float ClipStartTime = ClipData.ClipStartFrame * FGlobalData::DefaultTimeTickSpace;
const float ClipEndTime = ClipData.ClipEndFrame * FGlobalData::DefaultTimeTickSpace;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("ClipStartTime : %f"), ClipStartTime));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("ClipEndTime : %f"), ClipEndTime));
if (StartPos.X < ClipStartTime && EndPos.X > ClipStartTime)
{
return true;
}
if (StartPos.X < ClipEndTime && ClipEndTime > EndPos.X && ClipStartTime < EndPos.X)
{
return true;
}
if (ClipStartTime < StartPos.X && ClipEndTime > EndPos.X)
{
return true;
}
if (ClipStartTime < StartPos.X && ClipEndTime < EndPos.X && ClipEndTime > StartPos.X)
{
return true;
}
return false;
};
Timeline->SelectedClips.Empty();
int32 i = 0;
for (FSingleTrackGroupInstance& TrackGroupInstance : Timeline->TrackGroupInstances)
{
float Height = i * FGlobalData::DefaultTrackHeight;
if (StartPos.Y > Height || EndPos.Y < Height)
{
i++;
continue;
}
TSharedPtr<STrackBody> TrackBody = StaticCastSharedPtr<STrackBody>(TrackGroupInstance.Body);
for (FClipData& ClipData : TrackBody->TrackHead->TrackData.ClipData)
if (IsInRange(ClipData))
{
Timeline->SelectedClips.Add(ClipData.ClipGuid);
}
i++;
}
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("SelectedClips : %d"), Timeline->SelectedClips.Num()));
Timeline->bRenderBox = true;
Timeline->RenderBoxPos = {{}, {}};
}
if (DragDropOperation.DragDropType == FCutDragDropBase::EType::PresetDrag)
{
TSharedPtr<FPresetDragOperation> PresetDragOperation = DragDropEvent.GetOperationAs<FPresetDragOperation>();

View File

@ -494,6 +494,10 @@ FReply SCutMainWindow::OnDragOver(const FGeometry& MyGeometry, const FDragDropEv
FReply SCutMainWindow::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent)
{
TSharedPtr<FCutDragDropBase> DragDropOperation = DragDropEvent.GetOperationAs<FCutDragDropBase>();
if (DragDropOperation->DragDropType == FCutDragDropBase::EType::SelectClips)
{
DragDropOperator::GetDragDropOperator()->OnDrop(MyGeometry, DragDropEvent, nullptr);
}
if (DragDropOperation->DragDropType == FCutDragDropBase::EType::Clip2Clip)
{
TSharedPtr<STrackBody> Body = StaticCastSharedPtr<STrackBody>(DragDropOperation->OverrideWidget);

View File

@ -26,8 +26,17 @@ FReply SCutTimeline::OnMouseButtonDown(const FGeometry& MyGeometry, const FPoint
DragDropOperator->DragDropType = FCutDragDropBase::EType::MovePanel;
DragDropOperator->DragOffset = MyGeometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()).X;
DragDropOperator->DraggingWidget = SharedThis(this);
return FReply::Handled().DetectDrag(SharedThis(this), EKeys::RightMouseButton).BeginDragDrop(DragDropOperator.ToSharedRef());
}
if (MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton))
{
TSharedPtr<FClipSelectDragDrop> DragDropOperator = MakeShared<FClipSelectDragDrop>();
DragDropOperator->StartPosition = MyGeometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition());
DragDropOperator->ScrollStartPosition = TrackBodyScrollBox->GetCachedGeometry().AbsoluteToLocal(MouseEvent.GetScreenSpacePosition());
DragDropOperator->DraggingWidget = SharedThis(this);
return FReply::Handled().DetectDrag(SharedThis(this), EKeys::LeftMouseButton).BeginDragDrop(DragDropOperator.ToSharedRef());
}
return FReply::Handled();
}
FReply SCutTimeline::OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent)
@ -429,22 +438,39 @@ int32 SCutTimeline::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeo
if (TrackBodyHScrollBox->GetCachedGeometry().AbsoluteToLocal(TimelineTick->TickCursor->GetCachedGeometry().GetAbsolutePosition()).X < 0)
if (TrackBodyHScrollBox->GetCachedGeometry().AbsoluteToLocal(TimelineTick->TickCursor->GetCachedGeometry().GetAbsolutePosition()).X >= 0)
{
return SCompoundWidget::OnPaint(Args, AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle,
bParentEnabled);
}
FSlateDrawElement::MakeBox(
FSlateDrawElement::MakeBox(
OutDrawElements,
LayerId + 1,
AllottedGeometry.ToPaintGeometry(FVector2f(2, GetCachedGeometry().Size.Y), FSlateLayoutTransform(FVector2f(GetCachedGeometry().AbsoluteToLocal(TimelineTick->TickCursor->GetCachedGeometry().GetAbsolutePosition()).X, AllottedGeometry.GetLocalSize().Y - GetCachedGeometry().GetLocalSize().Y))),
&Brush,
ESlateDrawEffect::None,
FColor(255, 255, 255, 255));
}
if (bRenderBox)
{
const float X = RenderBoxPos[1].X - RenderBoxPos[0].X;
const float Y = RenderBoxPos[1].Y - RenderBoxPos[0].Y;
const FVector2D Size = FVector2D(X, Y);
FSlateDrawElement::MakeBox(
OutDrawElements,
LayerId + 1,
AllottedGeometry.ToPaintGeometry(Size, FSlateLayoutTransform(RenderBoxPos[0])),
&Brush,
ESlateDrawEffect::None,
FColor(255, 255, 255, 255));
}
return SCompoundWidget::OnPaint(Args, AllottedGeometry, MyCullingRect, OutDrawElements, LayerId, InWidgetStyle,
bParentEnabled);
}

View File

@ -113,6 +113,14 @@ public:
FTimelineInfo TimelineInfo;
FGuid SelectedClipGUID;
/**
* @brief Selected Clips Guid, Use for Multi-Select.
*/
TArray<FGuid> SelectedClips;
TSharedPtr<STextBlock> CurrentTimeData;
TSharedPtr<STextBlock> MaxTimeData;
virtual FReply OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent) override;
@ -120,6 +128,9 @@ public:
TArray<FDeviceTrackGroup> DeviceTrackGroups;
void AddNewDeviceToGroup(FString GroupName, FDeviceTrack DeviceTrack, ETrackType GroupTrack = ETrackType::None);
bool bRenderBox = false;
TArray<FVector2D> RenderBoxPos {{}, {}};
};

View File

@ -294,7 +294,7 @@ void STimelineClip::Seek(int32 Frame)
FLinearColor LinearColor = FLinearColor::Black;
FLinearColor CustomColor = ClipData->PresetsCustomData.Colors[0];
LinearColor = FMath::Lerp((int32)Between % 2 == 0 ? CustomColor : FLinearColor::Black, (int32)Between % 2 == 0 ? FLinearColor::Black : CustomColor, Between - (int32)Between);
GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Red, FString::Printf(TEXT("Between %s"), *CustomColor.ToString()));
// GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Red, FString::Printf(TEXT("Between %s"), *CustomColor.ToString()));
MainWidgetInterface->OnUpdateSpotLight(0, LinearColor.ToFColor(false));
}
}
@ -507,7 +507,7 @@ void STimelineClip::Seek(int32 Frame)
FLinearColor LinearColor = FLinearColor::Black;
FLinearColor CustomColor = ClipData->PresetsCustomData.Colors[0];
LinearColor = FMath::Lerp((int32)Between % 2 == 0 ? CustomColor : FLinearColor::Black, (int32)Between % 2 == 0 ? FLinearColor::Black : CustomColor, Between - (int32)Between);
GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Red, FString::Printf(TEXT("Between %s"), *CustomColor.ToString()));
// GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Red, FString::Printf(TEXT("Between %s"), *CustomColor.ToString()));
MainWidgetInterface->OnUpdatePlayers(Body, LinearColor.ToFColor(false));
}
}
@ -653,13 +653,18 @@ int32 STimelineClip::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGe
FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle,
bool bParentEnabled) const
{
// if (bIsDragOver)
// {
// const FSlateBrush SlateBrush;
// FSlateDrawElement::MakeBox(OutDrawElements, LayerId + 8, AllottedGeometry.ToPaintGeometry(),
// &SlateBrush, ESlateDrawEffect::None, FLinearColor::Green);
// return LayerId + 8;
// }
if (MainWidgetInterface->GetCutTimeline()->SelectedClips.Contains(ClipData->ClipGuid))
{
const FSlateBrush SlateBrush;
TArray<FVector2f> Vectors;
Vectors.Add(FVector2f(0, 0));
Vectors.Add(FVector2f(0, AllottedGeometry.Size.Y));
Vectors.Add(FVector2f(AllottedGeometry.Size.X, AllottedGeometry.Size.Y));
Vectors.Add(FVector2f(AllottedGeometry.Size.X, 0));
FSlateDrawElement::MakeLines(OutDrawElements, LayerId + 2, AllottedGeometry.ToPaintGeometry(), Vectors, ESlateDrawEffect::None, FLinearColor::White, true, 2.0f);
return SCompoundWidget::OnPaint(Args, AllottedGeometry, MyCullingRect, OutDrawElements, LayerId + 1, InWidgetStyle,
bParentEnabled);
}
TArray<FSlateGradientStop> BreatheGradientStops;

View File

@ -122,11 +122,23 @@ void STrackBody::OnDragLeave(const FDragDropEvent& DragDropEvent)
FReply STrackBody::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
TSharedPtr<FCutDragDropBase> DragDropOperator = MakeShared<FCutDragDropBase>();
DragDropOperator->DragDropType = FCutDragDropBase::EType::MovePanel;
DragDropOperator->DragOffset = MainWidgetInterface->GetCutTimeline()->GetCachedGeometry().AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()).X;
DragDropOperator->DraggingWidget = TrackHead->CutTimeline;
return FReply::Handled().DetectDrag(SharedThis(this), EKeys::LeftMouseButton).BeginDragDrop(DragDropOperator.ToSharedRef());
if (MouseEvent.IsMouseButtonDown(EKeys::RightMouseButton))
{
TSharedPtr<FCutDragDropBase> DragDropOperator = MakeShared<FCutDragDropBase>();
DragDropOperator->DragDropType = FCutDragDropBase::EType::MovePanel;
DragDropOperator->DragOffset = MainWidgetInterface->GetCutTimeline()->GetCachedGeometry().AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()).X;
DragDropOperator->DraggingWidget = TrackHead->CutTimeline;
return FReply::Handled().DetectDrag(SharedThis(this), EKeys::RightMouseButton).BeginDragDrop(DragDropOperator.ToSharedRef());
}
if (MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton))
{
TSharedPtr<FClipSelectDragDrop> DragDropOperator = MakeShared<FClipSelectDragDrop>();
DragDropOperator->StartPosition = MainWidgetInterface->GetCutTimeline()->GetCachedGeometry().AbsoluteToLocal(MouseEvent.GetScreenSpacePosition());
DragDropOperator->ScrollStartPosition = MainWidgetInterface->GetCutTimeline()->TrackBodyScrollBox->GetCachedGeometry().AbsoluteToLocal(MouseEvent.GetScreenSpacePosition());
DragDropOperator->DraggingWidget = TrackHead->CutTimeline;
return FReply::Handled().DetectDrag(SharedThis(this), EKeys::LeftMouseButton).BeginDragDrop(DragDropOperator.ToSharedRef());
}
return FReply::Handled();
}
void STrackBody::RemoveClip(const FGuid& Guid)