14#include <egt/detail/meta.h>
15#include <egt/geometry.h>
16#include <egt/painter.h>
17#include <egt/serialize.h>
18#include <egt/surface.h>
54 Image(
const std::string& uri = {},
float scale = 1.0,
bool is_cached =
false);
64 Image(
const std::string& uri,
float hscale,
float vscale,
bool is_cached =
false);
72 Image(
const unsigned char* data,
size_t len);
83 void load(
const std::string& uri,
float hscale = 1.0,
float vscale = 1.0,
bool approx =
false,
bool is_cached =
false);
95 Image(std::shared_ptr<Surface> surface);
113 void scale(
float hscale,
float vscale,
bool approximate =
false,
bool is_cached =
false);
120 inline void scale(
float scale,
bool approximate =
false,
bool is_cached =
false)
122 this->scale(scale, scale, approximate, is_cached);
132 if (!m_orig_size.empty() && this->size() != size)
134 float hs =
static_cast<float>(size.width()) /
static_cast<float>(m_orig_size.width());
135 float vs =
static_cast<float>(size.height()) /
static_cast<float>(m_orig_size.height());
136 scale(hs, vs,
false, is_cached);
143 EGT_NODISCARD
float hscale()
const {
return m_hscale; }
148 EGT_NODISCARD
float vscale()
const {
return m_vscale; }
157 return size().width();
162 return size().height();
173 EGT_NODISCARD
const std::shared_ptr<Surface>&
surface()
const
198 m_keep_image_ratio = enable;
206 return m_keep_image_ratio;
209 EGT_NODISCARD std::string
uri()
const
214 void uri(
const std::string& uri,
bool is_cached =
false) { load(uri, m_hscale, m_vscale,
false, is_cached); }
228 void deserialize(
const std::string& name,
const std::string& value,
250 bool m_keep_image_ratio{
true};
261 :
Image(std::move(surface))
269static_assert(detail::rule_of_5<Image>(),
"must fulfill rule of 5");
Alignment flags.
Definition widgetflags.h:380
Raster image resource used for drawing or displaying.
Definition image.h:38
EGT_NODISCARD float hscale() const
Get the horizontal scale value.
Definition image.h:143
void handle_surface_changed()
Image(const std::string &uri={}, float scale=1.0, bool is_cached=false)
Construct a raster image from a URI with an optional scale.
void load(const std::string &uri, float hscale=1.0, float vscale=1.0, bool approx=false, bool is_cached=false)
Load a new source image with an optional scale.
EGT_NODISCARD DefaultDim width() const
Definition image.h:155
EGT_NODISCARD Size size_orig() const
Get the original size of the image before any Image::resize() or Image::scale() calls.
Definition image.h:182
void deserialize(const std::string &name, const std::string &value, const Serializer::Attributes &attrs)
Deserialized property.
void resize(const Size &size, bool is_cached=false)
Resize the image to the specified absolute size.
Definition image.h:130
void keep_image_ratio(bool enable)
Enable/disable ratio preservation while scaling the image.
Definition image.h:196
void scale(float hscale, float vscale, bool approximate=false, bool is_cached=false)
Scale the image.
bool keep_image_ratio() const
Get the keep image ratio state.
Definition image.h:204
void serialize(const std::string &name, Serializer &serializer) const
Serialize to the specified serializer.
EGT_NODISCARD float vscale() const
Get the vertical scale value.
Definition image.h:148
EGT_NODISCARD const std::shared_ptr< Surface > & surface() const
Get a reference to the internal image surface.
Definition image.h:173
std::shared_ptr< Surface > m_surface
Shared surface pointer.
Definition image.h:244
Image(std::shared_ptr< Surface > surface)
EGT_NODISCARD std::string uri() const
Definition image.h:209
std::string m_uri
If a URI was used, the URI.
Definition image.h:235
void uri(const std::string &uri, bool is_cached=false)
Definition image.h:214
Image(const std::string &uri, float hscale, float vscale, bool is_cached=false)
Construct a raster image from a URI with an optional scale.
EGT_NODISCARD Size size() const
Get the absolute size of the image.
void scale(float scale, bool approximate=false, bool is_cached=false)
Scale the image.
Definition image.h:120
EGT_NODISCARD DefaultDim height() const
Definition image.h:160
EGT_NODISCARD bool empty() const
Returns true if no internal surface is set.
Size m_orig_size
Original image size.
Definition image.h:247
Image crop(const Rect &rect) const
EGT_NODISCARD Rect align(const Rect &bounding, const AlignFlags &align)
Get the position and size of the image once aligned inside the bounding area.
Image(const unsigned char *data, size_t len)
Construct a raster image from memory.
void reset_uri()
Definition image.h:216
Abstract base serializer class.
Definition serialize.h:34
std::list< std::pair< std::string, std::string > > Attributes
Attributes array type.
Definition serialize.h:45
An SVG image.
Definition svgimage.h:57
int DefaultDim
Define the default dimension type used for geometry.
Definition geometry.h:34
EGT framework namespace.
Definition animation.h:24