guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
image.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/components/image.hpp"
24
26{
27 Image &Image::setTexturePath(const std::string &path)
28 {
29 if (_texturePath == path) {
30 return *this;
31 }
32 _texturePath = path;
33 _loadState = LoadState::Pending;
34 _usingFallback = false;
35 setHasChanged(true);
36 return *this;
37 }
38
39 Image &Image::setFallbackPath(const std::string &path)
40 {
41 if (_fallbackPath == path) {
42 return *this;
43 }
44 _fallbackPath = path;
45 if (_loadState == LoadState::Failed) {
46 _loadState = LoadState::Pending;
47 }
48 setHasChanged(true);
49 return *this;
50 }
51
52 const std::string &Image::getFallbackPath(void) const
53 {
54 return _fallbackPath;
55 }
56
58 {
59 return _loadState;
60 }
61
62 Image &Image::setLoadState(LoadState state, bool usingFallback)
63 {
64 // Bookkeeping only: the render system records the outcome without
65 // flagging a change, which would re-run entity updates every frame.
66 _loadState = state;
67 _usingFallback = usingFallback;
68 return *this;
69 }
70
71 bool Image::isUsingFallback(void) const
72 {
73 return _usingFallback;
74 }
75
76 const std::string &Image::getTexturePath(void) const
77 {
78 return _texturePath;
79 }
80} // namespace guillaume::components
Image(void)=default
Default constructor for the Image component.
Image & setTexturePath(const std::string &path)
Choose the texture to draw.
Definition image.cpp:27
LoadState
Whether the texture could be loaded, as recorded by systems::ImageRender.
Definition image.hpp:62
@ Pending
Not attempted since the path was set.
Definition image.hpp:63
@ Failed
Neither loaded; nothing is drawn.
Definition image.hpp:65
Image & setLoadState(LoadState state, bool usingFallback=false)
Record the outcome of a load attempt. Called by systems::ImageRender.
Definition image.cpp:62
Image & setFallbackPath(const std::string &path)
Set the texture drawn when the main texture fails to load.
Definition image.cpp:39
LoadState getLoadState(void) const
Get the outcome of the last load attempt.
Definition image.cpp:57
const std::string & getTexturePath(void) const
Get the path of the texture to draw.
Definition image.cpp:76
bool isUsingFallback(void) const
Check whether the fallback texture is drawn.
Definition image.cpp:71
const std::string & getFallbackPath(void) const
Get the path of the fallback texture.
Definition image.cpp:52
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.