1#include "NetImageElement.hpp"
7 std::string key = std::string(url);
20 imgFallback = getImageFallback();
24 imgDownload->url = std::string(url);
25 imgDownload->cb = std::bind(&NetImageElement::imgDownloadComplete,
this, std::placeholders::_1);
33NetImageElement::~NetImageElement()
40 DownloadQueue::downloadQueue->downloadCancel(imgDownload);
47 if (!downloadStarted && imgDownload) {
48 downloadStarted =
true;
49 DownloadQueue::downloadQueue->downloadAdd(imgDownload);
58 if (!downloadStarted && !loaded && imgDownload) {
59 CST_Rect rect = { this->xAbs, this->yAbs, this->
width, this->height };
60 if (!CST_isRectOffscreen(&rect)) {
72 if (download->status == DownloadStatus::COMPLETE)
74 CST_Surface *surface = IMG_Load_RW(SDL_RWFromMem((
void*)download->buffer.c_str(), download->buffer.size()), 1);
76 CST_FreeSurface(surface);
85 imgFallback =
nullptr;
87 if (updateSizeAfterLoad) {
94 imgDownload =
nullptr;
107 else if (imgFallback)
115 imgFallback->height = height;
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
virtual void render(Element *parent)
display the current state of the display
bool hidden
whether this element should skip rendering or not
virtual bool process(InputEvents *event)
process any input that is received for this element
bool needsRedraw
whether or not this element needs the screen redrawn next time it's processed
Element * parent
the parent element (reference only, not owned)
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 render(Element *parent) override
Render the image.
bool process(InputEvents *event) override
Checks if we're onscreen and start download if needed.
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.