Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
Public Member Functions | Public Attributes | List of all members
NetImageElement Class Reference
Inheritance diagram for NetImageElement:
Inheritance graph
[legend]
Collaboration diagram for NetImageElement:
Collaboration graph
[legend]

Public Member Functions

 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, getImageFallback will be called to get a Texture to be shown while downloading the correct image; the provided Texture is free'd when the download is complete or the destructor is called If immediateLoad is set to false, the loading won't begin until load() is called. More...
 
void fetch ()
 Start downloading the image (called in the constructor unless immediateLoad is false) More...
 
void render (Element *parent)
 Render the image. More...
 
- Public Member Functions inherited from Texture
void clear (void)
 Reinitialize Texture Resets texture content, size and color. More...
 
bool loadFromSurface (CST_Surface *surface)
 Loads the texture from a surface Returns true if successful. More...
 
bool loadFromCache (std::string &key)
 Loads the texture from caches Returns true if successful. More...
 
bool loadFromSurfaceSaveToCache (std::string &key, CST_Surface *surface)
 Loads the texture from a surface and saves the results in caches Returns true if successful. More...
 
void render (Element *parent)
 Renders the texture. More...
 
void resize (int w, int h)
 Resizes the texture. More...
 
void setScaleMode (TextureScaleMode mode)
 Sets texture scaling mode. More...
 
void getTextureSize (int *w, int *h)
 Return texture's original size. More...
 
TexturesetSize (int w, int h)
 
bool saveTo (std::string &path)
 save this texture to the given file path as a PNG More...
 
void loadPath (std::string &path, bool forceReload=false)
 update and load or reload the texture More...
 
- Public Member Functions inherited from Element
virtual bool process (InputEvents *event)
 process any input that is received for this element More...
 
virtual void render (Element *parent)
 display the current state of the display More...
 
bool onTouchDown (InputEvents *event)
 
bool onTouchDrag (InputEvents *event)
 
bool onTouchUp (InputEvents *event)
 
void hide ()
 
void unhide ()
 
void renderBackground (bool fill=true)
 
void append (Element *element)
 
void remove (Element *element)
 
void removeAll (bool moveToTrash=false)
 
void position (int x, int y)
 position the element More...
 
void recalcPosition (Element *parent)
 
CST_Rect getBounds ()
 
CST_Renderer * getRenderer ()
 
void wipeAll (bool delSelf=false)
 
Elementchild (Element *child)
 
ElementsetPosition (int x, int y)
 
ElementsetAction (std::function< void()> func)
 
ElementcenterHorizontallyIn (Element *parent)
 
ElementcenterVerticallyIn (Element *parent)
 
ElementcenterIn (Element *parent)
 
ElementsetAbsolute (bool isAbs)
 
Elementconstrain (int flags, int padding=0)
 
Elementanimate (int durationIn, std::function< void(float)> onStep, std::function< void()> onFinish)
 
ElementmoveToFront ()
 
ElementsetTouchable (bool touchable)
 
void screenshot (std::string path)
 Take a screenshot of this element and its children, and save it to the given path. More...
 

Public Attributes

bool loaded = false
 
bool updateSizeAfterLoad = false
 
- Public Attributes inherited from Texture
int cornerRadius = 0
 Rounded corner radius (if >0, will round) More...
 
- Public Attributes inherited from Element
std::function< void()> action = NULL
 the action to call (from binded callback) on touch or button selection https://stackoverflow.com/questions/14189440/c-class-member-callback-simple-examples More...
 
std::function< void(InputEvents *event)> actionWithEvents = NULL
 
std::vector< Element * > elements
 visible GUI child elements of this element More...
 
float scale = 1.0f
 
bool touchable = false
 whether or not this element can be touched (highlights bounds) More...
 
bool dragging = false
 whether or not this element is currently being dragged More...
 
bool needsRedraw = false
 whether or not this element needs the screen redrawn next time it's processed More...
 
int futureRedrawCounter = 0
 whether this element needs a redraw for the next X redraws (decreases each time) (0 is no redraws) More...
 
int lastMouseY = 0
 the last Y, X coordinate of the mouse (from a drag probably) More...
 
int lastMouseX = 0
 
bool hasBackground = false
 
rgb backgroundColor = {0, 0, 0}
 
bool isAbsolute = false
 
Elementparent = NULL
 the parent element (can sometimes be null if it isn't set) More...
 
bool hidden = false
 whether this element should skip rendering or not More...
 
bool isProtected = false
 
int elasticCounter = 0
 how much time is left in an elastic-type flick/scroll set by the last distance traveled in a scroll, and counts down every frame More...
 
int width = 0
 width and height of this element (must be manually set, isn't usually calculated (but is in some cases, like text or images)) More...
 
int height = 0
 
int x = 0
 
int y = 0
 
int xAbs = 0
 
int yAbs = 0
 
double angle = 0
 rotation angle in degrees More...
 
int xOff = 0
 
int yOff = 0
 
std::vector< Constraint * > constraints
 
std::vector< Animation * > animations
 
bool useColorMask = false
 whether or not to overlay a color mask on top of this element More...
 
CST_Color maskColor = {0,0,0,0}
 The color to overlay on top. More...
 

Additional Inherited Members

- Public Types inherited from Element
typedef Element super
 
- Protected Attributes inherited from Texture
CST_Texture * mTexture = nullptr
 The actual texture. More...
 
int texW = 0
 The size of the texture. More...
 
int texH = 0
 
CST_Color texFirstPixel = {0,0,0,0}
 The color of the first pixel. More...
 
TextureScaleMode texScaleMode = SCALE_STRETCH
 Texture's scaling mode. More...
 
- Static Protected Attributes inherited from Texture
static std::unordered_map< std::string, TextureDatatexCache
 Cache previously displayed textures. More...
 

Detailed Description

Definition at line 8 of file NetImageElement.hpp.

Constructor & Destructor Documentation

◆ NetImageElement()

NetImageElement::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, getImageFallback will be called to get a Texture to be shown while downloading the correct image; the provided Texture is free'd when the download is complete or the destructor is called If immediateLoad is set to false, the loading won't begin until load() is called.

Definition at line 3 of file NetImageElement.cpp.

4{
5 std::string key = std::string(url);
6 // printf("Key: %s\n", key.c_str());
7 if (loadFromCache(key)) {
8 loaded = true;
9
10 // if we're using the cache, we can update the size now
11 // printf("The size of the image is %d x %d\n", texW, texH);
12 width = texW;
13 height = texH;
14 }
15 else {
16 // setup a temporary image fallback
17 if (getImageFallback)
18 imgFallback = getImageFallback();
19
20 // start downloading the correct image
21 imgDownload = new DownloadOperation();
22 imgDownload->url = std::string(url);
23 imgDownload->cb = std::bind(&NetImageElement::imgDownloadComplete, this, std::placeholders::_1);
24
25 // load immediately
26 if (immediateLoad)
27 fetch();
28 }
29}
int width
width and height of this element (must be manually set, isn't usually calculated (but is in some case...
Definition: Element.hpp:118
void fetch()
Start downloading the image (called in the constructor unless immediateLoad is false)
int texW
The size of the texture.
Definition: Texture.hpp:76
bool loadFromCache(std::string &key)
Loads the texture from caches Returns true if successful.
Definition: Texture.cpp:76

References fetch(), Texture::loadFromCache(), Texture::texW, and Element::width.

◆ ~NetImageElement()

NetImageElement::~NetImageElement ( )

Definition at line 31 of file NetImageElement.cpp.

32{
33 if (imgFallback)
34 delete imgFallback;
35
36 if (imgDownload)
37 {
38 DownloadQueue::downloadQueue->downloadCancel(imgDownload);
39 delete imgDownload;
40 }
41}
void downloadCancel(DownloadOperation *download)
cancel a download operation

Member Function Documentation

◆ fetch()

void NetImageElement::fetch ( )

Start downloading the image (called in the constructor unless immediateLoad is false)

Definition at line 43 of file NetImageElement.cpp.

44{
45 if (!downloadStarted && imgDownload) {
46 DownloadQueue::downloadQueue->downloadAdd(imgDownload);
47 downloadStarted = true;
48 }
49}
void downloadAdd(DownloadOperation *download)
add a new download operation

References DownloadQueue::downloadAdd().

Referenced by NetImageElement().

◆ render()

void NetImageElement::render ( Element parent)
virtual

Render the image.

Reimplemented from Element.

Definition at line 81 of file NetImageElement.cpp.

82{
83 // if we're hidden, don't render
84 if (hidden) return;
85
86 if (mTexture)
87 {
89 }
90 else if (imgFallback)
91 {
92 imgFallback->x = x;
93 imgFallback->y = y;
94 imgFallback->width = width;
95 imgFallback->height = height;
96 imgFallback->render(parent);
97 }
98}
bool hidden
whether this element should skip rendering or not
Definition: Element.hpp:105
Element * parent
the parent element (can sometimes be null if it isn't set)
Definition: Element.hpp:102
void render(Element *parent)
Renders the texture.
Definition: Texture.cpp:108
CST_Texture * mTexture
The actual texture.
Definition: Texture.hpp:73

References Element::hidden, Texture::mTexture, Element::parent, Texture::render(), and Element::width.

Member Data Documentation

◆ loaded

bool NetImageElement::loaded = false

Definition at line 26 of file NetImageElement.hpp.

◆ updateSizeAfterLoad

bool NetImageElement::updateSizeAfterLoad = false

Definition at line 27 of file NetImageElement.hpp.


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