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>
53 Image(
const std::string& uri = {},
float scale = 1.0);
62 Image(
const std::string& uri,
float hscale,
float vscale);
70 Image(
const unsigned char* data,
size_t len);
80 void load(
const std::string& uri,
float hscale = 1.0,
float vscale = 1.0,
bool approx =
false);
92 Image(std::shared_ptr<Surface> surface);
109 void scale(
float hscale,
float vscale,
bool approximate =
false);
116 inline void scale(
float scale,
bool approximate =
false)
118 this->scale(scale, scale, approximate);
128 if (!m_orig_size.empty() && this->size() != size)
130 float hs =
static_cast<float>(size.width()) /
static_cast<float>(m_orig_size.width());
131 float vs =
static_cast<float>(size.height()) /
static_cast<float>(m_orig_size.height());
139 EGT_NODISCARD
float hscale()
const {
return m_hscale; }
144 EGT_NODISCARD
float vscale()
const {
return m_vscale; }
153 return size().width();
158 return size().height();
169 EGT_NODISCARD
const std::shared_ptr<Surface>&
surface()
const
194 m_keep_image_ratio = enable;
202 return m_keep_image_ratio;
205 EGT_NODISCARD std::string
uri()
const
210 void uri(
const std::string& uri) { load(uri, m_hscale, m_vscale); }
224 void deserialize(
const std::string& name,
const std::string& value,
246 bool m_keep_image_ratio{
true};
257 :
Image(std::move(surface))
265static_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
Image(const std::string &uri={}, float scale=1.0)
Construct a raster image from a URI with an optional scale.
EGT_NODISCARD float hscale() const
Get the horizontal scale value.
Definition image.h:139
void handle_surface_changed()
EGT_NODISCARD DefaultDim width() const
Definition image.h:151
EGT_NODISCARD Size size_orig() const
Get the original size of the image before any Image::resize() or Image::scale() calls.
Definition image.h:178
void deserialize(const std::string &name, const std::string &value, const Serializer::Attributes &attrs)
Deserialized property.
void keep_image_ratio(bool enable)
Enable/disable ratio preservation while scaling the image.
Definition image.h:192
bool keep_image_ratio() const
Get the keep image ratio state.
Definition image.h:200
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:144
EGT_NODISCARD const std::shared_ptr< Surface > & surface() const
Get a reference to the internal image surface.
Definition image.h:169
std::shared_ptr< Surface > m_surface
Shared surface pointer.
Definition image.h:240
Image(std::shared_ptr< Surface > surface)
EGT_NODISCARD std::string uri() const
Definition image.h:205
std::string m_uri
If a URI was used, the URI.
Definition image.h:231
void uri(const std::string &uri)
Definition image.h:210
void resize(const Size &size)
Resize the image to the specified absolute size.
Definition image.h:126
EGT_NODISCARD Size size() const
Get the absolute size of the image.
void scale(float scale, bool approximate=false)
Scale the image.
Definition image.h:116
void scale(float hscale, float vscale, bool approximate=false)
Scale the image.
Image(const std::string &uri, float hscale, float vscale)
Construct a raster image from a URI with an optional scale.
EGT_NODISCARD DefaultDim height() const
Definition image.h:156
EGT_NODISCARD bool empty() const
Returns true if no internal surface is set.
void load(const std::string &uri, float hscale=1.0, float vscale=1.0, bool approx=false)
Load a new source image with an optional scale.
Size m_orig_size
Original image size.
Definition image.h:243
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:212
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