Fix some waterfall zoom navigation mistakes

This commit is contained in:
Charles J. Cliffe 2015-12-11 19:57:40 -05:00
parent fe25aaefdf
commit 7038652141
3 changed files with 19 additions and 11 deletions

View File

@ -53,6 +53,12 @@ long long InteractiveCanvas::getFrequencyAt(float x) {
return freq; 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) { void InteractiveCanvas::setCenterFrequency(long long center_freq_in) {
centerFreq = center_freq_in; centerFreq = center_freq_in;
} }

View File

@ -12,7 +12,8 @@ public:
~InteractiveCanvas(); ~InteractiveCanvas();
long long getFrequencyAt(float x); 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 setView(long long center_freq_in, int bandwidth_in);
virtual void disableView(); virtual void disableView();
bool getViewState(); bool getViewState();

View File

@ -182,9 +182,8 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
bw = minBandwidth; bw = minBandwidth;
} }
if (mouseInView) { if (mouseInView) {
long long mfreqA = getFrequencyAt(mpos); long long mfreqA = getFrequencyAt(mpos, centerFreq, getBandwidth());
setBandwidth(bw); long long mfreqB = getFrequencyAt(mpos, centerFreq, bw);
long long mfreqB = getFrequencyAt(mpos);
centerFreq += mfreqA - mfreqB; centerFreq += mfreqA - mfreqB;
} }
@ -198,12 +197,14 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
if (spectrumCanvas) { if (spectrumCanvas) {
spectrumCanvas->disableView(); spectrumCanvas->disableView();
} }
bw = wxGetApp().getSampleRate();
centerFreq = wxGetApp().getFrequency();
} else { } else {
if (mouseInView) { if (mouseInView) {
long long mfreqA = getFrequencyAt(mpos); long long mfreqA = getFrequencyAt(mpos, centerFreq, getBandwidth());
setBandwidth(bw); long long mfreqB = getFrequencyAt(mpos, centerFreq, bw);
long long mfreqB = getFrequencyAt(mpos);
centerFreq += mfreqA - mfreqB; centerFreq += mfreqA - mfreqB;
setBandwidth(bw);
} else { } else {
setBandwidth(bw); setBandwidth(bw);
} }
@ -822,11 +823,11 @@ void WaterfallCanvas::updateCenterFrequency(long long freq) {
long long minFreq = wxGetApp().getFrequency()-(wxGetApp().getSampleRate()/2); long long minFreq = wxGetApp().getFrequency()-(wxGetApp().getSampleRate()/2);
long long maxFreq = wxGetApp().getFrequency()+(wxGetApp().getSampleRate()/2); long long maxFreq = wxGetApp().getFrequency()+(wxGetApp().getSampleRate()/2);
if (freq < minFreq) { if (freq - bandwidth / 2 < minFreq) {
wxGetApp().setFrequency(freq+(wxGetApp().getSampleRate()/2)); wxGetApp().setFrequency(wxGetApp().getFrequency() - (minFreq - (freq - bandwidth/2)));
} }
if (freq > maxFreq) { if (freq + bandwidth / 2 > maxFreq) {
wxGetApp().setFrequency(freq-(wxGetApp().getSampleRate()/2)); wxGetApp().setFrequency(wxGetApp().getFrequency() + ((freq + bandwidth/2) - maxFreq));
} }
} else { } else {
if (spectrumCanvas) { if (spectrumCanvas) {