guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
surface_tone.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#include "guillaume/systems/surface_tone.hpp"
23
24#include "guillaume/theme.hpp"
25
26namespace guillaume::systems
27{
30 components::Elevation>(ecs::Phase::Measure)
31 {
32 }
33
35 const ecs::Entity::Identifier &entityIdentifier)
36 {
37 const auto &tone =
38 componentRegistry.getComponent<components::SurfaceTone>(
39 entityIdentifier);
40 const auto shadowLevel = tone.hasShadow()
41 ? tone.getElevation()
43
44 componentRegistry.getComponent<components::Color>(entityIdentifier)
45 .setColor(getElevatedSurfaceColor(tone.getElevation()));
46
47 componentRegistry.getComponent<components::Elevation>(entityIdentifier)
48 .setElevationLevel(shadowLevel);
49 }
50
51 void SurfaceTone::update(const ecs::Entity::Identifier &entityIdentifier)
52 {
54 || !requireComponent<components::Color>(entityIdentifier)
55 || !requireComponent<components::Elevation>(entityIdentifier)) {
56 return;
57 }
58
59 apply(getComponentRegistry(), entityIdentifier);
60 }
61} // namespace guillaume::systems
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Definition color.hpp:58
Soft shadow drawn around an elevated surface.
Definition elevation.hpp:63
State of a tonal surface: how high it sits above the background, and whether it casts a shadow.
bool hasShadow(void) const noexcept
Tell whether the surface casts a shadow.
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 apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Write the color and the shadow of one surface from its components::SurfaceTone.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Write the color and the shadow of one surface for this frame.
SurfaceTone(void)
Create the system in the Measure phase.
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.
@ Level0
Flat: no shadow, no tint.
Definition tokens.hpp:131
utility::graphic::Color32Bit getElevatedSurfaceColor(theme::ElevationLevel level)
Get the background color of a surface raised to an elevation level.