lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
canvas.hpp
Go to the documentation of this file.
1
12
13#pragma once
14
16
17#include <glm/glm.hpp>
18#include <memory>
19#include <vector>
20
21namespace lmgl {
22
23namespace ui {
24
32class Canvas {
33 public:
40 Canvas(int width = 1920, int height = 1080);
41
45 ~Canvas() = default;
46
55 void resize(int width, int height);
56
62 void add_element(std::shared_ptr<UIElement> element);
63
69 void remove_element(std::shared_ptr<UIElement> element);
70
76 inline const std::vector<std::shared_ptr<UIElement>> &get_elements() const { return m_elements; }
77
84 void render();
85
93 inline const glm::mat4 &get_projection_matrix() const { return m_projection; }
94
100 inline int get_width() const { return m_width; }
101
107 inline int get_height() const { return m_height; }
108
114 inline void set_visible(bool visible) { m_visible = visible; }
115
121 inline bool is_visible() const { return m_visible; }
122
123 private:
125 int m_width;
126
128 int m_height;
129
131 glm::mat4 m_projection;
132
134 std::vector<std::shared_ptr<UIElement>> m_elements;
135
137 bool m_visible = true;
138
144 void update_projection();
145
151 void collect_render_items(std::vector<std::shared_ptr<UIElement>> &out_items);
152
159 void collect_element_recursive(const std::shared_ptr<UIElement> element,
160 std::vector<std::shared_ptr<UIElement>> &out_items);
161};
162
163} // namespace ui
164
165} // namespace lmgl
void set_visible(bool visible)
Set visibility of the entire canvas.
Definition canvas.hpp:114
void render()
Render all UI elements.
Definition canvas.cpp:36
~Canvas()=default
Destructor for Canvas.
void resize(int width, int height)
Resize the canvas to match window dimensions.
Definition canvas.cpp:15
const glm::mat4 & get_projection_matrix() const
Get the orthographic projection matrix.
Definition canvas.hpp:93
bool is_visible() const
Check if the canvas is visible.
Definition canvas.hpp:121
int get_height() const
Get the canvas height.
Definition canvas.hpp:107
Canvas(int width=1920, int height=1080)
Constructor for Canvas.
Definition canvas.cpp:13
void add_element(std::shared_ptr< UIElement > element)
Add a UI element to the canvas.
Definition canvas.cpp:21
int get_width() const
Get the canvas width.
Definition canvas.hpp:100
void remove_element(std::shared_ptr< UIElement > element)
Remove a UI element from the canvas.
Definition canvas.cpp:27
const std::vector< std::shared_ptr< UIElement > > & get_elements() const
Get all UI elements in the canvas.
Definition canvas.hpp:76
Definition button.cpp:15
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12
Base class for all UI elements.