29#include "container.hpp"
30#include "renderer.hpp"
41 static_assert(std::is_base_of<Renderer, RendererType>::value,
42 "RendererType must be derived from Renderer");
45 std::shared_ptr<RendererType> _renderer;
46 std::shared_ptr<Container> _root;
47 bool _running =
false;
58 void drawTree(
const std::shared_ptr<Component> &component) {
59 if (!_renderer || !component)
63 for (
const auto &primitive : component->getPrimitives()) {
64 _renderer->draw(primitive);
68 for (
const auto &child : component->getChildren()) {
80 _renderer = std::make_shared<RendererType>();
81 }
catch (std::exception &execption) {
82 std::cerr <<
"Failed to create renderer: " << execption.what()
84 throw std::runtime_error(
"Failed to create renderer");
98 std::shared_ptr<RendererType>
getRenderer(
void)
const {
return _renderer; }
105 std::shared_ptr<Container>
getRoot(
void)
const {
return _root; }
112 void setRoot(std::shared_ptr<Container> root) { _root = root; }
136 _renderer->present();
158 _renderer->present();
165 void stop(
void) { _running =
false; }
Entry point of the application.
void setRoot(std::shared_ptr< Container > root)
Sets the root container.
void stop(void)
Stop the application run loop (if managed externally).
std::shared_ptr< RendererType > getRenderer(void) const
Gets the renderer.
void drawTree(const std::shared_ptr< Component > &component)
Recursively draw the component tree using the renderer.
Application(void)
Constructs an Application object.
std::shared_ptr< Container > getRoot(void) const
Gets the root container.
~Application(void)=default
Destroys the Application object.
void update(void)
Updates the application state.
void run(void)
Runs the application.
Specialized component to group other components.