UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SColorValueSlider.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5// HEADER_UNIT_SKIP - Bad header, does not compile
6
7#include "CoreMinimal.h"
8#include "Misc/Attribute.h"
9#include "InputCoreTypes.h"
10#include "Input/Reply.h"
13#include "Styling/CoreStyle.h"
14#include "Widgets/SLeafWidget.h"
16
17class FPaintArgs;
18class FSlateRect;
19class FWidgetStyle;
20struct FGeometry;
21struct FPointerEvent;
22struct FSlateBrush;
23
28 : public SLeafWidget
29{
30public:
31
38
41
42
44
45
47
48
50
52
53 void Construct( const FArguments& InArgs )
54 {
55 SelectorImage = FCoreStyle::Get().GetBrush("ColorPicker.Selector");
56
57 OnValueChanged = InArgs._OnValueChanged;
58 OnMouseCaptureBegin = InArgs._OnMouseCaptureBegin;
59 OnMouseCaptureEnd = InArgs._OnMouseCaptureEnd;
60 SelectedColor = InArgs._SelectedColor;
61 }
62
63 virtual int32 OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const
64 {
65 const bool bIsEnabled = ShouldBeEnabled(bParentEnabled);
67
71
72 TArray<FSlateGradientStop> GradientStops;
73 GradientStops.Add(FSlateGradientStop(FVector2D::ZeroVector, FLinearColor(0.0f, 0.0f, 0.0f, 1.0f)));
74 GradientStops.Add(FSlateGradientStop(AllottedGeometry.Size, StopColor));
75
77 OutDrawElements,
78 LayerId,
79 AllottedGeometry.ToPaintGeometry(),
80 GradientStops,
82 MyCullingRect,
83 DrawEffects
84 );
85
86 float Value = SelectedColor.Get().B;
88
90 OutDrawElements,
91 LayerId + 1,
94 MyCullingRect,
95 DrawEffects,
96 InWidgetStyle.GetColorAndOpacityTint() * SelectorImage->GetTint( InWidgetStyle ) );
97
98 return LayerId + 1;
99 }
100
102 {
103 if ( MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton )
104 {
105 OnMouseCaptureBegin.ExecuteIfBound();
106
107 return FReply::Handled().CaptureMouse( SharedThis(this) );
108 }
109 else
110 {
111 return FReply::Unhandled();
112 }
113 }
114
116 {
117 if ( MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton && HasMouseCapture() )
118 {
119 OnMouseCaptureEnd.ExecuteIfBound();
120
122 }
123 else
124 {
125 return FReply::Unhandled();
126 }
127 }
128
130 {
131 if (!HasMouseCapture())
132 {
133 return FReply::Unhandled();
134 }
135
136 FVector2D LocalMouseCoordinate = MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() );
137 FVector2D Location = LocalMouseCoordinate / (MyGeometry.Size);
138 float Value = FMath::Clamp(Location.X, 0.f, 1.f);
139
140 FLinearColor NewColor = SelectedColor.Get();
141 NewColor.B = Value;
142
143 OnValueChanged.ExecuteIfBound(NewColor);
144
145 return FReply::Handled();
146 }
147
152
153 virtual FVector2D ComputeDesiredSize(float) const
154 {
155 return SelectorImage->ImageSize * 2.f;
156 }
157
158protected:
159
162
165
168
171
174};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define SLATE_ATTRIBUTE(AttrType, AttrName)
Definition DeclarativeSyntaxSupport.h:192
#define SLATE_EVENT(DelegateName, EventName)
Definition DeclarativeSyntaxSupport.h:458
#define SLATE_END_ARGS()
Definition DeclarativeSyntaxSupport.h:116
UE::Math::TVector2< double > FVector2D
Definition MathFwd.h:48
ESlateDrawEffect
Definition RenderingCommon.h:89
static const ISlateStyle & Get()
Definition CoreStyle.h:33
Definition PaintArgs.h:23
Definition Reply.h:24
FReply & ReleaseMouseCapture()
Definition Reply.h:114
static FReply Unhandled()
Definition Reply.h:241
FReply & CaptureMouse(TSharedRef< SWidget > InMouseCaptor)
Definition Reply.h:28
static FReply Handled()
Definition Reply.h:233
static SLATECORE_API void MakeBox(FSlateWindowElementList &ElementList, uint32 InLayer, const FPaintGeometry &PaintGeometry, const FSlateBrush *InBrush, ESlateDrawEffect InDrawEffects=ESlateDrawEffect::None, const FLinearColor &InTint=FLinearColor::White)
Definition DrawElementTypes.cpp:333
static SLATECORE_API void MakeGradient(FSlateWindowElementList &ElementList, uint32 InLayer, const FPaintGeometry &PaintGeometry, TArray< FSlateGradientStop > InGradientStops, EOrientation InGradientType, ESlateDrawEffect InDrawEffects=ESlateDrawEffect::None, FVector4f CornerRadius=FVector4f(0.0f))
Definition DrawElementTypes.cpp:554
Definition SlateRect.h:26
Definition DrawElements.h:220
Definition WidgetStyle.h:15
const FLinearColor & GetColorAndOpacityTint() const
Definition WidgetStyle.h:87
virtual const FSlateBrush * GetBrush(const FName PropertyName, const ANSICHAR *Specifier=nullptr, const ISlateStyle *RequestingStyle=nullptr) const =0
Definition SColorValueSlider.h:29
FSimpleDelegate OnMouseCaptureEnd
Definition SColorValueSlider.h:173
const FSlateBrush * SelectorImage
Definition SColorValueSlider.h:161
virtual FVector2D ComputeDesiredSize(float) const
Definition SColorValueSlider.h:153
void Construct(const FArguments &InArgs)
Definition SColorValueSlider.h:53
TAttribute< FLinearColor > SelectedColor
Definition SColorValueSlider.h:164
FOnLinearColorValueChanged OnValueChanged
Definition SColorValueSlider.h:167
virtual FReply OnMouseButtonDoubleClick(const FGeometry &InMyGeometry, const FPointerEvent &InMouseEvent)
Definition SColorValueSlider.h:148
virtual FReply OnMouseButtonUp(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent)
Definition SColorValueSlider.h:115
virtual FReply OnMouseMove(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent)
Definition SColorValueSlider.h:129
virtual int32 OnPaint(const FPaintArgs &Args, const FGeometry &AllottedGeometry, const FSlateRect &MyCullingRect, FSlateWindowElementList &OutDrawElements, int32 LayerId, const FWidgetStyle &InWidgetStyle, bool bParentEnabled) const
Definition SColorValueSlider.h:63
virtual FReply OnMouseButtonDown(const FGeometry &MyGeometry, const FPointerEvent &MouseEvent)
Definition SColorValueSlider.h:101
FSimpleDelegate OnMouseCaptureBegin
Definition SColorValueSlider.h:170
SLATE_BEGIN_ARGS(SColorValueSlider)
Definition SColorValueSlider.h:32
Definition SLeafWidget.h:29
bool ShouldBeEnabled(bool InParentEnabled) const
Definition SWidget.h:1603
SLATECORE_API bool HasMouseCapture() const
Definition SWidget.cpp:994
Definition Array.h:670
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
const ObjectType & Get() const
Definition Attribute.h:241
static UE_FORCEINLINE_HINT TSharedRef< OtherType, Mode > SharedThis(OtherType *ThisPtr)
Definition SharedPointer.h:1780
static INPUTCORE_API const FKey LeftMouseButton
Definition InputCoreTypes.h:300
Definition Geometry.h:40
const FDeprecateSlateVector2D Size
Definition Geometry.h:590
FORCEINLINE_DEBUGGABLE FPaintGeometry ToPaintGeometry() const
Definition Geometry.h:315
Definition Color.h:48
float B
Definition Color.h:55
CORE_API FLinearColor HSVToLinearRGB() const
Definition Color.cpp:411
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
Definition Events.h:695
Definition SlateBrush.h:239
FLinearColor GetTint(const FWidgetStyle &InWidgetStyle) const
Definition SlateBrush.h:339
FDeprecateSlateVector2D ImageSize
Definition SlateBrush.h:268
Definition DrawElementTypes.h:395
static CORE_API const TVector2< double > ZeroVector
Definition Vector2D.h:63