1 #ifndef AETHER_RENDERER_HPP 2 #define AETHER_RENDERER_HPP 4 #include "Aether/types/Colour.hpp" 37 typedef std::function<void(const std::string, const bool)>
LogHandler;
40 SDL_Renderer * renderer;
42 unsigned int windowWidth_;
43 unsigned int windowHeight_;
45 LogHandler logHandler;
46 std::atomic<unsigned long> memoryUsage_;
47 std::atomic<unsigned int> surfaceCount_;
48 std::atomic<unsigned int> textureCount_;
50 std::stack<SDL_Rect *> clipStack;
64 void logMessage(
const std::string & msg,
const bool imp);
74 SDL_Texture * convertSurfaceToTexture(SDL_Surface * surf);
83 SDL_Texture * createTexture(
const unsigned int width,
const unsigned int height);
91 void destroyTexture(SDL_Texture * tex,
const bool stats);
99 void destroySurface(SDL_Surface * surf,
const bool stats);
110 void drawFilledRect(
const Colour & col,
const int x,
const int y,
const int width,
const int height);
126 void drawTexture(SDL_Texture * tex,
const Colour & col,
const int x,
const int y,
const unsigned int width,
const unsigned int height,
const int maskX,
const int maskY,
const unsigned int maskW,
const unsigned int maskH);
135 void renderOnTexture(SDL_Texture * tex,
const std::function<
void(SDL_Renderer *)> & func);
145 SDL_Surface * scaleSurface(SDL_Surface * surface,
const size_t width,
const size_t height);
175 bool initialize(
const std::string & name,
const unsigned int windowW,
const unsigned int windowH);
244 void setClipArea(
const int x1,
const int y1,
const int x2,
const int y2);
253 void setFont(
const std::string & path);
284 std::tuple<std::vector<std::string>, int,
int>
calculateWrappedTextDimensions(
const std::string & str,
const unsigned int size,
const unsigned int width);
Drawable * renderEllipseTexture(const unsigned int rx, const unsigned int ry, const unsigned int thick)
Render an ellipse as a texture.
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...
Caches SDL_ttf font objects + surfaces to reduce rendering. This class is not thread-safe, all operations should be protected from the outside by a mutex.
Definition: FontCache.hpp:55
Drawable * renderFilledEllipseTexture(const unsigned int rx, const unsigned int ry)
Render a filled ellipse as a texture.
void setFontSpacing(const double amt)
Set the font spacing for wrapped text. Expects a multiplier for the line height. Defaults to 1...
Drawable * renderFilledRectTexture(const int width, const int height)
Render a filled rectangle as a texture.
void setLogHandler(const LogHandler &func)
Sets the handler to be used for logging. Expects a function that is passed the log message as a strin...
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...
std::function< void(const std::string, const bool)> LogHandler
Function to handle log messages.
Definition: Renderer.hpp:37
unsigned int windowWidth()
Returns the width of the window.
bool initialize(const std::string &name, const unsigned int windowW, const unsigned int windowH)
Initialize the rendering backend.
std::vector< Colour > readTexturePixels(SDL_Texture *texture)
Returns the RGBA pixel data stored in the passed surface.
Renderer()
Initializes the renderer object, but does not initialize the actual rendering backend (SDL)...
Aether's main renderer instance. It provides all methods relating to drawing directly to the screen...
Definition: Renderer.hpp:30
void setClipArea(const int x1, const int y1, const int x2, const int y2)
Set the clipping area for rendered objects.
std::vector< Colour > readSurfacePixels(SDL_Surface *surface)
Returns the RGBA pixel data stored in the passed surface.
void cleanup()
Clean up the rendering backend. This should always be called, even if initialization failed...
~Renderer()
Deletes the renderer object, but does not clean up the backend (SDL). See cleanup().
unsigned int textureCount()
Returns the number of allocated 'textures' that haven't been destroyed.
Stores RGBA values representing a colour. Each component can be within the range 0 to 255 (inclusive)...
Definition: Colour.hpp:9
Stores either a surface or texture which can be drawn on screen by providing a renderer to render()...
Definition: Drawable.hpp:22
void resetClipArea()
Reset the clipping area for rendered objects.
Drawable * renderRectTexture(const int width, const int height, const unsigned int thick)
Render a rectangle (outline) as a texture.
Drawable * renderTextSurface(const std::string str, const unsigned int size)
Render a UTF8 string as a surface.
Base namespace for all Aether related classes and functions.
unsigned int windowHeight()
Returns the height of the window.
unsigned int memoryUsage()
Returns an approximated value for memory used by all rendered textures.
void present()
Present all rendered graphics.
Drawable * renderImageSurface(const std::string &path, const size_t scaleWidth, const size_t scaleHeight)
Render the image at the specified path as a surface.
Drawable * renderFilledRoundRectTexture(const int width, const int height, const unsigned int radius)
Render a filled rounded rectangle as a texture.
unsigned int surfaceCount()
Returns the number of allocated 'surfaces' that haven't been destroyed.
Drawable * renderRoundRectTexture(const int width, const int height, const unsigned int radius, const unsigned int thick)
Render an rounded rectangle (outline) as a texture.
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.
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...
void fillWindow(const Colour &col)
Fill the window with the given colour.