Touch Interface Designer 2025.2
Create touch interface with a visual editor and manage all mobile inputs like gestures
Loading...
Searching...
No Matches
STouchInterface.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 "Widgets/SCompoundWidget.h"
7#include "Widgets/Layout/Anchors.h"
8
10class UComponentLogic;
11class UTouchInputComponent;
12class STouchInputComponent;
13class UTouchInterfaceSettings;
15class SConstraintCanvas;
18class SRetainerWidget;
19class ULocalPlayer;
20class UMaterialInterface;
21
23{
24 int32 ZOrder;
25 FAnchors Anchors;
26 FVector2D Alignment;
27 FVector2D Location;
28 FVector Size;
29 float Angle;
30
31 TSharedPtr<SLayoutComponent> Widget;
32};
33
34DECLARE_DELEGATE_TwoParams(FOnLayoutTouch, int32, FVector2D)
35DECLARE_DELEGATE_OneParam(FOnTouchInterfaceNotification, bool)
36DECLARE_DELEGATE(FOnTouchInterfaceEvent)
37
38
41
42class TOUCHINTERFACE_API STouchInterface : public SCompoundWidget
43{
44
45public:
47 : _RenderOpacity(1.0f)
48 {}
49 SLATE_ARGUMENT(bool, bRenderOnInvalidation)
50 SLATE_ARGUMENT(bool, bRenderOnPhase)
51 SLATE_ARGUMENT(bool, bRetainRender)
52 SLATE_ARGUMENT(int32, Phase)
53 SLATE_ARGUMENT(int32, PhaseCount)
54 SLATE_ARGUMENT(TObjectPtr<UMaterialInterface>, RetainerMaterial)
55 SLATE_ARGUMENT(FName, TextureParamName)
56 SLATE_ARGUMENT(float, RenderOpacity)
57 SLATE_END_ARGS()
58
60
62 void Construct(const FArguments& InArgs);
63
64 //TODO: STouchInterface contains only functions that are used both in editor and runtime (Shares code between the editor and runtime)
65
66 //Called by subsystem on deinitialization or before this widget is removed from viewport
67 virtual void Clean();
68
69protected:
70 virtual void GenerateLayout(const TObjectPtr<UTouchInterfaceLayout> Layout) = 0;
71
72public:
73 //Begin SWidget Implementation
74
75 //virtual void Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime ) override;
76 //virtual int32 OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const override;
77 //End SWidget Implementation
78
79
80 //GETTERS
81
82 TArray<TSharedPtr<SLayoutComponent>> GetComponents() { return Children; }
83
84 float GetLayoutOpacity() const;
85
86 FVector2D GetGeometrySize() const;
87
88 //SETTERS
89
90 void SetLayoutVisibility(const bool bIsVisible) const;
91
92 void SetRetainRender(const bool bValue);
93 void SetRenderOnPhase(const bool bValue);
94 void SetRenderOnInvalidation(const bool bValue);
95 void SetRenderPhase(const int32 Phase, const int32 PhaseCount);
96 void SetRetainerMaterial(TObjectPtr<UMaterialInterface> Value);
97 void SetTextureParameterName(const FName Name);
98 void SetCanvasRenderOpacity(const float Value);
99
100
101 //UTILITY
102
103 void EnableDebug();
104 void DisableDebug();
105
106 bool IsLayoutVisible() const;
107
108 FVector2D AbsoluteToLocal(const FVector2D AbsolutePosition) const;
109
110 //INPUT
111
114 virtual void Rebuild(const TObjectPtr<UTouchInterfaceLayout> Layout);
115
116 //virtual void Rebuild(TArray<TSharedPtr<SLayoutComponent>> WidgetComponent);
117
118 virtual void SortByPriority();
119
120 virtual bool GetAllTouchInputUnderLocation(TArray<TSharedPtr<SLayoutComponent>>& OutComponents, const FVector2D AbsoluteLocation);
121
122protected:
123 template <typename T>
124 TSharedRef<T> AddComponentOfType();
125
126 FMargin GenerateOffsetMargin(const FVector2D& Size, const FVector2D& Position);
127
129 virtual void HandleDisplayMetricsChanged(const FDisplayMetrics& NewDisplayMetric);
130
131 virtual float CalculateScaleFactor(const FGeometry& Geometry) const;
132
133protected:
134 TSharedPtr<SRetainerWidget> RetainerWidget;
135
136 TSharedPtr<SConstraintCanvas> MainCanvas;
137
138 TArray<TSharedPtr<SLayoutComponent>> Children;
139
140 FOnTouchInterfaceNotification OnActiveStateChanged;
141 FOnTouchInterfaceNotification OnVisibilityChanged;
142
143 FOnTouchInterfaceEvent OnLayoutGenerated;
144
145 TArray<TSharedPtr<SLayoutComponent>> TouchInputWidgets;
146
148
150
152
154
156
157 uint8 bBlockInput:1;
158
160
162
164
166
167#if WITH_EDITOR
168 friend class STouchInterfaceLayoutEditor;
169#endif
170};
DECLARE_DELEGATE_TwoParams(FOnLayoutTouch, int32, FVector2D) DECLARE_DELEGATE_OneParam(FOnTouchInterfaceNotification
DECLARE_DELEGATE_OneParam(FOnVirtualInputSelected, FName)
Definition SLayoutComponent.h:55
Definition STouchInterface.h:43
TSharedPtr< SRetainerWidget > RetainerWidget
Definition STouchInterface.h:134
FOnTouchInterfaceNotification OnVisibilityChanged
Definition STouchInterface.h:141
SLATE_BEGIN_ARGS(STouchInterface)
Definition STouchInterface.h:46
TArray< TSharedPtr< SLayoutComponent > > TouchInputWidgets
Definition STouchInterface.h:145
STouchInterface()
Definition STouchInterface.cpp:14
uint8 bBlockInput
Definition STouchInterface.h:157
uint8 bBlockTouchEvent
Definition STouchInterface.h:153
uint8 bCaptureMouse
Definition STouchInterface.h:155
FVector2D CurrentGeometrySize
Definition STouchInterface.h:151
uint8 bMoveEventAllowed
Definition STouchInterface.h:159
TArray< TSharedPtr< SLayoutComponent > > GetComponents()
Definition STouchInterface.h:82
TArray< TSharedPtr< SLayoutComponent > > Children
Definition STouchInterface.h:138
int32 ActiveFingerCount
Definition STouchInterface.h:161
TSharedPtr< SConstraintCanvas > MainCanvas
Definition STouchInterface.h:136
int32 DebugType
Definition STouchInterface.h:165
FOnTouchInterfaceEvent OnLayoutGenerated
Definition STouchInterface.h:143
FVector2D PreviousGeometrySize
Definition STouchInterface.h:149
float PreviousScalingFactor
Definition STouchInterface.h:147
FOnTouchInterfaceNotification OnActiveStateChanged
Definition STouchInterface.h:140
virtual void GenerateLayout(const TObjectPtr< UTouchInterfaceLayout > Layout)=0
bool bDrawDebug
Definition STouchInterface.h:163
Definition LayoutComponent.h:94
Definition TouchInterfaceLayout.h:20
Definition TouchInterfaceListener.h:16
Definition STouchInterface.h:23
float Angle
Definition STouchInterface.h:29
FVector Size
Definition STouchInterface.h:28
TSharedPtr< SLayoutComponent > Widget
Definition STouchInterface.h:31
FAnchors Anchors
Definition STouchInterface.h:25
FVector2D Alignment
Definition STouchInterface.h:26
FVector2D Location
Definition STouchInterface.h:27
int32 ZOrder
Definition STouchInterface.h:24