![]() |
1.11 |
Raster image resource used for drawing or displaying. More...
#include <image.h>
Public Member Functions | |
Image (const std::string &uri, float hscale, float vscale) | |
Construct a raster image from a URI with an optional scale. | |
Image (const std::string &uri={}, float scale=1.0) | |
Construct a raster image from a URI with an optional scale. | |
Image (const unsigned char *data, size_t len) | |
Construct a raster image from memory. | |
Image (std::shared_ptr< Surface > surface) | |
Image (Surface &&surface) | |
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 | crop (const Rect &rect) const |
void | deserialize (const std::string &name, const std::string &value, const Serializer::Attributes &attrs) |
Deserialized property. | |
EGT_NODISCARD bool | empty () const |
Returns true if no internal surface is set. | |
EGT_NODISCARD DefaultDim | height () const |
EGT_NODISCARD float | hscale () const |
Get the horizontal scale value. | |
bool | keep_image_ratio () const |
Get the keep image ratio state. | |
void | keep_image_ratio (bool enable) |
Enable/disable ratio preservation while scaling the image. | |
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. | |
void | reset_uri () |
void | resize (const Size &size) |
Resize the image to the specified absolute size. | |
void | scale (float hscale, float vscale, bool approximate=false) |
Scale the image. | |
void | scale (float scale, bool approximate=false) |
Scale the image. | |
void | serialize (const std::string &name, Serializer &serializer) const |
Serialize to the specified serializer. | |
EGT_NODISCARD Size | size () const |
Get the absolute size of the image. | |
EGT_NODISCARD Size | size_orig () const |
Get the original size of the image before any Image::resize() or Image::scale() calls. | |
EGT_NODISCARD const std::shared_ptr< Surface > & | surface () const |
Get a reference to the internal image surface. | |
EGT_NODISCARD std::string | uri () const |
void | uri (const std::string &uri) |
EGT_NODISCARD float | vscale () const |
Get the vertical scale value. | |
EGT_NODISCARD DefaultDim | width () const |
Protected Member Functions | |
void | handle_surface_changed () |
Protected Attributes | |
float | m_hscale {1.0} |
Horizontal scale value, compared to original. | |
bool | m_keep_image_ratio {true} |
Keep the image ratio when the aligned with AlignFlag::expand. | |
Size | m_orig_size |
Original image size. | |
std::shared_ptr< Surface > | m_surface |
Shared surface pointer. | |
std::string | m_uri |
If a URI was used, the URI. | |
float | m_vscale {1.0} |
Vertical scale value, compared to original. | |
Friends | |
class | SvgImage |
Raster image resource used for drawing or displaying.
This class by default shares the internal surface pointer with anything else using the surface.
Image | ( | const std::string & | uri = {} , |
float | scale = 1.0 |
||
) |
Image | ( | const std::string & | uri, |
float | hscale, | ||
float | vscale | ||
) |
Construct a raster image from a URI with an optional scale.
uri | Resource path. |
hscale | Horizontal scale of the image, with 1.0 being 100%. |
vscale | Vertical scale of the image, with 1.0 being 100%. |
Image | ( | const unsigned char * | data, |
size_t | len | ||
) |
Construct a raster image from memory.
data | Pointer to the data. |
len | Length of the data. |
surface | A pre-existing surface. |
This takes a reference to the passed in image.
EGT_NODISCARD Rect align | ( | const Rect & | bounding, |
const AlignFlags & | align | ||
) |
Get the position and size of the image once aligned inside the bounding area.
void deserialize | ( | const std::string & | name, |
const std::string & | value, | ||
const Serializer::Attributes & | attrs | ||
) |
Deserialized property.
EGT_NODISCARD bool empty | ( | ) | const |
Returns true if no internal surface is set.
|
protected |
|
inline |
|
inline |
Get the horizontal scale value.
|
inline |
Get the keep image ratio state.
|
inline |
Enable/disable ratio preservation while scaling the image.
If enabled, the original image ratio won't be changed during the image auto scale operation. By default, set to true.
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.
uri | Resource path. |
hscale | Horizontal scale of the image, with 1.0 being 100%. |
vscale | Vertical scale of the image, with 1.0 being 100%. |
approx | Approximate the scale to increase image cache hit efficiency. |
|
inline |
|
inline |
Resize the image to the specified absolute size.
size | The new size of the image. |
void scale | ( | float | hscale, |
float | vscale, | ||
bool | approximate = false |
||
) |
Scale the image.
Change the scale of the image, similar to calling Image::resize().
This scales relative to the original size of the image. Not the result of any subsequent Image::resize() or Image::scale() call.
hscale | Horizontal scale of the image, with 1.0 being 100%. |
vscale | Vertical scale of the image, with 1.0 being 100%. |
approximate | Approximate the scale to increase image cache hit efficiency. |
|
inline |
Scale the image.
void serialize | ( | const std::string & | name, |
Serializer & | serializer | ||
) | const |
Serialize to the specified serializer.
EGT_NODISCARD Size size | ( | ) | const |
Get the absolute size of the image.
|
inline |
Get the original size of the image before any Image::resize() or Image::scale() calls.
|
inline |
Get a reference to the internal image surface.
|
inline |
|
inline |
|
inline |
Get the vertical scale value.
|
inline |
|
friend |
|
protected |
Horizontal scale value, compared to original.
|
protected |
Keep the image ratio when the aligned with AlignFlag::expand.
|
protected |
Original image size.
|
protected |
Shared surface pointer.
|
protected |
If a URI was used, the URI.
|
protected |
Vertical scale value, compared to original.