move the freq. scale selector to the sidebar

This commit is contained in:
2026-03-25 22:33:44 +01:00
parent 2e91ed8570
commit dfe61b65e1

View File

@@ -349,17 +349,6 @@ void Application::render() {
ImGui::MenuItem("Grid", nullptr, &specDisplay_.showGrid); ImGui::MenuItem("Grid", nullptr, &specDisplay_.showGrid);
ImGui::MenuItem("Fill Spectrum", nullptr, &specDisplay_.fillSpectrum); ImGui::MenuItem("Fill Spectrum", nullptr, &specDisplay_.fillSpectrum);
ImGui::Separator();
// Frequency scale
int fs = static_cast<int>(freqScale_);
const char* fsNames[] = {"Linear", "Logarithmic"};
ImGui::SetNextItemWidth(120);
if (ImGui::Combo("Freq Scale", &fs, fsNames, 2)) {
freqScale_ = static_cast<FreqScale>(fs);
saveConfig();
}
ImGui::Separator(); ImGui::Separator();
if (ImGui::MenuItem("VSync", nullptr, &vsync_)) { if (ImGui::MenuItem("VSync", nullptr, &vsync_)) {
SDL_GL_SetSwapInterval(vsync_ ? 1 : 0); SDL_GL_SetSwapInterval(vsync_ ? 1 : 0);
@@ -618,6 +607,41 @@ void Application::renderControlPanel() {
specDisplay_.clearPeakHold(); specDisplay_.clearPeakHold();
} }
{
bool isLog = (freqScale_ == FreqScale::Logarithmic);
bool canLog = !settings_.isIQ;
ImGui::AlignTextToFramePadding();
ImGui::Text("Freq. scale:");
ImGui::SameLine();
if (ImGui::Button(isLog ? "Logarithmic" : "Linear", {ImGui::GetContentRegionAvail().x, 0})) {
if (canLog) {
constexpr float kMinBF = 0.001f;
float logMin = std::log10(kMinBF);
auto screenToBin = [&](float sf) -> float {
if (isLog) return std::pow(10.0f, logMin + sf * (0.0f - logMin));
return sf;
};
auto binToScreen = [&](float bf, bool toLog) -> float {
if (toLog) {
if (bf < kMinBF) bf = kMinBF;
return (std::log10(bf) - logMin) / (0.0f - logMin);
}
return bf;
};
float bfLo = screenToBin(viewLo_);
float bfHi = screenToBin(viewHi_);
bool newLog = !isLog;
freqScale_ = newLog ? FreqScale::Logarithmic : FreqScale::Linear;
viewLo_ = std::clamp(binToScreen(bfLo, newLog), 0.0f, 1.0f);
viewHi_ = std::clamp(binToScreen(bfHi, newLog), 0.0f, 1.0f);
if (viewHi_ <= viewLo_) { viewLo_ = 0.0f; viewHi_ = 1.0f; }
saveConfig();
}
}
if (!canLog && ImGui::IsItemHovered())
ImGui::SetTooltip("Log scale not available in I/Q mode");
}
{ {
float span = viewHi_ - viewLo_; float span = viewHi_ - viewLo_;
float zoomX = 1.0f / span; float zoomX = 1.0f / span;