1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Improve the audio bus editor appearance

- Use the editor font color for notch lines and text instead of a more
  contrasted color.
- Reuse the editor theme's tooltip styling and apply it on theme change.
- Make the preview label display an explicit `+` sign for positive values.
- Prevent a zero value from displaying as `-0.0 dB` instead of `0.0 dB`.
- Scale notch lines on hiDPI displays.

(cherry picked from commit 534c990e41)
This commit is contained in:
Hugo Locurcio
2021-05-27 09:58:44 +02:00
committed by Rémi Verschelde
parent 93d157d213
commit d71077f463
2 changed files with 31 additions and 24 deletions

View File

@@ -173,6 +173,9 @@ void EditorAudioBus::_notification(int p_what) {
bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons")); bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
bus_options->set_icon(get_icon("GuiTabMenuHl", "EditorIcons")); bus_options->set_icon(get_icon("GuiTabMenuHl", "EditorIcons"));
audio_value_preview_box->add_color_override("font_color", get_color("font_color", "TooltipLabel"));
audio_value_preview_box->add_style_override("panel", get_stylebox("panel", "TooltipPanel"));
} break; } break;
case NOTIFICATION_MOUSE_EXIT: case NOTIFICATION_MOUSE_EXIT:
case NOTIFICATION_DRAG_END: { case NOTIFICATION_DRAG_END: {
@@ -379,15 +382,24 @@ void EditorAudioBus::_show_value(float slider_value) {
db = _normalized_volume_to_scaled_db(slider_value); db = _normalized_volume_to_scaled_db(slider_value);
} }
String text = vformat("%10.1f dB", db); String text;
if (Math::is_zero_approx(Math::stepify(db, 0.1))) {
// Prevent displaying `-0.0 dB` and show ` 0.0 dB` instead.
// The leading space makes the text visually line up with its positive/negative counterparts.
text = " 0.0 dB";
} else {
// Show an explicit `+` sign if positive.
text = vformat("%+.1f dB", db);
}
// Also set the preview text as a standard Control tooltip.
// This way, it can be seen when the slider is merely hovered (instead of dragged).
slider->set_tooltip(text); slider->set_tooltip(text);
audio_value_preview_label->set_text(text); audio_value_preview_label->set_text(text);
Vector2 slider_size = slider->get_size(); const Vector2 slider_size = slider->get_size();
Vector2 slider_position = slider->get_global_position(); const Vector2 slider_position = slider->get_global_position();
float left_padding = 5.0f; const float vert_padding = 10.0f;
float vert_padding = 10.0f; const Vector2 box_position = Vector2(slider_size.x, (slider_size.y - vert_padding) * (1.0f - slider->get_value()) - vert_padding);
Vector2 box_position = Vector2(slider_size.x + left_padding, (slider_size.y - vert_padding) * (1.0f - slider->get_value()) - vert_padding);
audio_value_preview_box->set_position(slider_position + box_position); audio_value_preview_box->set_position(slider_position + box_position);
audio_value_preview_box->set_size(audio_value_preview_label->get_size()); audio_value_preview_box->set_size(audio_value_preview_label->get_size());
if (slider->has_focus() && !audio_value_preview_box->is_visible()) { if (slider->has_focus() && !audio_value_preview_box->is_visible()) {
@@ -818,7 +830,7 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
bus_options = memnew(MenuButton); bus_options = memnew(MenuButton);
bus_options->set_h_size_flags(SIZE_SHRINK_END); bus_options->set_h_size_flags(SIZE_SHRINK_END);
bus_options->set_anchor(MARGIN_RIGHT, 0.0); bus_options->set_anchor(MARGIN_RIGHT, 0.0);
bus_options->set_tooltip(TTR("Bus options")); bus_options->set_tooltip(TTR("Bus Options"));
hbc->add_child(bus_options); hbc->add_child(bus_options);
Ref<StyleBoxEmpty> sbempty = memnew(StyleBoxEmpty); Ref<StyleBoxEmpty> sbempty = memnew(StyleBoxEmpty);
@@ -853,14 +865,13 @@ EditorAudioBus::EditorAudioBus(EditorAudioBuses *p_buses, bool p_is_master) {
audio_value_preview_label->set_v_size_flags(SIZE_EXPAND_FILL); audio_value_preview_label->set_v_size_flags(SIZE_EXPAND_FILL);
audio_value_preview_label->set_h_size_flags(SIZE_EXPAND_FILL); audio_value_preview_label->set_h_size_flags(SIZE_EXPAND_FILL);
audio_value_preview_label->set_mouse_filter(MOUSE_FILTER_PASS); audio_value_preview_label->set_mouse_filter(MOUSE_FILTER_PASS);
audio_value_preview_box->add_color_override("font_color", get_color("font_color", "TooltipLabel"));
audioprev_hbc->add_child(audio_value_preview_label); audioprev_hbc->add_child(audio_value_preview_label);
slider->add_child(audio_value_preview_box); slider->add_child(audio_value_preview_box);
audio_value_preview_box->set_as_toplevel(true); audio_value_preview_box->set_as_toplevel(true);
Ref<StyleBoxFlat> panel_style = memnew(StyleBoxFlat); audio_value_preview_box->add_style_override("panel", get_stylebox("panel", "TooltipPanel"));
panel_style->set_bg_color(Color(0.0f, 0.0f, 0.0f, 0.8f));
audio_value_preview_box->add_style_override("panel", panel_style);
audio_value_preview_box->set_mouse_filter(MOUSE_FILTER_PASS); audio_value_preview_box->set_mouse_filter(MOUSE_FILTER_PASS);
audio_value_preview_box->hide(); audio_value_preview_box->hide();
@@ -1427,7 +1438,7 @@ void EditorAudioMeterNotches::_bind_methods() {
void EditorAudioMeterNotches::_notification(int p_what) { void EditorAudioMeterNotches::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(0, 0, 0); notch_color = get_color("font_color", "Editor");
} break; } break;
case NOTIFICATION_DRAW: { case NOTIFICATION_DRAW: {
_draw_audio_notches(); _draw_audio_notches();
@@ -1442,13 +1453,13 @@ void EditorAudioMeterNotches::_draw_audio_notches() {
for (int i = 0; i < notches.size(); i++) { for (int i = 0; i < notches.size(); i++) {
AudioNotch n = notches[i]; AudioNotch n = notches[i];
draw_line(Vector2(0, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding), draw_line(Vector2(0, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
Vector2(line_length, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding), Vector2(line_length * EDSCALE, (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + top_padding),
notch_color, notch_color,
1); Math::round(EDSCALE));
if (n.render_db_value) { if (n.render_db_value) {
draw_string(font, draw_string(font,
Vector2(line_length + label_space, Vector2((line_length + label_space) * EDSCALE,
(1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + (font_height / 4) + top_padding), (1.0f - n.relative_position) * (get_size().y - btm_padding - top_padding) + (font_height / 4) + top_padding),
String::num(Math::abs(n.db_value)) + "dB", String::num(Math::abs(n.db_value)) + "dB",
notch_color); notch_color);
@@ -1456,10 +1467,6 @@ void EditorAudioMeterNotches::_draw_audio_notches() {
} }
} }
EditorAudioMeterNotches::EditorAudioMeterNotches() : EditorAudioMeterNotches::EditorAudioMeterNotches() {
line_length(5.0f), notch_color = get_color("font_color", "Editor");
label_space(2.0f),
btm_padding(9.0f),
top_padding(5.0f) {
notch_color = EditorSettings::get_singleton()->is_dark_theme() ? Color(1, 1, 1) : Color(0, 0, 0);
} }

View File

@@ -244,10 +244,10 @@ private:
List<AudioNotch> notches; List<AudioNotch> notches;
public: public:
float line_length; const float line_length = 5.0f;
float label_space; const float label_space = 2.0f;
float btm_padding; const float btm_padding = 9.0f;
float top_padding; const float top_padding = 5.0f;
Color notch_color; Color notch_color;
void add_notch(float p_normalized_offset, float p_db_value, bool p_render_value = false); void add_notch(float p_normalized_offset, float p_db_value, bool p_render_value = false);