Display freelook speed and zoom in units in the 3D editor viewport

Now that the 3D editor grid is infinite and adjusts its step automatically,
this helps people get a better sense of scale when moving around in the
3D viewport.

This also fixes the indicator bar drawing on hiDPI displays.
This commit is contained in:
Hugo Locurcio 2020-06-13 21:56:03 +02:00
parent 58034f3982
commit eaae50fe4a

View file

@ -2583,14 +2583,14 @@ void Node3DEditorViewport::_notification(int p_what) {
}
}
static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture2D> icon) {
static void draw_indicator_bar(Control &surface, real_t fill, const Ref<Texture2D> icon, const Ref<Font> font, const String &text) {
// Adjust bar size from control height
Vector2 surface_size = surface.get_size();
real_t h = surface_size.y / 2.0;
real_t y = (surface_size.y - h) / 2.0;
const Vector2 surface_size = surface.get_size();
const real_t h = surface_size.y / 2.0;
const real_t y = (surface_size.y - h) / 2.0;
Rect2 r(10, y, 6, h);
real_t sy = r.size.y * fill;
const Rect2 r(10 * EDSCALE, y, 6 * EDSCALE, h);
const real_t sy = r.size.y * fill;
// Note: because this bar appears over the viewport, it has to stay readable for any background color
// Draw both neutral dark and bright colors to account this
@ -2598,9 +2598,12 @@ static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture2D> ico
surface.draw_rect(Rect2(r.position.x, r.position.y + r.size.y - sy, r.size.x, sy), Color(1, 1, 1, 0.6));
surface.draw_rect(r.grow(1), Color(0, 0, 0, 0.7), false, Math::round(EDSCALE));
Vector2 icon_size = icon->get_size();
Vector2 icon_pos = Vector2(r.position.x - (icon_size.x - r.size.x) / 2, r.position.y + r.size.y + 2);
const Vector2 icon_size = icon->get_size();
const Vector2 icon_pos = Vector2(r.position.x - (icon_size.x - r.size.x) / 2, r.position.y + r.size.y + 2 * EDSCALE);
surface.draw_texture(icon, icon_pos);
// Draw text below the bar (for speed/zoom information).
surface.draw_string(font, Vector2(icon_pos.x, icon_pos.y + icon_size.y + 16 * EDSCALE), text);
}
void Node3DEditorViewport::_draw() {
@ -2697,7 +2700,14 @@ void Node3DEditorViewport::_draw() {
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
}
draw_indicator_bar(*surface, 1.0 - logscale_t, get_theme_icon("ViewportSpeed", "EditorIcons"));
// Display the freelook speed to help the user get a better sense of scale.
const int precision = freelook_speed < 1.0 ? 2 : 1;
draw_indicator_bar(
*surface,
1.0 - logscale_t,
get_theme_icon("ViewportSpeed", "EditorIcons"),
get_theme_font("font", "Label"),
vformat("%s u/s", String::num(freelook_speed).pad_decimals(precision)));
}
} else {
@ -2716,7 +2726,14 @@ void Node3DEditorViewport::_draw() {
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
}
draw_indicator_bar(*surface, logscale_t, get_theme_icon("ViewportZoom", "EditorIcons"));
// Display the zoom center distance to help the user get a better sense of scale.
const int precision = cursor.distance < 1.0 ? 2 : 1;
draw_indicator_bar(
*surface,
logscale_t,
get_theme_icon("ViewportZoom", "EditorIcons"),
get_theme_font("font", "Label"),
vformat("%s u", String::num(cursor.distance).pad_decimals(precision)));
}
}
}