| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
|
| 35 |
class Viewport; |
| 36 |
class VisibleOnScreenNotifier2D : public Node2D { |
| 37 |
GDCLASS(VisibleOnScreenNotifier2D, Node2D); |
| 38 |
|
| 39 |
Rect2 rect; |
| 40 |
bool show_rect = true; |
| 41 |
|
| 42 |
private: |
| 43 |
bool on_screen = false; |
| 44 |
void _visibility_enter(); |
| 45 |
void _visibility_exit(); |
| 46 |
|
| 47 |
protected: |
| 48 |
virtual void _screen_enter() {} |
| 49 |
virtual void _screen_exit() {} |
| 50 |
|
| 51 |
void _notification(int p_what); |
| 52 |
static void _bind_methods(); |
| 53 |
|
| 54 |
public: |
| 55 |
#ifdef TOOLS_ENABLED |
| 56 |
virtual Dictionary _edit_get_state() const override; |
| 57 |
virtual void _edit_set_state(const Dictionary &p_state) override; |
| 58 |
|
| 59 |
virtual Vector2 _edit_get_minimum_size() const override { return Vector2(); } |
| 60 |
|
| 61 |
virtual void _edit_set_rect(const Rect2 &p_edit_rect) override; |
| 62 |
#endif |
| 63 |
|
| 64 |
#ifdef DEBUG_ENABLED |
| 65 |
virtual Rect2 _edit_get_rect() const override; |
| 66 |
|
| 67 |
virtual bool _edit_use_rect() const override; |
| 68 |
#endif |
| 69 |
|
| 70 |
void set_rect(const Rect2 &p_rect); |
| 71 |
Rect2 get_rect() const; |
| 72 |
|
| 73 |
void set_show_rect(bool p_show_rect); |
| 74 |
bool is_showing_rect() const; |
| 75 |
|
| 76 |
bool is_on_screen() const; |
| 77 |
|
| 78 |
VisibleOnScreenNotifier2D(); |
| 79 |
}; |
| 80 |
|
| 81 |
class VisibleOnScreenEnabler2D : public VisibleOnScreenNotifier2D { |
| 82 |
GDCLASS(VisibleOnScreenEnabler2D, VisibleOnScreenNotifier2D); |
| 83 |
|
| 84 |
public: |
| 85 |
enum EnableMode { |
| 86 |
ENABLE_MODE_INHERIT, |
| 87 |
ENABLE_MODE_ALWAYS, |
| 88 |
ENABLE_MODE_WHEN_PAUSED, |
| 89 |
}; |
| 90 |
|
| 91 |
protected: |
| 92 |
ObjectID node_id; |
| 93 |
virtual void _screen_enter() override; |
| 94 |
virtual void _screen_exit() override; |
| 95 |
|
| 96 |
EnableMode enable_mode = ENABLE_MODE_INHERIT; |
| 97 |
NodePath enable_node_path = NodePath(".."); |
| 98 |
|
| 99 |
void _notification(int p_what); |
| 100 |
static void _bind_methods(); |
| 101 |
|
| 102 |
void _update_enable_mode(bool p_enable); |
| 103 |
|
| 104 |
public: |
| 105 |
void set_enable_mode(EnableMode p_mode); |
| 106 |
EnableMode get_enable_mode(); |
| 107 |
|
| 108 |
void set_enable_node_path(NodePath p_path); |
| 109 |
NodePath get_enable_node_path(); |
| 110 |
|
| 111 |
VisibleOnScreenEnabler2D(); |
| 112 |
}; |
| 113 |
|
| 114 |
VARIANT_ENUM_CAST(VisibleOnScreenEnabler2D::EnableMode); |