1#include "NetImageElement.hpp"
5 std::string key = std::string(url);
18 imgFallback = getImageFallback();
22 imgDownload->url = std::string(url);
23 imgDownload->cb = std::bind(&NetImageElement::imgDownloadComplete,
this, std::placeholders::_1);
31NetImageElement::~NetImageElement()
45 if (!downloadStarted && imgDownload) {
46 DownloadQueue::downloadQueue->
downloadAdd(imgDownload);
47 downloadStarted =
true;
55 if (download->status == DownloadStatus::COMPLETE)
57 CST_Surface *surface = IMG_Load_RW(SDL_RWFromMem((
void*)download->buffer.c_str(), download->buffer.size()), 1);
59 CST_FreeSurface(surface);
68 imgFallback =
nullptr;
70 if (updateSizeAfterLoad) {
77 imgDownload =
nullptr;
95 imgFallback->height = height;
void downloadAdd(DownloadOperation *download)
add a new download operation
void downloadCancel(DownloadOperation *download)
cancel a download operation
bool hidden
whether this element should skip rendering or not
bool needsRedraw
whether or not this element needs the screen redrawn next time it's processed
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Element * parent
the parent element (can sometimes be null if it isn't set)
void render(Element *parent)
Render the image.
NetImageElement(const char *url, std::function< Texture *(void)> getImageFallback=NULL, bool immediateLoad=true)
Creates a new image element, downloading the image from url If the url is not cached,...
void fetch()
Start downloading the image (called in the constructor unless immediateLoad is false)
bool loadFromSurfaceSaveToCache(std::string &key, CST_Surface *surface)
Loads the texture from a surface and saves the results in caches Returns true if successful.
int texW
The size of the texture.
bool loadFromCache(std::string &key)
Loads the texture from caches Returns true if successful.
void render(Element *parent)
Renders the texture.
CST_Texture * mTexture
The actual texture.