Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement snapping in the audio bus editor #32021

Merged
merged 1 commit into from
Sep 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions editor/editor_audio_buses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -376,14 +383,23 @@ 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
akien-mga marked this conversation as resolved.
Show resolved Hide resolved
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);

audio_value_preview_label->set_text(text);
Vector2 slider_size = slider->get_size();
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()) {
Expand Down