Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
UIContext.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <RmlUi/Core.h>
4#include <RmlUi/Core/EventListener.h>
5
6#include <functional>
7#include <memory>
8#include <optional>
9#include <string>
10#include <unordered_map>
11#include <vector>
12
13#include "AUIContext.hpp"
14#include "FunctionID.hpp"
15#include "RmlUi/Config/Config.h"
16#include "RmlUi/Core/Context.h"
17#include "RmlUi/Core/ElementDocument.h"
18#include "core/Core.hpp"
19
20namespace Rmlui::Resource {
21class UIContext : public AUIContext {
22 public:
24 std::optional<FunctionUtils::FunctionID> keyCallbackId;
25 std::optional<FunctionUtils::FunctionID> charCallbackId;
26 std::optional<FunctionUtils::FunctionID> mouseButtonCallbackId;
27 std::optional<FunctionUtils::FunctionID> cursorPosCallbackId;
28 std::optional<FunctionUtils::FunctionID> scrollCallbackId;
29 };
30
31 UIContext() = default;
32 ~UIContext() override = default;
33
34 UIContext(const UIContext &) = delete;
35 UIContext &operator=(const UIContext &) = delete;
36 UIContext(UIContext &&) noexcept = default;
37 UIContext &operator=(UIContext &&) noexcept = default;
38
39 void Update(Engine::Core &core) override;
40 void Render(Engine::Core &core) override;
41 void Destroy(Engine::Core &core) override;
42 void UpdateMouseMoveEvent(Engine::Core &core) override;
43
44 void SetFont(const std::string &fontPath) override;
45 void LoadDocument(const std::string &docPath) override;
46 bool LoadOverlayDocument(const std::string &docPath);
47 bool UnloadOverlayDocument(const std::string &docPath);
48 const std::string &GetTitle() const override;
49 Rml::ElementDocument *GetDocument();
50 Rml::ElementDocument *GetOverlayDocument(const std::string &docPath);
51 const Rml::ElementDocument *GetDocument() const;
52 const Rml::ElementDocument *GetOverlayDocument(const std::string &docPath) const;
53 void EnableDebugger(bool enable);
54 Rml::Element *GetElementById(const std::string &elementId);
55 bool RegisterEventListener(Rml::Element &element, const Rml::String &eventType,
56 std::function<void(Rml::Event &)> callback, bool useCapture = false);
57 bool UnregisterEventListener(Rml::Element &element, const Rml::String &eventType);
58 void RequestLateUpdate();
60 bool AreInputCallbacksRegistered() const;
61 void SetInputCallbacksRegistered(bool registered);
62
63 bool ProcessKey(int key, int action, int mods) override;
64 bool ProcessText(unsigned int codepoint) override;
65 bool ProcessMouseMove(double x, double y, int mods) override;
66 bool ProcessMouseButton(int button, int action, int mods) override;
67 bool ProcessMouseWheel(double xoffset, double yoffset, int mods) override;
68
69 protected:
70 void _setup(Engine::Core &core) override;
71
72 private:
74 Rml::Element *element = nullptr;
75 Rml::String eventType;
76 bool useCapture = false;
77 std::unique_ptr<Rml::EventListener> listener;
78 };
79
80 Rml::Context *_context = nullptr;
81 Rml::ElementDocument *_document = nullptr;
82 std::unordered_map<std::string, Rml::ElementDocument *> _overlayDocuments;
83 std::string _titleCache;
85 std::vector<EventListenerEntry> _eventListeners;
89
90 bool _isReady() const;
91};
92} // namespace Rmlui::Resource
void Update(Engine::Core &core) override
Definition UIContext.cpp:239
Rml::ElementDocument * GetDocument()
Definition UIContext.cpp:402
void _setup(Engine::Core &core) override
Definition UIContext.cpp:168
UIContext(const UIContext &)=delete
bool ProcessText(unsigned int codepoint) override
Definition UIContext.cpp:520
bool AreInputCallbacksRegistered() const
Definition UIContext.cpp:495
UIContext(UIContext &&) noexcept=default
Rml::ElementDocument * _document
Definition UIContext.hpp:81
bool ProcessMouseMove(double x, double y, int mods) override
Definition UIContext.cpp:529
bool ProcessKey(int key, int action, int mods) override
Definition UIContext.cpp:499
void UpdateMouseMoveEvent(Engine::Core &core) override
Definition UIContext.cpp:275
void LoadDocument(const std::string &docPath) override
Definition UIContext.cpp:311
void SetInputCallbackIds(const InputCallbackIds &ids)
Definition UIContext.cpp:493
bool _lateUpdateRequested
Definition UIContext.hpp:88
bool _inputCallbacksRegistered
Definition UIContext.hpp:87
std::vector< EventListenerEntry > _eventListeners
Definition UIContext.hpp:85
UIContext & operator=(const UIContext &)=delete
std::unordered_map< std::string, Rml::ElementDocument * > _overlayDocuments
Definition UIContext.hpp:82
bool RegisterEventListener(Rml::Element &element, const Rml::String &eventType, std::function< void(Rml::Event &)> callback, bool useCapture=false)
Definition UIContext.cpp:462
bool UnregisterEventListener(Rml::Element &element, const Rml::String &eventType)
Definition UIContext.cpp:476
void Destroy(Engine::Core &core) override
Definition UIContext.cpp:185
void EnableDebugger(bool enable)
Definition UIContext.cpp:416
bool _debuggerInitialized
Definition UIContext.hpp:84
const std::string & GetTitle() const override
Definition UIContext.cpp:400
void SetInputCallbacksRegistered(bool registered)
Definition UIContext.cpp:497
void RequestLateUpdate()
Definition UIContext.cpp:491
~UIContext() override=default
void Render(Engine::Core &core) override
Definition UIContext.cpp:251
bool ProcessMouseWheel(double xoffset, double yoffset, int mods) override
Definition UIContext.cpp:559
void SetFont(const std::string &fontPath) override
Definition UIContext.cpp:296
std::string _titleCache
Definition UIContext.hpp:83
bool LoadOverlayDocument(const std::string &docPath)
Definition UIContext.cpp:357
Rml::Element * GetElementById(const std::string &elementId)
Definition UIContext.cpp:434
Rml::ElementDocument * GetOverlayDocument(const std::string &docPath)
Definition UIContext.cpp:406
bool ProcessMouseButton(int button, int action, int mods) override
Definition UIContext.cpp:538
InputCallbackIds _inputCallbackIds
Definition UIContext.hpp:86
bool UnloadOverlayDocument(const std::string &docPath)
Definition UIContext.cpp:383
Rml::Context * _context
Definition UIContext.hpp:80
bool _isReady() const
Definition UIContext.cpp:290
Definition Core.hpp:17
Definition PluginEvent.hpp:5
Definition AUIContext.hpp:20
bool useCapture
Definition UIContext.hpp:76
Rml::Element * element
Definition UIContext.hpp:74
Rml::String eventType
Definition UIContext.hpp:75
std::unique_ptr< Rml::EventListener > listener
Definition UIContext.hpp:77
std::optional< FunctionUtils::FunctionID > scrollCallbackId
Definition UIContext.hpp:28
std::optional< FunctionUtils::FunctionID > cursorPosCallbackId
Definition UIContext.hpp:27
std::optional< FunctionUtils::FunctionID > charCallbackId
Definition UIContext.hpp:25
std::optional< FunctionUtils::FunctionID > mouseButtonCallbackId
Definition UIContext.hpp:26
std::optional< FunctionUtils::FunctionID > keyCallbackId
Definition UIContext.hpp:24