Unravel Engine C++ Reference
Loading...
Searching...
No Matches
ui_system.h
Go to the documentation of this file.
1#pragma once
2
3#include "entt/entity/fwd.hpp"
4#include <engine/engine_export.h>
5#include <base/basetypes.hpp>
6#include <context/context.hpp>
7#include <ospp/event.h>
8#include <hpp/utility.hpp>
9#include <engine/ecs/scene.h>
10#include <math/math.h>
11#include <string>
12#include <vector>
13#include <entt/entt.hpp>
16
17// Forward declarations
18namespace Rml
19{
20 class Context;
21 class ElementDocument;
22 class Element;
23}
24
25namespace unravel
26{
27 class camera;
28 struct ui_document_component;
29
39{
40 static void on_create_component(entt::registry& r, entt::entity e);
41 static void on_load_component(entt::registry& r, entt::entity e);
42 static void on_destroy_component(entt::registry& r, entt::entity e);
43
49 auto init(rtti::context& ctx) -> bool;
50
56 auto deinit(rtti::context& ctx) -> bool;
57
61 void update_world_space(rtti::context& ctx, entt::handle camera_entity, scene& scn, bool& process_input);
62
66 void render_world_space(rtti::context& ctx, entt::handle camera_entity, scene& scn, delta_t dt);
67
71 void update_screen_space(rtti::context& ctx, entt::handle camera_entity, scene& scn, bool& process_input);
72
76 void render_screen_space(rtti::context& ctx, const gfx::frame_buffer::ptr& output, entt::handle camera_entity,
77 scene& scn, delta_t dt);
78
79
80
86 void on_os_event(rtti::context& ctx, os::event& event);
87
91 void load_fonts();
92
93 void release_resources();
94
100
101 auto is_debugger_enabled() const -> bool;
102 void set_debugger_enabled(bool enabled);
103
109 void update_ui_documents(rtti::context& ctx, scene& scn);
110
122 const camera& cam, float dp_ratio, bool process_input, bool& hit_found);
123
134 void update_screen_space_document(rtti::context& ctx, Rml::Context* context, int viewport_width,
135 int viewport_height, float dp_ratio, scene& scn, bool process_input, bool& hit_found);
136
137
138 void update_ui_document_common(entt::handle handle, ui_document_component& ui_comp, bool is_playing);
145 auto load_ui_document(entt::handle entity, ui_document_component& component, bool log_error = true) -> bool;
146
147
148
149 auto is_not_root_element(scene& scn, Rml::Element* element) -> bool;
150
151 // OS event input routing (implemented in ui_system_input.cpp)
153 {
154 Rml::Context* target_context = nullptr;
155 };
156
157 auto find_keyboard_context(scene& scn) const -> Rml::Context*;
158 auto try_consume_keyboard_event(scene& scn, os::event& event) -> bool;
160 void apply_mouse_press_focus(scene& scn, os::event& event, Rml::Context* target_context, bool input_allowed);
161
162 void blur_ui_context(Rml::Context* context) const;
163 void refresh_mouse_state(rtti::context& ctx, scene& scn);
164 auto process_mouse_move(scene& scn, Rml::Context* context, int x, int y) -> bool;
165 auto process_event(scene& scn, Rml::Context* context, os::event& event) -> bool;
166
167 void load_font(const std::string& path);
168
171 private:
172
174 Rml::Context* debug_context_ = nullptr;
175 Rml::Context* debug_target_context_ = nullptr;
176 std::shared_ptr<RmlUi_RenderLayerStack> debug_render_layer_stack_ = nullptr;
177
178
179 std::shared_ptr<int> sentinel_ = std::make_shared<int>();
180 std::set<std::string> fonts_loaded_;
181};
182
183} // namespace unravel
event_type event
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:62
float y
float x
std::chrono::duration< float > delta_t
entt::handle entity
Represents a scene in the ACE framework, managing entities and their relationships.
Definition scene.h:70
Component that holds a reference to a UI document for RmlUi rendering.
System responsible for managing user interface components and rendering.
Definition ui_system.h:39
void on_os_event(rtti::context &ctx, os::event &event)
Handle OS events and forward to RmlUi.
void update_world_space(rtti::context &ctx, entt::handle camera_entity, scene &scn, bool &process_input)
Update world-space UI documents (common + world-space specific). Call before render_world_space.
auto init(rtti::context &ctx) -> bool
Initializes the UI system with the given context.
Definition ui_system.cpp:68
auto try_consume_keyboard_event(scene &scn, os::event &event) -> bool
void render_screen_space(rtti::context &ctx, const gfx::frame_buffer::ptr &output, entt::handle camera_entity, scene &scn, delta_t dt)
Render screen-space overlay UI documents to output. Call after update_screen_space.
static void on_create_component(entt::registry &r, entt::entity e)
void update_screen_space(rtti::context &ctx, entt::handle camera_entity, scene &scn, bool &process_input)
Update screen-space UI documents (common + screen-space specific). Call before render_screen_space.
void apply_mouse_press_focus(scene &scn, os::event &event, Rml::Context *target_context, bool input_allowed)
static void on_load_component(entt::registry &r, entt::entity e)
void update_ui_document_common(entt::handle handle, ui_document_component &ui_comp, bool is_playing)
void update_ui_documents(rtti::context &ctx, scene &scn)
Update UI documents (load, reload, visibility). No camera dependency.
auto process_mouse_move(scene &scn, Rml::Context *context, int x, int y) -> bool
void set_debugger_enabled(bool enabled)
void render_world_space(rtti::context &ctx, entt::handle camera_entity, scene &scn, delta_t dt)
Render world-space UI documents (sort + frame-state render). Call after update_world_space.
auto find_keyboard_context(scene &scn) const -> Rml::Context *
void blur_ui_context(Rml::Context *context) const
auto dispatch_pointer_event(rtti::context &ctx, scene &scn, os::event &event) -> ui_pointer_dispatch_result
static void on_destroy_component(entt::registry &r, entt::entity e)
auto deinit(rtti::context &ctx) -> bool
Deinitializes the UI system with the given context.
auto is_debugger_enabled() const -> bool
void refresh_mouse_state(rtti::context &ctx, scene &scn)
void ensure_document_framebuffer(ui_document_component &comp)
Ensure framebuffer exists for document; create or resize if needed.
void register_component_callbacks(rtti::context &ctx)
Register component creation/destruction callbacks with ECS.
void update_screen_space_document(rtti::context &ctx, Rml::Context *context, int viewport_width, int viewport_height, float dp_ratio, scene &scn, bool process_input, bool &hit_found)
Update a single screen-space document (dimensions, density, input). Call from render path.
auto is_not_root_element(scene &scn, Rml::Element *element) -> bool
void load_fonts()
Load fonts.
void update_world_space_document(rtti::context &ctx, scene &scn, entt::handle handle, ui_document_component &comp, const camera &cam, float dp_ratio, bool process_input, bool &hit_found)
Update a single world-space document (dimensions, density, input). Call from render path,...
auto process_event(scene &scn, Rml::Context *context, os::event &event) -> bool
void load_font(const std::string &path)
auto load_ui_document(entt::handle entity, ui_document_component &component, bool log_error=true) -> bool
Load a UI document for a specific component.
gfx::uniform_handle handle
Definition uniform.cpp:9
bool enabled