23#include "guillaume/systems/overlay.hpp"
35 , _lastTime(std::chrono::steady_clock::now())
43 const auto now = std::chrono::steady_clock::now();
44 const std::chrono::duration<float> elapsed = now - _lastTime;
49 if (key && key->getIsDownEvent()
51 == utility::event::KeyboardEvent::ScanCode::Escape) {
64 if (overlay.isVisible() && !
isOpen(entityIdentifier)) {
65 _stack.push_back(entityIdentifier);
66 _engine.setShouldCaptureViewportInput(
false);
67 }
else if (!overlay.isVisible() &&
isOpen(entityIdentifier)) {
74 if (
isOpen(entityIdentifier)) {
78 _stack.push_back(entityIdentifier);
85 _engine.setShouldCaptureViewportInput(
false);
94 const auto top = _stack.back();
99 overlay.setVisible(
false);
100 overlay.setElapsed(0.0f);
101 if (
const auto handler = overlay.getOnDismissHandler()) {
106 if (_stack.empty()) {
107 _engine.setShouldCaptureViewportInput(
true);
113 const auto iterator =
114 std::find(_stack.begin(), _stack.end(), entityIdentifier);
115 if (iterator == _stack.end()) {
118 _stack.erase(iterator);
122 overlay.setVisible(
false);
123 overlay.setElapsed(0.0f);
124 if (
const auto handler = overlay.getOnDismissHandler()) {
129 if (_stack.empty()) {
130 _engine.setShouldCaptureViewportInput(
true);
136 return std::find(_stack.begin(), _stack.end(), entityIdentifier)
147 return _stack.size();
152 if (_stack.empty()) {
156 const auto top = _stack.back();
165 if (_stack.empty()) {
169 const auto top = _stack.back();
177 if (!overlay.dismissesOnOutsideClick()) {
184 const float x = pose.getPosition().getX();
185 const float y = pose.getPosition().getY();
186 const float width = bound.getWidth();
187 const float height = bound.getHeight();
191 const bool inside = point.x >= x && point.x <= x + width && point.y <= y
192 && point.y >= y - height;
201 if (_stack.empty()) {
205 const auto top = _stack.back();
211 if (!overlay.hasAutoDismiss()) {
215 overlay.setElapsed(overlay.getElapsed() + deltaTime);
216 if (overlay.getElapsed() >= overlay.getAutoDismiss()) {
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
SystemFiller(Phase phase)
bool hasComponent(const ecs::Entity::Identifier &entityIdentifier) const
Tell whether an entity has a component, in the bound registry.
ComponentType & getComponent(const ecs::Entity::Identifier &entityIdentifier)
Get a component of an entity from the bound registry, to read or modify it.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
Hands each engine event to the listeners subscribed to its type.
void consumeNextEvent(void)
EventManager(EventBus &eventBus)
std::shared_ptr< EventType > getLastEvent(void)
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...
std::size_t getDepth(void) const
The number of open overlays.
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...
bool isOpen(const ecs::Entity::Identifier &entityIdentifier) const
Whether an overlay is open, that is, in the stack.
void advance(float deltaTime)
Count down the top overlay and close it when its time is up.
void handleEscape(void)
Close the top overlay if its component says it dismisses on Escape. Called by prepare() on an Escape ...
void dismiss(void)
Close the top overlay.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Make the stack agree with the visibility of one overlay.
Overlay(event::EventBus &eventBus, utility::Engine &engine)
Create the system, in the Event phase, and subscribe it to keyboard events (for Escape).
void prepare(void) override
Once per frame: take the next pending keyboard event, count down the top overlay, and handle Escape.
ecs::Entity::Identifier getTop(void) const
The overlay opened last, the one Escape and the countdown apply to.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Delivery of engine events to the systems that subscribed to them.
Rules. Every class here runs each frame on the entities that have the components it declares.