Cursors: optional snapping

This commit is contained in:
2026-03-25 21:53:36 +01:00
parent 608ff9ed85
commit 1918645d53
3 changed files with 15 additions and 12 deletions

View File

@@ -1112,17 +1112,17 @@ void Application::handleSpectrumInput(float posX, float posY,
cursors_.hover = {true, freq, dB, bin};
}
// Left click: cursor A
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
int peakBin = cursors_.findLocalPeak(spec, bin, 10);
double peakFreq = analyzer_.binToFreq(peakBin);
cursors_.setCursorA(peakFreq, spec[peakBin], peakBin);
// Left drag: cursor A
if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) {
int cBin = cursors_.snapToPeaks ? cursors_.findLocalPeak(spec, bin, 10) : bin;
double cFreq = analyzer_.binToFreq(cBin);
cursors_.setCursorA(cFreq, spec[cBin], cBin);
}
// Right click: cursor B
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
int peakBin = cursors_.findLocalPeak(spec, bin, 10);
double peakFreq = analyzer_.binToFreq(peakBin);
cursors_.setCursorB(peakFreq, spec[peakBin], peakBin);
// Right drag: cursor B
if (ImGui::IsMouseDown(ImGuiMouseButton_Right)) {
int cBin = cursors_.snapToPeaks ? cursors_.findLocalPeak(spec, bin, 10) : bin;
double cFreq = analyzer_.binToFreq(cBin);
cursors_.setCursorB(cFreq, spec[cBin], cBin);
}
{