summaryrefslogtreecommitdiff
path: root/editor/plugins/node_3d_editor_plugin.cpp
diff options
context:
space:
mode:
authorJFonS <joan.fonssanchez@gmail.com>2020-04-28 16:41:01 +0200
committerJFonS <joan.fonssanchez@gmail.com>2020-05-07 19:19:54 +0200
commit051f02a3a096f46f332b2cb8b7849b12b9c80c41 (patch)
treeade8a4027b4c27261c7552ae6782376175dfdb33 /editor/plugins/node_3d_editor_plugin.cpp
parentb62218bbac6f4d5f534e667aeaa361c4e746ef27 (diff)
Keep mouse inside 3D viewport rotation widget
Hide and keep the mouse in place when the user oribts the scene via the 3D rotation widget.
Diffstat (limited to 'editor/plugins/node_3d_editor_plugin.cpp')
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 55b50f526c..ead3813734 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -51,7 +51,6 @@
#include "scene/gui/subviewport_container.h"
#include "scene/resources/packed_scene.h"
#include "scene/resources/surface_tool.h"
-#include "servers/display_server.h"
#define DISTANCE_DEFAULT 4
@@ -196,12 +195,20 @@ void ViewportRotationControl::_gui_input(Ref<InputEvent> p_event) {
_update_focus();
}
orbiting = false;
+ if (Input::get_singleton()->get_mouse_mode() == Input::MOUSE_MODE_CAPTURED) {
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
+ Input::get_singleton()->warp_mouse_position(orbiting_mouse_start);
+ }
}
}
const Ref<InputEventMouseMotion> mm = p_event;
if (mm.is_valid()) {
if (orbiting) {
+ if (Input::get_singleton()->get_mouse_mode() == Input::MOUSE_MODE_VISIBLE) {
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
+ orbiting_mouse_start = mm->get_global_position();
+ }
viewport->_nav_orbit(mm, viewport->_get_warped_mouse_motion(mm));
focused_axis = -1;
} else {
@@ -2210,14 +2217,14 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) {
}
// Hide mouse like in an FPS (warping doesn't work)
- DisplayServer::get_singleton()->mouse_set_mode(DisplayServer::MOUSE_MODE_CAPTURED);
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
} else if (freelook_active && !active_now) {
// Sync camera cursor to cursor to "cut" interpolation jumps due to changing referential
cursor = camera_cursor;
// Restore mouse
- DisplayServer::get_singleton()->mouse_set_mode(DisplayServer::MOUSE_MODE_VISIBLE);
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
}
freelook_active = active_now;