guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
backdrop.cpp
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#include "guillaume/systems/backdrop.hpp"
24
25#include <cmath>
26#include <cstdint>
27
28#include "guillaume/systems/layout.hpp"
29#include "guillaume/theme.hpp"
30
31namespace guillaume::systems
32{
35 ecs::Phase::Layout)
36 {
37 }
38
39 void Backdrop::apply(ecs::ComponentRegistry &componentRegistry,
40 const ecs::Entity::Identifier &entityIdentifier)
41 {
42 const auto &state =
43 componentRegistry.getComponent<components::Backdrop>(
44 entityIdentifier);
45 const auto backdrop = getActiveColor(SchemeColorRole::Backdrop);
46 const float alpha = state.isVisible()
47 ? static_cast<float>(backdrop.getAlpha()) * state.getProgress()
48 : 0.0f;
49
50 componentRegistry.getComponent<components::Scrim>(entityIdentifier)
51 .setColor(backdrop.withAlpha(
52 static_cast<std::uint8_t>(std::lround(alpha))));
53 }
54
56 const ecs::Entity::Identifier &entityIdentifier,
57 bool visible)
58 {
59 auto &state = componentRegistry.getComponent<components::Backdrop>(
60 entityIdentifier);
61 if (state.isVisible() == visible) {
62 return;
63 }
64 state.setVisible(visible).setProgress(0.0f);
65
66 auto &animation = componentRegistry.getComponent<components::Animation>(
67 entityIdentifier);
68 if (visible) {
69 animation.setElapsed(0.0f).play();
70 } else {
71 animation.stop();
72 }
73 apply(componentRegistry, entityIdentifier);
74 }
75
77 const ecs::Entity::Identifier &entityIdentifier,
78 const utility::graphic::PoseF &ownerPose,
79 float ownerWidth, float ownerHeight)
80 {
81 const auto &orientation = ownerPose.getOrientation();
82 utility::graphic::PositionF position = ownerPose.getPosition();
83 position.translate(utility::graphic::PositionF(
84 -(orientation.getRight() * ((Extent - ownerWidth) / 2.0f))
85 - (orientation.getUp() * ((Extent - ownerHeight) / 2.0f))
86 + orientation.getForward() * (Layout::LayerDepthStep * 0.5f)));
87
88 componentRegistry.getComponent<components::Transform>(entityIdentifier)
89 .setPose(utility::graphic::PoseF(position, orientation));
90 }
91
92 void Backdrop::update(const ecs::Entity::Identifier &entityIdentifier)
93 {
94 if (!requireComponent<components::Backdrop>(entityIdentifier)
95 || !requireComponent<components::Scrim>(entityIdentifier)) {
96 return;
97 }
98
99 apply(getComponentRegistry(), entityIdentifier);
100 }
101} // namespace guillaume::systems
A timer that runs from 0 to a duration and reports its eased progress, from 0 to 1,...
Definition animation.hpp:61
State of a modal backdrop, the dimming layer behind a dialog or a drawer: whether it is shown and how...
Definition backdrop.hpp:52
Backdrop & setProgress(float progress)
Set the fade-in progress. Called by the entity's fade animation on every sample.
Definition backdrop.cpp:47
Backdrop & setVisible(bool visible)
Store whether the backdrop is shown.
Definition backdrop.cpp:32
A translucent veil drawn over the whole bound of its entity, to dim what is behind a modal surface.
Definition scrim.hpp:44
Where an entity is in space: its pose (position and orientation) and its scale.
Definition transform.hpp:64
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
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
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
Definition system.cpp:53
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...
static void follow(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, const utility::graphic::PoseF &ownerPose, float ownerWidth, float ownerHeight)
Center a backdrop on its owner and place it half a layer behind it.
Definition backdrop.cpp:76
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Write the Scrim color that matches the current state of a backdrop.
Definition backdrop.cpp:39
static void setVisible(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool visible)
Show or hide a backdrop.
Definition backdrop.cpp:55
Backdrop(void)
Create the system in the Layout phase.
Definition backdrop.cpp:33
static constexpr float Extent
Definition backdrop.hpp:74
void update(const ecs::Entity::Identifier &entityIdentifier) override
Write the Scrim color of one backdrop for this frame, so a theme change is picked up without any call...
Definition backdrop.cpp:92
Arranges the children of a container in a row or a column and sizes the container around them.
Definition layout.hpp:84
static constexpr float LayerDepthStep
Depth of one layer: the distance a child is moved towards the viewer, against the forward axis of its...
Definition layout.hpp:91
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Definition component.hpp:28
Rules. Every class here runs each frame on the entities that have the components it declares.
@ Backdrop
Modal backdrop behind dialogs and drawers.
Definition theme.hpp:110
utility::graphic::Color32Bit getActiveColor(SchemeColorRole role)
Get the color the active scheme gives to a role.