Debian Codegraph @

scene/2d/visible_on_screen_notifier_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* visible_on_screen_notifier_2d.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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 // TOOLS_ENABLED
63
64 #ifdef DEBUG_ENABLED
65 virtual Rect2 _edit_get_rect() const override;
66
67 virtual bool _edit_use_rect() const override;
68 #endif // DEBUG_ENABLED
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);