2021-11-13 14:49:56 -05:00
|
|
|
/* /\ +--------------------------------------------------------------+
|
|
|
|
____/ \____ /| - zlib/MIT/Unlicenced game framework licensed to freely use, |
|
|
|
|
\ / / | copy, and modify without restriction |
|
|
|
|
+--\ ^__^ /--+ | |
|
|
|
|
| ~/ \~ | | - originally created at [http://nugget.fun] |
|
|
|
|
| ~~~~~~~~~~~~ | +--------------------------------------------------------------+
|
|
|
|
| SPACE ~~~~~ | /
|
|
|
|
| ~~~~~~~ BOX |/
|
|
|
|
+-------------*/
|
|
|
|
|
2021-11-09 23:30:27 -05:00
|
|
|
#ifndef SB_NODE_H_
|
|
|
|
#define SB_NODE_H_
|
2019-04-23 01:42:19 -04:00
|
|
|
|
2020-09-04 23:10:39 -04:00
|
|
|
#include <string>
|
2019-04-23 01:42:19 -04:00
|
|
|
#include <iostream>
|
2020-08-06 18:54:50 -04:00
|
|
|
#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"
|
|
|
|
|
2021-06-24 17:40:30 -04:00
|
|
|
class Game;
|
2021-11-09 23:30:27 -05:00
|
|
|
class Delegate;
|
|
|
|
class Input;
|
2021-06-26 20:25:03 -04:00
|
|
|
class Box;
|
2020-09-11 18:01:27 -04:00
|
|
|
struct Audio;
|
2019-04-23 01:42:19 -04:00
|
|
|
|
2021-11-19 14:13:37 -05:00
|
|
|
namespace sb
|
|
|
|
{
|
|
|
|
class Display;
|
|
|
|
}
|
|
|
|
|
2021-06-24 17:40:30 -04:00
|
|
|
class Node
|
2019-04-23 01:42:19 -04:00
|
|
|
{
|
|
|
|
|
2021-06-24 17:40:30 -04:00
|
|
|
public:
|
|
|
|
|
2019-05-02 06:45:41 -04:00
|
|
|
Node();
|
2020-07-21 01:09:34 -04:00
|
|
|
Node(Node*);
|
2020-07-13 00:53:12 -04:00
|
|
|
void set_parent(Node*);
|
2020-08-19 03:29:46 -04:00
|
|
|
virtual void reset() { deactivate(); }
|
|
|
|
virtual void activate() { active = true; }
|
|
|
|
virtual void deactivate() { active = false; }
|
2020-09-04 23:10:39 -04:00
|
|
|
void set_canvas(SDL_Texture*);
|
|
|
|
SDL_Texture* get_canvas();
|
2020-07-17 22:58:23 -04:00
|
|
|
bool is_active() const;
|
2022-06-16 16:45:41 -04:00
|
|
|
const nlohmann::json& configuration() const;
|
|
|
|
nlohmann::json& configuration();
|
2019-05-18 17:39:47 -04:00
|
|
|
Delegate& get_delegate();
|
2021-11-19 14:13:37 -05:00
|
|
|
const sb::Display& get_display() const;
|
2020-08-09 16:32:32 -04:00
|
|
|
const SDL_Renderer* get_renderer() const;
|
2020-08-06 18:54:50 -04:00
|
|
|
SDL_Renderer* get_renderer();
|
2022-06-16 16:45:41 -04:00
|
|
|
const SDL_Window* window() const;
|
|
|
|
SDL_Window* window();
|
2020-08-19 03:29:46 -04:00
|
|
|
const Input& get_input() const;
|
|
|
|
Input& get_input();
|
2020-09-11 18:01:27 -04:00
|
|
|
Audio& get_audio();
|
2020-08-09 16:32:32 -04:00
|
|
|
const Game* get_root() const;
|
2021-09-06 22:11:56 -04:00
|
|
|
Box window_box(bool = false);
|
2020-08-19 03:29:46 -04:00
|
|
|
void suppress_input();
|
2020-07-22 00:53:40 -04:00
|
|
|
void suppress_input_temporarily(int = 0);
|
2020-08-19 03:29:46 -04:00
|
|
|
void unsuppress_input();
|
2021-06-24 17:40:30 -04:00
|
|
|
const std::string get_branch_as_string() const;
|
2021-08-14 19:53:39 -04:00
|
|
|
virtual std::string class_name() const { return "Node"; };
|
2020-07-13 00:53:12 -04:00
|
|
|
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()
|
|
|
|
{
|
2020-09-04 23:10:39 -04:00
|
|
|
if (parent == nullptr)
|
2020-07-27 14:19:11 -04:00
|
|
|
{
|
|
|
|
return static_cast<T*>(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return parent->get_root<T>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-29 17:15:47 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
Node* parent;
|
|
|
|
std::shared_ptr<SDL_Texture> canvas;
|
|
|
|
bool active = true;
|
|
|
|
|
2019-04-23 01:42:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|