Touch Interface Designer 2025.2
Create touch interface with a visual editor and manage all mobile inputs like gestures
Loading...
Searching...
No Matches
STouchInterfaceLayoutPreviewer.h
Go to the documentation of this file.
1// Copyright 2025 Lost in Game Studio. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "Widgets/SCompoundWidget.h"
8#include "Widgets/Layout/SConstraintCanvas.h"
9#include "Styling/SlateBrush.h"
10
12class SConstraintCanvas;
15
17{
18 TSharedPtr<SComponentPreviewer> Widget;
19 SConstraintCanvas::FSlot* Slot;
20
22 : Widget(nullptr)
23 , Slot(nullptr)
24 {
25
26 }
27
28 FLayoutPreviewerWidget(TSharedPtr<SComponentPreviewer> InWidget, SConstraintCanvas::FSlot* InSlot)
29 : Widget(InWidget)
30 , Slot(InSlot)
31 {
32
33 }
34};
35
36DECLARE_DELEGATE_TwoParams(FOnComponentEditedSignature, FName, FVector2D)
37
38
41class TOUCHINTERFACE_API STouchInterfaceLayoutPreviewer : public SCompoundWidget
42{
43public:
44 SLATE_BEGIN_ARGS(STouchInterfaceLayoutPreviewer)
45 {
46 }
47 SLATE_ARGUMENT(UTouchInterfaceLayout*, EditedLayout)
48 SLATE_ARGUMENT(UTouchInterfaceLayout*, DesignedLayout)
49 SLATE_ARGUMENT(float, StartOpacity)
50 SLATE_ARGUMENT(bool, DrawHitBox)
51 SLATE_ARGUMENT(FIntPoint, ScreenSize)
52 SLATE_ARGUMENT(float, DPIScale)
53
54 SLATE_ARGUMENT(bool, bDesignMode)
55 SLATE_ARGUMENT(float, ResizeSensibility)
56
57 SLATE_EVENT(FOnComponentEditedSignature, OnComponentSelected)
58 SLATE_EVENT(FOnComponentEditedSignature, OnComponentLocationEdited)
59 SLATE_EVENT(FOnComponentEditedSignature, OnComponentSizeEdited)
60
61 SLATE_END_ARGS()
62
63 STouchInterfaceLayoutPreviewer();
64
66 void Construct(const FArguments& InArgs);
67
68private:
69 void GenerateLayout();
70
71public:
72 //Begin SWidget
73 virtual FVector2D ComputeDesiredSize(float LayoutScaleMultiplier) const override;
74
75 virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
76 //End SWidget
77
78 virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
79 virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
80 virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
81
82 virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
83
84 virtual FReply OnTouchStarted(const FGeometry& MyGeometry, const FPointerEvent& InTouchEvent) override;
85 virtual FReply OnDragDetected(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
86 virtual FReply OnTouchMoved(const FGeometry& MyGeometry, const FPointerEvent& InTouchEvent) override;
87 virtual FReply OnTouchEnded(const FGeometry& MyGeometry, const FPointerEvent& InTouchEvent) override;
88
89public:
90 void EnablePreview(bool bReset = false);
91 void DisablePreview();
92
93 bool IsPreview() const { return bPreview; }
94
95 //TODO: Use Anchor Offset
96 //Update only one component
97 void Update(FName ComponentName, FVector2D Location, FVector2D Size) const;
98
99 //Full rebuild of widget
100 void RebuildLayout();
101
102 void SetEditedLayoutAsset(const UTouchInterfaceLayout* NewLayout);
103 //void SetDesignedLayoutAsset(const UTouchInterfaceLayout* NewDesignedLayout);
104
105 void SetScreenSize(const FIntPoint InScreenSize);
106 void SetOpacity(const float InOpacity) { Opacity = InOpacity; }
107 void SetDPIScale(const float InDPIScale);
108 void SetDrawHitBox(const bool bEnable) { bDrawHitBox = bEnable; }
109 void SetPressedStateVisibility(const bool bVisible) { bShowPressedState = bVisible; }
110
111 void SetCanDrawPositioningBrush(const bool bEnable) { bCanDrawPositioningBrush = bEnable; }
112 void SetCanDrawDesignLocationBrush(const bool bEnable) { bCanDrawDesignLocationBrush = bEnable; }
113
114 void ClearSelect();
115
116 //TODO: Draw current location of component and indicate offset from design location
117
118private:
119 virtual FMargin GenerateOffset(const TObjectPtr<ULayoutComponent> Component);
120
121 float GetScaleFactor(const FGeometry& AllottedGeometry) const;
122
123public:
124 uint8 bUseTouchForPositioning:1;
125 uint8 bUseTouchForResizing:1;
126
127 float ResizeSensibility;
128
129 uint8 bDrawPositioningBrush:1;
130 FSlateBrush PositioningBrush;
131
132 uint8 bDrawOriginalCenterBrush:1;
133 FSlateBrush OriginalCenterBrush;
134
135private:
136 FOnComponentEditedSignature OnComponentSelected;
137 FOnComponentEditedSignature OnComponentLocationEdited;
138 FOnComponentEditedSignature OnComponentResized;
139
140 FVector2D ScreenSize;
141
142 float DPIScale;
143 float ActiveOpacity;
144 float InactiveOpacity;
145 float LastDistanceBetweenFingers;
146
147
148 uint8 bPreview:1;
149
150 FVector2D TouchLocation_Finger0;
151 FVector2D TouchLocation_Finger1;
152
153 FName SelectedComponentName;
154
155 bool bIsTouching;
156
157 uint8 bDragVirtualControl:1;
158 uint8 bResizeVirtualControl:1;
159 uint8 bCanDrawPositioningBrush:1;
160 uint8 bCanDrawDesignLocationBrush:1;
161
162 TSharedPtr<SConstraintCanvas> MainCanvas;
163
164 const UTouchInterfaceLayout* EditedLayout;
165 //const UTouchInterfaceLayout* DesignedLayout;
166
167 TMap<FName, FLayoutPreviewerWidget> Components;
168
169 TArray<TSharedPtr<SComponentPreviewer>> ComponentPreviewers;
170
171 uint8 bDesignMode:1;
172
173 float Opacity;
174
175 uint8 bDrawHitBox:1;
176
177 uint8 bShowPressedState:1;
178};
DECLARE_DELEGATE_TwoParams(FOnTouchEvent, int32, FVector2D)
Definition SComponentPreviewer.h:17
Definition ComponentDecorator.h:36
Definition TouchInterfaceLayout.h:20
FLayoutPreviewerWidget()
Definition STouchInterfaceLayoutPreviewer.h:21
FLayoutPreviewerWidget(TSharedPtr< SComponentPreviewer > InWidget, SConstraintCanvas::FSlot *InSlot)
Definition STouchInterfaceLayoutPreviewer.h:28
SConstraintCanvas::FSlot * Slot
Definition STouchInterfaceLayoutPreviewer.h:19
TSharedPtr< SComponentPreviewer > Widget
Definition STouchInterfaceLayoutPreviewer.h:18