spacebox/src/Node.hpp

89 lines
2.2 KiB
C++
Raw Normal View History

/* /\ +--------------------------------------------------------------+
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
\ / / | copy, and modify without restriction |
+--\ ^__^ /--+ | |
| ~/ \~ | | - originally created at [http://nugget.fun] |
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+-------------*/
#ifndef SB_NODE_H_
#define SB_NODE_H_
2019-04-23 01:42:19 -04:00
#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"
2021-10-02 19:21:07 -04:00
#include "Log.hpp"
2019-05-02 06:45:41 -04:00
#include "filesystem.hpp"
class Game;
class Delegate;
class Input;
2021-06-26 20:25:03 -04:00
class Box;
struct Audio;
2019-04-23 01:42:19 -04:00
namespace sb
{
class Display;
}
class Node
2019-04-23 01:42:19 -04:00
{
public:
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& configuration() const;
nlohmann::json& configuration();
Delegate& get_delegate();
const sb::Display& get_display() const;
const SDL_Renderer* get_renderer() const;
SDL_Renderer* get_renderer();
const SDL_Window* window() const;
SDL_Window* window();
const Input& get_input() const;
Input& get_input();
Audio& get_audio();
const Game* get_root() const;
2021-09-06 22:11:56 -04:00
Box window_box(bool = false);
void suppress_input();
2020-07-22 00:53:40 -04:00
void suppress_input_temporarily(int = 0);
void unsuppress_input();
const std::string get_branch_as_string() const;
virtual std::string 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>();
}
}
private:
Node* parent;
std::shared_ptr<SDL_Texture> canvas;
bool active = true;
2019-04-23 01:42:19 -04:00
};
#endif