diff --git a/src/demod/DemodulatorMgr.cpp b/src/demod/DemodulatorMgr.cpp index 55b7219..1384d61 100644 --- a/src/demod/DemodulatorMgr.cpp +++ b/src/demod/DemodulatorMgr.cpp @@ -97,3 +97,23 @@ void DemodulatorMgr::terminateAll() { std::vector &DemodulatorMgr::getDemodulators() { return demods; } + +std::vector *DemodulatorMgr::getDemodulatorsAt(int freq, int bandwidth) { + std::vector *foundDemods = new std::vector(); + + for (int i = 0, iMax = demods.size(); i < iMax; i++) { + DemodulatorInstance *testDemod = demods[i]; + + int freqTest = testDemod->getParams().frequency; + int bandwidthTest = testDemod->getParams().bandwidth; + int halfBandwidthTest = bandwidthTest / 2; + + int halfBuffer = bandwidth / 2; + + if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) { + foundDemods->push_back(testDemod); + } + } + + return foundDemods; +} diff --git a/src/demod/DemodulatorMgr.h b/src/demod/DemodulatorMgr.h index a39289e..9bcfbd2 100644 --- a/src/demod/DemodulatorMgr.h +++ b/src/demod/DemodulatorMgr.h @@ -37,6 +37,7 @@ public: DemodulatorInstance *newThread(); std::vector &getDemodulators(); + std::vector *getDemodulatorsAt(int freq, int bandwidth); void terminateAll(); private: diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index d763541..8b9cfca 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -29,7 +29,7 @@ wxEND_EVENT_TABLE() WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, - wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), bwChange(false), demodBW(0) { + wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), bwChange(false), demodBW(0), hoveredDemod(-1) { int in_block_size = BUF_SIZE / 2; int out_block_size = FFT_SIZE; @@ -54,6 +54,14 @@ WaterfallCanvas::~WaterfallCanvas() { } +int WaterfallCanvas::GetFrequencyAt(float x) { + + int center_freq = wxGetApp().getFrequency(); + int freq = center_freq - (int) (0.5 * (float) SRATE) + (int) ((float) x * (float) SRATE); + + return freq; +} + void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this); const wxSize ClientSize = GetClientSize(); @@ -64,15 +72,25 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { glContext->BeginDraw(); glContext->Draw(spectrum_points); - std::vector *demods = &wxGetApp().getDemodMgr().getDemodulators(); - - for (int i = 0, iMax = demods->size(); i < iMax; i++) { - glContext->DrawDemod((*demods)[i]); - } + std::vector &demods = wxGetApp().getDemodMgr().getDemodulators(); if (mTracker.mouseInView()) { - glContext->DrawFreqSelector(mTracker.getMouseX(),0,1,0); + + if (hoveredDemod == -1) { + glContext->DrawFreqSelector(mTracker.getMouseX(), 0, 1, 0); + } else { + glContext->DrawDemod(demods[hoveredDemod],1,1,0); + } } + + + for (int i = 0, iMax = demods.size(); i < iMax; i++) { + if (hoveredDemod == i) { + continue; + } + glContext->DrawDemod(demods[i]); + } + glContext->EndDraw(); SwapBuffers(); @@ -225,6 +243,33 @@ void WaterfallCanvas::mouseMoved(wxMouseEvent& event) { // wxString::Format(wxT("Set center frequency: %s"), // wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep))); // } + } else { + + int hovered = -1; + int nearest = -1; + int near_dist = SRATE; + + int freqPos = GetFrequencyAt(mTracker.getMouseX()); + + std::vector *demodsHover = wxGetApp().getDemodMgr().getDemodulatorsAt(freqPos, 15000); + + if (demodsHover->size()) { + for (int i = 0, iMax = demodsHover->size(); i < iMax; i++) { + DemodulatorInstance *hoverDemod = (*demodsHover)[i]; + + int dist = abs(hoverDemod->getParams().frequency-freqPos); + + if (dist < near_dist) { + nearest = i; + } + } + + hovered = nearest; + } + + hoveredDemod = hovered; + + delete demodsHover; } } @@ -269,6 +314,7 @@ void WaterfallCanvas::mouseReleased(wxMouseEvent& event) { void WaterfallCanvas::mouseLeftWindow(wxMouseEvent& event) { mTracker.OnMouseLeftWindow(event); SetCursor(wxCURSOR_CROSS); + hoveredDemod = -1; } void WaterfallCanvas::mouseEnterWindow(wxMouseEvent& event) { diff --git a/src/visual/WaterfallCanvas.h b/src/visual/WaterfallCanvas.h index 7d27f35..1e03525 100644 --- a/src/visual/WaterfallCanvas.h +++ b/src/visual/WaterfallCanvas.h @@ -18,6 +18,8 @@ public: ~WaterfallCanvas(); void setData(std::vector *data); + int GetFrequencyAt(float x); + private: void OnPaint(wxPaintEvent& event); void OnKeyDown(wxKeyEvent& event); @@ -50,6 +52,7 @@ private: MouseTracker mTracker; bool bwChange; int demodBW; + int hoveredDemod; // event table wxDECLARE_EVENT_TABLE(); diff --git a/src/visual/WaterfallContext.cpp b/src/visual/WaterfallContext.cpp index e7fd6f3..3d3509d 100644 --- a/src/visual/WaterfallContext.cpp +++ b/src/visual/WaterfallContext.cpp @@ -82,7 +82,7 @@ void WaterfallContext::Draw(std::vector &points) { } -void WaterfallContext::DrawDemod(DemodulatorInstance *demod) { +void WaterfallContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) { if (!demod) { return; } @@ -94,7 +94,7 @@ void WaterfallContext::DrawDemod(DemodulatorInstance *demod) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); - glColor4f(1.0, 1.0, 1.0, 0.6); + glColor4f(r, g, b, 0.6); glBegin(GL_LINES); glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0); @@ -111,7 +111,7 @@ void WaterfallContext::DrawDemod(DemodulatorInstance *demod) { glEnd(); glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); - glColor4f(1.0, 1.0, 1.0, 0.2); + glColor4f(r, g, b, 0.2); glBegin(GL_QUADS); glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); @@ -125,7 +125,7 @@ void WaterfallContext::DrawDemod(DemodulatorInstance *demod) { } -void WaterfallContext::DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1) { +void WaterfallContext::DrawFreqSelector(float uxPos, float r, float g, float b) { DemodulatorInstance *demod = wxGetApp().getDemodTest(); if (!demod) { diff --git a/src/visual/WaterfallContext.h b/src/visual/WaterfallContext.h index 74db958..bf0a23d 100644 --- a/src/visual/WaterfallContext.h +++ b/src/visual/WaterfallContext.h @@ -14,8 +14,8 @@ public: void BeginDraw(); void Draw(std::vector &points); - void DrawFreqSelector(float uxPos, float r, float g, float b); - void DrawDemod(DemodulatorInstance *demod); + void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1); + void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1); void EndDraw(); private: