diff --git a/editor/icons/icon_crosshair.svg b/editor/icons/icon_crosshair.svg deleted file mode 100644 index b6fa5ec654b..00000000000 --- a/editor/icons/icon_crosshair.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 571d52564b2..88983e419f7 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2189,6 +2189,8 @@ void SpatialEditorViewport::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); @@ -2198,6 +2200,11 @@ void SpatialEditorViewport::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; @@ -2359,13 +2366,6 @@ void SpatialEditorViewport::_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_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(); @@ -2489,10 +2489,6 @@ void SpatialEditorViewport::_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"; @@ -3846,10 +3842,6 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed 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); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index c0b4cdadf8c..e977b8ed4c2 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -266,8 +266,8 @@ private: bool freelook_active; real_t freelook_speed; + Vector2 previous_mouse_position; - TextureRect *crosshair; Label *info_label; Label *cinema_label; Label *locked_label;