guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
overlay.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <chrono>
26#include <vector>
27
28#include "guillaume/ecs/system_filler.hpp"
29
30#include "guillaume/event/event_bus.hpp"
31#include "guillaume/event/event_manager.hpp"
32
33#include "guillaume/components/bound.hpp"
34#include "guillaume/components/overlay.hpp"
35#include "guillaume/components/transform.hpp"
36
37#include <utility/engine.hpp>
38#include <utility/event/keyboard_event.hpp>
39#include <utility/math/vector.hpp>
40
41namespace guillaume::systems
42{
43
78 class Overlay:
79 public ecs::SystemFiller<components::Overlay, components::Transform,
80 components::Bound>,
81 public event::EventManager<utility::event::KeyboardEvent>
82 {
83 private:
84 utility::Engine &_engine;
86 std::vector<ecs::Entity::Identifier>
87 _stack;
88 std::chrono::steady_clock::time_point
89 _lastTime;
91
92 public:
100 Overlay(event::EventBus &eventBus, utility::Engine &engine);
101
105 ~Overlay(void) override = default;
106
115 void prepare(void) override;
116
126 void update(const ecs::Entity::Identifier &entityIdentifier) override;
127
135 void show(const ecs::Entity::Identifier &entityIdentifier);
136
145 void dismiss(void);
146
154 void dismiss(const ecs::Entity::Identifier &entityIdentifier);
155
161 bool isOpen(const ecs::Entity::Identifier &entityIdentifier) const;
162
170
175 std::size_t getDepth(void) const;
176
181 void handleEscape(void);
182
193 void handleOutsideClick(const utility::math::Vector2F &point);
194
204 void advance(float deltaTime);
205 };
206
207} // namespace guillaume::systems
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
The base class to derive a system from: a System whose signature is the list of component types given...
Hands each engine event to the listeners subscribed to its type.
Definition event_bus.hpp:67
Base class that gives a system the input events of one type, one event per frame.
void handleOutsideClick(const utility::math::Vector2F &point)
Close the top overlay if a click landed outside it and its component says it dismisses on outside cli...
Definition overlay.cpp:163
std::size_t getDepth(void) const
The number of open overlays.
Definition overlay.cpp:145
void show(const ecs::Entity::Identifier &entityIdentifier)
Open an overlay at once: push it on top of the stack, make its component visible and turn viewport in...
Definition overlay.cpp:72
bool isOpen(const ecs::Entity::Identifier &entityIdentifier) const
Whether an overlay is open, that is, in the stack.
Definition overlay.cpp:134
void advance(float deltaTime)
Count down the top overlay and close it when its time is up.
Definition overlay.cpp:199
void handleEscape(void)
Close the top overlay if its component says it dismisses on Escape. Called by prepare() on an Escape ...
Definition overlay.cpp:150
void dismiss(void)
Close the top overlay.
Definition overlay.cpp:88
void update(const ecs::Entity::Identifier &entityIdentifier) override
Make the stack agree with the visibility of one overlay.
Definition overlay.cpp:56
Overlay(event::EventBus &eventBus, utility::Engine &engine)
Create the system, in the Event phase, and subscribe it to keyboard events (for Escape).
Definition overlay.cpp:29
~Overlay(void) override=default
Default destructor.
void prepare(void) override
Once per frame: take the next pending keyboard event, count down the top overlay, and handle Escape.
Definition overlay.cpp:39
ecs::Entity::Identifier getTop(void) const
The overlay opened last, the one Escape and the countdown apply to.
Definition overlay.cpp:140
Rules. Every class here runs each frame on the entities that have the components it declares.