Touch Interface Designer 2025.2
Create touch interface with a visual editor and manage all mobile inputs like gestures
Loading...
Searching...
No Matches
STouchInterfaceRuntime.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 "STouchInterface.h"
8#include "Widgets/SCompoundWidget.h"
9
11class UComponentLogic;
12class UTouchInputComponent;
13class STouchInputComponent;
14class UTouchInterfaceSettings;
16class SConstraintCanvas;
19class SRetainerWidget;
20class ULocalPlayer;
21
22DECLARE_DELEGATE_TwoParams(FOnLayoutTouch, int32, FVector2D)
23DECLARE_DELEGATE_OneParam(FOnTouchInterfaceNotification, bool)
24DECLARE_DELEGATE(FOnTouchInterfaceEvent)
25
26
29class TOUCHINTERFACE_API STouchInterfaceRuntime : public STouchInterface
30{
31
32public:
34 : _bLoadLayoutFromSave(false)
35 , _LayoutIndex(0)
36 {}
37 //Begin STouchInterface
38 SLATE_ARGUMENT(bool, bRenderOnInvalidation)
39 SLATE_ARGUMENT(bool, bRenderOnPhase)
40 SLATE_ARGUMENT(bool, bRetainRender)
41 SLATE_ARGUMENT(int32, Phase)
42 SLATE_ARGUMENT(int32, PhaseCount)
43 SLATE_ARGUMENT(TObjectPtr<UMaterialInterface>, RetainerMaterial)
44 SLATE_ARGUMENT(FName, TextureParamName)
45 //End STouchInterface
46
47 SLATE_ARGUMENT(bool, bLoadLayoutFromSave)
48 SLATE_ARGUMENT(int32, LayoutIndex)
49 SLATE_ARGUMENT(TObjectPtr<ULocalPlayer>, LocalPlayer)
50 SLATE_ARGUMENT(bool, EnableShapeDrawer)
51 SLATE_ARGUMENT(TSubclassOf<UVirtualShapeDrawer>, DrawerClass)
52 SLATE_ARGUMENT(int32, DebugType)
53
54 SLATE_EVENT(FOnLayoutTouch, OnTouchBegan)
55 SLATE_EVENT(FOnLayoutTouch, OnTouchMove)
56 SLATE_EVENT(FOnLayoutTouch, OnTouchEnd)
57 SLATE_EVENT(FOnTouchInterfaceNotification, OnActiveStateChanged)
58 SLATE_EVENT(FOnTouchInterfaceNotification, OnVisibilityChanged)
59 SLATE_EVENT(FOnTouchInterfaceEvent, OnLayoutGenerated)
60
61 //TODO: TAttribute to get children in layout object?
62 //TODO: RetainerSettings?
63 //TODO TAttribute for opacity
64 SLATE_END_ARGS()
65
67
69 void Construct(const FArguments& InArgs, TObjectPtr<UTouchInterfaceLayout> Layout);
70
71 //TODO: STouchInterface contains only functions that are used both in editor and runtime (Shares code between the editor and runtime)
72
73 //Called by subsystem on deinitialization or before this widget is removed from viewport
74 virtual void Clean() override;
75
76protected:
77 EActiveTimerReturnType ActivateTouchInterface(double InCurrentTime, float InDeltaTime);
78
79 virtual EActiveTimerReturnType BeginGenerateLayout(double InCurrentTime, float InDeltaTime);
80
81 virtual void GenerateLayout(TObjectPtr<UTouchInterfaceLayout> Layout) override;
82
83public:
84 //Begin SWidget Implementation
85 virtual bool SupportsKeyboardFocus() const override { return false; }
86 virtual FVector2D ComputeDesiredSize(float) const override { return FVector2D(100, 100); }
87
88 virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override;
89
90 virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
91 virtual FReply OnMouseButtonDoubleClick(const FGeometry& InMyGeometry, const FPointerEvent& InMouseEvent) override;
92 virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
93 virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
94
95 virtual FReply OnTouchStarted(const FGeometry& MyGeometry, const FPointerEvent& InTouchEvent) override;
96 virtual FReply OnTouchMoved(const FGeometry& MyGeometry, const FPointerEvent& InTouchEvent) override;
97 virtual FReply OnTouchEnded(const FGeometry& MyGeometry, const FPointerEvent& InTouchEvent) override;
98 virtual FReply OnTouchFirstMove(const FGeometry& MyGeometry, const FPointerEvent& TouchEvent) override;
99 virtual FReply OnTouchForceChanged(const FGeometry& MyGeometry, const FPointerEvent& TouchEvent) override;
100 virtual void Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime ) override;
101 virtual int32 OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const override;
102 //End SWidget Implementation
103
104
105 //GETTERS
106
108 UWorld* GetWorldContext() const;
109
110 TArray<UTouchInterfaceListener*>& GetListeners() { return Listeners; }
111
112 ULocalPlayer* GetLocalPlayer() const { return LocalPlayer; }
113
114
115 //SETTERS
116
117 void SetListenerList(TArray<UTouchInterfaceListener*> NewListenerList);
118
119
120 //UTILITY
121
122 bool IsActive() const { return State == State_Active; }
123
124 UVirtualShapeDrawer* GetShapeDrawerInstance() const { return ShapeDrawerInstance; }
125
126 UVirtualShapeDrawer* AddShapeDrawer(TSubclassOf<UVirtualShapeDrawer> ShapeDrawerClass);
127 void RemoveShapeDrawer();
128
129 void ShowShapeDrawer() const;
130 void HideShapeDrawer() const;
131
132 void ResetComponentLocation();
133
134 //INPUT
135
136 // Whether or not input is enabled
137 void BlockInput(const bool bBlock) { bBlockInput = bBlock; }
138
139 // Whether or not gesture is enabled
140 //void BlockRecognizerOfType(TSubclassOf<UTouchInterfaceListener> RecognizerClass);
141
142
143 //Check if layout children has changed. If so, add or remove widget accordingly
144 virtual void AddOrRemoveComponent();
145
148 virtual void Rebuild(const TObjectPtr<UTouchInterfaceLayout> Layout) override;
149
150private:
151 // Callback for handling device orientation changes
152 virtual void HandleOnOrientationChanged(const int32 Mode);
153
154 virtual float CalculateScaleFactor(const FGeometry& Geometry) const override;
155
156 bool CanSendInputsToRecognizer(const bool bHitControl) const;
157
158
159protected:
160 TObjectPtr<UTouchInterfaceLayout> CurrentLayout;
161
162 const UTouchInterfaceSettings* Settings;
163
164 //TSharedPtr<SRetainerWidget> RetainerWidget;
165
166 //TSharedPtr<SConstraintCanvas> MainCanvas;
167
168 //TArray<TSharedPtr<SLayoutComponent>> Children;
169
170 FOnLayoutTouch OnTouchBegan;
171 FOnLayoutTouch OnTouchMove;
172 FOnLayoutTouch OnTouchEnd;
173
174 //FOnTouchInterfaceNotification OnActiveStateChanged;
175 //FOnTouchInterfaceNotification OnVisibilityChanged;
176
177 //FOnTouchInterfaceEvent OnLayoutGenerated;
178
179private:
180 TArray<UTouchInterfaceListener*> Listeners;
181
182 UVirtualShapeDrawer* ShapeDrawerInstance;
183
184 struct FFingerDebugData
185 {
186 uint32 FingerIndex;
187 FVector2D Position;
188
189 FFingerDebugData(const uint32 InFingerIndex, const FVector2D InPosition) :
190 FingerIndex(InFingerIndex),
191 Position(InPosition)
192 {
193
194 }
195 };
196
197 uint8 bDrawDebug:1;
198
199 TArray<FFingerDebugData> Fingers;
200
201 uint8 bLoadLayoutFromSave:1;
202 int32 LayoutIndex;
203
204 UWorld* WorldContext;
205 ULocalPlayer* LocalPlayer;
206
207 enum ELayoutState
208 {
209 State_GoingToActive,
210 State_Active,
211 State_CountingDownToInactive,
212 State_CountingDownToReset,
213 State_GoingToInactive,
214 State_Inactive,
215 };
216
217 ELayoutState State;
218
219 //Countdown until next state change
220 float Countdown;
221
222 //GESTURE RECOGNIZER
223
225 uint8 bGestureRecognizerEnabled:1;
226
228 uint8 bBlockRecognizers:1;
229
230
231 //SHAPE RECOGNIZER
232
233 // True if the widget should send input to the Shape Recognition Manager
234 uint8 bShapeRecognizerEnabled:1;
235
237 uint8 bBlockShapeRecognition:1;
238};
DECLARE_DELEGATE_OneParam(FOnVirtualInputSelected, FName)
DECLARE_DELEGATE_TwoParams(FOnLayoutTouch, int32, FVector2D) DECLARE_DELEGATE_OneParam(FOnTouchInterfaceNotification
Definition SLayoutComponent.h:55
STouchInterface()
Definition STouchInterface.cpp:14
uint8 bBlockInput
Definition STouchInterface.h:157
Definition STouchInterfaceRuntime.h:30
SLATE_BEGIN_ARGS(STouchInterfaceRuntime)
Definition STouchInterfaceRuntime.h:33
bool IsActive() const
Definition STouchInterfaceRuntime.h:122
TObjectPtr< UTouchInterfaceLayout > CurrentLayout
Definition STouchInterfaceRuntime.h:160
ULocalPlayer * GetLocalPlayer() const
Definition STouchInterfaceRuntime.h:112
TArray< UTouchInterfaceListener * > & GetListeners()
Definition STouchInterfaceRuntime.h:110
FOnLayoutTouch OnTouchEnd
Definition STouchInterfaceRuntime.h:172
FOnLayoutTouch OnTouchBegan
Definition STouchInterfaceRuntime.h:170
const UTouchInterfaceSettings * Settings
Definition STouchInterfaceRuntime.h:162
void BlockInput(const bool bBlock)
Definition STouchInterfaceRuntime.h:137
virtual bool SupportsKeyboardFocus() const override
Definition STouchInterfaceRuntime.h:85
virtual FVector2D ComputeDesiredSize(float) const override
Definition STouchInterfaceRuntime.h:86
FOnLayoutTouch OnTouchMove
Definition STouchInterfaceRuntime.h:171
UVirtualShapeDrawer * GetShapeDrawerInstance() const
Definition STouchInterfaceRuntime.h:124
STouchInterfaceRuntime()
Definition STouchInterfaceRuntime.cpp:21
Definition LayoutComponent.h:94
Definition TouchInterfaceLayout.h:20
Definition TouchInterfaceListener.h:16
Definition VirtualShapeDrawer.h:22