diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 8d5eb8b2..f0269fed 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -246,6 +246,7 @@ namespace ImGui { ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_PressedOnClick); bool draging = ImGui::IsMouseDragging(ImGuiMouseButton_Left) && ImGui::IsWindowFocused(); + mouseInFFTResize = (dragOrigin.x > widgetPos.x && dragOrigin.x < widgetPos.x + widgetSize.x && dragOrigin.y >= widgetPos.y + newFFTAreaHeight - 2 && dragOrigin.y <= widgetPos.y + newFFTAreaHeight + 2); mouseInFreq = IS_IN_AREA(dragOrigin, freqAreaMin, freqAreaMax); mouseInFFT = IS_IN_AREA(dragOrigin, fftAreaMin, fftAreaMax); mouseInWaterfall = IS_IN_AREA(dragOrigin, wfMin, wfMax); @@ -266,15 +267,31 @@ namespace ImGui { // Deselect everything if the mouse is released if (!ImGui::IsMouseDown(ImGuiMouseButton_Left)) { + if (fftResizeSelect) { + FFTAreaHeight = newFFTAreaHeight; + onResize(); + } + + fftResizeSelect = false; freqScaleSelect = false; vfoSelect = false; vfoBorderSelect = false; lastDrag = 0; } - // If mouse was clicked, check what was clicked - if (mouseClicked) { - bool targetFound = false; + bool targetFound = false; + + // If the mouse was clicked anywhere in the waterfall, check if the resize was clicked + if (mouseInFFTResize) { + ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS); + if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { + fftResizeSelect = true; + targetFound = true; + } + } + + // If mouse was clicked inside the central part, check what was clicked + if (mouseClicked && !targetFound) { mouseDownPos = mousePos; // First, check if a VFO border was selected @@ -311,6 +328,16 @@ namespace ImGui { } } + // If the FFT resize bar was selected, resize FFT accordingly + if (fftResizeSelect) { + ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS); + newFFTAreaHeight = mousePos.y - widgetPos.y; + newFFTAreaHeight = std::clamp(newFFTAreaHeight, 150, widgetSize.y - 50); + ImGui::GetForegroundDrawList()->AddLine(ImVec2(widgetPos.x, newFFTAreaHeight + widgetPos.y), ImVec2(widgetEndPos.x, newFFTAreaHeight + widgetPos.y), + ImGui::GetColorU32(ImGuiCol_SeparatorActive)); + return; + } + // If a vfo border is selected, resize VFO accordingly if (vfoBorderSelect) { ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW); @@ -808,33 +835,6 @@ namespace ImGui { return; } - // Handle fft resize - if (!gui::mainWindow.lockWaterfallControls && !inputHandled) { - ImVec2 winSize = ImGui::GetWindowSize(); - ImVec2 mousePos = ImGui::GetMousePos(); - mousePos.x -= widgetPos.x; - mousePos.y -= widgetPos.y; - bool click = ImGui::IsMouseClicked(ImGuiMouseButton_Left); - bool down = ImGui::IsMouseDown(ImGuiMouseButton_Left); - if (draggingFW) { - newFFTAreaHeight = mousePos.y; - newFFTAreaHeight = std::clamp(newFFTAreaHeight, 150, widgetSize.y - 50); - ImGui::GetForegroundDrawList()->AddLine(ImVec2(widgetPos.x, newFFTAreaHeight + widgetPos.y), ImVec2(widgetEndPos.x, newFFTAreaHeight + widgetPos.y), - ImGui::GetColorU32(ImGuiCol_SeparatorActive)); - } - if (mousePos.y >= newFFTAreaHeight - 2 && mousePos.y <= newFFTAreaHeight + 2 && mousePos.x > 0 && mousePos.x < widgetSize.x) { - ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeNS); - if (click) { - draggingFW = true; - } - } - if(!down && draggingFW) { - draggingFW = false; - FFTAreaHeight = newFFTAreaHeight; - onResize(); - } - } - buf_mtx.unlock(); } diff --git a/core/src/gui/widgets/waterfall.h b/core/src/gui/widgets/waterfall.h index 957d821d..42ccf58e 100644 --- a/core/src/gui/widgets/waterfall.h +++ b/core/src/gui/widgets/waterfall.h @@ -137,6 +137,7 @@ namespace ImGui { bool bandplanEnabled = false; bandplan::BandPlan_t* bandplan = NULL; + bool mouseInFFTResize = false; bool mouseInFreq = false; bool mouseInFFT = false; bool mouseInWaterfall = false; @@ -280,6 +281,7 @@ namespace ImGui { int bandPlanPos = BANDPLAN_POS_BOTTOM; // UI Select elements + bool fftResizeSelect = false; bool freqScaleSelect = false; bool vfoSelect = false; bool vfoBorderSelect = false;