From a35d0252e7776161214aedb4502d257a30ba910f Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Sat, 24 Apr 2021 04:06:04 +0200 Subject: [PATCH] Fixed scroll bug and added keybinds --- core/src/gui/main_window.cpp | 58 +++++++++++++---------- core/src/gui/menus/display.cpp | 3 +- core/src/gui/widgets/frequency_select.cpp | 20 ++------ core/src/gui/widgets/waterfall.cpp | 29 +++++++++++- make_windows_package.ps1 | 2 + 5 files changed, 69 insertions(+), 43 deletions(-) diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index dc877def..c9325aac 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -434,26 +434,6 @@ void drawWindow() { core::configManager.release(true); } - // Handle arrow keys - if (vfo != NULL) { - if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && !gui::freqSelect.digitHovered) { - double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset - vfo->snapInterval; - nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval; - setVFO(nfreq); - } - if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && !gui::freqSelect.digitHovered) { - double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval; - nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval; - setVFO(nfreq); - } - core::configManager.aquire(); - core::configManager.conf["frequency"] = gui::waterfall.getCenterFrequency(); - if (vfo != NULL) { - core::configManager.conf["vfoOffsets"][gui::waterfall.selectedVFO] = vfo->generalOffset; - } - core::configManager.release(true); - } - int _fftHeight = gui::waterfall.getFFTHeight(); if (fftHeight != _fftHeight) { fftHeight = _fftHeight; @@ -470,7 +450,7 @@ void drawWindow() { // To Bar ImGui::PushID(ImGui::GetID("sdrpp_menu_btn")); - if (ImGui::ImageButton(icons::MENU, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5)) { + if (ImGui::ImageButton(icons::MENU, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(GLFW_KEY_MENU, false)) { showMenu = !showMenu; core::configManager.aquire(); core::configManager.conf["showMenu"] = showMenu; @@ -482,7 +462,7 @@ void drawWindow() { if (playing) { ImGui::PushID(ImGui::GetID("sdrpp_stop_btn")); - if (ImGui::ImageButton(icons::STOP, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5)) { + if (ImGui::ImageButton(icons::STOP, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(GLFW_KEY_END, false)) { sigpath::sourceManager.stop(); playing = false; } @@ -490,7 +470,7 @@ void drawWindow() { } else { // TODO: Might need to check if there even is a device ImGui::PushID(ImGui::GetID("sdrpp_play_btn")); - if (ImGui::ImageButton(icons::PLAY, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5)) { + if (ImGui::ImageButton(icons::PLAY, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(GLFW_KEY_END, false)) { sigpath::sourceManager.start(); // TODO: tune in module instead sigpath::sourceManager.tune(gui::waterfall.getCenterFrequency()); @@ -648,12 +628,40 @@ void drawWindow() { ImGui::EndChild(); + // Handle arrow keys + if (vfo != NULL && (gui::waterfall.mouseInFFT || gui::waterfall.mouseInWaterfall)) { + if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && !gui::freqSelect.digitHovered) { + double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset - vfo->snapInterval; + nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval; + setVFO(nfreq); + } + if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && !gui::freqSelect.digitHovered) { + double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval; + nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval; + setVFO(nfreq); + } + core::configManager.aquire(); + core::configManager.conf["frequency"] = gui::waterfall.getCenterFrequency(); + if (vfo != NULL) { + core::configManager.conf["vfoOffsets"][gui::waterfall.selectedVFO] = vfo->generalOffset; + } + core::configManager.release(true); + } + // Handle scrollwheel int wheel = ImGui::GetIO().MouseWheel; if (wheel != 0 && (gui::waterfall.mouseInFFT || gui::waterfall.mouseInWaterfall)) { - double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset + (vfo->snapInterval * wheel); - nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval; + double nfreq; + if (vfo != NULL) { + nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset + (vfo->snapInterval * wheel); + nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval; + } + else { + nfreq = gui::waterfall.getCenterFrequency() - (gui::waterfall.getViewBandwidth() * wheel / 20.0); + } + setVFO(nfreq); + gui::freqSelect.setFrequency(nfreq); core::configManager.aquire(); core::configManager.conf["frequency"] = gui::waterfall.getCenterFrequency(); if (vfo != NULL) { diff --git a/core/src/gui/menus/display.cpp b/core/src/gui/menus/display.cpp index 9da71fc0..c98a25ff 100644 --- a/core/src/gui/menus/display.cpp +++ b/core/src/gui/menus/display.cpp @@ -74,7 +74,8 @@ namespace displaymenu { void draw(void* ctx) { float menuWidth = ImGui::GetContentRegionAvailWidth(); - if (ImGui::Checkbox("Show Waterfall##_sdrpp", &showWaterfall)) { + if (ImGui::Checkbox("Show Waterfall##_sdrpp", &showWaterfall) || ImGui::IsKeyPressed(GLFW_KEY_HOME, false)) { + if (ImGui::IsKeyPressed(GLFW_KEY_HOME, false)) { showWaterfall = !showWaterfall; } showWaterfall ? gui::waterfall.showWaterfall() : gui::waterfall.hideWaterfall(); core::configManager.aquire(); core::configManager.conf["showWaterfall"] = showWaterfall; diff --git a/core/src/gui/widgets/frequency_select.cpp b/core/src/gui/widgets/frequency_select.cpp index 86a24f07..edc04499 100644 --- a/core/src/gui/widgets/frequency_select.cpp +++ b/core/src/gui/widgets/frequency_select.cpp @@ -155,7 +155,7 @@ void FrequencySelect::draw() { } if (onDigit) { hovered = true; - if (rightClick) { + if (rightClick || (ImGui::IsKeyPressed(GLFW_KEY_DELETE) || ImGui::IsKeyPressed(GLFW_KEY_ENTER) || ImGui::IsKeyPressed(GLFW_KEY_KP_ENTER))) { for (int j = i; j < 12; j++) { digits[j] = 0; } @@ -167,7 +167,7 @@ void FrequencySelect::draw() { if (ImGui::IsKeyPressed(GLFW_KEY_DOWN)) { decrementDigit(i); } - if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && i > 0) { + if ((ImGui::IsKeyPressed(GLFW_KEY_LEFT) || ImGui::IsKeyPressed(GLFW_KEY_BACKSPACE)) && i > 0) { moveCursorToDigit(i - 1); } if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && i < 11) { @@ -180,23 +180,11 @@ void FrequencySelect::draw() { for (int j = 0; j < chars.Size; j++) { if (chars[j] >= '0' && chars[j] <= '9') { digits[i + j] = chars[j] - '0'; + if ((i + j) < 11) { moveCursorToDigit(i + j + 1); } + frequencyChanged = true; } - if ((i + j) < 11) { moveCursorToDigit(i + j + 1); } - frequencyChanged = true; } - // Check each digit - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_0)) { digits[i] = 0; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_1)) { digits[i] = 1; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_2)) { digits[i] = 2; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_3)) { digits[i] = 3; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_4)) { digits[i] = 4; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_5)) { digits[i] = 5; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_6)) { digits[i] = 6; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_7)) { digits[i] = 7; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_8)) { digits[i] = 8; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - // if (ImGui::IsKeyPressed(GLFW_KEY_KP_9)) { digits[i] = 9; if (i < 11) { moveCursorToDigit(i + 1); frequencyChanged = true; } } - if (mw != 0) { int count = abs(mw); for (int j = 0; j < count; j++) { diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 08c53307..29852b8a 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -5,7 +5,7 @@ #include #include #include - +#include #include float DEFAULT_COLOR_MAP[][3] = { @@ -390,6 +390,33 @@ namespace ImGui { return; } + // If the left and right keys are pressed while hovering the freq scale, move it too + if ((ImGui::IsKeyPressed(GLFW_KEY_LEFT) || ImGui::IsKeyPressed(GLFW_KEY_RIGHT)) && mouseInFreq) { + viewOffset += ImGui::IsKeyPressed(GLFW_KEY_LEFT) ? (viewBandwidth / 20.0) : (-viewBandwidth / 20.0); + + if (viewOffset + (viewBandwidth / 2.0) > wholeBandwidth / 2.0) { + double freqOffset = (viewOffset + (viewBandwidth / 2.0)) - (wholeBandwidth / 2.0); + viewOffset = (wholeBandwidth / 2.0) - (viewBandwidth / 2.0); + centerFreq += freqOffset; + centerFreqMoved = true; + } + if (viewOffset - (viewBandwidth / 2.0) < -(wholeBandwidth / 2.0)) { + double freqOffset = (viewOffset - (viewBandwidth / 2.0)) + (wholeBandwidth / 2.0); + viewOffset = (viewBandwidth / 2.0) - (wholeBandwidth / 2.0); + centerFreq += freqOffset; + centerFreqMoved = true; + } + + lowerFreq = (centerFreq + viewOffset) - (viewBandwidth / 2.0); + upperFreq = (centerFreq + viewOffset) + (viewBandwidth / 2.0); + + if (viewBandwidth != wholeBandwidth) { + updateAllVFOs(); + if (_fullUpdate) { updateWaterfallFb(); }; + } + return; + } + // Finally, if nothing else was selected, just move the VFO if (ImGui::IsMouseDown(ImGuiMouseButton_Left) && (mouseInFFT|mouseInWaterfall)) { if (selVfo != NULL) { diff --git a/make_windows_package.ps1 b/make_windows_package.ps1 index d4f30e05..fe90adc3 100644 --- a/make_windows_package.ps1 +++ b/make_windows_package.ps1 @@ -42,6 +42,8 @@ cp build/meteor_demodulator/Release/meteor_demodulator.dll sdrpp_windows_x64/mod cp build/audio_sink/Release/audio_sink.dll sdrpp_windows_x64/modules/ cp "C:/Program Files (x86)/RtAudio/bin/rtaudio.dll" sdrpp_windows_x64/ +cp build/discord_integration/Release/discord_integration.dll sdrpp_windows_x64/modules/ + # Copy supporting libs cp 'C:/Program Files/PothosSDR/bin/libusb-1.0.dll' sdrpp_windows_x64/ cp 'C:/Program Files/PothosSDR/bin/pthreadVC2.dll' sdrpp_windows_x64/