stmm-games-doc  0.32.0
Public Member Functions | List of all members
stmg::Image Class Reference

Image class. More...

Public Member Functions

 Image (const File &oImageFile) noexcept
 Image from a file constructor. More...
 
 Image (const shared_ptr< Image > &refImage, const NRect &oSubRect) noexcept
 Sub-image of another image constructor. More...
 
 Image (const shared_ptr< Image > &refImage, int32_t nSubX, int32_t nSubY, int32_t nSubW, int32_t nSubH) noexcept
 Sub-image of another image constructor. More...
 
 ~Image () noexcept
 Non virtual destructor. More...
 
void draw (const Cairo::RefPtr< Cairo::Context > &refCc, int32_t nX, int32_t nY, int32_t nW, int32_t nH) noexcept
 Draws the image within a rectangle. More...
 
bool isLoaded () const noexcept
 Whether the image is already loaded into memory. More...
 
bool load () noexcept
 Loads the image into memory. More...
 
NSize getNaturalSize () noexcept
 The natural size of the image. More...
 
void addCachedSize (int32_t nW, int32_t nH) noexcept
 Add a cached size. More...
 
void addCachedSize (NSize oSize) noexcept
 Add a cached size. More...
 
void releaseCachedSize (int32_t nW, int32_t nH) noexcept
 Release a cached size. More...
 
void releaseCachedSize (NSize oSize) noexcept
 Release a cached size. More...
 
Cairo::RefPtr< Cairo::Surface > getAsSurface (int32_t nW, int32_t nH) noexcept
 Gets a surface of a given size with the image painted on it. More...
 
const Cairo::RefPtr< Cairo::Surface > & getAsCachedSurface (int32_t nW, int32_t nH) noexcept
 Gets a cached surface with the image painted on it. More...
 
Cairo::RefPtr< Cairo::Surface > getAsMaskSurface (int32_t nW, int32_t nH) noexcept
 Gets a mask surface of a given size with the image painted on it. More...
 
const Cairo::RefPtr< Cairo::Surface > & getAsCachedMaskSurface (int32_t nW, int32_t nH) noexcept
 Gets a cached mask surface with the image painted on it. More...
 

Detailed Description

Image class.

Can explicitely cache specific sizes of the image.

Constructor & Destructor Documentation

◆ Image() [1/3]

stmg::Image::Image ( const File oImageFile)
explicitnoexcept

Image from a file constructor.

Parameters
oImageFileThe file. Must be defined.

◆ Image() [2/3]

stmg::Image::Image ( const shared_ptr< Image > &  refImage,
const NRect oSubRect 
)
noexcept

Sub-image of another image constructor.

Parameters
refImageThe master image. Cannot be null.
oSubRectThe rectangle within the master image in pixels. Width and height must be positive numbers.

◆ Image() [3/3]

stmg::Image::Image ( const shared_ptr< Image > &  refImage,
int32_t  nSubX,
int32_t  nSubY,
int32_t  nSubW,
int32_t  nSubH 
)
noexcept

Sub-image of another image constructor.

Parameters
refImageThe master image. Cannot be null.
nSubXThe rectangle's x within the master image in pixels.
nSubYThe rectangle's y within the master image in pixels.
nSubWThe rectangle's w within the master image in pixels. Must be positive.
nSubHThe rectangle's h within the master image in pixels. Must be positive.

◆ ~Image()

stmg::Image::~Image ( )
noexcept

Non virtual destructor.

Member Function Documentation

◆ addCachedSize() [1/2]

void stmg::Image::addCachedSize ( int32_t  nW,
int32_t  nH 
)
noexcept

Add a cached size.

Cached sizes are reference counted. Remember to call releaseCachedSize() when no longer needed.

Parameters
nWThe width in pixels.
nHThe height in pixels.

◆ addCachedSize() [2/2]

void stmg::Image::addCachedSize ( NSize  oSize)
noexcept

Add a cached size.

Cached sizes are reference counted. Remember to call releaseCachedSize() when no longer needed.

Parameters
oSizeThe size in pixel.

◆ draw()

void stmg::Image::draw ( const Cairo::RefPtr< Cairo::Context > &  refCc,
int32_t  nX,
int32_t  nY,
int32_t  nW,
int32_t  nH 
)
noexcept

Draws the image within a rectangle.

The image is loaded if necessary. The image is stretched over the rectangle. If the image cannot be loaded draws nothing.

Parameters
refCcThe context. Cannot be null.
nXThe rectangle's x in pixels.
nYThe rectangle's y in pixels.
nWThe rectangle's w in pixels.
nHThe rectangle's h in pixels.

◆ getAsCachedMaskSurface()

const Cairo::RefPtr<Cairo::Surface>& stmg::Image::getAsCachedMaskSurface ( int32_t  nW,
int32_t  nH 
)
noexcept

Gets a cached mask surface with the image painted on it.

The addCachedSize() function must have been called for the size.

Parameters
nWThe width. Must be > 0.
nHThe height. Must be > 0.
Returns
The mask (8 bit) surface or null if not cached.

◆ getAsCachedSurface()

const Cairo::RefPtr<Cairo::Surface>& stmg::Image::getAsCachedSurface ( int32_t  nW,
int32_t  nH 
)
noexcept

Gets a cached surface with the image painted on it.

The addCachedSize() function must have been called for the size.

Parameters
nWThe width. Must be > 0.
nHThe height. Must be > 0.
Returns
The surface or null if not cached.

◆ getAsMaskSurface()

Cairo::RefPtr<Cairo::Surface> stmg::Image::getAsMaskSurface ( int32_t  nW,
int32_t  nH 
)
noexcept

Gets a mask surface of a given size with the image painted on it.

If the requested size is cached the cached surface is returned.

Parameters
nWThe width in pixels.
nHThe height in pixels.
Returns
The mask (8 bit) surface. Is not null.

◆ getAsSurface()

Cairo::RefPtr<Cairo::Surface> stmg::Image::getAsSurface ( int32_t  nW,
int32_t  nH 
)
noexcept

Gets a surface of a given size with the image painted on it.

If the requested size is cached the cached surface is returned.

Parameters
nWThe width in pixels.
nHThe height in pixels.
Returns
The surface. Is not null.

◆ getNaturalSize()

NSize stmg::Image::getNaturalSize ( )
noexcept

The natural size of the image.

Returns
The natural size.

◆ isLoaded()

bool stmg::Image::isLoaded ( ) const
noexcept

Whether the image is already loaded into memory.

Returns
Whether already loaded.

◆ load()

bool stmg::Image::load ( )
noexcept

Loads the image into memory.

Returns
Whether succeeded.

◆ releaseCachedSize() [1/2]

void stmg::Image::releaseCachedSize ( int32_t  nW,
int32_t  nH 
)
noexcept

Release a cached size.

If the reference count reaches 0 the cached image is removed.

Parameters
nWThe width in pixels.
nHThe height in pixels.

◆ releaseCachedSize() [2/2]

void stmg::Image::releaseCachedSize ( NSize  oSize)
noexcept

Release a cached size.

If the reference count reaches 0 the cached image is removed.

Parameters
oSizeThe size in pixel.