You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
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.
(cherry picked from commit eaae50fe4a)
This commit is contained in:
committed by
Rémi Verschelde
parent
74d10e766e
commit
5200ff03d2
@@ -2574,15 +2574,14 @@ void SpatialEditorViewport::_notification(int p_what) {
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture> icon) {
|
||||
|
||||
static void draw_indicator_bar(Control &surface, real_t fill, const Ref<Texture> 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
|
||||
@@ -2590,9 +2589,12 @@ static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture> icon)
|
||||
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 SpatialEditorViewport::_draw() {
|
||||
@@ -2696,7 +2698,14 @@ void SpatialEditorViewport::_draw() {
|
||||
if (logscale_t < 0.25)
|
||||
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
|
||||
|
||||
draw_indicator_bar(*surface, 1.0 - logscale_t, get_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_icon("ViewportSpeed", "EditorIcons"),
|
||||
get_font("font", "Label"),
|
||||
vformat("%s u/s", String::num(freelook_speed).pad_decimals(precision)));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -2714,7 +2723,14 @@ void SpatialEditorViewport::_draw() {
|
||||
if (logscale_t < 0.25)
|
||||
logscale_t = 0.25 * Math::exp(4.0 * logscale_t - 1.0);
|
||||
|
||||
draw_indicator_bar(*surface, logscale_t, get_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_icon("ViewportZoom", "EditorIcons"),
|
||||
get_font("font", "Label"),
|
||||
vformat("%s u", String::num(cursor.distance).pad_decimals(precision)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user