|
@@ -31,12 +31,28 @@
|
|
|
#include "visible_on_screen_notifier_2d.h"
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
+Dictionary VisibleOnScreenNotifier2D::_edit_get_state() const {
|
|
|
+ Dictionary state = Node2D::_edit_get_state();
|
|
|
+ state["rect"] = rect;
|
|
|
+ return state;
|
|
|
+}
|
|
|
+
|
|
|
+void VisibleOnScreenNotifier2D::_edit_set_state(const Dictionary &p_state) {
|
|
|
+ ERR_FAIL_COND(p_state.is_empty() || !p_state.has("rect"));
|
|
|
+ set_rect(p_state["rect"]);
|
|
|
+ Node2D::_edit_set_state(p_state);
|
|
|
+}
|
|
|
+
|
|
|
+void VisibleOnScreenNotifier2D::_edit_set_rect(const Rect2 &p_edit_rect) {
|
|
|
+ set_rect(p_edit_rect);
|
|
|
+}
|
|
|
+
|
|
|
Rect2 VisibleOnScreenNotifier2D::_edit_get_rect() const {
|
|
|
return rect;
|
|
|
}
|
|
|
|
|
|
bool VisibleOnScreenNotifier2D::_edit_use_rect() const {
|
|
|
- return true;
|
|
|
+ return show_rect;
|
|
|
}
|
|
|
#endif // DEBUG_ENABLED
|
|
|
|
|
@@ -71,6 +87,18 @@ Rect2 VisibleOnScreenNotifier2D::get_rect() const {
|
|
|
return rect;
|
|
|
}
|
|
|
|
|
|
+void VisibleOnScreenNotifier2D::set_show_rect(bool p_show_rect) {
|
|
|
+ if (show_rect == p_show_rect) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ show_rect = p_show_rect;
|
|
|
+ queue_redraw();
|
|
|
+}
|
|
|
+
|
|
|
+bool VisibleOnScreenNotifier2D::is_showing_rect() const {
|
|
|
+ return show_rect;
|
|
|
+}
|
|
|
+
|
|
|
void VisibleOnScreenNotifier2D::_notification(int p_what) {
|
|
|
switch (p_what) {
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
@@ -79,7 +107,7 @@ void VisibleOnScreenNotifier2D::_notification(int p_what) {
|
|
|
} break;
|
|
|
|
|
|
case NOTIFICATION_DRAW: {
|
|
|
- if (Engine::get_singleton()->is_editor_hint()) {
|
|
|
+ if (show_rect && Engine::get_singleton()->is_editor_hint()) {
|
|
|
draw_rect(rect, Color(1, 0.5, 1, 0.2));
|
|
|
}
|
|
|
} break;
|
|
@@ -98,9 +126,12 @@ bool VisibleOnScreenNotifier2D::is_on_screen() const {
|
|
|
void VisibleOnScreenNotifier2D::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("set_rect", "rect"), &VisibleOnScreenNotifier2D::set_rect);
|
|
|
ClassDB::bind_method(D_METHOD("get_rect"), &VisibleOnScreenNotifier2D::get_rect);
|
|
|
+ ClassDB::bind_method(D_METHOD("set_show_rect", "show_rect"), &VisibleOnScreenNotifier2D::set_show_rect);
|
|
|
+ ClassDB::bind_method(D_METHOD("is_showing_rect"), &VisibleOnScreenNotifier2D::is_showing_rect);
|
|
|
ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibleOnScreenNotifier2D::is_on_screen);
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect", PROPERTY_HINT_NONE, "suffix:px"), "set_rect", "get_rect");
|
|
|
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_rect"), "set_show_rect", "is_showing_rect");
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("screen_entered"));
|
|
|
ADD_SIGNAL(MethodInfo("screen_exited"));
|