1 /*************************************************************************/ 2 /* visibility_notifier_2d.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ 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 #ifndef VISIBILITY_NOTIFIER_2D_H 31 #define VISIBILITY_NOTIFIER_2D_H 32 33 #include "scene/2d/node_2d.h" 34 35 class Viewport; 36 class VisibilityNotifier2D : public Node2D { 37 38 OBJ_TYPE(VisibilityNotifier2D, Node2D); 39 40 Set<Viewport *> viewports; 41 42 Rect2 rect; 43 44 protected: 45 friend class SpatialIndexer2D; 46 47 void _enter_viewport(Viewport *p_viewport); 48 void _exit_viewport(Viewport *p_viewport); 49 _screen_enter()50 virtual void _screen_enter() {} _screen_exit()51 virtual void _screen_exit() {} 52 53 void _notification(int p_what); 54 static void _bind_methods(); 55 56 public: 57 void set_rect(const Rect2 &p_rect); 58 Rect2 get_rect() const; 59 60 bool is_on_screen() const; 61 62 virtual Rect2 get_item_rect() const; 63 64 VisibilityNotifier2D(); 65 }; 66 67 class VisibilityEnabler2D : public VisibilityNotifier2D { 68 69 OBJ_TYPE(VisibilityEnabler2D, VisibilityNotifier2D); 70 71 public: 72 enum Enabler { 73 ENABLER_PAUSE_ANIMATIONS, 74 ENABLER_FREEZE_BODIES, 75 ENABLER_PAUSE_PARTICLES, 76 ENABLER_PARENT_PROCESS, 77 ENABLER_PARENT_FIXED_PROCESS, 78 ENABLER_PAUSE_ANIMATED_SPRITES, 79 ENABLER_MAX 80 }; 81 82 protected: 83 virtual void _screen_enter(); 84 virtual void _screen_exit(); 85 86 bool visible; 87 88 void _find_nodes(Node *p_node); 89 90 Map<Node *, Variant> nodes; 91 void _node_removed(Node *p_node); 92 bool enabler[ENABLER_MAX]; 93 94 void _change_node_state(Node *p_node, bool p_enabled); 95 96 void _notification(int p_what); 97 static void _bind_methods(); 98 99 public: 100 void set_enabler(Enabler p_enabler, bool p_enable); 101 bool is_enabler_enabled(Enabler p_enabler) const; 102 103 String get_configuration_warning() const; 104 105 VisibilityEnabler2D(); 106 }; 107 108 VARIANT_ENUM_CAST(VisibilityEnabler2D::Enabler); 109 110 #endif // VISIBILITY_NOTIFIER_2D_H 111