15#include <egt/detail/meta.h>
16#include <egt/geometry.h>
17#include <egt/painter.h>
18#include <egt/serialize.h>
54 Image(
const std::string& uri = {},
float scale = 1.0);
63 Image(
const std::string& uri,
float hscale,
float vscale);
71 Image(
const unsigned char* data,
size_t len);
81 void load(
const std::string& uri,
float hscale = 1.0,
float vscale = 1.0,
bool approx =
false);
118 void scale(
float hscale,
float vscale,
bool approximate =
false);
125 inline void scale(
float scale,
bool approximate =
false)
127 this->scale(scale, scale, approximate);
137 if (this->size() != size)
139 float hs =
static_cast<float>(size.width()) /
static_cast<float>(m_orig_size.width());
140 float vs =
static_cast<float>(size.height()) /
static_cast<float>(m_orig_size.height());
148 EGT_NODISCARD
float hscale()
const {
return m_hscale; }
153 EGT_NODISCARD
float vscale()
const {
return m_vscale; }
163 return {cairo_image_surface_get_width(surface().
get()),
164 cairo_image_surface_get_height(surface().
get())};
169 return size().width();
174 return size().height();
190 if (m_surface_local.get())
191 return m_surface_local;
196 EGT_NODISCARD cairo_pattern_t*
pattern()
const
199 m_pattern.reset(cairo_pattern_create_for_surface(surface().
get()),
200 cairo_pattern_destroy);
201 assert(m_pattern.get());
202 return m_pattern.get();
225 m_keep_image_ratio = enable;
233 return m_keep_image_ratio;
246 EGT_NODISCARD std::string
uri()
const
251 void uri(
const std::string& uri) { load(uri, m_hscale, m_vscale); }
270 void deserialize(
const std::string& name,
const std::string& value,
295 bool m_keep_image_ratio{
true};
317static_assert(detail::rule_of_5<Image>(),
"must fulfill rule of 5");
Alignment flags.
Definition widgetflags.h:379
Raster image resource used for drawing or displaying.
Definition image.h:39
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:148
void handle_surface_changed()
EGT_NODISCARD DefaultDim width() const
Definition image.h:167
EGT_NODISCARD Size size_orig() const
Get the original size of the image before any Image::resize() or Image::scale() calls.
Definition image.h:209
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:223
bool keep_image_ratio() const
Get the keep image ratio state.
Definition image.h:231
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:153
Image crop(const Rect &rect)
Definition image.h:257
Image(shared_cairo_surface_t surface)
EGT_NODISCARD std::string uri() const
Definition image.h:246
std::string m_uri
If a URI was used, the URI.
Definition image.h:277
EGT_NODISCARD cairo_pattern_t * pattern() const
Get internal pattern representation.
Definition image.h:196
shared_cairo_surface_t m_surface_local
Local surface pointer.
Definition image.h:289
void uri(const std::string &uri)
Definition image.h:251
void resize(const Size &size)
Resize the image to the specified absolute size.
Definition image.h:135
EGT_NODISCARD Size size() const
Get the absolute size of the image.
Definition image.h:158
void scale(float scale, bool approximate=false)
Scale the image.
Definition image.h:125
void copy()
This function must be called any time the surface is going to be modified.
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:172
EGT_NODISCARD shared_cairo_surface_t surface() const
Get a reference to the internal image surface.
Definition image.h:188
EGT_NODISCARD bool empty() const
Returns true if no internal surface is set.
Definition image.h:180
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.
Image crop(const RectF &rect)
shared_cairo_pattern_t m_pattern
Internal pattern representation.
Definition image.h:298
Size m_orig_size
Original image size.
Definition image.h:292
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.
shared_cairo_surface_t m_surface
Shared surface pointer.
Definition image.h:286
Image(cairo_surface_t *surface)
void reset_uri()
Definition image.h:253
EGT_NODISCARD constexpr Dim width() const noexcept
Get the width value.
Definition geometry.h:913
EGT_NODISCARD constexpr Dim x() const noexcept
Get the x value.
Definition geometry.h:903
EGT_NODISCARD constexpr Dim height() const noexcept
Get the height value.
Definition geometry.h:915
EGT_NODISCARD constexpr Dim y() const noexcept
Get the y value.
Definition geometry.h:905
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
std::shared_ptr< cairo_surface_t > shared_cairo_surface_t
Shared pointer for a cairo surface.
Definition types.h:29
std::list< T > get(const BitFields< T > &fields)
std::shared_ptr< cairo_pattern_t > shared_cairo_pattern_t
Shared pointer for a cairo pattern.
Definition types.h:41
int DefaultDim
Define the default dimension type used for geometry.
Definition geometry.h:34
EGT framework namespace.
Definition animation.h:24