diff options
-rw-r--r-- | editor/editor_audio_buses.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 05b5fa7905..31095b1100 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -31,6 +31,7 @@ #include "editor_audio_buses.h" #include "core/io/resource_saver.h" +#include "core/os/input.h" #include "core/os/keyboard.h" #include "editor_node.h" #include "filesystem_dock.h" @@ -321,7 +322,13 @@ void EditorAudioBus::_volume_changed(float p_normalized) { updating_bus = true; - float p_db = this->_normalized_volume_to_scaled_db(p_normalized); + const float p_db = this->_normalized_volume_to_scaled_db(p_normalized); + + if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + // Snap the value when holding Ctrl for easier editing. + // To do so, it needs to be converted back to normalized volume (as the slider uses that unit). + slider->set_value(_scaled_db_to_normalized_volume(Math::round(p_db))); + } UndoRedo *ur = EditorNode::get_undo_redo(); ur->create_action(TTR("Change Audio Bus Volume"), UndoRedo::MERGE_ENDS); @@ -376,7 +383,16 @@ float EditorAudioBus::_scaled_db_to_normalized_volume(float db) { } void EditorAudioBus::_show_value(float slider_value) { - String text = vformat("%10.1f dB", _normalized_volume_to_scaled_db(slider_value)); + + float db; + if (Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { + // Display the correct (snapped) value when holding Ctrl + db = Math::round(_normalized_volume_to_scaled_db(slider_value)); + } else { + db = _normalized_volume_to_scaled_db(slider_value); + } + + String text = vformat("%10.1f dB", db); slider->set_tooltip(text); audio_value_preview_label->set_text(text); @@ -384,7 +400,7 @@ void EditorAudioBus::_show_value(float slider_value) { Vector2 slider_position = slider->get_global_position(); float left_padding = 5.0f; float vert_padding = 10.0f; - Vector2 box_position = Vector2(slider_size.x + left_padding, (slider_size.y - vert_padding) * (1.0f - slider_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_size(audio_value_preview_label->get_size()); if (slider->has_focus() && !audio_value_preview_box->is_visible()) { |