From 10a4e391d7ba17ee091cf6aad88188bcafe53c5f Mon Sep 17 00:00:00 2001 From: vsonnier Date: Sun, 11 Mar 2018 08:14:44 +0100 Subject: [PATCH] Fix #630 improvement on Zoom(s) functions: - Right-drag now does the same thing on both Spectrum and Waterfall, i.e change and hold vertical scale, - So Right-drag on Waterfall no longer zoom bandwidth, there are already much more practical ways to do it (up/down, wheel) - Right-click to reset vertical scale stays only enabled on Spectrum. - Adapted mouse cursors to reflect the possible moves on Spectrum and Waterfall. - Updated both Waterfall and Spectrum tooltips to match those features. --- src/visual/SpectrumCanvas.cpp | 42 +++++++++++++++++++++------------- src/visual/SpectrumCanvas.h | 4 +++- src/visual/WaterfallCanvas.cpp | 10 ++++---- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/visual/SpectrumCanvas.cpp b/src/visual/SpectrumCanvas.cpp index 4630f9b..6dc18b4 100644 --- a/src/visual/SpectrumCanvas.cpp +++ b/src/visual/SpectrumCanvas.cpp @@ -215,6 +215,21 @@ void SpectrumCanvas::updateScaleFactor(float factor) { wp->setScaleFactor(factor); } +void SpectrumCanvas::updateScaleFactorFromYMove(float yDeltaMouseMove) { + + scaleFactor += yDeltaMouseMove * 2.0; + + if (scaleFactor < 0.25) { + scaleFactor = 0.25; + } + if (scaleFactor > 10.0) { + scaleFactor = 10.0; + } + + resetScaleFactor = false; + updateScaleFactor(scaleFactor); +} + void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) { InteractiveCanvas::OnMouseMoved(event); if (mouseTracker.mouseDown()) { @@ -226,21 +241,11 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) { } else if (scaleFactorEnabled && mouseTracker.mouseRightDown()) { - float yDelta = mouseTracker.getDeltaMouseY(); + updateScaleFactorFromYMove(mouseTracker.getDeltaMouseY()); - scaleFactor += yDelta*2.0; - if (scaleFactor < 0.25) { - scaleFactor = 0.25; - } - if (scaleFactor > 10.0) { - scaleFactor = 10.0; - } - - resetScaleFactor = false; - updateScaleFactor(scaleFactor); } else { if (scaleFactorEnabled) { - setStatusText("Drag horizontal to adjust center frequency. Right-drag or SHIFT+UP/DOWN to adjust vertical scale; right-click to reset. 'B' to toggle decibels display."); + setStatusText("Drag horizontal to adjust center frequency. Arrow keys or wheel to navigate/zoom bandwith. Right-drag or SHIFT+UP/DOWN to adjust vertical scale, right-click to reset. 'B' to toggle decibels display."); } else { setStatusText("Displaying spectrum of active demodulator."); } @@ -248,9 +253,9 @@ void SpectrumCanvas::OnMouseMoved(wxMouseEvent& event) { } void SpectrumCanvas::OnMouseDown(wxMouseEvent& event) { + SetCursor(wxCURSOR_SIZEWE); mouseTracker.setVertDragLock(true); InteractiveCanvas::OnMouseDown(event); - SetCursor(wxCURSOR_CROSS); } void SpectrumCanvas::OnMouseWheelMoved(wxMouseEvent& event) { @@ -263,12 +268,12 @@ void SpectrumCanvas::OnMouseWheelMoved(wxMouseEvent& event) { void SpectrumCanvas::OnMouseReleased(wxMouseEvent& event) { mouseTracker.setVertDragLock(false); InteractiveCanvas::OnMouseReleased(event); - SetCursor(wxCURSOR_SIZEWE); + SetCursor(wxCURSOR_CROSS); } void SpectrumCanvas::OnMouseEnterWindow(wxMouseEvent& event) { InteractiveCanvas::OnMouseEnterWindow(event); - SetCursor(wxCURSOR_SIZEWE); + SetCursor(wxCURSOR_CROSS); #ifdef _WIN32 if (wxGetApp().getAppFrame()->canFocus()) { this->SetFocus(); @@ -278,7 +283,7 @@ void SpectrumCanvas::OnMouseEnterWindow(wxMouseEvent& event) { void SpectrumCanvas::OnMouseLeftWindow(wxMouseEvent& event) { InteractiveCanvas::OnMouseLeftWindow(event); - SetCursor(wxCURSOR_SIZEWE); + SetCursor(wxCURSOR_CROSS); } void SpectrumCanvas::attachWaterfallCanvas(WaterfallCanvas* canvas_in) { @@ -290,15 +295,19 @@ SpectrumVisualDataQueuePtr SpectrumCanvas::getVisualDataQueue() { } void SpectrumCanvas::OnMouseRightDown(wxMouseEvent& event) { + SetCursor(wxCURSOR_SIZENS); mouseTracker.setHorizDragLock(true); mouseTracker.OnMouseRightDown(event); scaleFactor = wxGetApp().getSpectrumProcessor()->getScaleFactor(); } void SpectrumCanvas::OnMouseRightReleased(wxMouseEvent& event) { + SetCursor(wxCURSOR_CROSS); mouseTracker.setHorizDragLock(false); + if (!mouseTracker.getOriginDeltaMouseY()) { resetScaleFactor = true; + wxGetApp().getSpectrumProcessor()->setPeakHold(wxGetApp().getSpectrumProcessor()->getPeakHold()); //make the peak hold act on the current dmod also, like a zoomed-in version. @@ -306,6 +315,7 @@ void SpectrumCanvas::OnMouseRightReleased(wxMouseEvent& event) { wxGetApp().getDemodSpectrumProcessor()->setPeakHold(wxGetApp().getSpectrumProcessor()->getPeakHold()); } } + mouseTracker.OnMouseRightReleased(event); } diff --git a/src/visual/SpectrumCanvas.h b/src/visual/SpectrumCanvas.h index 580d917..c88d66c 100644 --- a/src/visual/SpectrumCanvas.h +++ b/src/visual/SpectrumCanvas.h @@ -47,6 +47,9 @@ public: SpectrumVisualDataQueuePtr getVisualDataQueue(); + // called by Waterfall to forward the update of the vertical scale. + void updateScaleFactorFromYMove(float yDeltaMouseMove); + private: void OnPaint(wxPaintEvent& event); @@ -60,7 +63,6 @@ private: void OnMouseLeftWindow(wxMouseEvent& event); void OnMouseRightDown(wxMouseEvent& event); void OnMouseRightReleased(wxMouseEvent& event); - void updateScaleFactor(float factor); diff --git a/src/visual/WaterfallCanvas.cpp b/src/visual/WaterfallCanvas.cpp index 8efd1e5..ac6e37b 100644 --- a/src/visual/WaterfallCanvas.cpp +++ b/src/visual/WaterfallCanvas.cpp @@ -583,7 +583,7 @@ void WaterfallCanvas::updateHoverState() { } else { setStatusText( - "Click to set demodulator frequency or hold ALT to drag range; hold SHIFT to create new. Right drag or wheel to Zoom. Arrow keys to navigate/zoom, C to center. Shift-R record/stop all."); + "Click to set demodulator frequency or hold ALT to drag range; hold SHIFT to create new. Arrow keys or wheel to navigate/zoom bandwith, C to center. Right-drag or SHIFT+UP/DOWN to adjust vertical scale. Shift-R record/stop all."); } } } @@ -637,8 +637,11 @@ void WaterfallCanvas::OnMouseMoved(wxMouseEvent& event) { demod->updateLabel(currentFreq); } } - } else if (mouseTracker.mouseRightDown()) { - mouseZoom = mouseZoom + ((1.0 - (mouseTracker.getDeltaMouseY() * 4.0)) - mouseZoom) * 0.1; + } else if (mouseTracker.mouseRightDown() && spectrumCanvas) { + + //Right-drag has the same effect on both Waterfall and Spectrum. + spectrumCanvas->updateScaleFactorFromYMove(mouseTracker.getDeltaMouseY()); + } else { updateHoverState(); } @@ -879,7 +882,6 @@ void WaterfallCanvas::OnMouseRightReleased(wxMouseEvent& event) { SetCursor(wxCURSOR_CROSS); mouseTracker.setVertDragLock(false); mouseTracker.setHorizDragLock(false); - mouseZoom = 1.0; } SpectrumVisualDataQueuePtr WaterfallCanvas::getVisualDataQueue() {