Rose
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
rose::ImageRepository Class Reference

A cache of texture data structures that may be shared by other widgets to render textures. More...

#include <ImageRepository.h>

Public Types

using ImageStore = map< ImageId, sdl::TextureData >
 The store of TextureData objects.
 
using SurfaceStore = map< ImageId, sdl::Surface >
 The store of surfaces to be made into textures.
 

Public Member Functions

ImageId getImageId ()
 Get the next available ImageId. More...
 
sdl::TextureDataimage (ImageId imageId)
 Access the TextureData object for an ImageId. More...
 
const sdl::TextureDataimage (ImageId imageId) const
 Const access the TextureData object for an ImageId. More...
 
string_view imageName (ImageId imageId) const
 Access the name associated with the TextureData object. More...
 
string_view imagePath (ImageId imageId) const
 Access the file path associated with the TextureData object. More...
 
string_view imageURI (ImageId imageId) const
 Access the URI associated with the TextureData object. More...
 
void renderCopy (sdl::Renderer &renderer, ImageId imageId, SDL_Rect &imgSrcRect, SDL_Rect &imgPaintRect)
 Render the texture. More...
 
void renderCopy (sdl::Renderer &renderer, ImageId imageId, SDL_Rect &imgPaintRect)
 Render the full texture to the destination rectangle. More...
 
void renderCopy (sdl::Renderer &renderer, ImageId imageId, Rectangle &imgSrcRect, Rectangle &imgDstRect)
 Render the texture. More...
 
void renderCopy (sdl::Renderer &renderer, ImageId imageId, Rectangle &imgDstRect)
 Render the full source of the texture to the destination. More...
 
void setImage (ImageId imageId, sdl::TextureData textureData)
 Set an image in the cache replacing any existing image with the provided imageId. More...
 
void setImageSurface (ImageId imageId, sdl::Surface &surface)
 Set a Surface to be used to create or update the image Texture. More...
 
bool empty () const
 Determine if the image store is empty. More...
 
auto size () const
 Determine the size of the image store. More...
 
bool isValidImage (sdl::Renderer &renderer, ImageId imageId)
 Determine if an image id retrieves an image. More...
 

Static Public Attributes

static constexpr ImageId InvalidImageId = 0x0u
 An invalid image ID which may be used for initialization.
 
static constexpr ImageId FirstApplicationImageId = 0x100u
 ImageId values [FirstApplicationImageId ... FirstUserImageId) are reserved for Application static images.
 

Protected Member Functions

void getSurface (sdl::Renderer &renderer, ImageId imageId)
 Check for a future for an image and get the data if available. More...
 

Protected Attributes

ImageId mNextUserImageId
 A variable to keep track of used image IDs.
 
ImageStore mImageStore {}
 The texture cache.
 
SurfaceStore mSurfaceStore {}
 The surface cache.
 

Static Protected Attributes

static constexpr ImageId FirstUserImageId = 0x200u
 This and all following image IDs are available to user applications.
 

Detailed Description

A cache of texture data structures that may be shared by other widgets to render textures.

Member Function Documentation

◆ empty()

bool rose::ImageRepository::empty ( ) const
inline

Determine if the image store is empty.

Returns
true if empty.

◆ getImageId()

ImageId rose::ImageRepository::getImageId ( )
inline

Get the next available ImageId.

Returns
the next ImageId.

◆ getSurface()

void rose::ImageRepository::getSurface ( sdl::Renderer renderer,
ImageId  imageId 
)
inlineprotected

Check for a future for an image and get the data if available.

Parameters
rendererThe renderer used to convert the generated surface to a texture.
imageIdthe image identifier

◆ image() [1/2]

sdl::TextureData& rose::ImageRepository::image ( ImageId  imageId)
inline

Access the TextureData object for an ImageId.

Throws a std::out_of_range if no such ImageId is in the cache.

Parameters
imageIdthe image identifier
Returns
a reference to the TextureData object.

◆ image() [2/2]

const sdl::TextureData& rose::ImageRepository::image ( ImageId  imageId) const
inline

Const access the TextureData object for an ImageId.

Throws a std::out_of_range if no such ImageId is in the cache.

Parameters
imageIdthe image identifier
Returns
a const reference to the TextureData object.

◆ imageName()

string_view rose::ImageRepository::imageName ( ImageId  imageId) const
inline

Access the name associated with the TextureData object.

Throws a std::out_of_range if no such ImageId is in the cache.

Parameters
imageIdthe image identifier.
Returns
a const std::string_view of the image name.

◆ imagePath()

string_view rose::ImageRepository::imagePath ( ImageId  imageId) const
inline

Access the file path associated with the TextureData object.

Throws a std::out_of_range if no such ImageId is in the cache.

Parameters
imageIdthe image identifier.
Returns
a const std::string_view of the image path.

◆ imageURI()

string_view rose::ImageRepository::imageURI ( ImageId  imageId) const
inline

Access the URI associated with the TextureData object.

Throws a std::out_of_range if no such ImageId is in the cache.

Parameters
imageIdthe image identifier.
Returns
a const std::string_view of the image URI.

◆ isValidImage()

bool rose::ImageRepository::isValidImage ( sdl::Renderer renderer,
ImageId  imageId 
)
inline

Determine if an image id retrieves an image.

Parameters
imageIdThe ImageId to test.
Returns
true if there is an image for the id.

◆ renderCopy() [1/4]

void rose::ImageRepository::renderCopy ( sdl::Renderer renderer,
ImageId  imageId,
SDL_Rect &  imgSrcRect,
SDL_Rect &  imgPaintRect 
)
inline

Render the texture.

The texture is rendered using the supplied renderer, source and paint rectangles. Throws a std::out_of_range if no such ImageId is in the cache.

Parameters
rendererthe Renderer to use.
imageIdthe image identifier.
imgSrcRectthe source SDL_Rectangle
imgPaintRectthe destination SDL_Rectangle

◆ renderCopy() [2/4]

void rose::ImageRepository::renderCopy ( sdl::Renderer renderer,
ImageId  imageId,
SDL_Rect &  imgPaintRect 
)
inline

Render the full texture to the destination rectangle.

Parameters
rendererThe Renderer to use.
imageIdThe ImageId to render.
imgPaintRectThe destination rectangle.

◆ renderCopy() [3/4]

void rose::ImageRepository::renderCopy ( sdl::Renderer renderer,
ImageId  imageId,
Rectangle imgSrcRect,
Rectangle imgDstRect 
)
inline

Render the texture.

The texture is rendered using the supplied renderer, source and paint rectangles. Throws a std::out_of_range if no such ImageId is in the cache.

Parameters
rendererthe Renderer to use.
imageIdthe image identifier.
imgSrcRectthe source rose::Rectangle
imgDstRectthe destination rose::Rectangle

◆ renderCopy() [4/4]

void rose::ImageRepository::renderCopy ( sdl::Renderer renderer,
ImageId  imageId,
Rectangle imgDstRect 
)
inline

Render the full source of the texture to the destination.

Parameters
rendererThe Renderer to use.
imageIdThe ImageId to render.
imgDstRectThe destination rectangle.

◆ setImage()

void rose::ImageRepository::setImage ( ImageId  imageId,
sdl::TextureData  textureData 
)
inline

Set an image in the cache replacing any existing image with the provided imageId.

Throws a std::out_of_range if no such ImageId is in the cache.

Parameters
imageIdthe image identifier.
textureDatathe TextureData to store.

◆ setImageSurface()

void rose::ImageRepository::setImageSurface ( ImageId  imageId,
sdl::Surface &  surface 
)
inline

Set a Surface to be used to create or update the image Texture.

Parameters
imageIdThe ImageId to set or update.
surfaceThe Surface.

◆ size()

auto rose::ImageRepository::size ( ) const
inline

Determine the size of the image store.

Returns
the number of images in the store.

The documentation for this class was generated from the following file: