diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-08-24 10:29:27 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2018-08-24 10:30:11 -0300 |
commit | 683c3f2fcf0d9ade35e3f2ef180d42e35f800ad6 (patch) | |
tree | 119a75fd1ed2129945c667042c9410c909bb8281 /scene | |
parent | cd945e28def309222abdb2fdc057a0913abde4b8 (diff) |
Avoid misuse of set_drag_preview() function where it shouldn't be. Closes #20100
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/control.cpp | 1 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 11 | ||||
-rw-r--r-- | scene/main/viewport.h | 3 |
3 files changed, 15 insertions, 0 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index c784ec1756..e094a063be 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -769,6 +769,7 @@ void Control::force_drag(const Variant &p_data, Control *p_control) { void Control::set_drag_preview(Control *p_control) { ERR_FAIL_COND(!is_inside_tree()); + ERR_FAIL_COND(get_viewport()->gui_is_dragging()); get_viewport()->_gui_set_drag_preview(this, p_control); } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index b6d0a0caa8..d1b3eb9d9a 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -185,6 +185,7 @@ public: Viewport::GUI::GUI() { + dragging = false; mouse_focus = NULL; mouse_click_grabber = NULL; mouse_focus_button = -1; @@ -1718,6 +1719,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } gui.drag_data = Variant(); + gui.dragging = false; if (gui.drag_preview) { memdelete(gui.drag_preview); @@ -1747,6 +1749,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { } gui.drag_data = Variant(); + gui.dragging = false; _propagate_viewport_notification(this, NOTIFICATION_DRAG_END); //change mouse accordingly } @@ -1809,10 +1812,13 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { Control *control = Object::cast_to<Control>(ci); if (control) { + gui.dragging = true; gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum); if (gui.drag_data.get_type() != Variant::NIL) { gui.mouse_focus = NULL; + } else { + gui.dragging = false; } if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) @@ -2252,6 +2258,7 @@ void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control * ERR_EXPLAIN("Drag data must be a value"); ERR_FAIL_COND(p_data.get_type() == Variant::NIL); + gui.dragging = true; gui.drag_data = p_data; gui.mouse_focus = NULL; @@ -2691,6 +2698,9 @@ bool Viewport::is_snap_controls_to_pixels_enabled() const { return snap_controls_to_pixels; } +bool Viewport::gui_is_dragging() const { + return gui.dragging; +} void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_arvr", "use"), &Viewport::set_use_arvr); @@ -2777,6 +2787,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack); ClassDB::bind_method(D_METHOD("gui_get_drag_data"), &Viewport::gui_get_drag_data); + ClassDB::bind_method(D_METHOD("gui_is_dragging"), &Viewport::gui_is_dragging); ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input); ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index e4ef373c77..450f235b79 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -274,6 +274,7 @@ private: bool roots_order_dirty; List<Control *> roots; int canvas_sort_index; //for sorting items with canvas as root + bool dragging; GUI(); } gui; @@ -474,6 +475,8 @@ public: void _subwindow_visibility_changed(); + bool gui_is_dragging() const; + Viewport(); ~Viewport(); }; |