mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 20:23:53 +00:00
Avoid misuse of set_drag_preview() function where it shouldn't be. Closes #20100
This commit is contained in:
parent
cd945e28de
commit
683c3f2fcf
@ -769,6 +769,7 @@ void Control::force_drag(const Variant &p_data, Control *p_control) {
|
|||||||
void Control::set_drag_preview(Control *p_control) {
|
void Control::set_drag_preview(Control *p_control) {
|
||||||
|
|
||||||
ERR_FAIL_COND(!is_inside_tree());
|
ERR_FAIL_COND(!is_inside_tree());
|
||||||
|
ERR_FAIL_COND(get_viewport()->gui_is_dragging());
|
||||||
get_viewport()->_gui_set_drag_preview(this, p_control);
|
get_viewport()->_gui_set_drag_preview(this, p_control);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +185,7 @@ public:
|
|||||||
|
|
||||||
Viewport::GUI::GUI() {
|
Viewport::GUI::GUI() {
|
||||||
|
|
||||||
|
dragging = false;
|
||||||
mouse_focus = NULL;
|
mouse_focus = NULL;
|
||||||
mouse_click_grabber = NULL;
|
mouse_click_grabber = NULL;
|
||||||
mouse_focus_button = -1;
|
mouse_focus_button = -1;
|
||||||
@ -1718,6 +1719,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gui.drag_data = Variant();
|
gui.drag_data = Variant();
|
||||||
|
gui.dragging = false;
|
||||||
|
|
||||||
if (gui.drag_preview) {
|
if (gui.drag_preview) {
|
||||||
memdelete(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.drag_data = Variant();
|
||||||
|
gui.dragging = false;
|
||||||
_propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
|
_propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
|
||||||
//change mouse accordingly
|
//change mouse accordingly
|
||||||
}
|
}
|
||||||
@ -1809,10 +1812,13 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
|||||||
Control *control = Object::cast_to<Control>(ci);
|
Control *control = Object::cast_to<Control>(ci);
|
||||||
if (control) {
|
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);
|
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) {
|
if (gui.drag_data.get_type() != Variant::NIL) {
|
||||||
|
|
||||||
gui.mouse_focus = NULL;
|
gui.mouse_focus = NULL;
|
||||||
|
} else {
|
||||||
|
gui.dragging = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
|
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_EXPLAIN("Drag data must be a value");
|
||||||
ERR_FAIL_COND(p_data.get_type() == Variant::NIL);
|
ERR_FAIL_COND(p_data.get_type() == Variant::NIL);
|
||||||
|
|
||||||
|
gui.dragging = true;
|
||||||
gui.drag_data = p_data;
|
gui.drag_data = p_data;
|
||||||
gui.mouse_focus = NULL;
|
gui.mouse_focus = NULL;
|
||||||
|
|
||||||
@ -2691,6 +2698,9 @@ bool Viewport::is_snap_controls_to_pixels_enabled() const {
|
|||||||
return snap_controls_to_pixels;
|
return snap_controls_to_pixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Viewport::gui_is_dragging() const {
|
||||||
|
return gui.dragging;
|
||||||
|
}
|
||||||
void Viewport::_bind_methods() {
|
void Viewport::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_use_arvr", "use"), &Viewport::set_use_arvr);
|
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_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_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("set_disable_input", "disable"), &Viewport::set_disable_input);
|
||||||
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);
|
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);
|
||||||
|
@ -274,6 +274,7 @@ private:
|
|||||||
bool roots_order_dirty;
|
bool roots_order_dirty;
|
||||||
List<Control *> roots;
|
List<Control *> roots;
|
||||||
int canvas_sort_index; //for sorting items with canvas as root
|
int canvas_sort_index; //for sorting items with canvas as root
|
||||||
|
bool dragging;
|
||||||
|
|
||||||
GUI();
|
GUI();
|
||||||
} gui;
|
} gui;
|
||||||
@ -474,6 +475,8 @@ public:
|
|||||||
|
|
||||||
void _subwindow_visibility_changed();
|
void _subwindow_visibility_changed();
|
||||||
|
|
||||||
|
bool gui_is_dragging() const;
|
||||||
|
|
||||||
Viewport();
|
Viewport();
|
||||||
~Viewport();
|
~Viewport();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user