commit no. 8
This commit is contained in:
@@ -61,7 +61,8 @@ void Cursors::draw(const SpectrumDisplay& specDisplay,
|
|||||||
float viewLo, float viewHi) const {
|
float viewLo, float viewHi) const {
|
||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
|
|
||||||
auto drawCursor = [&](const CursorInfo& c, float dispDB, ImU32 color, const char* label) {
|
// Draw cursor lines and crosshairs (no labels here).
|
||||||
|
auto drawCursorMarker = [&](const CursorInfo& c, float dispDB, ImU32 color) {
|
||||||
if (!c.active) return;
|
if (!c.active) return;
|
||||||
float x = specDisplay.freqToScreenX(c.freq, posX, sizeX,
|
float x = specDisplay.freqToScreenX(c.freq, posX, sizeX,
|
||||||
sampleRate, isIQ, freqScale,
|
sampleRate, isIQ, freqScale,
|
||||||
@@ -70,36 +71,53 @@ void Cursors::draw(const SpectrumDisplay& specDisplay,
|
|||||||
dbNorm = std::clamp(dbNorm, 0.0f, 1.0f);
|
dbNorm = std::clamp(dbNorm, 0.0f, 1.0f);
|
||||||
float y = posY + sizeY * (1.0f - dbNorm);
|
float y = posY + sizeY * (1.0f - dbNorm);
|
||||||
|
|
||||||
// Vertical line
|
|
||||||
dl->AddLine({x, posY}, {x, posY + sizeY}, color, 1.0f);
|
dl->AddLine({x, posY}, {x, posY + sizeY}, color, 1.0f);
|
||||||
// Horizontal line
|
|
||||||
dl->AddLine({posX, y}, {posX + sizeX, y}, color & 0x80FFFFFF, 1.0f);
|
dl->AddLine({posX, y}, {posX + sizeX, y}, color & 0x80FFFFFF, 1.0f);
|
||||||
// Crosshair
|
|
||||||
dl->AddCircle({x, y}, 5.0f, color, 12, 2.0f);
|
dl->AddCircle({x, y}, 5.0f, color, 12, 2.0f);
|
||||||
|
};
|
||||||
|
|
||||||
// Label
|
// Format a cursor label string.
|
||||||
char buf[128];
|
auto formatLabel = [](char* buf, size_t sz, const char* label, double freq, float dB) {
|
||||||
if (std::abs(c.freq) >= 1e6)
|
if (std::abs(freq) >= 1e6)
|
||||||
std::snprintf(buf, sizeof(buf), "%s: %.6f MHz %.1f dB",
|
std::snprintf(buf, sz, "%s: %.6f MHz %.1f dB", label, freq / 1e6, dB);
|
||||||
label, c.freq / 1e6, dispDB);
|
else if (std::abs(freq) >= 1e3)
|
||||||
else if (std::abs(c.freq) >= 1e3)
|
std::snprintf(buf, sz, "%s: %.3f kHz %.1f dB", label, freq / 1e3, dB);
|
||||||
std::snprintf(buf, sizeof(buf), "%s: %.3f kHz %.1f dB",
|
|
||||||
label, c.freq / 1e3, dispDB);
|
|
||||||
else
|
else
|
||||||
std::snprintf(buf, sizeof(buf), "%s: %.1f Hz %.1f dB",
|
std::snprintf(buf, sz, "%s: %.1f Hz %.1f dB", label, freq, dB);
|
||||||
label, c.freq, dispDB);
|
};
|
||||||
|
|
||||||
ImVec2 textSize = ImGui::CalcTextSize(buf);
|
float aDB = avgDBA(), bDB = avgDBB();
|
||||||
float tx = std::min(x + 8, posX + sizeX - textSize.x - 4);
|
drawCursorMarker(cursorA, aDB, IM_COL32(255, 255, 0, 220));
|
||||||
float ty = std::max(y - 18, posY + 2);
|
drawCursorMarker(cursorB, bDB, IM_COL32(0, 200, 255, 220));
|
||||||
dl->AddRectFilled({tx - 2, ty - 1}, {tx + textSize.x + 2, ty + textSize.y + 1},
|
|
||||||
|
// 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.
|
||||||
|
auto drawCursorLabel = [&](const CursorInfo& c, float dispDB, ImU32 color,
|
||||||
|
const char* label, int row) {
|
||||||
|
if (!c.active) return;
|
||||||
|
float x = specDisplay.freqToScreenX(c.freq, posX, sizeX,
|
||||||
|
sampleRate, isIQ, freqScale,
|
||||||
|
viewLo, viewHi);
|
||||||
|
char buf[128];
|
||||||
|
formatLabel(buf, sizeof(buf), label, c.freq, dispDB);
|
||||||
|
ImVec2 sz = ImGui::CalcTextSize(buf);
|
||||||
|
float lineH = ImGui::GetTextLineHeight();
|
||||||
|
float ty = posY + 4 + row * (lineH + 4);
|
||||||
|
|
||||||
|
// Place right of cursor line; flip left if it would overflow.
|
||||||
|
float tx;
|
||||||
|
if (x + 6 + sz.x + 2 <= posX + sizeX)
|
||||||
|
tx = x + 6;
|
||||||
|
else
|
||||||
|
tx = x - 6 - sz.x;
|
||||||
|
|
||||||
|
dl->AddRectFilled({tx - 2, ty - 1}, {tx + sz.x + 2, ty + sz.y + 1},
|
||||||
IM_COL32(0, 0, 0, 180));
|
IM_COL32(0, 0, 0, 180));
|
||||||
dl->AddText({tx, ty}, color, buf);
|
dl->AddText({tx, ty}, color, buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
float aDB = avgDBA(), bDB = avgDBB();
|
drawCursorLabel(cursorA, aDB, IM_COL32(255, 255, 0, 220), "A", 0);
|
||||||
drawCursor(cursorA, aDB, IM_COL32(255, 255, 0, 220), "A");
|
drawCursorLabel(cursorB, bDB, IM_COL32(0, 200, 255, 220), "B", cursorA.active ? 1 : 0);
|
||||||
drawCursor(cursorB, bDB, IM_COL32(0, 200, 255, 220), "B");
|
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user