Files
UnrealEngineUWP/Engine/Source/Runtime/InteractiveToolsFramework/Public/BaseGizmos/ParameterSourcesFloat.h
michael balzer 2b10993563 Move InteractiveToolsFramework and GeometryFramework out of Experimental
#jira UETOOL-3823
#rb brooke.hubert
#preflight 6109d1e9b4288d0001acb7ef

[CL 17055606 by michael balzer in ue5-main branch]
2021-08-04 13:58:55 -04:00

117 lines
2.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "BaseGizmos/GizmoInterfaces.h"
#include "ParameterSourcesFloat.generated.h"
/**
* FGizmoVec2ParameterChange represents a change in the value of an IGizmoFloatParameterSource.
* IGizmoFloatParameterSource implementations use this to track changes and emit delta information.
*/
USTRUCT()
struct INTERACTIVETOOLSFRAMEWORK_API FGizmoFloatParameterChange
{
GENERATED_BODY()
UPROPERTY()
float InitialValue = 0;
UPROPERTY()
float CurrentValue = 0;
float GetChangeDelta() const
{
return CurrentValue - InitialValue;
}
explicit FGizmoFloatParameterChange(float StartValue = 0)
{
InitialValue = CurrentValue = StartValue;
}
};
/**
* UGizmoBaseFloatParameterSource is a base implementation of IGizmoFloatParameterSource,
* which is not functional but adds an OnParameterChanged delegate for further subclasses.
*/
UCLASS()
class INTERACTIVETOOLSFRAMEWORK_API UGizmoBaseFloatParameterSource : public UObject, public IGizmoFloatParameterSource
{
GENERATED_BODY()
public:
virtual float GetParameter() const
{
check(false); // this is an abstract base class
return 0.0f;
}
virtual void SetParameter(float NewValue)
{
check(false); // this is an abstract base class
}
virtual void BeginModify()
{
}
virtual void EndModify()
{
}
public:
DECLARE_MULTICAST_DELEGATE_TwoParams(FOnGizmoFloatParameterSourceChanged, IGizmoFloatParameterSource*, FGizmoFloatParameterChange);
FOnGizmoFloatParameterSourceChanged OnParameterChanged;
};
/**
* UGizmoLocalFloatParameterSource is an implementation of IGizmoFloatParameterSource
* (by way of UGizmoBaseFloatParameterSource) which locally stores the relevant Parameter
* and emits update events via the OnParameterChanged delegate.
*/
UCLASS()
class INTERACTIVETOOLSFRAMEWORK_API UGizmoLocalFloatParameterSource : public UGizmoBaseFloatParameterSource
{
GENERATED_BODY()
public:
virtual float GetParameter() const override
{
return Value;
}
virtual void SetParameter(float NewValue) override
{
Value = NewValue;
LastChange.CurrentValue = NewValue;
OnParameterChanged.Broadcast(this, LastChange);
}
virtual void BeginModify()
{
LastChange = FGizmoFloatParameterChange(Value);
}
virtual void EndModify()
{
}
public:
UPROPERTY()
float Value = 0.0f;
UPROPERTY()
FGizmoFloatParameterChange LastChange;
};