#include <tbx_web_sprite.hpp>
Public Member Functions | |
WebSprite (const tbCore::tbString &spriteURL, const tbGraphics::PixelSpace width, const tbGraphics::PixelSpace height, const tbCore::tbString &cacheID="", const bool alwaysFetch=false) | |
virtual | ~WebSprite (void) |
void | SetColorUntilLoaded (const tbGraphics::Color &color) |
void | SetOnLoaded (std::function< void(void)> callback) |
virtual tbGraphics::PixelSpace | GetPixelWidth (void) const override |
virtual tbGraphics::PixelSpace | GetPixelHeight (void) const override |
Public Member Functions inherited from TurtleBrains::Graphics::Graphic | |
Graphic (void) | |
Graphic (const Graphic &other) | |
virtual | ~Graphic (void) |
bool | IsActive (void) const |
void | SetActive (const bool isActive) |
void | Update (const float deltaTime) |
bool | IsVisible (void) const |
void | SetVisible (const bool isVisible) |
void | Render (void) const |
const tbMath::Vector2 & | GetPosition (void) const |
void | SetPosition (const float x, const float y) |
void | SetPosition (const tbMath::Vector2 &position) |
const tbMath::Vector2 & | GetOrigin (void) const |
void | SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero()) |
void | SetOrigin (const float originX, const float originY) |
void | SetOrigin (const tbMath::Vector2 &origin) |
float | GetDepth (void) const |
void | SetDepth (const float newDepth) |
const tbMath::Vector2 & | GetScale (void) const |
void | SetScale (const float scale) |
void | SetScale (const tbMath::Vector2 &scale) |
void | SetScale (const float scaleX, const float scaleY) |
float | GetRotation (void) const |
void | SetRotation (const float rotation) |
void | SetScroll (const float scroll) |
void | SetScroll (const float scrollX, const float scrollY) |
bool | IsRelative (void) const |
const Color & | GetColor (void) const |
virtual void | SetColor (const tbGraphics::Color &newColor) |
float | GetWidth (void) const |
float | GetHeight (void) const |
float | GetScaledWidth (void) const |
float | GetScaledHeight (void) const |
bool | UnstableIsPointContained (const tbMath::Vector2 &point) const |
Static Public Member Functions | |
static void | SetCacheDirectory (const tbCore::tbString &filepath) |
Protected Member Functions | |
virtual void | OnRender (void) const override |
Protected Member Functions inherited from TurtleBrains::Graphics::Graphic | |
virtual void | OnUpdate (const float deltaTime) |
virtual void | ApplyTransform (void) const |
virtual void | PopTransform (void) const |
The WebSprite will use TurtleBrains::Network to grab a texture from the web and then display it with an optional default texture to use until it is replaced.
|
explicit |
Creates a WebSprite image/object by loading from the url. This is done asynchronously and will not be done at time of construction unless using a cacheID that already exists. The size must be specified to know what size is expected. This will create a white box where the image will be placed until it finishes loading. Use SetVisible() or SetColorUntilLoaded() to change that behavior. Once loaded the image will stretch to fit the specified size even if different aspect ratio.
spriteURL | The location of the image file. See the TextureManager for a list of supported formats. |
width | The width the image will display at, will stretch to fit. |
height | The height the image will display at, will stretch to fit. |
cacheID | Can be empty to never cache the image, always requesting to load it. If used the cacheIDC:.txt must be a unique identifier for the image resource, and is only cached if SetCacheDirectory() was set. |
alwaysFetch | If using a cacheID and the image was loaded from cache, this can allow the WebSprite to still make a request anyway; remember the caching system is not smart like a browser. |
|
virtual |
Destroys all resources used for the WebSprite.
|
overridevirtual |
Reimplemented from TurtleBrains::Graphics::Graphic.
|
overridevirtual |
Reimplemented from TurtleBrains::Graphics::Graphic.
|
overrideprotectedvirtual |
This must be overridden by a subclass to actually display the Graphic on the screen. The function will be invoked when Render() is called and the object IsVisible().
Implements TurtleBrains::Graphics::Graphic.
|
static |
Set a directory for caching all sprites/images loaded from the web. This cache does not function the same as a browser-cache might instead if it has grabbed the image before and saved in the cache that cached image will be used directly. This cache directory and the cacheID of the image must be set in order for the image to be cached. Each cacheid must be unique, else images may conflict.
void TurtleBrainsExpress::Graphics::WebSprite::SetColorUntilLoaded | ( | const tbGraphics::Color & | color | ) |
While waiting for the image request, the white box can be changed to a different color which will reset once the image is finished loading. This may not be a perfect representation, but allows it to start a little closer.
color | The color the box should be displayed until loaded. |
void TurtleBrainsExpress::Graphics::WebSprite::SetOnLoaded | ( | std::function< void(void)> | callback | ) |
Set a function callback to be notified when the image finishes loading. This will be called immediately if the WebSprite loaded from cache, even if it is still making another request.
callback | The function to notify. |