spacebox/src/Node.hpp

76 lines
1.6 KiB
C++

#ifndef Node_h_
#define Node_h_
#include <string>
#include <iostream>
#include "glm/vec2.hpp"
#include "json/json.hpp"
#include "SDL.h"
#include "filesystem.hpp"
class Game;
struct Delegate;
struct Display;
struct Input;
class Box;
struct Audio;
class Node
{
public:
Node *parent;
SDL_Texture* canvas = nullptr;
bool active = true;
Node();
Node(Node*);
void set_parent(Node*);
virtual void reset() { deactivate(); }
virtual void activate() { active = true; }
virtual void deactivate() { active = false; }
void set_canvas(SDL_Texture*);
SDL_Texture* get_canvas();
bool is_active() const;
const nlohmann::json& get_configuration() const;
nlohmann::json& get_configuration();
Delegate& get_delegate();
const Display& get_display() const;
const SDL_Renderer* get_renderer() const;
SDL_Renderer* get_renderer();
const SDL_Window* get_window() const;
SDL_Window* get_window();
const Input& get_input() const;
Input& get_input();
Audio& get_audio();
const Game* get_root() const;
Box get_window_box();
void suppress_input();
void suppress_input_temporarily(int = 0);
void unsuppress_input();
void log(const std::string&) const;
void debug(const std::string&) const;
const std::string get_branch_as_string() const;
virtual std::string get_class_name() const { return "Node"; };
virtual ~Node();
template<typename T = Game>
T* get_root()
{
if (parent == nullptr)
{
return static_cast<T*>(this);
}
else
{
return parent->get_root<T>();
}
}
};
#endif