1 /** 2 Detects approximately when the node is visible on screen. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.visibilitynotifier2d; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.node2d; 25 import godot.canvasitem; 26 import godot.node; 27 /** 28 Detects approximately when the node is visible on screen. 29 30 The VisibilityNotifier2D detects when it is visible on the screen. It also notifies when its bounding rectangle enters or exits the screen or a viewport. 31 If you want nodes to be disabled automatically when they exit the screen, use $(D VisibilityEnabler2D) instead. 32 $(B Note:) For performance reasons, VisibilityNotifier2D uses an approximate heuristic with precision determined by $(D ProjectSettings.world/2d/cellSize). If you need precise visibility checking, use another method such as adding an $(D Area2D) node as a child of a $(D Camera2D) node. 33 */ 34 @GodotBaseClass struct VisibilityNotifier2D 35 { 36 package(godot) enum string _GODOT_internal_name = "VisibilityNotifier2D"; 37 public: 38 @nogc nothrow: 39 union { /** */ godot_object _godot_object; /** */ Node2D _GODOT_base; } 40 alias _GODOT_base this; 41 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 42 package(godot) __gshared bool _classBindingInitialized = false; 43 package(godot) static struct GDNativeClassBinding 44 { 45 __gshared: 46 @GodotName("get_rect") GodotMethod!(Rect2) getRect; 47 @GodotName("is_on_screen") GodotMethod!(bool) isOnScreen; 48 @GodotName("set_rect") GodotMethod!(void, Rect2) setRect; 49 } 50 /// 51 pragma(inline, true) bool opEquals(in VisibilityNotifier2D other) const 52 { return _godot_object.ptr is other._godot_object.ptr; } 53 /// 54 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 55 { _godot_object.ptr = n; return null; } 56 /// 57 pragma(inline, true) bool opEquals(typeof(null) n) const 58 { return _godot_object.ptr is n; } 59 /// 60 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 61 mixin baseCasts; 62 /// Construct a new instance of VisibilityNotifier2D. 63 /// Note: use `memnew!VisibilityNotifier2D` instead. 64 static VisibilityNotifier2D _new() 65 { 66 static godot_class_constructor constructor; 67 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VisibilityNotifier2D"); 68 if(constructor is null) return typeof(this).init; 69 return cast(VisibilityNotifier2D)(constructor()); 70 } 71 @disable new(size_t s); 72 /** 73 74 */ 75 Rect2 getRect() const 76 { 77 checkClassBinding!(typeof(this))(); 78 return ptrcall!(Rect2)(GDNativeClassBinding.getRect, _godot_object); 79 } 80 /** 81 If `true`, the bounding rectangle is on the screen. 82 $(B Note:) It takes one frame for the node's visibility to be assessed once added to the scene tree, so this method will return `false` right after it is instantiated, even if it will be on screen in the draw pass. 83 */ 84 bool isOnScreen() const 85 { 86 checkClassBinding!(typeof(this))(); 87 return ptrcall!(bool)(GDNativeClassBinding.isOnScreen, _godot_object); 88 } 89 /** 90 91 */ 92 void setRect(in Rect2 rect) 93 { 94 checkClassBinding!(typeof(this))(); 95 ptrcall!(void)(GDNativeClassBinding.setRect, _godot_object, rect); 96 } 97 /** 98 The VisibilityNotifier2D's bounding rectangle. 99 */ 100 @property Rect2 rect() 101 { 102 return getRect(); 103 } 104 /// ditto 105 @property void rect(Rect2 v) 106 { 107 setRect(v); 108 } 109 }