summaryrefslogtreecommitdiffstats
path: root/editor/plugins/node_3d_editor_plugin.cpp
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2020-06-17 20:02:46 +0200
committerHugo Locurcio <hugo.locurcio@hugo.pro>2020-06-17 20:02:46 +0200
commit4a542e0007b6288ca328eafe5819e58b92bbad15 (patch)
tree9c4e89584853b9492c5027305a681dba6c60f453 /editor/plugins/node_3d_editor_plugin.cpp
parentd341181f30b4f2e154748911f5d8a59b43aa6e62 (diff)
downloadredot-engine-4a542e0007b6288ca328eafe5819e58b92bbad15.tar.gz
Restore previous mouse position when leaving the editor freelook mode
- Remove the crosshair as it no longer serves a purpose (the cursor will now appear where the user "expects" it to). This closes https://github.com/godotengine/godot-proposals/issues/1076.
Diffstat (limited to 'editor/plugins/node_3d_editor_plugin.cpp')
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp22
1 files changed, 7 insertions, 15 deletions
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 7bf8fd7d26..975957d56c 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -2174,6 +2174,8 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) {
freelook_speed = base_speed * cursor.distance;
}
+ previous_mouse_position = get_local_mouse_position();
+
// Hide mouse like in an FPS (warping doesn't work)
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
@@ -2183,6 +2185,11 @@ void Node3DEditorViewport::set_freelook_active(bool active_now) {
// Restore mouse
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
+
+ // Restore the previous mouse position when leaving freelook mode.
+ // This is done because leaving `Input.MOUSE_MODE_CAPTURED` will center the cursor
+ // due to OS limitations.
+ warp_mouse(previous_mouse_position);
}
freelook_active = active_now;
@@ -2341,13 +2348,6 @@ void Node3DEditorViewport::_notification(int p_what) {
call_deferred("update_transform_gizmo_view");
}
- if (p_what == NOTIFICATION_READY) {
- // The crosshair icon doesn't depend on the editor theme.
- crosshair->set_texture(get_theme_icon("Crosshair", "EditorIcons"));
- // Set the anchors and margins after changing the icon to ensure it's centered correctly.
- crosshair->set_anchors_and_margins_preset(PRESET_CENTER);
- }
-
if (p_what == NOTIFICATION_PROCESS) {
real_t delta = get_process_delta_time();
@@ -2473,10 +2473,6 @@ void Node3DEditorViewport::_notification(int p_what) {
current_camera = camera;
}
- // Display the crosshair only while freelooking. Hide it otherwise,
- // as the crosshair can be distracting.
- crosshair->set_visible(freelook_active);
-
if (show_info) {
String text;
text += "X: " + rtos(current_camera->get_translation().x).pad_decimals(1) + "\n";
@@ -3866,10 +3862,6 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito
camera->make_current();
surface->set_focus_mode(FOCUS_ALL);
- crosshair = memnew(TextureRect);
- crosshair->set_mouse_filter(MOUSE_FILTER_IGNORE);
- surface->add_child(crosshair);
-
VBoxContainer *vbox = memnew(VBoxContainer);
surface->add_child(vbox);
vbox->set_position(Point2(10, 10) * EDSCALE);