LkEngine 0.1.2
 
Loading...
Searching...
No Matches
Viewport.h
Go to the documentation of this file.
1
5#pragma once
6
8#include "LkEngine/Core/LObject/ObjectPtr.h"
9
10#include "LkEngine/Core/Delegate/Delegate.h"
12
13namespace LkEngine {
14
20 class LViewport : public LObject
21 {
22 LK_DECLARE_MULTICAST_DELEGATE(FOnViewportSizeUpdated, const uint16_t, const uint16_t);
23 public:
24 LViewport();
25 ~LViewport() = default;
26
32 void Update();
33
37 FORCEINLINE LVector2 GetSize() const { return Size; }
38
42 FORCEINLINE LVector2 GetPosition() const { return Position; }
43
47 FORCEINLINE LVector2 GetScalers() const { return Scalers; }
48
49 FORCEINLINE void SetSize(const LVector2& NewSize)
50 {
51 if (Size != NewSize)
52 {
53 Size = NewSize;
54 bDirty = true;
55 }
56 }
57
58 FORCEINLINE void SetSize(const float InX, const float InY)
59 {
60 if ((Size.X != InX) || (Size.Y != InY))
61 {
62 Size.X = InX;
63 Size.Y = InY;
64 bDirty = true;
65 }
66 }
67
68 template<typename T>
69 FORCEINLINE void SetSizeX(const T InX)
70 {
71 static_assert(std::is_floating_point_v<T>, "Invalid type, cannot set size");
72 if (Size.X != InX)
73 {
74 Size.X = InX;
75 bDirty = true;
76 }
77 }
78
79 template<typename T>
80 FORCEINLINE void SetSizeY(const T InY)
81 {
82 static_assert(std::is_floating_point_v<T>, "Invalid type, cannot set size");
83 if (Size.Y != InY)
84 {
85 Size.Y = InY;
86 bDirty = true;
87 }
88 }
89
93 FORCEINLINE void SetPosition(const LVector2& NewPosition)
94 {
95 if (Position != NewPosition)
96 {
97 Position = NewPosition;
98 }
99 }
100
104 FORCEINLINE void SetPositionX(const float NewPosX)
105 {
106 Position.X = NewPosX;
107 bDirty = true;
108 }
109
113 FORCEINLINE void SetPositionY(const float NewPosY)
114 {
115 Position.Y = NewPosY;
116 bDirty = true;
117 }
118
122 FORCEINLINE void SetViewportBounds(const uint8_t Index, const LVector2& Bounds)
123 {
124 LK_CORE_ASSERT((Index >= 0) && (Index <= 1), "Invalid viewport index: {}", Index);
125 if (PrimaryViewportBounds[Index] != Bounds)
126 {
127 PrimaryViewportBounds[Index] = Bounds;
128 //LK_CORE_TRACE_TAG("Viewport", "Set viewport bounds {} to {}", Index, Bounds.ToString());
129 bDirty = true;
130 }
131 }
132
136 FORCEINLINE void SetViewportBoundsX(const uint8_t Index, const float Bound)
137 {
138 LK_CORE_ASSERT((Index >= 0) && (Index <= 1), "Invalid viewport index: {}", Index);
139 if (PrimaryViewportBounds[Index].X != Bound)
140 {
141 PrimaryViewportBounds[Index].X = Bound;
142 //LK_CORE_TRACE_TAG("Viewport", "Set viewport bounds {} on the X-axis to {}", Index, Bound);
143 bDirty = true;
144 }
145 }
146
150 FORCEINLINE void SetViewportBoundsY(const uint8_t Index, const float Bound)
151 {
152 LK_CORE_ASSERT((Index >= 0) && (Index <= 1), "Invalid viewport index: {}", Index);
153 if (PrimaryViewportBounds[Index].Y != Bound)
154 {
155 PrimaryViewportBounds[Index].Y = Bound;
156 //LK_CORE_TRACE_TAG("Viewport", "Set viewport bounds {} on the Y-axis to {}", Index, Bound);
157 bDirty = true;
158 }
159 }
160
164 FORCEINLINE const LVector2* GetViewportBounds() const
165 {
166 return PrimaryViewportBounds.data();
167 }
168
169 FORCEINLINE LVector2& GetViewportBounds(const uint8_t Index)
170 {
171 LK_VERIFY((Index >= 0) && (Index <= 1), "Invalid viewport index");
172 return PrimaryViewportBounds[Index];
173 }
174
175 FORCEINLINE const LVector2& GetViewportBounds(const uint8_t Index) const
176 {
177 LK_VERIFY((Index >= 0) && (Index <= 1), "Invalid viewport index");
178 return PrimaryViewportBounds[Index];
179 }
180
181 FORCEINLINE void SetScalers(const LVector2& NewScalers)
182 {
183 if (!NewScalers.IsNull() && (Scalers != NewScalers))
184 {
185 Scalers = NewScalers;
186 }
187 }
188
192 FORCEINLINE void SetDirty(const bool Dirty)
193 {
194 bDirty = Dirty;
195 }
196
197 static void SetViewport(const int PosX, const int PosY, const int Width, const int Height);
198
199 public:
200 FOnViewportSizeUpdated OnSizeUpdated;
201 private:
202 TVector2<uint16_t> Size = { 0.0f, 0.0f };
203 TVector2<uint16_t> Position = { 0.0f, 0.0f };
204 TVector2<float> Scalers = { 1.0f, 1.0f };
205
206 std::array<LVector2, 2> PrimaryViewportBounds = {
207 LVector2(0.0f, 0.0f),
208 LVector2(0.0f, 0.0f)
209 };
210
211 bool bDirty = true;
212
213 LCLASS(LViewport);
214 };
215
216}
Mathematics used by the engine.
LObject implementation.
Definition Object.h:46
Definition Viewport.h:21
FORCEINLINE const LVector2 * GetViewportBounds() const
Return viewport bounds array.
Definition Viewport.h:164
void Update()
Update the viewport.
Definition Viewport.cpp:16
FORCEINLINE LVector2 GetScalers() const
Get the viewport scalers.
Definition Viewport.h:47
FORCEINLINE LVector2 GetSize() const
Get viewport size.
Definition Viewport.h:37
FORCEINLINE void SetViewportBoundsX(const uint8_t Index, const float Bound)
Set viewport bounds on the X axis for top-left or bottom-right bound.
Definition Viewport.h:136
FORCEINLINE void SetPositionY(const float NewPosY)
Sey position in the Y-axis.
Definition Viewport.h:113
FORCEINLINE void SetViewportBounds(const uint8_t Index, const LVector2 &Bounds)
Definition Viewport.h:122
FORCEINLINE void SetPosition(const LVector2 &NewPosition)
Set viewport position.
Definition Viewport.h:93
FORCEINLINE void SetViewportBoundsY(const uint8_t Index, const float Bound)
Set viewport bounds on the Y axis for top-left or bottom-right bound.
Definition Viewport.h:150
FORCEINLINE void SetDirty(const bool Dirty)
Set the viewport as dirty.
Definition Viewport.h:192
FORCEINLINE LVector2 GetPosition() const
Get viewport position.
Definition Viewport.h:42
FORCEINLINE void SetPositionX(const float NewPosX)
Sey position in the X-axis.
Definition Viewport.h:104
#define LCLASS(Class)
Definition CoreMacros.h:226
TVector2< float > LVector2
Definition Vector.h:48
Definition Asset.h:11