Cursors: optional snapping
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -83,7 +83,7 @@ void Cursors::draw(const SpectrumDisplay& specDisplay,
|
||||
|
||||
float aDB = avgDBA(), bDB = avgDBB();
|
||||
drawCursorMarker(cursorA, aDB, IM_COL32(255, 255, 0, 220));
|
||||
drawCursorMarker(cursorB, bDB, IM_COL32(0, 200, 255, 220));
|
||||
drawCursorMarker(cursorB, bDB, IM_COL32(100, 220, 255, 220));
|
||||
|
||||
// Draw labels at the top, touching the cursor's vertical line.
|
||||
// If the label would overflow the right edge, flip it to the left side.
|
||||
@@ -113,7 +113,7 @@ void Cursors::draw(const SpectrumDisplay& specDisplay,
|
||||
};
|
||||
|
||||
drawCursorLabel(cursorA, aDB, IM_COL32(255, 255, 0, 220), "A", 0);
|
||||
drawCursorLabel(cursorB, bDB, IM_COL32(0, 200, 255, 220), "B", cursorA.active ? 1 : 0);
|
||||
drawCursorLabel(cursorB, bDB, IM_COL32(100, 220, 255, 220), "B", cursorA.active ? 1 : 0);
|
||||
|
||||
// Delta display (two lines, column-aligned on '=')
|
||||
if (showDelta && cursorA.active && cursorB.active) {
|
||||
@@ -156,6 +156,8 @@ void Cursors::drawPanel() {
|
||||
ImGui::Text("%s", dbuf);
|
||||
}
|
||||
|
||||
ImGui::Checkbox("Snap to peaks", &snapToPeaks);
|
||||
|
||||
// Averaging slider (logarithmic scale)
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
ImGui::SliderInt("##avgcount", &avgCount, 1, 20000, avgCount == 1 ? "No avg" : "Avg: %d",
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
CursorInfo cursorA;
|
||||
CursorInfo cursorB;
|
||||
bool showDelta = true;
|
||||
bool snapToPeaks = true;
|
||||
|
||||
// Hover cursor (follows mouse, always active)
|
||||
CursorInfo hover;
|
||||
|
||||
Reference in New Issue
Block a user