25#include "guillaume/systems/glyph_render.hpp"
28#include "guillaume/text_renderable.hpp"
33 std::shared_ptr<utility::RessourceProvider> ressourceProvider,
34 utility::Engine &engine)
38 , _ressourceProvider(ressourceProvider)
41 "fonts/Material_Symbols_Outlined/"
42 "MaterialSymbolsOutlined-VariableFont_FILL,GRAD,opsz,wght.ttf")
44 "fonts/Material_Symbols_Outlined/"
45 "MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].codepoints")
47 _codePoints = _ressourceProvider->loadCodePoints(_glyphCodePath);
49 getLogger().info() <<
"Loaded code points from " + _glyphCodePath;
52 <<
"Failed to load glyph code asset: " << _glyphCodePath;
55 _hasFont = _ressourceProvider->loadFont(_defaultFontPath) !=
nullptr;
58 <<
"Failed to load glyph font: " << _defaultFontPath
59 <<
". Icons will not be rendered.";
81 <<
"Updating GlyphRender system for entity " << entityIdentifier;
95 const auto &transformComponent =
97 const auto &glyphComponent =
99 const auto &colorComponent =
108 getLogger().debug() <<
"Rendering glyph '" << glyphComponent.getName()
109 <<
"' for entity " << entityIdentifier;
114 _codePoints ? _codePoints->getCode(glyphComponent.getName()) : 0;
116 if (glyphCode == 0) {
122 auto renderable = std::make_shared<TextRenderable>(
123 _ressourceProvider, transformComponent.getPose(),
124 colorComponent.getColor(),
125 utility::graphic::CodePoints::toUtf8(glyphCode),
126 glyphComponent.getFontSize(), _defaultFontPath);
129 if (handle ==
nullptr) {
130 size_t objectId = _engine.createObject(renderable);
134 if (!_engine.updateObject(renderable, handle->
objectId)) {
135 handle->
objectId = _engine.createObject(renderable);
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
SystemFiller(Phase phase)
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...
void cleanup(void) override
Remove the engine objects of the entities that were not drawn this frame. Called once per frame after...
~GlyphRender(void)
Forget the engine objects without removing them from the engine.
GlyphRender(std::shared_ptr< utility::RessourceProvider > ressourceProvider, utility::Engine &engine)
Create the system in the Render phase and load the icon font and its code point table.
void prepare(void) override
Mark every icon as not drawn yet. Called once per frame before the entities are visited.
virtual void update(const ecs::Entity::Identifier &entityIdentifier) override
Build the renderable of one icon from its current components and upload it, creating the engine objec...
void insert(const ecs::Entity::Identifier &identifier, RenderHandle handle)
Store the handle of an entity, replacing the one it had.
void markAllUnused(void)
Clear the used flag of every handle. Call it from the system's prepare(), before any entity is drawn.
void clear(void)
Forget every handle without calling utility::Engine::removeObject. Use it only when the engine object...
void removeUnused(utility::Engine &engine)
Remove from the engine, then from the map, every handle whose used flag is still false....
RenderHandle * find(const ecs::Entity::Identifier &identifier)
Look up the handle of an entity.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Rules. Every class here runs each frame on the entities that have the components it declares.
Mesh builders shared by the shape render systems.
bool isInvisible(const utility::graphic::Color32Bit &color)
Whether a color draws nothing.
What a render system remembers about the engine object it created for one entity.
bool used
Whether the entity was drawn this frame.
std::shared_ptr< utility::graphic::Renderable > renderable
Renderable uploaded last for this object.
size_t objectId
Identifier given by the engine.