mirror of
https://github.com/godotengine/godot.git
synced 2024-12-15 10:12:40 +08:00
Merge pull request #100259 from Sauermann/proposal-right-click-cancel-drag
Allow canceling drag-and-drop with right mouse button
This commit is contained in:
commit
2b41a217d2
@ -1742,6 +1742,11 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
|
||||
if (mb.is_valid()) {
|
||||
Point2 mpos = mb->get_position();
|
||||
if (mb->is_pressed()) {
|
||||
if (gui.dragging && mb->get_button_index() == MouseButton::RIGHT) {
|
||||
_perform_drop();
|
||||
set_input_as_handled();
|
||||
return;
|
||||
}
|
||||
MouseButtonMask button_mask = mouse_button_to_mask(mb->get_button_index());
|
||||
if (!gui.mouse_focus_mask.is_empty() && !gui.mouse_focus_mask.has_flag(button_mask)) {
|
||||
// Do not steal mouse focus and stuff while a focus mask without the current mouse button exists.
|
||||
|
@ -1341,8 +1341,8 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") {
|
||||
SEND_GUI_MOUSE_MOTION_EVENT(on_d, MouseButtonMask::NONE, Key::NONE);
|
||||
|
||||
// Force Drop doesn't get triggered by mouse Buttons other than LMB.
|
||||
SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
|
||||
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::RIGHT, MouseButtonMask::NONE, Key::NONE);
|
||||
SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::MIDDLE, MouseButtonMask::MIDDLE, Key::NONE);
|
||||
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::MIDDLE, MouseButtonMask::NONE, Key::NONE);
|
||||
CHECK(root->gui_is_dragging());
|
||||
|
||||
// Force Drop with LMB-Down.
|
||||
@ -1351,6 +1351,15 @@ TEST_CASE("[SceneTree][Viewport] Controls and InputEvent handling") {
|
||||
CHECK(root->gui_is_drag_successful());
|
||||
|
||||
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_d, MouseButton::LEFT, MouseButtonMask::NONE, Key::NONE);
|
||||
|
||||
node_a->force_drag(SNAME("Drag Data"), nullptr);
|
||||
CHECK(root->gui_is_dragging());
|
||||
|
||||
// Cancel with RMB.
|
||||
SEND_GUI_MOUSE_BUTTON_EVENT(on_d, MouseButton::RIGHT, MouseButtonMask::RIGHT, Key::NONE);
|
||||
CHECK_FALSE(root->gui_is_dragging());
|
||||
CHECK_FALSE(root->gui_is_drag_successful());
|
||||
SEND_GUI_MOUSE_BUTTON_RELEASED_EVENT(on_a, MouseButton::RIGHT, MouseButtonMask::NONE, Key::NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user