spacebox/src/Node.hpp

76 lines
1.6 KiB
C++
Raw Normal View History

2019-04-23 01:42:19 -04:00
#ifndef Node_h_
#define Node_h_
#include <string>
2019-04-23 01:42:19 -04:00
#include <iostream>
#include "glm/vec2.hpp"
2019-05-04 03:25:35 -04:00
#include "json/json.hpp"
2019-05-03 02:09:48 -04:00
#include "SDL.h"
2019-05-02 06:45:41 -04:00
#include "filesystem.hpp"
class Game;
2019-05-03 02:09:48 -04:00
struct Delegate;
2019-05-07 03:33:54 -04:00
struct Display;
struct Input;
2021-06-26 20:25:03 -04:00
class Box;
struct Audio;
2019-04-23 01:42:19 -04:00
class Node
2019-04-23 01:42:19 -04:00
{
public:
Node *parent;
SDL_Texture* canvas = nullptr;
2020-07-21 01:09:34 -04:00
bool active = true;
2019-04-23 01:42:19 -04:00
2019-05-02 06:45:41 -04:00
Node();
2020-07-21 01:09:34 -04:00
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;
2019-05-04 03:25:35 -04:00
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();
2020-07-22 00:53:40 -04:00
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();
2019-04-23 01:42:19 -04:00
2020-07-27 14:19:11 -04:00
template<typename T = Game>
T* get_root()
{
if (parent == nullptr)
2020-07-27 14:19:11 -04:00
{
return static_cast<T*>(this);
}
else
{
return parent->get_root<T>();
}
}
2019-04-23 01:42:19 -04:00
};
#endif