Agrarsense
UnrealWindow.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "Slate/SceneViewport.h"
10#include "Widgets/SViewport.h"
11#include "Widgets/SWindow.h"
12#include "TextureResource.h"
13
16
17class UWidget;
18class SOverlay;
19
21{
22 UWidget* Widget;
23
24 int Index;
25};
26
27/*
28* Class for custom Unreal Engine window.
29* This is used to create new window for each camera in the AGRARSENSE simulation.
30* This allows to use FrameGrabber class to capture Window pixels in efficient manner.
31* Otherwise we would need to use other methods of capturing the pixels (ReadPixels for example),
32* which for whatever reason are extremely slow in Unreal Engine.
33* See Camera.cpp for how to setup.
34*/
36{
37
38public:
39
46 FUnrealWindow(int32 Width, int32 Height, FString WindowName = "Camera");
47
49
54 void SetupComponent(UTextureRenderTarget2D* TextureRenderTarget);
55
61 void ResizeWindow(int32 Width, int32 Height);
62
66 void DestroyWindow();
67
68 /*
69 * Change window texture (DVSCamera)
70 */
71 void UpdateTexture(FTextureResource* Texture);
72
73 /*
74 * Draw current texture manually to screen.
75 * If bool DrawToScreen is true and this is called, function will print warning and return.
76 */
77 void DrawManually();
78
83 TSharedPtr<FSceneViewport> GetSceneViewport()
84 {
85 return SceneViewport;
86 }
87
92 TSharedPtr<SWindow> GetSWindow()
93 {
94 return sWindow;
95 }
96
102 void SetAutomaticDraw(bool Draw)
103 {
104 DrawToScreen = Draw;
105 if (Viewport.IsValid())
106 {
107 Viewport->DrawToScreen = DrawToScreen;
108 }
109 }
110
116 {
117 return DrawToScreen;
118 }
119
124 void AddUWidgetToWindow(UWidget* WidgetToAdd);
125
130 void RemoveUWidgetFromWindow(UWidget* WidgetToRemove);
131
132
134 {
135 return WindowWidth;
136 }
137
139 {
140 return WindowHeight;
141 }
142
143private:
144
149 void OnWindowClosed(const TSharedRef<SWindow>& Window);
150
151 int WindowWidth = 1280;
152 int WindowHeight = 720;
153
155
156 bool DrawToScreen = true;
157
158 FOnWindowClosed onWindowClosedDelegate;
159
160 TSharedPtr<FUnrealWindowViewportClient> ViewportClient;
161 TSharedPtr<SUnrealWindowViewport> Viewport;
162
163 TSharedPtr<FSceneViewport> SceneViewport;
164 TSharedPtr<SViewport> sViewport;
165 TSharedPtr<SWindow> sWindow;
166
167 TSharedPtr<SOverlay> FullScreenOverlay;
168
169 UPROPERTY()
171
172};
TSharedPtr< FUnrealWindowViewportClient > ViewportClient
Definition: UnrealWindow.h:160
TSharedPtr< SWindow > GetSWindow()
Definition: UnrealWindow.h:92
void UpdateTexture(FTextureResource *Texture)
FOnWindowClosed onWindowClosedDelegate
Definition: UnrealWindow.h:158
void SetupComponent(UTextureRenderTarget2D *TextureRenderTarget)
TSharedPtr< SUnrealWindowViewport > Viewport
Definition: UnrealWindow.h:161
int GetWindowWidth()
Definition: UnrealWindow.h:133
int GetWindowHeight()
Definition: UnrealWindow.h:138
TSharedPtr< FSceneViewport > GetSceneViewport()
Definition: UnrealWindow.h:83
void AddUWidgetToWindow(UWidget *WidgetToAdd)
void SetAutomaticDraw(bool Draw)
Definition: UnrealWindow.h:102
void OnWindowClosed(const TSharedRef< SWindow > &Window)
TArray< FAddedWidgetInfo > AddedWidgets
Definition: UnrealWindow.h:170
FUnrealWindow(int32 Width, int32 Height, FString WindowName="Camera")
void ResizeWindow(int32 Width, int32 Height)
TSharedPtr< SWindow > sWindow
Definition: UnrealWindow.h:165
void DestroyWindow()
TSharedPtr< FSceneViewport > SceneViewport
Definition: UnrealWindow.h:163
TSharedPtr< SViewport > sViewport
Definition: UnrealWindow.h:164
bool IsDrawing()
Definition: UnrealWindow.h:115
TSharedPtr< SOverlay > FullScreenOverlay
Definition: UnrealWindow.h:167
void RemoveUWidgetFromWindow(UWidget *WidgetToRemove)
UWidget * Widget
Definition: UnrealWindow.h:22