vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
ui_system.h
1#pragma once
2
3#include <string_view>
4#include <vector>
5
6#include <glm/glm.hpp>
7
8#include "core/system.h"
9#include "ecs/entity.h"
10#include "ecs/component/ui/ui_element.h"
11#include "ecs/component/ui/ui_shape.h"
12#include "system/ui/ui_draw_data.h"
13
14namespace Vkm::Engine {
15
24class UISystem : public System {
25 public:
26 UISystem() = default;
27 ~UISystem() override = default;
28
29 UISystem(const UISystem& other) = delete;
30 UISystem& operator=(const UISystem& other) = delete;
31
32 UISystem(UISystem && other) = delete;
33 UISystem& operator=(UISystem && other) = delete;
34
35 public:
36 void update(FrameContext& ctx) override;
37
38 private:
42 struct CanvasRef {
43 int32_t sortOrder;
44 EntityId entity;
45 };
46
50 struct ButtonHit {
51 EntityId entity;
52 uint32_t firstVertex;
53 };
54
58 struct ScrollTarget {
59 EntityId entity;
60 size_t blockersBefore;
61 };
62
63 private:
79 glm::vec2 resolveElement(
80 FrameContext& ctx,
81 EntityId entity,
82 const UIRect& parentRect,
83 const UIRect& clip,
84 float scale,
85 uint32_t depth
86 );
87
100 void appendCommand(
101 uint32_t first,
102 uint32_t count,
103 FontHandle font,
104 TextureHandle image,
105 const UIRect& clip
106 );
107
118 bool emitImage(
119 FrameContext& ctx,
120 EntityId entity,
121 const UIElement& element,
122 const UIRect& clip,
123 float canvasScale
124 );
125
136 bool emitButton(
137 FrameContext& ctx,
138 EntityId entity,
139 const UIElement& element,
140 const UIRect& clip,
141 float canvasScale
142 );
143
155 glm::vec2 emitText(
156 FrameContext& ctx,
157 EntityId entity,
158 const UIElement& element,
159 const UIRect& clip,
160 float canvasScale
161 );
162
175 void breakLines(std::string_view text, const FontAsset& font, float scale, float maxWidth, bool wrap);
176
185 void resolveInteraction(FrameContext& ctx);
186
201 void appendQuad(
202 const glm::vec2& p0,
203 const glm::vec2& p1,
204 const glm::vec2& uv0,
205 const glm::vec2& uv1,
206 const glm::vec4& color,
207 const glm::vec4& bottom,
208 const glm::vec2& shape,
209 const glm::vec4& border,
210 bool image
211 );
212
222 void recolourQuad(uint32_t first, const glm::vec4& top, const glm::vec4& bottom);
223
233 void appendShaped(
234 const UIRect& rect,
235 const glm::vec4& color,
236 const UIShape& shape,
237 float scale,
238 bool image
239 );
240
241 private:
242 UIDrawData m_drawData;
243
244 std::vector<CanvasRef> m_canvases;
246 std::vector<ButtonHit> m_buttonHits;
247
253 std::vector<ScrollTarget> m_scrollTargets;
254
256 std::vector<std::string_view> m_lines;
257
259 std::vector<EntityId> m_pointerBlockers;
260
261 EntityId m_pressedButton{};
262 glm::vec2 m_pointer{0.0f};
263 float m_wheel = 0.0f;
264 bool m_mouseDown = false;
265 bool m_mouseDownEdge = false;
266 bool m_mouseUpEdge = false;
267 bool m_cursorFree = false;
268 bool m_pointerIsOurs = false;
269};
270
271} // namespace Vkm::Engine
void update(FrameContext &ctx) override
Execute this system for the current frame.
Names one entity of one Scene, for as long as that slot holds it.
Definition entity.h:23
Per-frame state bundle passed to every system.
Definition system.h:55