2016-12-08 08:52:44 -05:00
|
|
|
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
2015-05-07 06:44:00 -04:00
|
|
|
|
|
|
|
|
#include "STimingTrack.h"
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "Layout/ArrangedChildren.h"
|
|
|
|
|
|
2015-05-07 06:44:00 -04:00
|
|
|
#include "SCurveEditor.h"
|
|
|
|
|
|
|
|
|
|
void STimingTrack::Construct(const FArguments& Args)
|
|
|
|
|
{
|
|
|
|
|
STrack::FArguments BaseArgs;
|
|
|
|
|
BaseArgs.ViewInputMin(Args._ViewInputMin);
|
|
|
|
|
BaseArgs.ViewInputMax(Args._ViewInputMax);
|
|
|
|
|
BaseArgs.TrackMinValue(Args._TrackMinValue);
|
|
|
|
|
BaseArgs.TrackMaxValue(Args._TrackMaxValue);
|
|
|
|
|
BaseArgs.TrackNumDiscreteValues(Args._TrackNumDiscreteValues);
|
|
|
|
|
|
|
|
|
|
STrack::Construct(BaseArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void STimingTrack::OnArrangeChildren(const FGeometry& AllottedGeometry, FArrangedChildren& ArrangedChildren) const
|
|
|
|
|
{
|
|
|
|
|
// To make this track look nice and have no overlapping nodes we're going to
|
|
|
|
|
// treat this as a 1D collision problem and build/resolve islands until everything
|
|
|
|
|
// is nicely resolved (or until we hit an upper limit as it can't be solved)
|
|
|
|
|
|
|
|
|
|
// Helper holding info about a single node
|
|
|
|
|
struct NodeData
|
|
|
|
|
{
|
|
|
|
|
NodeData(TSharedRef<STrackNode>& NodeRef, const FGeometry& Geometry)
|
|
|
|
|
: Node(NodeRef)
|
|
|
|
|
{
|
|
|
|
|
// Separation of the nodes on the track
|
|
|
|
|
const float NodeSeparation = 3.0f;
|
|
|
|
|
|
|
|
|
|
Node->CacheTrackGeometry(Geometry);
|
|
|
|
|
FVector2D Offset = Node->GetOffsetRelativeToParent(Geometry);
|
|
|
|
|
FVector2D Size = Node->GetSizeRelativeToParent(Geometry);
|
|
|
|
|
|
|
|
|
|
Offset.Y += (Geometry.GetLocalSize().Y - Size.Y) * 0.5f;
|
|
|
|
|
|
|
|
|
|
ActualRect = FBox2D(Offset, Offset + Size);
|
|
|
|
|
QueryRect = FBox2D(Offset - FVector2D(NodeSeparation, 0.0f), Offset + Size + FVector2D(NodeSeparation, 0.0f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSharedRef<STrackNode> Node; // The node widget
|
|
|
|
|
FBox2D ActualRect; // The actual render rect of the widget
|
|
|
|
|
FBox2D QueryRect; // An expanded rect used to detect collisions
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Helper holding list of overlapping nodes
|
|
|
|
|
struct NodeIsland
|
|
|
|
|
{
|
|
|
|
|
TArray<NodeData*> Nodes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int32 NumNodes = TrackNodes.Num();
|
|
|
|
|
|
|
|
|
|
TArray<NodeData> SortedNodeData;
|
|
|
|
|
SortedNodeData.Reserve(NumNodes);
|
|
|
|
|
|
|
|
|
|
// List of collision islands
|
|
|
|
|
TArray<NodeIsland> Islands;
|
|
|
|
|
// Scaling info to translate between local positions and data values
|
|
|
|
|
FTrackScaleInfo ScaleInfo(ViewInputMin.Get(), ViewInputMax.Get(), 0, 0, AllottedGeometry.Size);
|
|
|
|
|
|
|
|
|
|
for(int32 TrackIndex = 0; TrackIndex < NumNodes; ++TrackIndex)
|
|
|
|
|
{
|
|
|
|
|
TSharedRef<STrackNode> TrackNode = (TrackNodes[TrackIndex]);
|
|
|
|
|
|
|
|
|
|
SortedNodeData.Add(NodeData(TrackNode, AllottedGeometry));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const static int32 MaxRetries = 5;
|
|
|
|
|
int32 Retries = 0;
|
|
|
|
|
bool bResolved = true;
|
|
|
|
|
|
|
|
|
|
while(bResolved && Retries < MaxRetries)
|
|
|
|
|
{
|
|
|
|
|
++Retries;
|
|
|
|
|
bResolved = false;
|
|
|
|
|
|
|
|
|
|
for(int32 NodeIdx = 0; NodeIdx < NumNodes; ++NodeIdx)
|
|
|
|
|
{
|
|
|
|
|
NodeData& CurrentNode = SortedNodeData[NodeIdx];
|
|
|
|
|
// Island generation
|
|
|
|
|
NodeIsland* CurrentIsland = nullptr;
|
|
|
|
|
CurrentIsland = &Islands[Islands.AddZeroed()];
|
|
|
|
|
|
|
|
|
|
int32 Direction = -1;
|
|
|
|
|
int32 Next = NodeIdx + 1;
|
|
|
|
|
int32 HighestNode = NodeIdx;
|
|
|
|
|
FBox2D& CurrentRect = CurrentNode.ActualRect;
|
|
|
|
|
FBox2D CurrentQueryRect = CurrentNode.QueryRect;
|
|
|
|
|
|
|
|
|
|
CurrentIsland->Nodes.Add(&CurrentNode);
|
|
|
|
|
|
|
|
|
|
// Walk Nodes
|
|
|
|
|
while(Next >= 0 && Next < NumNodes)
|
|
|
|
|
{
|
|
|
|
|
NodeData& NextNode = SortedNodeData[Next];
|
|
|
|
|
FBox2D& NextRect = NextNode.ActualRect;
|
|
|
|
|
FBox2D& NextQueryRect = NextNode.QueryRect;
|
|
|
|
|
if(NextQueryRect.Intersect(CurrentQueryRect))
|
|
|
|
|
{
|
|
|
|
|
// Add to island
|
|
|
|
|
CurrentIsland->Nodes.Add(&NextNode);
|
|
|
|
|
HighestNode = Next;
|
|
|
|
|
|
|
|
|
|
// Expand the current query
|
|
|
|
|
CurrentQueryRect.Max = NextQueryRect.Max;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// No island, next node
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++Next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Skip processed nodes (those already in islands)
|
|
|
|
|
NodeIdx = HighestNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Separation of the nodes on the track
|
|
|
|
|
const float NodeSeparation = 3.0f;
|
|
|
|
|
|
|
|
|
|
for(NodeIsland& Island : Islands)
|
|
|
|
|
{
|
|
|
|
|
if(Island.Nodes.Num() == 1)
|
|
|
|
|
{
|
|
|
|
|
// Keep single nodes on the data track range but skip everything else
|
|
|
|
|
FBox2D& NodeBox = Island.Nodes[0]->ActualRect;
|
|
|
|
|
FBox2D& NodeQueryRect = Island.Nodes[0]->QueryRect;
|
|
|
|
|
float Offset = 0.0f;
|
|
|
|
|
float Begin = ScaleInfo.LocalXToInput(NodeBox.Min.X);
|
|
|
|
|
float End = ScaleInfo.LocalXToInput(NodeBox.Max.X);
|
|
|
|
|
if(Begin < 0)
|
|
|
|
|
{
|
|
|
|
|
Offset = ScaleInfo.InputToLocalX(-Begin);
|
|
|
|
|
}
|
|
|
|
|
else if(End > TrackMaxValue.Get())
|
|
|
|
|
{
|
|
|
|
|
Offset = ScaleInfo.InputToLocalX(TrackMaxValue.Get() - End);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(Offset != 0.0f)
|
|
|
|
|
{
|
|
|
|
|
NodeBox.Min.X += Offset;
|
|
|
|
|
NodeBox.Max.X += Offset;
|
|
|
|
|
NodeQueryRect.Min.X = NodeBox.Min.X - NodeSeparation;
|
|
|
|
|
NodeQueryRect.Max.X = NodeBox.Max.X + NodeSeparation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bResolved = true;
|
|
|
|
|
// Island resolution
|
|
|
|
|
int32 NumIslandNodes = Island.Nodes.Num();
|
|
|
|
|
float Width = FMath::Max<float>((NumIslandNodes - 1), 0.0f) * NodeSeparation;
|
|
|
|
|
float Centre = 0.0f;
|
|
|
|
|
|
|
|
|
|
for(NodeData* Node : Island.Nodes)
|
|
|
|
|
{
|
|
|
|
|
Width += Node->ActualRect.GetSize().X;
|
|
|
|
|
Centre += Node->ActualRect.GetCenter().X;
|
|
|
|
|
}
|
|
|
|
|
Centre /= NumIslandNodes;
|
|
|
|
|
|
|
|
|
|
// Make sure the group stays on the track
|
|
|
|
|
float Begin = Centre - Width / 2.0f;
|
|
|
|
|
float WidthAsInput = Width / ScaleInfo.PixelsPerInput;
|
|
|
|
|
float BeginAsInput = FMath::Clamp(ScaleInfo.LocalXToInput(Begin), 0.0f, TrackMaxValue.Get() - WidthAsInput);
|
|
|
|
|
Begin = ScaleInfo.InputToLocalX(BeginAsInput);
|
|
|
|
|
|
|
|
|
|
for(int32 NodeIdx = 0 ; NodeIdx < NumIslandNodes ; ++NodeIdx)
|
|
|
|
|
{
|
|
|
|
|
FBox2D& NodeBox = Island.Nodes[NodeIdx]->ActualRect;
|
|
|
|
|
float NodeWidth = NodeBox.GetSize().X;
|
|
|
|
|
float SeparationOffset = NodeIdx * NodeSeparation;
|
|
|
|
|
float PositionOffset = 0.0f;
|
|
|
|
|
|
|
|
|
|
for(int32 PositionNodeIdx = 0 ; PositionNodeIdx < NodeIdx ; ++PositionNodeIdx)
|
|
|
|
|
{
|
|
|
|
|
PositionOffset += Island.Nodes[PositionNodeIdx]->ActualRect.GetSize().X;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FBox2D& OriginalRect = Island.Nodes[NodeIdx]->ActualRect;
|
|
|
|
|
OriginalRect.Min.X = Begin + PositionOffset + SeparationOffset;
|
|
|
|
|
OriginalRect.Max.X = OriginalRect.Min.X + NodeWidth;
|
|
|
|
|
|
|
|
|
|
// Alter Query rect for next pass
|
|
|
|
|
FBox2D& NodeQueryRect = Island.Nodes[NodeIdx]->QueryRect;
|
|
|
|
|
NodeQueryRect.Min = OriginalRect.Min - FVector2D(NodeSeparation, 0.0f);
|
|
|
|
|
NodeQueryRect.Max = OriginalRect.Max + FVector2D(NodeSeparation, 0.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int32 TrackIndex = 0; TrackIndex < NumNodes; ++TrackIndex)
|
|
|
|
|
{
|
|
|
|
|
TSharedRef<STrackNode> TrackNode = (SortedNodeData[TrackIndex].Node);
|
|
|
|
|
if(TrackNode->IsBeingDragged())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FBox2D& Rect = SortedNodeData[TrackIndex].ActualRect;
|
|
|
|
|
|
|
|
|
|
ArrangedChildren.AddWidget(AllottedGeometry.MakeChild(TrackNode, Rect.Min, Rect.GetSize()));
|
|
|
|
|
}
|
|
|
|
|
}
|