From 703865214133371fcb0fdb67870e0816db5171e4 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 11 Dec 2015 19:57:40 -0500 Subject: [PATCH] Fix some waterfall zoom navigation mistakes --- src/visual/InteractiveCanvas.cpp | 6 ++++++ src/visual/InteractiveCanvas.h | 3 ++- src/visual/WaterfallCanvas.cpp | 21 +++++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/visual/InteractiveCanvas.cpp b/src/visual/InteractiveCanvas.cpp index 9015de9..228277f 100644 --- a/src/visual/InteractiveCanvas.cpp +++ b/src/visual/InteractiveCanvas.cpp @@ -53,6 +53,12 @@ long long InteractiveCanvas::getFrequencyAt(float x) { return freq; } +long long InteractiveCanvas::getFrequencyAt(float x, long long iqCenterFreq, long long iqBandwidth) { + long long freq = iqCenterFreq - (long long)(0.5 * (long double) iqBandwidth) + ((long double) x * (long double) iqBandwidth); + + return freq; +} + void InteractiveCanvas::setCenterFrequency(long long center_freq_in) { centerFreq = center_freq_in; } diff --git a/src/visual/InteractiveCanvas.h b/src/visual/InteractiveCanvas.h index 28072cf..f310918 100644 --- a/src/visual/InteractiveCanvas.h +++ b/src/visual/InteractiveCanvas.h @@ -12,7 +12,8 @@ public: ~InteractiveCanvas(); long long getFrequencyAt(float x); - + long long getFrequencyAt(float x, long long iqCenterFreq, long long iqBandwidth); + virtual void setView(long long center_freq_in, int bandwidth_in); virtual void disableView(); bool getViewState(); diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 6f4ed05..da8302c 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -182,9 +182,8 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { bw = minBandwidth; } if (mouseInView) { - long long mfreqA = getFrequencyAt(mpos); - setBandwidth(bw); - long long mfreqB = getFrequencyAt(mpos); + long long mfreqA = getFrequencyAt(mpos, centerFreq, getBandwidth()); + long long mfreqB = getFrequencyAt(mpos, centerFreq, bw); centerFreq += mfreqA - mfreqB; } @@ -198,12 +197,14 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { if (spectrumCanvas) { spectrumCanvas->disableView(); } + bw = wxGetApp().getSampleRate(); + centerFreq = wxGetApp().getFrequency(); } else { if (mouseInView) { - long long mfreqA = getFrequencyAt(mpos); - setBandwidth(bw); - long long mfreqB = getFrequencyAt(mpos); + long long mfreqA = getFrequencyAt(mpos, centerFreq, getBandwidth()); + long long mfreqB = getFrequencyAt(mpos, centerFreq, bw); centerFreq += mfreqA - mfreqB; + setBandwidth(bw); } else { setBandwidth(bw); } @@ -822,11 +823,11 @@ void WaterfallCanvas::updateCenterFrequency(long long freq) { long long minFreq = wxGetApp().getFrequency()-(wxGetApp().getSampleRate()/2); long long maxFreq = wxGetApp().getFrequency()+(wxGetApp().getSampleRate()/2); - if (freq < minFreq) { - wxGetApp().setFrequency(freq+(wxGetApp().getSampleRate()/2)); + if (freq - bandwidth / 2 < minFreq) { + wxGetApp().setFrequency(wxGetApp().getFrequency() - (minFreq - (freq - bandwidth/2))); } - if (freq > maxFreq) { - wxGetApp().setFrequency(freq-(wxGetApp().getSampleRate()/2)); + if (freq + bandwidth / 2 > maxFreq) { + wxGetApp().setFrequency(wxGetApp().getFrequency() + ((freq + bandwidth/2) - maxFreq)); } } else { if (spectrumCanvas) {