Touch Interface Designer 2025.2
Create touch interface with a visual editor and manage all mobile inputs like gestures
Loading...
Searching...
No Matches
ComponentDecorator.h
Go to the documentation of this file.
1// Copyright 2024 Lost in Game Studio. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "UObject/Object.h"
7#include "Rendering/DrawElements.h"
8#include "Styling/WidgetStyle.h"
9#include "Styling/SlateBrush.h"
10#include "Widgets/SNullWidget.h"
11#include "Types/SlateEnums.h"
12#include "ComponentDecorator.generated.h"
13
16class UComponentDecorator_Animation;
17
18UENUM(BlueprintType)
19enum class EDrawType : uint8
20{
21 //Draw only when component is pressed
23
24 //Draw only when component is not pressed
26
27 //Always draw
29};
30
31//TODO: Make widget for all layer. Keep a reference to generated widget to allow modification. In editor, widget is reconstructed each time?
32
33//Simple image decorator
34UCLASS(BlueprintType)
35class TOUCHINTERFACE_API UComponentDecorator : public UObject
36{
37 GENERATED_BODY()
38
39public:
41
42 virtual void BeginDestroy() override;
43
44 virtual void Initialize(TObjectPtr<ULayoutComponent> Component);
45
46#if WITH_EDITOR
47 virtual void EditorInitialize() {}
48 virtual FName GetStyleSetName() { return FName(""); }
49 virtual TSharedRef<SWidget> GetEditorWidget();
50 virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
51
52 virtual void SynchronizeProperties();
53#endif
54
55 virtual bool CanAcceptChildren() { return false; }
56
57 bool IsInGroup() const;
58
59 //TODO: Bool to false by default
62 TSharedRef<SWidget> GetWidget(const bool bForceReconstruct = true);
63
65 virtual TSharedRef<SWidget> CreateWidgetInstance();
66
70 //virtual TSharedRef<SWidget> GetWidget(EHorizontalAlignment& HAlign, EVerticalAlignment& VAlign);
71
72 const TObjectPtr<ULayoutComponent>& GetOwner() const { return Owner; }
73
74 TObjectPtr<UComponentDecoratorGroup> GetGroup() const;
75
76 //Can be decorator group or layout component
77 bool EjectFromParent();
78
79 // Returns the size of decorator in percent
80 UFUNCTION(Category="Decorator", BlueprintCallable, BlueprintPure)
81 FVector2D GetSize() const { return Size; }
82
83 UFUNCTION(Category="Decorator", BlueprintCallable, BlueprintPure)
84 FVector2D GetAbsoluteSize() const;
85
86 UFUNCTION(Category="Decorator", BlueprintCallable, BlueprintPure)
87 virtual float GetMaxHorizontalSize(bool bRecursive = false) const;
88
89 UFUNCTION(Category="Decorator", BlueprintCallable, BlueprintPure)
90 virtual float GetMaxVerticalSize(bool bRecursive = false) const;
91
92 // Returns offset value from geometry center
93 UFUNCTION(Category="Decorator", BlueprintCallable, BlueprintPure)
94 FVector2D GetOffset() const { return Offset; }
95
96 // Returns rotation value
97 UFUNCTION(Category="Decorator", BlueprintCallable, BlueprintPure)
98 float GetRotation() const { return Rotation; }
99
100 // Returns slate brush used by this decorator. Warning! Can be null
101 UFUNCTION(Category="Decorator", BlueprintCallable, BlueprintPure)
102 FSlateBrush GetBrush() const { return Brush; }
103
106 UFUNCTION(Category="Decorator", BlueprintCallable)
107 virtual void SetBrushResource(UObject* Resource);
108
109 // Set the slate brush used by this decorator
110 UFUNCTION(Category="Decorator", BlueprintCallable)
111 virtual void SetBrush(const FSlateBrush InBrush);
112
113 UFUNCTION(Category="Decorator", BlueprintCallable)
114 virtual void SetBrushOpacity(const float Value);
115
116 // Set the size of decorator
117 UFUNCTION(Category="Decorator", BlueprintCallable)
118 virtual void SetSize(const FVector2D Value);
119
120 // Set the new offset value of decorator (offset from component geometry center)
121 UFUNCTION(Category="Decorator", BlueprintCallable)
122 virtual void SetOffset(FVector2D NewOffset);
123
124 // Set the new rotation value of decorator
125 UFUNCTION(Category="Decorator", BlueprintCallable)
126 virtual void SetRotation(float Angle);
127
128 // Set the new draw type of this decorator
129 UFUNCTION(Category="Decorator", BlueprintCallable)
130 virtual void SetDrawType(const EDrawType NewType);
131
132 // Add delta to current rotation of decorator. Returns new rotation value.
133 UFUNCTION(Category="Decorator", BlueprintCallable)
134 virtual float AddRotationDelta(float Delta);
135
138 UFUNCTION(Category="Decorator", BlueprintCallable)
139 virtual UMaterialInstanceDynamic* GetDynamicMaterialInstance();
140
141 // Display decorator
142 UFUNCTION(Category="Decorator", BlueprintCallable)
143 virtual void ShowDecorator();
144
145 // Hide decorator
146 UFUNCTION(Category="Decorator", BlueprintCallable)
147 virtual void HideDecorator();
148
149 // Returns true if decorator is visible
150 UFUNCTION(Category="Decorator", BlueprintCallable)
151 virtual bool IsVisible() const;
152
153protected:
154 virtual void HandleOnPressEvent(const FGeometry& ComponentGeometry, const FGeometry& LayoutGeometry, const FPointerEvent& PointerEvent);
155 virtual void HandleOnReleaseEvent(const FGeometry& ComponentGeometry, const FGeometry& LayoutGeometry, const FPointerEvent& PointerEvent);
156
157
158private:
159 void UpdateRenderTransform() const;
160
161
162public:
163 // Is enabled, this decorator appear hidden at startup
164 UPROPERTY(Category="Decorator", EditAnywhere, BlueprintReadOnly)
166
167 //Resource object (texture, material, render target, etc)
168 UPROPERTY(Category="Decorator", EditAnywhere, BlueprintReadOnly)
169 FSlateBrush Brush;
170
178 UPROPERTY(Category="Decorator", EditAnywhere, BlueprintReadOnly, meta=(ClampMin=0.0f))
179 FVector2D Size;
180
181 //Offset from component geometry center
182 UPROPERTY(Category="Decorator", EditAnywhere, BlueprintReadOnly)
183 FVector2D Offset;
184
185 //Rotation value of this decorator
186 UPROPERTY(Category="Decorator", EditAnywhere, BlueprintReadOnly)
187 float Rotation;
188
189 //Select when decorator is drawn
190 UPROPERTY(Category="Decorator", EditAnywhere, BlueprintReadOnly)
192
195 UPROPERTY(Category="Decorator", EditAnywhere, BlueprintReadOnly)
196 int32 ZOrder;
197
198
199 UPROPERTY(Category="Decorator|Widget", EditAnywhere, BlueprintReadOnly)
200 TEnumAsByte<EHorizontalAlignment> HorizontalAlignment;
201
202 UPROPERTY(Category="Decorator|Widget", EditAnywhere, BlueprintReadOnly)
203 TEnumAsByte<EVerticalAlignment> VerticalAlignment;
204
205
206 UPROPERTY(Category="Decorator", EditAnywhere, BlueprintReadOnly, Instanced)
207 TArray<TObjectPtr<UComponentDecorator_Animation>> Animations;
208
209protected:
210 uint8 bIsVisible:1;
211
212 //This decorator cannot be modified, as it has been generated by the logic of the layout component, which is responsible for defining its appearance.
214
215 UPROPERTY()
217
218 TSharedPtr<SWidget> DecoratorWidget;
219
220private:
223};
EDrawType
Definition ComponentDecorator.h:20
@ Both
Definition ComponentDecorator.h:28
@ Pressed
Definition ComponentDecorator.h:22
@ Released
Definition ComponentDecorator.h:25
BlueprintType
Definition ComponentDecorator_Animation.h:40
Definition ComponentDecoratorGroup.h:14
BlueprintReadOnly TEnumAsByte< EHorizontalAlignment > HorizontalAlignment
Definition ComponentDecorator.h:200
BlueprintPure FSlateBrush GetBrush() const
Definition ComponentDecorator.h:102
virtual void BeginDestroy() override
Definition ComponentDecorator.cpp:35
TSharedPtr< SWidget > DecoratorWidget
Definition ComponentDecorator.h:218
uint8 bIsVisible
Definition ComponentDecorator.h:210
BlueprintPure FVector2D GetSize() const
Definition ComponentDecorator.h:81
BlueprintReadOnly FVector2D Offset
Definition ComponentDecorator.h:183
BlueprintReadOnly FSlateBrush Brush
Definition ComponentDecorator.h:169
const TObjectPtr< ULayoutComponent > & GetOwner() const
Definition ComponentDecorator.h:72
meta
Definition ComponentDecorator.h:178
friend class FTouchInterfaceLayoutEditor
Definition ComponentDecorator.h:221
TObjectPtr< ULayoutComponent > Owner
Definition ComponentDecorator.h:216
virtual void Initialize(TObjectPtr< ULayoutComponent > Component)
Definition ComponentDecorator.cpp:56
BlueprintPure float GetRotation() const
Definition ComponentDecorator.h:98
BlueprintPure FVector2D GetOffset() const
Definition ComponentDecorator.h:94
virtual bool CanAcceptChildren()
Definition ComponentDecorator.h:55
EditAnywhere
Definition ComponentDecorator.h:164
UComponentDecorator()
Definition ComponentDecorator.cpp:19
uint8 bGeneratedByLayoutComponentLogic
Definition ComponentDecorator.h:213
Category
Definition ComponentDecorator.h:80
BlueprintReadOnly EDrawType DrawType
Definition ComponentDecorator.h:191
BlueprintReadOnly float Rotation
Definition ComponentDecorator.h:187
friend class FTouchInterfaceDesignerEditorMenuExtender
Definition ComponentDecorator.h:222
BlueprintReadOnly uint8 bStartHidden
Definition ComponentDecorator.h:165
BlueprintCallable
Definition ComponentDecorator.h:80
Instanced TArray< TObjectPtr< UComponentDecorator_Animation > > Animations
Definition ComponentDecorator.h:207
BlueprintReadOnly
Definition ComponentDecorator.h:178
BlueprintReadOnly int32 ZOrder
Definition ComponentDecorator.h:196
BlueprintReadOnly TEnumAsByte< EVerticalAlignment > VerticalAlignment
Definition ComponentDecorator.h:203
Definition LayoutComponent.h:94