Aether
SDL2 based UI Framework for NX
Classes | Public Types | Public Member Functions | List of all members
Aether::Drawable Class Reference

Stores either a surface or texture which can be drawn on screen by providing a renderer to render(). More...

#include <Drawable.hpp>

Public Types

enum  Type { Type::None, Type::Surface, Type::Texture }
 Type of raw data stored. More...
 

Public Member Functions

 Drawable ()
 Height of mask. More...
 
 Drawable (Renderer *renderer, SDL_Surface *surf, const unsigned int width, const unsigned int height)
 Create a Drawable from a surface. More...
 
 Drawable (Renderer *renderer, SDL_Texture *tex, const unsigned int width, const unsigned int height)
 Create a Drawable from a texture. More...
 
ImageData getImageData ()
 Returns the ImageData for the currently stored image. More...
 
void setColour (const Colour &colour)
 Set colour to tint Drawable with when rendered. More...
 
void setMask (const int x, const int y, const unsigned int width, const unsigned int height)
 Set the mask (area to draw) More...
 
void render (const int x, const int y, const unsigned int width=0, const unsigned int height=0)
 Render the Drawable on screen at the given coordinates. More...
 
bool convertToTexture ()
 Convert the contained surface to a texture. Has no effect if the Drawable does not contain a surface. More...
 
Type type ()
 Returns the type of the data stored. More...
 
int width ()
 Returns the width of the Drawable in pixels. More...
 
int height ()
 Returns the height of the Drawable in pixels. More...
 
 ~Drawable ()
 Destructor ensures contained data is deleted appropriately.
 

Detailed Description

Stores either a surface or texture which can be drawn on screen by providing a renderer to render().

Note
This class is not thread-safe by itself.
All instances of this should be deleted before deleting the main renderer.

Member Enumeration Documentation

◆ Type

Type of raw data stored.

Enumerator
None 

Doesn't store any data that can be rendered

Surface 

Currently stores a SDL 'surface'

Texture 

Currently stores a SDL 'texture'

Constructor & Destructor Documentation

◆ Drawable() [1/3]

Aether::Drawable::Drawable ( )

Height of mask.

Default constructor. Initializes with no data.

Note
This is effectively useless: it's here for default allocations.

◆ Drawable() [2/3]

Aether::Drawable::Drawable ( Renderer renderer,
SDL_Surface *  surf,
const unsigned int  width,
const unsigned int  height 
)

Create a Drawable from a surface.

Parameters
rendererRenderer to draw/manipulate Drawable with
surfSurface to instantiate with
widthWidth of given surface (in pixels)
heightHeight of given surface (in pixels)

◆ Drawable() [3/3]

Aether::Drawable::Drawable ( Renderer renderer,
SDL_Texture *  tex,
const unsigned int  width,
const unsigned int  height 
)

Create a Drawable from a texture.

Parameters
rendererRenderer to draw/manipulate Drawable with
texTexture to instantiate with
widthWidth of given texture (in pixels)
heightHeight of given texture (in pixels)

Member Function Documentation

◆ convertToTexture()

bool Aether::Drawable::convertToTexture ( )

Convert the contained surface to a texture. Has no effect if the Drawable does not contain a surface.

Note
This should be called by the same thread that instantiated the renderer!
Returns
true if successful/not a surface, false if conversion failed

◆ getImageData()

ImageData Aether::Drawable::getImageData ( )

Returns the ImageData for the currently stored image.

Returns
ImageData for the currently stored image.

◆ height()

int Aether::Drawable::height ( )

Returns the height of the Drawable in pixels.

Returns
Height of Drawable in pixels, 0 if no data stored

◆ render()

void Aether::Drawable::render ( const int  x,
const int  y,
const unsigned int  width = 0,
const unsigned int  height = 0 
)

Render the Drawable on screen at the given coordinates.

Parameters
xX coordinate (top-left)
yY coordinate (top-left)
widthWidth to render at (optional, defaults to Drawable size)
heightHeight to render at (optional, defaults to Drawable size)

◆ setColour()

void Aether::Drawable::setColour ( const Colour colour)

Set colour to tint Drawable with when rendered.

Parameters
colourColour to tint with

◆ setMask()

void Aether::Drawable::setMask ( const int  x,
const int  y,
const unsigned int  width,
const unsigned int  height 
)

Set the mask (area to draw)

Parameters
xX coordinate of mask (top-left)
yY coordinate of mask (top-left)
widthWidth of mask
heightHeight of mask

◆ type()

Type Aether::Drawable::type ( )

Returns the type of the data stored.

Returns
Type of raw data stored (see Type)

◆ width()

int Aether::Drawable::width ( )

Returns the width of the Drawable in pixels.

Returns
Width of Drawable in pixels, 0 if no data stored

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