Aether
SDL2 based UI Framework for NX
|
Aether's main renderer instance. It provides all methods relating to drawing directly to the screen, rendering graphics to memory as well as measuring resource usage (with respect to textures). More...
#include <Renderer.hpp>
Public Types | |
typedef std::function< void(const std::string, const bool)> | LogHandler |
Function to handle log messages. | |
Public Member Functions | |
Renderer () | |
Initializes the renderer object, but does not initialize the actual rendering backend (SDL). See initialize(). | |
void | setLogHandler (const LogHandler &func) |
Sets the handler to be used for logging. Expects a function that is passed the log message as a string, and a boolean specifying if the message is 'important'. Note that this may be called extremely quickly depending on the circumstances. More... | |
bool | initialize (const std::string &name, const unsigned int windowW, const unsigned int windowH) |
Initialize the rendering backend. More... | |
void | cleanup () |
Clean up the rendering backend. This should always be called, even if initialization failed. | |
unsigned int | memoryUsage () |
Returns an approximated value for memory used by all rendered textures. More... | |
unsigned int | surfaceCount () |
Returns the number of allocated 'surfaces' that haven't been destroyed. More... | |
unsigned int | textureCount () |
Returns the number of allocated 'textures' that haven't been destroyed. More... | |
unsigned int | windowWidth () |
Returns the width of the window. More... | |
unsigned int | windowHeight () |
Returns the height of the window. More... | |
void | fillWindow (const Colour &col) |
Fill the window with the given colour. More... | |
void | present () |
Present all rendered graphics. | |
void | resetClipArea () |
Reset the clipping area for rendered objects. | |
void | setClipArea (const int x1, const int y1, const int x2, const int y2) |
Set the clipping area for rendered objects. More... | |
void | setFont (const std::string &path) |
Set the font used for text rendering from a file. Pass an empty string to revert to the default font. More... | |
void | setFontSpacing (const double amt) |
Set the font spacing for wrapped text. Expects a multiplier for the line height. Defaults to 1.15. More... | |
std::pair< int, int > | calculateTextDimensions (const std::string &str, const unsigned int size) |
Return the dimensions of the given string if rendered using the current font and given font size. More... | |
std::tuple< std::vector< std::string >, int, int > | calculateWrappedTextDimensions (const std::string &str, const unsigned int size, const unsigned int width) |
Return the dimensions of the given string if rendered using the current font and given font size, as a text block. More... | |
std::vector< Colour > | readSurfacePixels (SDL_Surface *surface) |
Returns the RGBA pixel data stored in the passed surface. More... | |
std::vector< Colour > | readTexturePixels (SDL_Texture *texture) |
Returns the RGBA pixel data stored in the passed surface. More... | |
Drawable * | renderImageSurface (const std::string &path, const size_t scaleWidth, const size_t scaleHeight) |
Render the image at the specified path as a surface. More... | |
Drawable * | renderImageSurface (const std::vector< unsigned char > &data, const size_t scaleWidth, const size_t scaleHeight) |
Render the image passed in the vector as a surface. More... | |
Drawable * | renderTextSurface (const std::string str, const unsigned int size) |
Render a UTF8 string as a surface. More... | |
Drawable * | renderWrappedTextSurface (const std::string str, const unsigned int size, const unsigned int width) |
Render a UTF8 string with automatic text wrapping as a surface. More... | |
Drawable * | renderEllipseTexture (const unsigned int rx, const unsigned int ry, const unsigned int thick) |
Render an ellipse as a texture. More... | |
Drawable * | renderFilledEllipseTexture (const unsigned int rx, const unsigned int ry) |
Render a filled ellipse as a texture. More... | |
Drawable * | renderRectTexture (const int width, const int height, const unsigned int thick) |
Render a rectangle (outline) as a texture. More... | |
Drawable * | renderFilledRectTexture (const int width, const int height) |
Render a filled rectangle as a texture. More... | |
Drawable * | renderRoundRectTexture (const int width, const int height, const unsigned int radius, const unsigned int thick) |
Render an rounded rectangle (outline) as a texture. More... | |
Drawable * | renderFilledRoundRectTexture (const int width, const int height, const unsigned int radius) |
Render a filled rounded rectangle as a texture. More... | |
~Renderer () | |
Deletes the renderer object, but does not clean up the backend (SDL). See cleanup(). | |
Aether's main renderer instance. It provides all methods relating to drawing directly to the screen, rendering graphics to memory as well as measuring resource usage (with respect to textures).
std::pair<int, int> Aether::Renderer::calculateTextDimensions | ( | const std::string & | str, |
const unsigned int | size | ||
) |
Return the dimensions of the given string if rendered using the current font and given font size.
str | String to measure |
size | Font size to measure with |
std::tuple<std::vector<std::string>, int, int> Aether::Renderer::calculateWrappedTextDimensions | ( | const std::string & | str, |
const unsigned int | size, | ||
const unsigned int | width | ||
) |
Return the dimensions of the given string if rendered using the current font and given font size, as a text block.
str | String to measure |
size | Font size to measure with |
width | Maximum width of one line |
void Aether::Renderer::fillWindow | ( | const Colour & | col | ) |
Fill the window with the given colour.
col | Colour to fill the window with (can be transparent) |
bool Aether::Renderer::initialize | ( | const std::string & | name, |
const unsigned int | windowW, | ||
const unsigned int | windowH | ||
) |
Initialize the rendering backend.
name | Name of window |
windowW | Width of window to create |
windowH | Height of window to create |
unsigned int Aether::Renderer::memoryUsage | ( | ) |
Returns an approximated value for memory used by all rendered textures.
std::vector<Colour> Aether::Renderer::readSurfacePixels | ( | SDL_Surface * | surface | ) |
Returns the RGBA pixel data stored in the passed surface.
surface | Surface to read |
std::vector<Colour> Aether::Renderer::readTexturePixels | ( | SDL_Texture * | texture | ) |
Returns the RGBA pixel data stored in the passed surface.
texture | Texture to read |
Drawable* Aether::Renderer::renderEllipseTexture | ( | const unsigned int | rx, |
const unsigned int | ry, | ||
const unsigned int | thick | ||
) |
Render an ellipse as a texture.
rx | Radius along x dimension |
ry | Radius along y dimension |
thick | Thickness of outline |
Drawable* Aether::Renderer::renderFilledEllipseTexture | ( | const unsigned int | rx, |
const unsigned int | ry | ||
) |
Render a filled ellipse as a texture.
rx | Radius along x dimension |
ry | Radius along y dimension |
Drawable* Aether::Renderer::renderFilledRectTexture | ( | const int | width, |
const int | height | ||
) |
Render a filled rectangle as a texture.
width | Width of rectangle |
height | Height of rectangle |
Drawable* Aether::Renderer::renderFilledRoundRectTexture | ( | const int | width, |
const int | height, | ||
const unsigned int | radius | ||
) |
Render a filled rounded rectangle as a texture.
width | Width of rectangle |
height | Height of rectangle |
radius | Corner radius |
Drawable* Aether::Renderer::renderImageSurface | ( | const std::string & | path, |
const size_t | scaleWidth, | ||
const size_t | scaleHeight | ||
) |
Render the image at the specified path as a surface.
path | Path to image file |
scaleWidth | Width (in pixels) to scale image to (0 to disable scaling) |
scaleHeight | Height (in pixels) to scale image to (0 to disable scaling) |
Drawable* Aether::Renderer::renderImageSurface | ( | const std::vector< unsigned char > & | data, |
const size_t | scaleWidth, | ||
const size_t | scaleHeight | ||
) |
Render the image passed in the vector as a surface.
data | Vector containing image data |
scaleWidth | Width (in pixels) to scale image to (0 to disable scaling) |
scaleHeight | Height (in pixels) to scale image to (0 to disable scaling) |
Drawable* Aether::Renderer::renderRectTexture | ( | const int | width, |
const int | height, | ||
const unsigned int | thick | ||
) |
Render a rectangle (outline) as a texture.
width | Width of rectangle |
height | Height of rectangle |
thick | Thickness of outline |
Drawable* Aether::Renderer::renderRoundRectTexture | ( | const int | width, |
const int | height, | ||
const unsigned int | radius, | ||
const unsigned int | thick | ||
) |
Render an rounded rectangle (outline) as a texture.
width | Width of rectangle |
height | Height of rectangle |
radius | Corner radius |
thick | Thickness of outline |
Drawable* Aether::Renderer::renderTextSurface | ( | const std::string | str, |
const unsigned int | size | ||
) |
Render a UTF8 string as a surface.
str | String to render |
size | Font size to render text at |
Drawable* Aether::Renderer::renderWrappedTextSurface | ( | const std::string | str, |
const unsigned int | size, | ||
const unsigned int | width | ||
) |
Render a UTF8 string with automatic text wrapping as a surface.
str | String to render |
size | Font size to render text at |
width | Maximum width of one line |
void Aether::Renderer::setClipArea | ( | const int | x1, |
const int | y1, | ||
const int | x2, | ||
const int | y2 | ||
) |
Set the clipping area for rendered objects.
x1 | x value of top left corner |
y1 | y value of top left corner |
x2 | x value of bottom right corner |
y2 | y value of bottom right corner |
void Aether::Renderer::setFont | ( | const std::string & | path | ) |
Set the font used for text rendering from a file. Pass an empty string to revert to the default font.
path | Path to font file |
void Aether::Renderer::setFontSpacing | ( | const double | amt | ) |
Set the font spacing for wrapped text. Expects a multiplier for the line height. Defaults to 1.15.
amt | Amount of spacing for each line of wrapped text |
void Aether::Renderer::setLogHandler | ( | const LogHandler & | func | ) |
Sets the handler to be used for logging. Expects a function that is passed the log message as a string, and a boolean specifying if the message is 'important'. Note that this may be called extremely quickly depending on the circumstances.
func | The function to handle the provided log message, or nullptr to disable logging |
unsigned int Aether::Renderer::surfaceCount | ( | ) |
Returns the number of allocated 'surfaces' that haven't been destroyed.
unsigned int Aether::Renderer::textureCount | ( | ) |
Returns the number of allocated 'textures' that haven't been destroyed.
unsigned int Aether::Renderer::windowHeight | ( | ) |
Returns the height of the window.
unsigned int Aether::Renderer::windowWidth | ( | ) |
Returns the width of the window.