Files
UnrealEngineUWP/Engine/Source/Runtime/UMG/Private/Components/Slider.cpp
patrick boutot aab0524385 UMG: Update the Slider widget with accessors.
#preflight 62582e2d946114248db734d5

#ROBOMERGE-AUTHOR: patrick.boutot
#ROBOMERGE-SOURCE: CL 19759850 via CL 19760019 via CL 19760159
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v939-19570697)

[CL 19802099 by patrick boutot in ue5-main branch]
2022-04-18 23:30:29 -04:00

336 lines
6.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Components/Slider.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/Input/SSlider.h"
#include "Styling/UMGCoreStyle.h"
#define LOCTEXT_NAMESPACE "UMG"
/////////////////////////////////////////////////////
// USlider
static FSliderStyle* DefaultSliderStyle = nullptr;
#if WITH_EDITOR
static FSliderStyle* EditorSliderStyle = nullptr;
#endif
USlider::USlider(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
MinValue = 0.0f;
MaxValue = 1.0f;
Orientation = EOrientation::Orient_Horizontal;
SliderBarColor = FLinearColor::White;
SliderHandleColor = FLinearColor::White;
StepSize = 0.01f;
IsFocusable = true;
MouseUsesStep = false;
RequiresControllerLock = true;
if (DefaultSliderStyle == nullptr)
{
DefaultSliderStyle = new FSliderStyle(FUMGCoreStyle::Get().GetWidgetStyle<FSliderStyle>("Slider"));
// Unlink UMG default colors.
DefaultSliderStyle->UnlinkColors();
}
WidgetStyle = *DefaultSliderStyle;
#if WITH_EDITOR
if (EditorSliderStyle == nullptr)
{
EditorSliderStyle = new FSliderStyle(FCoreStyle::Get().GetWidgetStyle<FSliderStyle>("Slider"));
// Unlink UMG Editor colors from the editor settings colors.
EditorSliderStyle->UnlinkColors();
}
if (IsEditorWidget())
{
WidgetStyle = *EditorSliderStyle;
// The CDO isn't an editor widget and thus won't use the editor style, call post edit change to mark difference from CDO
PostEditChange();
}
#endif // WITH_EDITOR
PRAGMA_ENABLE_DEPRECATION_WARNINGS
#if WITH_EDITORONLY_DATA
AccessibleBehavior = ESlateAccessibleBehavior::Summary;
bCanChildrenBeAccessible = false;
#endif
}
TSharedRef<SWidget> USlider::RebuildWidget()
{
PRAGMA_DISABLE_DEPRECATION_WARNINGS
MySlider = SNew(SSlider)
.Style(&WidgetStyle)
.IsFocusable(IsFocusable)
.OnMouseCaptureBegin(BIND_UOBJECT_DELEGATE(FSimpleDelegate, HandleOnMouseCaptureBegin))
.OnMouseCaptureEnd(BIND_UOBJECT_DELEGATE(FSimpleDelegate, HandleOnMouseCaptureEnd))
.OnControllerCaptureBegin(BIND_UOBJECT_DELEGATE(FSimpleDelegate, HandleOnControllerCaptureBegin))
.OnControllerCaptureEnd(BIND_UOBJECT_DELEGATE(FSimpleDelegate, HandleOnControllerCaptureEnd))
.OnValueChanged(BIND_UOBJECT_DELEGATE(FOnFloatValueChanged, HandleOnValueChanged));
PRAGMA_ENABLE_DEPRECATION_WARNINGS
return MySlider.ToSharedRef();
}
void USlider::SynchronizeProperties()
{
Super::SynchronizeProperties();
PRAGMA_DISABLE_DEPRECATION_WARNINGS
TAttribute<float> ValueBinding = PROPERTY_BINDING(float, Value);
MySlider->SetOrientation(Orientation);
MySlider->SetMouseUsesStep(MouseUsesStep);
MySlider->SetRequiresControllerLock(RequiresControllerLock);
MySlider->SetSliderBarColor(SliderBarColor);
MySlider->SetSliderHandleColor(SliderHandleColor);
MySlider->SetValue(ValueBinding);
MySlider->SetMinAndMaxValues(MinValue, MaxValue);
MySlider->SetLocked(Locked);
MySlider->SetIndentHandle(IndentHandle);
MySlider->SetStepSize(StepSize);
PRAGMA_ENABLE_DEPRECATION_WARNINGS
}
void USlider::ReleaseSlateResources(bool bReleaseChildren)
{
Super::ReleaseSlateResources(bReleaseChildren);
MySlider.Reset();
}
void USlider::HandleOnValueChanged(float InValue)
{
OnValueChanged.Broadcast(InValue);
BroadcastFieldValueChanged(FFieldNotificationClassDescriptor::Value);
}
void USlider::HandleOnMouseCaptureBegin()
{
OnMouseCaptureBegin.Broadcast();
}
void USlider::HandleOnMouseCaptureEnd()
{
OnMouseCaptureEnd.Broadcast();
}
void USlider::HandleOnControllerCaptureBegin()
{
OnControllerCaptureBegin.Broadcast();
}
void USlider::HandleOnControllerCaptureEnd()
{
OnControllerCaptureEnd.Broadcast();
}
PRAGMA_DISABLE_DEPRECATION_WARNINGS
float USlider::GetValue() const
{
if ( MySlider.IsValid() )
{
return MySlider->GetValue();
}
return Value;
}
float USlider::GetNormalizedValue() const
{
if (MySlider.IsValid())
{
return MySlider->GetNormalizedValue();
}
if (MinValue == MaxValue)
{
return 1.0f;
}
else
{
return (Value - MinValue) / (MaxValue - MinValue);
}
}
void USlider::SetValue(float InValue)
{
Value = InValue;
if ( MySlider.IsValid() )
{
MySlider->SetValue(InValue);
}
}
float USlider::GetMinValue() const
{
if (MySlider.IsValid())
{
return MySlider->GetMinValue();
}
return MinValue;
}
void USlider::SetMinValue(float InValue)
{
MinValue = InValue;
if (MySlider.IsValid())
{
// Because SSlider clamps min/max values upon setting them,
// we have to send both values together to ensure that they
// don't get out of sync.
MySlider->SetMinAndMaxValues(MinValue, MaxValue);
}
}
float USlider::GetMaxValue() const
{
if (MySlider.IsValid())
{
return MySlider->GetMaxValue();
}
return MaxValue;
}
void USlider::SetMaxValue(float InValue)
{
MaxValue = InValue;
if (MySlider.IsValid())
{
MySlider->SetMinAndMaxValues(MinValue, MaxValue);
}
}
const FSliderStyle& USlider::GetWidgetStyle() const
{
return WidgetStyle;
}
void USlider::SetWidgetStyle(const FSliderStyle& InStyle)
{
WidgetStyle = InStyle;
if (MySlider.IsValid())
{
MySlider->SetStyle(&WidgetStyle);
}
}
EOrientation USlider::GetOrientation() const
{
return Orientation;
}
void USlider::SetOrientation(EOrientation InOrientation)
{
Orientation = InOrientation;
if (MySlider.IsValid())
{
MySlider->SetOrientation(Orientation);
}
}
bool USlider::HasIndentHandle() const
{
return IndentHandle;
}
void USlider::SetIndentHandle(bool InIndentHandle)
{
IndentHandle = InIndentHandle;
if ( MySlider.IsValid() )
{
MySlider->SetIndentHandle(InIndentHandle);
}
}
bool USlider::IsLocked() const
{
return Locked;
}
void USlider::SetLocked(bool InLocked)
{
Locked = InLocked;
if ( MySlider.IsValid() )
{
MySlider->SetLocked(InLocked);
}
}
float USlider::GetStepSize() const
{
if (MySlider.IsValid())
{
return MySlider->GetStepSize();
}
return StepSize;
}
void USlider::SetStepSize(float InValue)
{
StepSize = InValue;
if (MySlider.IsValid())
{
MySlider->SetStepSize(InValue);
}
}
FLinearColor USlider::GetSliderHandleColor() const
{
return SliderHandleColor;
}
void USlider::SetSliderHandleColor(FLinearColor InValue)
{
SliderHandleColor = InValue;
if (MySlider.IsValid())
{
MySlider->SetSliderHandleColor(InValue);
}
}
FLinearColor USlider::GetSliderBarColor() const
{
return SliderBarColor;
}
void USlider::SetSliderBarColor(FLinearColor InValue)
{
SliderBarColor = InValue;
if (MySlider.IsValid())
{
MySlider->SetSliderBarColor(InValue);
}
}
PRAGMA_ENABLE_DEPRECATION_WARNINGS
#if WITH_ACCESSIBILITY
TSharedPtr<SWidget> USlider::GetAccessibleWidget() const
{
return MySlider;
}
#endif
#if WITH_EDITOR
const FText USlider::GetPaletteCategory()
{
return LOCTEXT("Common", "Common");
}
#endif
/////////////////////////////////////////////////////
#undef LOCTEXT_NAMESPACE