Merge pull request #49310 from foxydevloper/add-drag-threshold-select-mode

Prevent accidental drags by adding drag distance threshold
This commit is contained in:
Rémi Verschelde 2021-06-15 15:34:28 +02:00 committed by GitHub
commit 9f8d892e4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 15 deletions

View file

@ -2292,6 +2292,24 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
// Start dragging
if (still_selected) {
// Drag the node(s) if requested
drag_start_origin = click;
drag_type = DRAG_QUEUED;
}
// Select the item
return true;
}
}
}
if (drag_type == DRAG_QUEUED) {
if (b.is_valid() && !b->is_pressed()) {
drag_type = DRAG_NONE;
return true;
}
if (m.is_valid()) {
Point2 click = transform.affine_inverse().xform(m->get_position());
bool movement_threshold_passed = drag_start_origin.distance_to(click) > 10 * EDSCALE;
if (m.is_valid() && movement_threshold_passed) {
List<CanvasItem *> selection2 = _get_edited_canvas_items();
drag_selection.clear();
@ -2306,8 +2324,6 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
drag_from = click;
_save_canvas_item_state(drag_selection);
}
}
// Select the item
return true;
}
}

View file

@ -206,6 +206,7 @@ private:
DRAG_ANCHOR_BOTTOM_RIGHT,
DRAG_ANCHOR_BOTTOM_LEFT,
DRAG_ANCHOR_ALL,
DRAG_QUEUED,
DRAG_MOVE,
DRAG_MOVE_X,
DRAG_MOVE_Y,
@ -379,6 +380,7 @@ private:
Control *top_ruler;
Control *left_ruler;
Point2 drag_start_origin;
DragType drag_type;
Point2 drag_from;
Point2 drag_to;

View file

@ -1244,6 +1244,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
_edit.mouse_pos = b->get_position();
_edit.original_mouse_pos = b->get_position();
_edit.snap = spatial_editor->is_snap_enabled();
_edit.mode = TRANSFORM_NONE;
@ -1450,7 +1451,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
} else if (nav_scheme == NAVIGATION_MODO && m->is_alt_pressed()) {
nav_mode = NAVIGATION_ORBIT;
} else {
if (clicked.is_valid()) {
bool movement_threshold_passed = _edit.original_mouse_pos.distance_to(_edit.mouse_pos) > 10 * EDSCALE;
if (clicked.is_valid() && movement_threshold_passed) {
if (!clicked_includes_current) {
_select_clicked(clicked_wants_append, true);
// Processing was deferred.

View file

@ -387,6 +387,7 @@ private:
Vector3 orig_gizmo_pos;
int edited_gizmo = 0;
Point2 mouse_pos;
Point2 original_mouse_pos;
bool snap = false;
Ref<EditorNode3DGizmo> gizmo;
int gizmo_handle = 0;