|
lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
|
Canvas for rendering 2D UI elements. More...
#include <canvas.hpp>
Public Member Functions | |
| Canvas (int width=1920, int height=1080) | |
| Constructor for Canvas. | |
| ~Canvas ()=default | |
| Destructor for Canvas. | |
| void | resize (int width, int height) |
| Resize the canvas to match window dimensions. | |
| void | add_element (std::shared_ptr< UIElement > element) |
| Add a UI element to the canvas. | |
| void | remove_element (std::shared_ptr< UIElement > element) |
| Remove a UI element from the canvas. | |
| const std::vector< std::shared_ptr< UIElement > > & | get_elements () const |
| Get all UI elements in the canvas. | |
| void | render () |
| Render all UI elements. | |
| const glm::mat4 & | get_projection_matrix () const |
| Get the orthographic projection matrix. | |
| int | get_width () const |
| Get the canvas width. | |
| int | get_height () const |
| Get the canvas height. | |
| void | set_visible (bool visible) |
| Set visibility of the entire canvas. | |
| bool | is_visible () const |
| Check if the canvas is visible. | |
Canvas for rendering 2D UI elements.
The Canvas class provides a 2D rendering surface that sits on top of the 3D world. It manages orthographic projection, automatic window resizing, blending for transparency, and proper render ordering of UI elements.
| lmgl::ui::Canvas::Canvas | ( | int | width = 1920, |
| int | height = 1080 ) |
Constructor for Canvas.
| width | Initial width of the canvas in pixels. |
| height | Initial height of the canvas in pixels. |
| void lmgl::ui::Canvas::add_element | ( | std::shared_ptr< UIElement > | element | ) |
Add a UI element to the canvas.
| element | Shared pointer to the UI element. |
|
inline |
Get all UI elements in the canvas.
|
inline |
Get the canvas height.
|
inline |
Get the orthographic projection matrix.
Maps pixels (0, 0) to (width, height) to normalized device coordinates (-1, -1) to (1, 1).
|
inline |
Get the canvas width.
|
inline |
Check if the canvas is visible.
| void lmgl::ui::Canvas::remove_element | ( | std::shared_ptr< UIElement > | element | ) |
Remove a UI element from the canvas.
| element | Shared pointer to the UI element. |
| void lmgl::ui::Canvas::render | ( | ) |
Render all UI elements.
Enables blending, sets up orthographic projection, and renders all UI elements in back-to-front order based on their render order.
| void lmgl::ui::Canvas::resize | ( | int | width, |
| int | height ) |
Resize the canvas to match window dimensions.
Updates the orthographic projection matrix to match the new dimensions.
| width | New width in pixels. |
| height | New height in pixels. |
|
inline |
Set visibility of the entire canvas.
| visible | True to show, false to hide. |