Files
UnrealEngineUWP/Engine/Source/Editor/MovieSceneTools/Private/Channels/BoolChannelCurveModel.cpp
Lauren Barnes 6248f8d412 Replacing legacy EditorStyle calls with AppStyle
#preflight 6272a74d2f6d177be3c6fdda
#rb Matt.Kuhlenschmidt

#ROBOMERGE-OWNER: Lauren.Barnes
#ROBOMERGE-AUTHOR: lauren.barnes
#ROBOMERGE-SOURCE: CL 20057269 via CL 20070159 via CL 20072035 via CL 20072203
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v943-19904690)
#ROBOMERGE-CONFLICT from-shelf

[CL 20105363 by Lauren Barnes in ue5-main branch]
2022-05-09 13:12:28 -04:00

125 lines
4.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Channels/BoolChannelCurveModel.h"
#include "Math/Vector2D.h"
#include "HAL/PlatformMath.h"
#include "Channels/MovieSceneBoolChannel.h"
#include "Channels/BoolChannelKeyProxy.h"
#include "MovieSceneSection.h"
#include "MovieScene.h"
#include "CurveDrawInfo.h"
#include "CurveDataAbstraction.h"
#include "CurveEditor.h"
#include "CurveEditorScreenSpace.h"
#include "CurveEditorSnapMetrics.h"
#include "Styling/AppStyle.h"
#include "BuiltInChannelEditors.h"
#include "SequencerChannelTraits.h"
#include "ISequencer.h"
#include "Channels/MovieSceneChannelProxy.h"
/**
* Buffered curve implementation for a bool channel curve model, stores a copy of the bool channel in order to draw itself.
*/
class FBoolChannelBufferedCurveModel : public IBufferedCurveModel
{
public:
/** Create a copy of the float channel while keeping the reference to the section */
FBoolChannelBufferedCurveModel(const FMovieSceneBoolChannel* InMovieSceneBoolChannel, TWeakObjectPtr<UMovieSceneSection> InWeakSection,
TArray<FKeyPosition>&& InKeyPositions, TArray<FKeyAttributes>&& InKeyAttributes, const FString& InLongDisplayName, const double InValueMin, const double InValueMax)
: IBufferedCurveModel(MoveTemp(InKeyPositions), MoveTemp(InKeyAttributes), InLongDisplayName, InValueMin, InValueMax)
, Channel(*InMovieSceneBoolChannel)
, WeakSection(InWeakSection)
{}
virtual void DrawCurve(const FCurveEditor& InCurveEditor, const FCurveEditorScreenSpace& InScreenSpace, TArray<TTuple<double, double>>& OutInterpolatingPoints) const override
{
UMovieSceneSection* Section = WeakSection.Get();
if (Section)
{
FFrameRate TickResolution = Section->GetTypedOuter<UMovieScene>()->GetTickResolution();
TMovieSceneChannelData<const bool> ChannelData = Channel.GetData();
TArrayView<const FFrameNumber> Times = ChannelData.GetTimes();
TArrayView<const bool> Values = ChannelData.GetValues();
const double StartTimeSeconds = InScreenSpace.GetInputMin();
const double EndTimeSeconds = InScreenSpace.GetInputMax();
const FFrameNumber StartFrame = (StartTimeSeconds * TickResolution).FloorToFrame();
const FFrameNumber EndFrame = (EndTimeSeconds * TickResolution).CeilToFrame();
const int32 StartingIndex = Algo::UpperBound(Times, StartFrame);
const int32 EndingIndex = Algo::LowerBound(Times, EndFrame);
for (int32 KeyIndex = StartingIndex; KeyIndex < EndingIndex; ++KeyIndex)
{
OutInterpolatingPoints.Add(MakeTuple(Times[KeyIndex] / TickResolution, double(Values[KeyIndex])));
}
}
}
private:
FMovieSceneBoolChannel Channel;
TWeakObjectPtr<UMovieSceneSection> WeakSection;
};
FBoolChannelCurveModel::FBoolChannelCurveModel(TMovieSceneChannelHandle<FMovieSceneBoolChannel> InChannel, UMovieSceneSection* OwningSection, TWeakPtr<ISequencer> InWeakSequencer)
: FChannelCurveModel<FMovieSceneBoolChannel, bool, bool>(InChannel, OwningSection, InWeakSequencer)
{
}
void FBoolChannelCurveModel::CreateKeyProxies(TArrayView<const FKeyHandle> InKeyHandles, TArrayView<UObject*> OutObjects)
{
for (int32 Index = 0; Index < InKeyHandles.Num(); ++Index)
{
UBoolChannelKeyProxy* NewProxy = NewObject<UBoolChannelKeyProxy>(GetTransientPackage(), NAME_None);
NewProxy->Initialize(InKeyHandles[Index], GetChannelHandle(), Cast<UMovieSceneSection>(GetOwningObject()));
OutObjects[Index] = NewProxy;
}
}
TUniquePtr<IBufferedCurveModel> FBoolChannelCurveModel::CreateBufferedCurveCopy() const
{
FMovieSceneBoolChannel* Channel = GetChannelHandle().Get();
if (Channel)
{
TArray<FKeyHandle> TargetKeyHandles;
TMovieSceneChannelData<bool> ChannelData = Channel->GetData();
TRange<FFrameNumber> TotalRange = ChannelData.GetTotalRange();
ChannelData.GetKeys(TotalRange, nullptr, &TargetKeyHandles);
TArray<FKeyPosition> KeyPositions;
KeyPositions.SetNumUninitialized(GetNumKeys());
TArray<FKeyAttributes> KeyAttributes;
KeyAttributes.SetNumUninitialized(GetNumKeys());
GetKeyPositions(TargetKeyHandles, KeyPositions);
GetKeyAttributes(TargetKeyHandles, KeyAttributes);
double ValueMin = 0.f, ValueMax = 1.f;
GetValueRange(ValueMin, ValueMax);
return MakeUnique<FBoolChannelBufferedCurveModel>(Channel, Cast<UMovieSceneSection>(GetOwningObject()), MoveTemp(KeyPositions), MoveTemp(KeyAttributes), GetLongDisplayName().ToString(), ValueMin, ValueMax);
}
return nullptr;
}
double FBoolChannelCurveModel::GetKeyValue(TArrayView<const bool> Values, int32 Index) const
{
return (double)Values[Index];
}
void FBoolChannelCurveModel::SetKeyValue(int32 Index, double KeyValue) const
{
FMovieSceneBoolChannel* Channel = GetChannelHandle().Get();
if (Channel)
{
TMovieSceneChannelData<bool> ChannelData = Channel->GetData();
ChannelData.GetValues()[Index] = KeyValue > 0 ? true : false;
}
}