mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-18 09:00:52 +02:00
FreqWindow: Save cursor position as frequency, not pixel position
Fixes the cursor remaining on the same pixel but changing frequency, when resizing the window horizontally with a cursor active (already broken), or zooming/scrolling horizontally with a cursor active (only possible in this branch). Signed-off-by: nyanpasu64 <nyanpasu64@tuta.io>
This commit is contained in:
parent
65b7c100d6
commit
2e5a05016b
@ -956,6 +956,30 @@ void FrequencyPlotDialog::PlotMouseEvent(wxMouseEvent & event)
|
|||||||
else
|
else
|
||||||
mFreqPlot->SetCursor(*mArrowCursor);
|
mFreqPlot->SetCursor(*mArrowCursor);
|
||||||
|
|
||||||
|
wxRect r = mPlotRect;
|
||||||
|
int width = r.width - 2;
|
||||||
|
if (
|
||||||
|
hNumberScale != NumberScale() &&
|
||||||
|
r.Contains(mMouseX, mMouseY) &&
|
||||||
|
(mMouseX!=0) &&
|
||||||
|
(mMouseX!=r.width-1)
|
||||||
|
) {
|
||||||
|
auto calcXPosFromMouseX = [&r, &width, &hNumberScale = this->hNumberScale](
|
||||||
|
int mouseX
|
||||||
|
) -> float {
|
||||||
|
float relativeMouseX = float(mouseX - (r.x + 1)) / float(width);
|
||||||
|
return hNumberScale.PositionToValue(relativeMouseX);
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Frequency of the mouse pixel
|
||||||
|
mCursorXLeft = calcXPosFromMouseX(mMouseX);
|
||||||
|
/// Frequency at 1 pixel to the right
|
||||||
|
mCursorXRight = calcXPosFromMouseX(mMouseX + 1);
|
||||||
|
} else {
|
||||||
|
mCursorXLeft = NO_CURSOR;
|
||||||
|
mCursorXRight = NO_CURSOR;
|
||||||
|
}
|
||||||
|
|
||||||
mFreqPlot->Refresh(false);
|
mFreqPlot->Refresh(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1023,18 +1047,11 @@ void FrequencyPlotDialog::PlotPaint(wxPaintEvent & event)
|
|||||||
int width = r.width - 2;
|
int width = r.width - 2;
|
||||||
|
|
||||||
// Find the peak nearest the cursor and plot it
|
// Find the peak nearest the cursor and plot it
|
||||||
if ( r.Contains(mMouseX, mMouseY) & (mMouseX!=0) & (mMouseX!=r.width-1) ) {
|
if ( mCursorXLeft != NO_CURSOR ) {
|
||||||
auto calcXPosFromMouseX = [&r, &width, &hNumberScale = this->hNumberScale](
|
|
||||||
int mouseX
|
|
||||||
) -> float {
|
|
||||||
float relativeMouseX = float(mouseX - (r.x + 1)) / float(width);
|
|
||||||
return hNumberScale.PositionToValue(relativeMouseX);
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Frequency of the mouse pixel
|
/// Frequency of the mouse pixel
|
||||||
float xPos = calcXPosFromMouseX(mMouseX);
|
float xPos = mCursorXLeft;
|
||||||
/// Frequency at 1 pixel to the right
|
/// Frequency at 1 pixel to the right
|
||||||
float xPosNext = calcXPosFromMouseX(mMouseX + 1);
|
float xPosNext = mCursorXRight;
|
||||||
|
|
||||||
float peakAmplitude = 0;
|
float peakAmplitude = 0;
|
||||||
float peakPos = mAnalyst->FindPeak(xPos, &peakAmplitude);
|
float peakPos = mAnalyst->FindPeak(xPos, &peakAmplitude);
|
||||||
|
@ -158,6 +158,12 @@ private:
|
|||||||
int mMouseX;
|
int mMouseX;
|
||||||
int mMouseY;
|
int mMouseY;
|
||||||
|
|
||||||
|
static constexpr float NO_CURSOR = -1.f;
|
||||||
|
/// Frequency/period under the mouse cursor, if present.
|
||||||
|
float mCursorXLeft = NO_CURSOR;
|
||||||
|
/// Frequency/period 1 pixel to the right of the mouse cursor, if present.
|
||||||
|
float mCursorXRight = NO_CURSOR;
|
||||||
|
|
||||||
std::unique_ptr<SpectrumAnalyst> mAnalyst;
|
std::unique_ptr<SpectrumAnalyst> mAnalyst;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user