23#include <utility/graphic/text/text.hpp>
24#include <utility/ressource_provider.hpp>
26#include "guillaume/systems/measure_glyph.hpp"
32 std::shared_ptr<utility::RessourceProvider> ressourceProvider,
33 utility::Engine &engine)
37 , _ressourceProvider(ressourceProvider)
40 "fonts/Material_Symbols_Outlined/"
41 "MaterialSymbolsOutlined-VariableFont_FILL,GRAD,opsz,wght.ttf")
43 "fonts/Material_Symbols_Outlined/"
44 "MaterialSymbolsOutlined[FILL,GRAD,opsz,wght].codepoints")
46 _codePoints = _ressourceProvider->loadCodePoints(_glyphCodePath);
48 getLogger().info() <<
"Loaded code points from " + _glyphCodePath;
51 <<
"Failed to load glyph code asset: " << _glyphCodePath;
54 _hasFont = _ressourceProvider->loadFont(_defaultFontPath) !=
nullptr;
57 <<
"Failed to load glyph font: " << _defaultFontPath
58 <<
". Icons will not be measured.";
77 <<
"Updating MeasureGlyph system for entity " << entityIdentifier;
91 const auto &glyphComponent =
93 auto &boundComponent =
95 auto &transformComponent =
97 auto &colorComponent =
101 glyphComponent.getFontSize(),
102 glyphComponent.getStyle(),
103 colorComponent.getColor() };
105 getLogger().debug() <<
"Measuring glyph '" << cacheKey.
glyphName
106 <<
"' for entity " << entityIdentifier;
107 getLogger().debug() <<
"Glyph code found for '" << cacheKey.
glyphName
108 <<
"': " << glyphComponent.getCode();
110 if (contains(cacheKey)) {
111 getLogger().debug() <<
"Glyph '" << cacheKey.
glyphName
112 <<
"' already measured, skipping.";
113 const auto &cacheValue = get(cacheKey);
114 if (cacheValue.has_value()) {
116 .setWidth(cacheValue->getWidth())
117 .setHeight(cacheValue->getHeight());
123 _codePoints ? _codePoints->getCode(cacheKey.
glyphName) : 0;
124 if (glyphCode == 0) {
128 utility::graphic::Text text(
129 _ressourceProvider, transformComponent.getPose(),
130 colorComponent.getColor(),
131 utility::graphic::CodePoints::toUtf8(glyphCode), cacheKey.
fontSize,
133 text.setColor(utility::graphic::Color32Bit());
135 auto textSize = _engine.measureText(text);
138 .setWidth(textSize.getWidth())
139 .setHeight(textSize.getHeight());
141 put(cacheKey, textSize);
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 prepare(void) override
Does nothing: the system needs no per-frame setup.
virtual void update(const ecs::Entity::Identifier &entityIdentifier) override
Write the size of one icon into its components::Bound, measuring it with the engine when it is not in...
~MeasureGlyph(void)
Destroy the system and its cache.
void cleanup(void) override
Does nothing: the cache is kept from one frame to the next.
MeasureGlyph(std::shared_ptr< utility::RessourceProvider > ressourceProvider, utility::Engine &engine)
Create the system in the Measure phase and load the icon font and its code point table.
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.
Key of the size cache of MeasureGlyph: everything a measured icon size is looked up by.
std::string glyphName
Name of the icon, such as "home".
float fontSize
Font size the icon was measured at.