21 #include <type_traits> 25 #include "Utilities.h" 48 static constexpr ImageId InvalidImageId = 0x0u;
51 static constexpr ImageId FirstApplicationImageId = 0x100u;
54 static constexpr ImageId FirstUserImageId = 0x200u;
66 if (!mSurfaceStore.empty()) {
67 if (
auto surface = mSurfaceStore.find(imageId); surface != mSurfaceStore.end()) {
68 if (!mImageStore.empty() && mImageStore.find(imageId) == mImageStore.end()) {
71 mImageStore[imageId] = std::move(textureData);
73 mImageStore.at(imageId) = surface->second.toTexture(renderer).release();
74 mImageStore.at(imageId).setLoadedTime(std::chrono::system_clock::now());
76 mSurfaceStore.erase(imageId);
91 return mNextUserImageId++;
101 return mImageStore.at(imageId);
111 return (mImageStore.at(imageId));
120 [[nodiscard]] string_view
imageName(ImageId imageId)
const {
121 return mImageStore.at(imageId).getName();
130 [[nodiscard]] string_view
imagePath(ImageId imageId)
const {
131 return mImageStore.at(imageId).getPath();
140 [[nodiscard]] string_view
imageURI(ImageId imageId)
const {
141 return mImageStore.at(imageId).getPath();
154 getSurface(renderer, imageId);
155 auto tex = mImageStore.at(imageId).get();
156 SDL_RenderCopy(renderer.
get(), tex, &imgSrcRect, &imgPaintRect);
166 getSurface(renderer, imageId);
167 SDL_RenderCopy(renderer.
get(), mImageStore.at(imageId).get(),
nullptr, &imgPaintRect);
180 auto src = imgSrcRect.toSdlRect();
181 auto dst = imgDstRect.toSdlRect();
182 renderCopy(renderer, imageId, src, dst);
192 auto dst = imgDstRect.toSdlRect();
195 clipRectangleGuard.intersection(clip);
196 renderCopy( renderer, imageId, dst);
206 mImageStore[imageId] = std::move(textureData);
215 mSurfaceStore[imageId] = std::move(surface);
222 [[nodiscard]]
bool empty()
const {
return mImageStore.empty(); }
228 [[nodiscard]]
auto size()
const {
return mImageStore.size(); }
236 if (!mImageStore.empty() && mImageStore.find(imageId) != mImageStore.end())
238 if (!mSurfaceStore.empty() && mSurfaceStore.find(imageId) != mSurfaceStore.end()) {
239 getSurface(renderer, imageId);
Store the current clip rectangle replacing it with a new clip rectangle.
Definition: Renderer.h:447
void renderCopy(sdl::Renderer &renderer, ImageId imageId, SDL_Rect &imgSrcRect, SDL_Rect &imgPaintRect)
Render the texture.
Definition: ImageRepository.h:153
void renderCopy(sdl::Renderer &renderer, ImageId imageId, Rectangle &imgDstRect)
Render the full source of the texture to the destination.
Definition: ImageRepository.h:191
bool isValidImage(sdl::Renderer &renderer, ImageId imageId)
Determine if an image id retrieves an image.
Definition: ImageRepository.h:235
void setImage(ImageId imageId, sdl::TextureData textureData)
Set an image in the cache replacing any existing image with the provided imageId. ...
Definition: ImageRepository.h:205
auto size() const
Determine the size of the image store.
Definition: ImageRepository.h:228
void renderCopy(sdl::Renderer &renderer, ImageId imageId, SDL_Rect &imgPaintRect)
Render the full texture to the destination rectangle.
Definition: ImageRepository.h:165
void setImageSurface(ImageId imageId, sdl::Surface &surface)
Set a Surface to be used to create or update the image Texture.
Definition: ImageRepository.h:214
sdl::TextureData & image(ImageId imageId)
Access the TextureData object for an ImageId.
Definition: ImageRepository.h:100
void getSurface(sdl::Renderer &renderer, ImageId imageId)
Check for a future for an image and get the data if available.
Definition: ImageRepository.h:65
A cache of texture data structures that may be shared by other widgets to render textures.
Definition: ImageRepository.h:35
ImageId getImageId()
Get the next available ImageId.
Definition: ImageRepository.h:90
A composite of a Position and a Size.
Definition: Types.h:307
auto get() const
The the underlying SDL_Renderer* for use with the SDL2 API.
Definition: Renderer.h:163
void renderCopy(sdl::Renderer &renderer, ImageId imageId, Rectangle &imgSrcRect, Rectangle &imgDstRect)
Render the texture.
Definition: ImageRepository.h:179
Written as a workaround for an issue in the SDL2 Library.
Definition: Renderer.h:64
const sdl::TextureData & image(ImageId imageId) const
Const access the TextureData object for an ImageId.
Definition: ImageRepository.h:110
ImageId mNextUserImageId
A variable to keep track of used image IDs.
Definition: ImageRepository.h:55
bool empty() const
Determine if the image store is empty.
Definition: ImageRepository.h:222
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
string_view imageName(ImageId imageId) const
Access the name associated with the TextureData object.
Definition: ImageRepository.h:120
map< ImageId, sdl::Surface > SurfaceStore
The store of surfaces to be made into textures.
Definition: ImageRepository.h:46
void setLoadedTime(const std::chrono::time_point< std::chrono::system_clock > loaded)
Set the time the texture was loaded.
Definition: Texture.h:254
A Texture with associated meta data.
Definition: Texture.h:90
string_view imageURI(ImageId imageId) const
Access the URI associated with the TextureData object.
Definition: ImageRepository.h:140
string_view imagePath(ImageId imageId) const
Access the file path associated with the TextureData object.
Definition: ImageRepository.h:130
map< ImageId, sdl::TextureData > ImageStore
The store of TextureData objects.
Definition: ImageRepository.h:41