spacebox/src/Node.hpp

115 lines
2.6 KiB
C++
Raw Normal View History

/* +------------------------------------------------------+
____/ \____ /| - Open source game framework licensed to freely use, |
\ / / | copy, modify and sell without restriction |
+--\ ^__^ /--+ | |
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
| ~~~~~~~~~~~~ | +------------------------------------------------------+
| SPACE ~~~~~ | /
| ~~~~~~~ BOX |/
+-------------*/
#pragma once
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;
namespace sb
{
class Delegate;
}
class Input;
2021-06-26 20:25:03 -04:00
class Box;
class Configuration;
struct Audio;
2019-04-23 01:42:19 -04:00
namespace sb
{
class Display;
}
/*!
* @deprecated Use an alternative to this class if possible because it will be removed soon. Global access to functionality in
* this class should instead go through the Game class directly.
*/
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; }
bool is_active() const;
const Configuration& configuration() const;
Configuration& configuration();
/*!
* @return const reference to the Delegate object
*/
const sb::Delegate& delegate() const;
/*!
* @return the Delegate object
*/
sb::Delegate& delegate();
/*!
* @deprecated use Node::delegate
*/
sb::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();
void suppress_input_temporarily(float length = 0.0f);
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;
bool active = true;
2019-04-23 01:42:19 -04:00
};
/* Add Node class to the sb namespace. This should be the default location, but Node is left in the global namespace
* for backward compatibility. */
namespace sb
{
using ::Node;
}