From 2b9f34b86711d5cab7c1bfb3bf21c30ada788c21 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sat, 4 Jan 2020 02:23:18 +0100 Subject: [PATCH] Add a crosshair to the 3D viewport The crosshair makes freelook navigation a bit easier, while making it clearer that it's possible to select nodes by clicking while in freelook mode. The crosshair is only displayed while in freelook mode. It uses an icon designed to be visible on any background. --- editor/icons/icon_crosshair.svg | 1 + editor/plugins/spatial_editor_plugin.cpp | 15 +++++++++++++++ editor/plugins/spatial_editor_plugin.h | 1 + 3 files changed, 17 insertions(+) create mode 100644 editor/icons/icon_crosshair.svg diff --git a/editor/icons/icon_crosshair.svg b/editor/icons/icon_crosshair.svg new file mode 100644 index 00000000000..b6fa5ec654b --- /dev/null +++ b/editor/icons/icon_crosshair.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 252f067eb17..31dce720db4 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2135,6 +2135,13 @@ 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(); @@ -2255,6 +2262,10 @@ 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"; @@ -3546,6 +3557,10 @@ 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 356646221ef..5cc2b24cbba 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -217,6 +217,7 @@ private: bool freelook_active; real_t freelook_speed; + TextureRect *crosshair; Label *info_label; Label *fps_label; Label *cinema_label;