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};
|
cursors_.hover = {true, freq, dB, bin};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Left click: cursor A
|
// Left drag: cursor A
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
|
if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) {
|
||||||
int peakBin = cursors_.findLocalPeak(spec, bin, 10);
|
int cBin = cursors_.snapToPeaks ? cursors_.findLocalPeak(spec, bin, 10) : bin;
|
||||||
double peakFreq = analyzer_.binToFreq(peakBin);
|
double cFreq = analyzer_.binToFreq(cBin);
|
||||||
cursors_.setCursorA(peakFreq, spec[peakBin], peakBin);
|
cursors_.setCursorA(cFreq, spec[cBin], cBin);
|
||||||
}
|
}
|
||||||
// Right click: cursor B
|
// Right drag: cursor B
|
||||||
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
|
if (ImGui::IsMouseDown(ImGuiMouseButton_Right)) {
|
||||||
int peakBin = cursors_.findLocalPeak(spec, bin, 10);
|
int cBin = cursors_.snapToPeaks ? cursors_.findLocalPeak(spec, bin, 10) : bin;
|
||||||
double peakFreq = analyzer_.binToFreq(peakBin);
|
double cFreq = analyzer_.binToFreq(cBin);
|
||||||
cursors_.setCursorB(peakFreq, spec[peakBin], peakBin);
|
cursors_.setCursorB(cFreq, spec[cBin], cBin);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ void Cursors::draw(const SpectrumDisplay& specDisplay,
|
|||||||
|
|
||||||
float aDB = avgDBA(), bDB = avgDBB();
|
float aDB = avgDBA(), bDB = avgDBB();
|
||||||
drawCursorMarker(cursorA, aDB, IM_COL32(255, 255, 0, 220));
|
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.
|
// 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.
|
// 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(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 '=')
|
// Delta display (two lines, column-aligned on '=')
|
||||||
if (showDelta && cursorA.active && cursorB.active) {
|
if (showDelta && cursorA.active && cursorB.active) {
|
||||||
@@ -156,6 +156,8 @@ void Cursors::drawPanel() {
|
|||||||
ImGui::Text("%s", dbuf);
|
ImGui::Text("%s", dbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::Checkbox("Snap to peaks", &snapToPeaks);
|
||||||
|
|
||||||
// Averaging slider (logarithmic scale)
|
// Averaging slider (logarithmic scale)
|
||||||
ImGui::SetNextItemWidth(-1);
|
ImGui::SetNextItemWidth(-1);
|
||||||
ImGui::SliderInt("##avgcount", &avgCount, 1, 20000, avgCount == 1 ? "No avg" : "Avg: %d",
|
ImGui::SliderInt("##avgcount", &avgCount, 1, 20000, avgCount == 1 ? "No avg" : "Avg: %d",
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public:
|
|||||||
CursorInfo cursorA;
|
CursorInfo cursorA;
|
||||||
CursorInfo cursorB;
|
CursorInfo cursorB;
|
||||||
bool showDelta = true;
|
bool showDelta = true;
|
||||||
|
bool snapToPeaks = true;
|
||||||
|
|
||||||
// Hover cursor (follows mouse, always active)
|
// Hover cursor (follows mouse, always active)
|
||||||
CursorInfo hover;
|
CursorInfo hover;
|
||||||
|
|||||||
Reference in New Issue
Block a user