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.
This commit is contained in:
Hugo Locurcio 2020-01-04 02:23:18 +01:00
parent 34c71157f0
commit 2b9f34b867
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
3 changed files with 17 additions and 0 deletions

View file

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m6 1v5h-5v1 3h5v5h4v-5h5v-4h-5v-5z" fill-opacity=".627451"/><path d="m2 7v2l5.0000803.0000197-.0000803 4.9999803h2l-.0000803-4.9999803 5.0000803-.0000197v-2l-5.0000803.0001803.0000803-5.0001803h-2l.0000803 5.0001803z" fill="#fefefe" fill-opacity=".862745"/></svg>

After

(image error) Size: 355 B

View file

@ -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);

View file

@ -217,6 +217,7 @@ private:
bool freelook_active;
real_t freelook_speed;
TextureRect *crosshair;
Label *info_label;
Label *fps_label;
Label *cinema_label;