summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorfox <12120644+foxydevloper@users.noreply.github.com>2021-06-04 11:39:46 -0400
committerfox <12120644+foxydevloper@users.noreply.github.com>2021-06-04 11:39:46 -0400
commit00a4ee5cf387b1060ba9e2b300e29cec6623e07a (patch)
tree79b8b44b9c4d21ccf90028c9b357f1b7980aa59d /editor/plugins
parent766c6dbb24c736eb1e24ca69eb15398eac654c2c (diff)
Add threshold to dragging nodes with select to prevent accidental drags
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp40
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h2
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp4
-rw-r--r--editor/plugins/node_3d_editor_plugin.h1
4 files changed, 34 insertions, 13 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 2be586733b..fe8036b95b 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -2556,22 +2556,38 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) {
// Start dragging
if (still_selected) {
// Drag the node(s) if requested
- List<CanvasItem *> selection2 = _get_edited_canvas_items();
+ drag_start_origin = click;
+ drag_type = DRAG_QUEUED;
+ }
+ // Select the item
+ return true;
+ }
+ }
+ }
- drag_selection.clear();
- for (int i = 0; i < selection2.size(); i++) {
- if (_is_node_movable(selection2[i], true)) {
- drag_selection.push_back(selection2[i]);
- }
- }
+ 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();
- if (selection2.size() > 0) {
- drag_type = DRAG_MOVE;
- drag_from = click;
- _save_canvas_item_state(drag_selection);
+ drag_selection.clear();
+ for (int i = 0; i < selection2.size(); i++) {
+ if (_is_node_movable(selection2[i], true)) {
+ drag_selection.push_back(selection2[i]);
}
}
- // Select the item
+
+ if (selection2.size() > 0) {
+ drag_type = DRAG_MOVE;
+ drag_from = click;
+ _save_canvas_item_state(drag_selection);
+ }
return true;
}
}
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 21ef3f88df..61f416d54a 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -209,6 +209,7 @@ private:
DRAG_ANCHOR_BOTTOM_RIGHT,
DRAG_ANCHOR_BOTTOM_LEFT,
DRAG_ANCHOR_ALL,
+ DRAG_QUEUED,
DRAG_MOVE,
DRAG_MOVE_X,
DRAG_MOVE_Y,
@@ -384,6 +385,7 @@ private:
Control *top_ruler;
Control *left_ruler;
+ Point2 drag_start_origin;
DragType drag_type;
Point2 drag_from;
Point2 drag_to;
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index dbda020346..2a714a1aae 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -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.
diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h
index 186e97fd15..1083ef54b2 100644
--- a/editor/plugins/node_3d_editor_plugin.h
+++ b/editor/plugins/node_3d_editor_plugin.h
@@ -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;