Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
DemoCommon.hpp
Go to the documentation of this file.
1// Common helpers for Rmlui demo entry points.
2#pragma once
3
4#include "GLFW/glfw3.h"
5#include "Logger.hpp"
8#include "core/Core.hpp"
9#include "entity/Entity.hpp"
10#include "glm/ext/vector_float3.hpp"
14#include "resource/Window.hpp"
15
16#include <cstdint>
17#include <string>
18
20inline constexpr uint32_t kDefaultWindowWidth = 1280;
21inline constexpr uint32_t kDefaultWindowHeight = 720;
22
23inline void EscapeKeySystem(Engine::Core &core)
24{
25 auto &inputManager = core.GetResource<Input::Resource::InputManager>();
26 if (inputManager.IsKeyPressed(GLFW_KEY_ESCAPE))
27 {
28 core.Stop();
29 }
30}
31
32inline void ConfigureWindowAndCamera(Engine::Core &core, uint32_t width, uint32_t height)
33{
34 auto &window = core.GetResource<Window::Resource::Window>();
35 window.SetSize(static_cast<int>(width), static_cast<int>(height));
36
37 auto camera = core.CreateEntity();
38 constexpr float kDefaultCameraZ = -2.0F;
39 camera.AddComponent<Object::Component::Transform>(glm::vec3(0.0F, 0.0F, kDefaultCameraZ));
40 camera.AddComponent<Object::Component::Camera>();
41
42 auto &cameraManager = core.GetResource<CameraMovement::Resource::CameraManager>();
43 cameraManager.SetActiveCamera(camera);
44}
45
50
52{
53 rmluiContext.SetFont("examples/rmlui_usage/asset/LatoLatin-Regular.ttf");
54 rmluiContext.SetFont("examples/rmlui_usage/asset/LatoLatin-Bold.ttf");
55 rmluiContext.SetFont("examples/rmlui_usage/asset/LatoLatin-Italic.ttf");
56 rmluiContext.SetFont("examples/rmlui_usage/asset/LatoLatin-BoldItalic.ttf");
57 rmluiContext.SetFont("examples/rmlui_usage/asset/NotoEmoji-Regular.ttf");
58}
59
60inline void RegisterHoverClick(Rmlui::Resource::UIContext &rmluiContext, const char *demoName)
61{
62 if (auto *hoverLogo = rmluiContext.GetElementById("hover-logo"))
63 {
64 std::string message = std::string(demoName) + " demo hover clicked";
65 rmluiContext.RegisterEventListener(*hoverLogo, "click", [message](auto &) { Log::Info(message); });
66 }
67}
68
69inline void AttachHoverOverlay(Rmlui::Resource::UIContext &rmluiContext, const char *demoName)
70{
71 rmluiContext.LoadOverlayDocument("examples/rmlui_usage/asset/hover_esq.rml");
72 RegisterHoverClick(rmluiContext, demoName);
73}
74} // namespace RmluiUsage::Demo
CameraManager is a resource that manages the active camera entity.
Definition CameraManager.hpp:24
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
void Stop()
Stop the core execution. It will finish the current loop, call shutdown systems if any and stop.
Definition Core.cpp:64
TResource & GetResource()
Get a reference of a resource.
Definition Core.inl:14
Entity CreateEntity()
Create an entity in the context of the registry.
Definition Core.cpp:44
decltype(auto) AddComponent(TComponent &&component)
Add a component to an entity.
Definition Entity.hpp:55
Definition InputManager.hpp:18
Definition UIContext.hpp:21
bool RegisterEventListener(Rml::Element &element, const Rml::String &eventType, std::function< void(Rml::Event &)> callback, bool useCapture=false)
Definition UIContext.cpp:462
void SetFont(const std::string &fontPath) override
Definition UIContext.cpp:296
bool LoadOverlayDocument(const std::string &docPath)
Definition UIContext.cpp:357
Rml::Element * GetElementById(const std::string &elementId)
Definition UIContext.cpp:434
Definition Window.hpp:25
void SetSize(int width, int height)
Set the window size.
Definition Window.cpp:31
void Info(const T &msg) noexcept
Definition Logger.hpp:47
Definition DemoCommon.hpp:19
void EscapeKeySystem(Engine::Core &core)
Definition DemoCommon.hpp:23
void RegisterHoverClick(Rmlui::Resource::UIContext &rmluiContext, const char *demoName)
Definition DemoCommon.hpp:60
void ConfigureWindowAndCamera(Engine::Core &core, uint32_t width, uint32_t height)
Definition DemoCommon.hpp:32
void ConfigureDefaultWindowAndCamera(Engine::Core &core)
Definition DemoCommon.hpp:46
void LoadDefaultFonts(Rmlui::Resource::UIContext &rmluiContext)
Definition DemoCommon.hpp:51
constexpr uint32_t kDefaultWindowHeight
Definition DemoCommon.hpp:21
void AttachHoverOverlay(Rmlui::Resource::UIContext &rmluiContext, const char *demoName)
Definition DemoCommon.hpp:69
constexpr uint32_t kDefaultWindowWidth
Definition DemoCommon.hpp:20
Definition Camera.hpp:10
Definition Transform.hpp:18