26#include "guillaume/entities/image.hpp"
27#include "guillaume/entities/builder_base.hpp"
32 Image::Image::Builder::Builder(ecs::ComponentRegistry &componentRegistry,
33 ecs::EntityRegistry &entityRegistry)
42 entity->setTexturePath(_texturePath);
43 entity->setFallbackPath(_fallbackPath);
44 if (_width > 0.0f && _height > 0.0f) {
45 entity->setSize(_width, _height);
53 _fallbackPath.clear();
61 _fallbackPath = fallbackPath;
75 _texturePath = texturePath;
79 std::shared_ptr<Image>
81 const std::string &texturePath)
87 const std::string &texturePath)
115 if (width <= 0.0f || height <= 0.0f) {
116 throw std::invalid_argument(
"Image size must be positive");
127 if (width <= 0.0f || aspectRatio <= 0.0f) {
128 throw std::invalid_argument(
129 "Image width and aspect ratio must be positive");
131 return setSize(width, width / aspectRatio);
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Size of an entity: the width and height, in dp, of the rectangle that starts at the position of its c...
Bound & setHeight(float height) noexcept
Set the height.
A picture drawn in the entity's rectangle: the texture to show, a fallback texture,...
LoadState
Whether the texture could be loaded, as recorded by systems::ImageRender.
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.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
EntityFiller(ComponentRegistry &componentRegistry)
ComponentRegistry & getComponentRegistry(void)
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
Base of every widget Builder: turns a configuration into a widget that is attached to a parent and ow...
Configures Image widgets and registers them in the scene's entity registry.
Builder & withFallbackPath(const std::string &fallbackPath)
Set the texture drawn when the main one fails to load.
std::shared_ptr< Image > makeImage(std::shared_ptr< Entity > parent, const std::string &texturePath)
Build an image, register it under parent and reset the builder.
std::shared_ptr< Image > buildEntity(void) override
Build an image from the current configuration, without registering it or giving it a parent.
Builder & withTexturePath(const std::string &texturePath)
Choose the texture to draw.
Builder & withSize(float width, float height)
Set the displayed size.
void reset(void) override
Restore the defaults: empty texture path, no fallback texture, and no size (width and height 0).
A picture loaded from a texture file and stretched over a rectangle.
Image & setAccessibilityLabel(const std::string &label)
Describe the picture for assistive technologies.
Image & setSize(float width, float height)
Set the displayed size, written to components::Bound.
Image & setAspectRatio(float width, float aspectRatio)
Set the displayed size from a width and an aspect ratio.
Image & setTexturePath(const std::string &texturePath)
Change the texture to draw.
Image & setFallbackPath(const std::string &fallbackPath)
Set the texture drawn when the main one fails to load.
components::Image::LoadState getLoadState(void) const
Tell whether the texture could be loaded.
const std::string & getTexturePath(void) const
Get the path of the texture the image was asked to draw.
static std::shared_ptr< Image > create(Arguments &&...arguments)
Build an image without registering it in an entity registry.
State. Every class here is plain data attached to an entity.
@ Image
Image or icon with meaning.
The entity-component-system core, independent of any widget.
Widgets: the classes used to create entities with the right components and children.