Aether
SDL2 based UI Framework for NX
Classes | Public Member Functions | Protected Member Functions | List of all members
Aether::Texture Class Referenceabstract

A Texture is an element that stores a texture to render in the window. It can't be instantiated alone as it's essentially a 'container' element, but is inherited by classes such as Text and Image which generate the texture. This class provides common getter methods and handles rendering texture asynchronously. More...

#include <Texture.hpp>

Inheritance diagram for Aether::Texture:
Aether::Element Aether::BaseText Aether::Box Aether::Ellipse Aether::Image Aether::Rectangle Aether::Text Aether::TextBlock

Classes

class  RenderJob
 Extends a thread pool job to render the given texture element on a separate thread. More...
 

Public Member Functions

 Texture (const int x=0, const int y=0)
 Constructs a new texture element. Position defaults to (0, 0). More...
 
void onRenderDone (const std::function< void()> func)
 Assigns a function to invoke when the texture is finished rendering. An example use for this is to resize/position based on the texture's size. More...
 
Colour colour ()
 Returns the texture's tint colour. More...
 
void setColour (const Colour &col)
 Set the colour to tint the texture with. More...
 
int textureWidth ()
 Returns the width of the stored texture. Returns 0 if the texture is being rendered asynchronously and isn't finished. More...
 
int textureHeight ()
 Returns the height of the stored texture. Returns 0 if the texture is being rendered asynchronously and isn't finished. More...
 
void setMask (const int x, const int y, const unsigned int w, const unsigned int h)
 Set the mask area for the texture. Pixels outside of this area are not drawn. More...
 
void destroy ()
 Destroy the stored texture, freeing memory. Safe to call even if no texture is stored. More...
 
bool ready ()
 Returns whether the texture is finished rendering and ready to be shown. More...
 
void renderSync ()
 Immediately render the texture synchronously. This has no effect if a texture is currently stored, or a task is already queued. To recreate the texture, call destroy() first.
 
void renderAsync ()
 Request to start rendering the texture asynchronously. This has no effect if a texture is currently stored, or a task is already queued. To recreate the texture, call destroy() first.
 
void update (unsigned int dt)
 Called internally. Overrides Element's update method to handle the asynchronous rendering operations. More...
 
void render ()
 Called internally. Overrides Element's render method to actually show the stored texture.
 
 ~Texture ()
 Destroys the texture, freeing all allocated memory.
 
- Public Member Functions inherited from Aether::Element
 Element (int x=0, int y=0, int w=100, int h=100)
 Construct a new Element object. More...
 
int x ()
 Returns x-coordinate of element. More...
 
int y ()
 Returns y-coordinate of element. More...
 
int w ()
 Returns width of element. More...
 
int h ()
 Returns height of element. More...
 
virtual void setX (int x)
 Set x-coordinate of element. More...
 
virtual void setY (int y)
 Set y-coordinate of element. More...
 
virtual void setW (int w)
 Set width of element. More...
 
virtual void setH (int h)
 Set height of element. More...
 
virtual void setXY (int x, int y)
 Set co-ordinates of element. More...
 
virtual void setWH (int w, int h)
 Set size of element. More...
 
virtual void setXYWH (int x, int y, int w, int h)
 Setter size and co-ordinates of element. More...
 
Elementparent ()
 Returns the parent element of this element. More...
 
void setParent (Element *p)
 Set the parent element of this element. More...
 
virtual void addElement (Element *e)
 Adds new element a child. More...
 
virtual bool removeElement (Element *e)
 Attempt to delete given child element. More...
 
virtual void removeAllElements ()
 Deletes all children elements.
 
virtual bool returnElement (Element *e)
 Attempt to remove the given child element. More...
 
virtual void returnAllElements ()
 Removes (but does not delete) all children elements.
 
bool isVisible ()
 Check if current element is visible on-screen. More...
 
bool hidden ()
 Check if current element is hidden. More...
 
void setHidden (bool b)
 Set whether element is hidden or not. More...
 
bool selected ()
 Check if current element is selected. More...
 
virtual void setSelected (bool b)
 Set whether element is selected or not. More...
 
bool selectable ()
 Check if current element is selectable. More...
 
void setSelectable (bool b)
 Set whether element is selectable or not. More...
 
bool touchable ()
 Check if current element is touch responsive. More...
 
void setTouchable (bool b)
 Set whether element is touch responsive or not. More...
 
bool highlighted ()
 Check if current element is highlighted. More...
 
void setHighlighted (bool b)
 Set whether element is highlighted or not. More...
 
bool hasHighlighted ()
 Check if current element has highlighted children element. More...
 
void setHasHighlighted (bool b)
 Set whether element has highlighted children element or not. More...
 
bool hasSelectable ()
 Check if current element has selectable children element. More...
 
void setHasSelectable (bool b)
 Set whether element has selectable children element or not. More...
 
bool hasSelected ()
 Check if current element has selected children element. More...
 
void setHasSelected (bool b)
 Set whether element has selected children element or not. More...
 
virtual void setActive ()
 Set element as activated.
 
virtual void setInactive ()
 Set element as in-activated.
 
void setFocused (Element *e)
 Sets current element as unfocused and instead focuses a sub-element. More...
 
void setFocussed (Element *e)
 Sets current element as unfocused and instead focuses a sub-element. More...
 
Elementfocused ()
 Returns the currently focused element. More...
 
Elementfocussed ()
 Returns the currently focused element. More...
 
std::function< void()> onPressFunc ()
 Returns function invoked when the element is pressed. More...
 
void onPress (std::function< void()> f)
 Sets the function to invoked when the element is pressed. More...
 
virtual bool handleEvent (InputEvent *e)
 Attempt to handle a given event. More...
 
virtual DrawablerenderHighlightBG ()
 Renders the highlight background. More...
 
virtual DrawablerenderHighlight ()
 Renders the highlight border. More...
 
virtual DrawablerenderSelection ()
 Renders the selection overlay. More...
 
virtual ~Element ()
 Destroy the Element object.
 

Protected Member Functions

virtual DrawablerenderDrawable ()=0
 Method provided by children defining how to render the texture.
 
- Protected Member Functions inherited from Aether::Element
void renderHighlightTextures ()
 Renders cached highlight textures.
 
void renderSelectionTexture ()
 Renders cached selection texture.
 
void addElementAt (Element *e, size_t i)
 Add element at given index in vector. More...
 

Additional Inherited Members

- Protected Attributes inherited from Aether::Element
Elementparent_
 Pointer to parent element, if there is one.
 
std::vector< Element * > children
 Vector of child elements (used to call their methods)
 
Elementfocused_
 Children element which is highlighted/focused (to regain focus on activation)
 
- Static Protected Attributes inherited from Aether::Element
static Colour hiBGColour
 Background colour if element is highlighted.
 
static Colour hiBorderColour
 Border colour if element is highlighted.
 
static Colour selColour
 Selected colour if element is highlighted.
 
static unsigned int hiSize
 Size of highlight border.
 
static DrawablehiBGTex
 Highlight background texture.
 
static DrawablehiBorderTex
 Highlight border texture.
 
static DrawableselTex
 Selection texture.
 
static Rendererrenderer
 
static bool isTouch
 Indicator on whether the touch is "active" (i.e. hide highlighting) or not.
 

Detailed Description

A Texture is an element that stores a texture to render in the window. It can't be instantiated alone as it's essentially a 'container' element, but is inherited by classes such as Text and Image which generate the texture. This class provides common getter methods and handles rendering texture asynchronously.

Constructor & Destructor Documentation

◆ Texture()

Aether::Texture::Texture ( const int  x = 0,
const int  y = 0 
)

Constructs a new texture element. Position defaults to (0, 0).

Parameters
xTop-left x coordinate
yTop-left y coordinate

Member Function Documentation

◆ colour()

Colour Aether::Texture::colour ( )

Returns the texture's tint colour.

Returns
Colour texture is tinted with.

◆ destroy()

void Aether::Texture::destroy ( )

Destroy the stored texture, freeing memory. Safe to call even if no texture is stored.

Note
This will block if the texture isn't finished rendering.

◆ onRenderDone()

void Aether::Texture::onRenderDone ( const std::function< void()>  func)

Assigns a function to invoke when the texture is finished rendering. An example use for this is to resize/position based on the texture's size.

Parameters
funcFunction to invoke, or nullptr to remove

◆ ready()

bool Aether::Texture::ready ( )

Returns whether the texture is finished rendering and ready to be shown.

Returns
Whether the texture can be rendered on the next frame.

◆ setColour()

void Aether::Texture::setColour ( const Colour col)

Set the colour to tint the texture with.

Parameters
colColour to tint with

◆ setMask()

void Aether::Texture::setMask ( const int  x,
const int  y,
const unsigned int  w,
const unsigned int  h 
)

Set the mask area for the texture. Pixels outside of this area are not drawn.

Note
This must be called after the texture is ready (see ready()), and is lost whenever the texture is changed.
Parameters
xTop-left x coordinate of mask
yTop-left y coordinate of mask
wMask width
hMask height

◆ textureHeight()

int Aether::Texture::textureHeight ( )

Returns the height of the stored texture. Returns 0 if the texture is being rendered asynchronously and isn't finished.

Returns
Stored texture's height in pixels.

◆ textureWidth()

int Aether::Texture::textureWidth ( )

Returns the width of the stored texture. Returns 0 if the texture is being rendered asynchronously and isn't finished.

Returns
Stored texture's width in pixels.

◆ update()

void Aether::Texture::update ( unsigned int  dt)
virtual

Called internally. Overrides Element's update method to handle the asynchronous rendering operations.

Parameters
dtDelta time since last frame in ms

Reimplemented from Aether::Element.

Reimplemented in Aether::Text.


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