mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Merge pull request #100874 from Lazy-Rabbit-2001/visible-on-screen-rect
Optimize usability of VisibleOnScreenNotifier2D
This commit is contained in:
commit
55cb380c3f
3 changed files with 47 additions and 2 deletions
|
|
@ -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"));
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class VisibleOnScreenNotifier2D : public Node2D {
|
|||
HashSet<Viewport *> viewports;
|
||||
|
||||
Rect2 rect;
|
||||
bool show_rect = true;
|
||||
|
||||
private:
|
||||
bool on_screen = false;
|
||||
|
|
@ -54,13 +55,23 @@ protected:
|
|||
|
||||
public:
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual Dictionary _edit_get_state() const override;
|
||||
virtual void _edit_set_state(const Dictionary &p_state) override;
|
||||
|
||||
virtual Vector2 _edit_get_minimum_size() const override { return Vector2(); }
|
||||
|
||||
virtual void _edit_set_rect(const Rect2 &p_edit_rect) override;
|
||||
virtual Rect2 _edit_get_rect() const override;
|
||||
|
||||
virtual bool _edit_use_rect() const override;
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void set_rect(const Rect2 &p_rect);
|
||||
Rect2 get_rect() const;
|
||||
|
||||
void set_show_rect(bool p_show_rect);
|
||||
bool is_showing_rect() const;
|
||||
|
||||
bool is_on_screen() const;
|
||||
|
||||
VisibleOnScreenNotifier2D();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue