From 012903fbf478d32a0beeec93f9b9b81ca041dd40 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Mon, 30 Aug 2021 19:22:00 +0200 Subject: [PATCH] Fixed wrong bandwidth when zooming --- core/src/core.cpp | 2 +- core/src/gui/main_window.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/core.cpp b/core/src/core.cpp index 2c2f7baf..0a880528 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -78,7 +78,7 @@ namespace core { gui::waterfall.setViewOffset(0); gui::waterfall.setViewBandwidth(effectiveSr); sigpath::signalPath.setSampleRate(effectiveSr); - gui::mainWindow.setViewBandwidthSlider(effectiveSr); + gui::mainWindow.setViewBandwidthSlider(1.0); } }; diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index d99ffba3..103b2a7c 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -176,7 +176,7 @@ void MainWindow::init() { gui::freqSelect.frequencyChanged = false; sigpath::sourceManager.tune(frequency); gui::waterfall.setCenterFrequency(frequency); - bw = gui::waterfall.getBandwidth(); + bw = 1.0; gui::waterfall.vfoFreqChanged = false; gui::waterfall.centerFreqMoved = false; gui::waterfall.selectFirstVFO(); @@ -598,12 +598,14 @@ void MainWindow::draw() { ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.0) - (ImGui::CalcTextSize("Zoom").x / 2.0)); ImGui::Text("Zoom"); ImGui::SetCursorPosX((ImGui::GetWindowSize().x / 2.0) - 10); - float minSliderBw = 1000.0; - float maxSliderBw = gui::waterfall.getBandwidth(); - if (ImGui::VSliderFloat("##_7_", ImVec2(20.0, 150.0), &bw, maxSliderBw, minSliderBw, "")) { - float normBw = bw / (maxSliderBw - minSliderBw); - float factor = normBw * normBw; - float finalBw = minSliderBw + bw * factor; + if (ImGui::VSliderFloat("##_7_", ImVec2(20.0, 150.0), &bw, 1.0, 0.0, "")) { + double factor = (double)bw * (double)bw; + + // Map 0.0 -> 1.0 to 1000.0 -> bandwidth + double delta = gui::waterfall.getBandwidth() - 1000.0; + double finalBw = 1000.0 + (factor * delta); + + spdlog::warn("{0} {1} {2}", bw, factor, finalBw); gui::waterfall.setViewBandwidth(finalBw); if (vfo != NULL) {