diff --git a/core/src/core.cpp b/core/src/core.cpp index effbc393..be81eccc 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ namespace core { ScriptManager scriptManager; ModuleManager moduleManager; ModuleComManager modComManager; + GLFWwindow* window; void setInputSampleRate(double samplerate) { // NOTE: Zoom controls won't work @@ -242,17 +244,17 @@ int sdrpp_main(int argc, char *argv[]) { // Create window with graphics context GLFWmonitor* monitor = glfwGetPrimaryMonitor(); - GLFWwindow* window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL); - if (window == NULL) + core::window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL); + if (core::window == NULL) return 1; - glfwMakeContextCurrent(window); + glfwMakeContextCurrent(core::window); #if (GLFW_VERSION_MAJOR == 3) && (GLFW_VERSION_MINOR >= 3) if (maximized) { - glfwMaximizeWindow(window); + glfwMaximizeWindow(core::window); } - glfwSetWindowMaximizeCallback(window, maximized_callback); + glfwSetWindowMaximizeCallback(core::window, maximized_callback); #endif // Load app icon @@ -281,7 +283,7 @@ int sdrpp_main(int argc, char *argv[]) { stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[7].pixels, 128, 128, 128 * 4, 4); stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[8].pixels, 196, 196, 196 * 4, 4); stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[9].pixels, 256, 256, 256 * 4, 4); - glfwSetWindowIcon(window, 10, icons); + glfwSetWindowIcon(core::window, 10, icons); stbi_image_free(icons[0].pixels); for (int i = 1; i < 10; i++) { free(icons[i].pixels); @@ -300,7 +302,7 @@ int sdrpp_main(int argc, char *argv[]) { io.IniFilename = NULL; // Setup Platform/Renderer bindings - ImGui_ImplGlfw_InitForOpenGL(window, true); + ImGui_ImplGlfw_InitForOpenGL(core::window, true); if (!ImGui_ImplOpenGL3_Init(glsl_version)) { // If init fail, try to fall back on GLSL 1.2 @@ -313,7 +315,7 @@ int sdrpp_main(int argc, char *argv[]) { if (!style::setDarkStyle(resDir)) { return -1; } - LoadingScreen::setWindow(window); + LoadingScreen::setWindow(core::window); LoadingScreen::show("Loading icons"); spdlog::info("Loading icons"); @@ -335,7 +337,7 @@ int sdrpp_main(int argc, char *argv[]) { int fsWidth, fsHeight, fsPosX, fsPosY; // Main loop - while (!glfwWindowShouldClose(window)) { + while (!glfwWindowShouldClose(core::window)) { glfwPollEvents(); // Start the Dear ImGui frame @@ -350,13 +352,13 @@ int sdrpp_main(int argc, char *argv[]) { core::configManager.aquire(); core::configManager.conf["maximized"]= _maximized; if (!maximized) { - glfwSetWindowSize(window, core::configManager.conf["windowSize"]["w"], core::configManager.conf["windowSize"]["h"]); + glfwSetWindowSize(core::window, core::configManager.conf["windowSize"]["w"], core::configManager.conf["windowSize"]["h"]); } core::configManager.release(true); } int _winWidth, _winHeight; - glfwGetWindowSize(window, &_winWidth, &_winHeight); + glfwGetWindowSize(core::window, &_winWidth, &_winHeight); if (ImGui::IsKeyPressed(GLFW_KEY_F11)) { fullScreen = !fullScreen; @@ -364,13 +366,13 @@ int sdrpp_main(int argc, char *argv[]) { spdlog::info("Fullscreen: ON"); fsWidth = _winWidth; fsHeight = _winHeight; - glfwGetWindowPos(window, &fsPosX, &fsPosY); + glfwGetWindowPos(core::window, &fsPosX, &fsPosY); const GLFWvidmode * mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); - glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, 0); + glfwSetWindowMonitor(core::window, monitor, 0, 0, mode->width, mode->height, 0); } else { spdlog::info("Fullscreen: OFF"); - glfwSetWindowMonitor(window, nullptr, fsPosX, fsPosY, fsWidth, fsHeight, 0); + glfwSetWindowMonitor(core::window, nullptr, fsPosX, fsPosY, fsWidth, fsHeight, 0); } } @@ -392,7 +394,7 @@ int sdrpp_main(int argc, char *argv[]) { // Rendering ImGui::Render(); int display_w, display_h; - glfwGetFramebufferSize(window, &display_w, &display_h); + glfwGetFramebufferSize(core::window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(0.0666f, 0.0666f, 0.0666f, 1.0f); //glClearColor(0.9f, 0.9f, 0.9f, 1.0f); @@ -400,7 +402,7 @@ int sdrpp_main(int argc, char *argv[]) { ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapInterval(1); // Enable vsync - glfwSwapBuffers(window); + glfwSwapBuffers(core::window); } // Cleanup @@ -408,7 +410,7 @@ int sdrpp_main(int argc, char *argv[]) { ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); - glfwDestroyWindow(window); + glfwDestroyWindow(core::window); glfwTerminate(); return 0; diff --git a/core/src/glfw_window.h b/core/src/glfw_window.h new file mode 100644 index 00000000..5c40d087 --- /dev/null +++ b/core/src/glfw_window.h @@ -0,0 +1,6 @@ +#include +#include + +namespace core { + SDRPP_EXPORT GLFWwindow* window; +}; \ No newline at end of file diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index dc7d0ee6..52b35d73 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -436,10 +436,10 @@ void drawWindow() { // Handle arrow keys if (vfo != NULL) { - if (ImGui::IsKeyPressed(GLFW_KEY_LEFT)) { + if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && !gui::freqSelect.digitHovered) { setVFO(gui::waterfall.getCenterFrequency() + vfo->generalOffset - vfo->snapInterval); } - if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT)) { + if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && !gui::freqSelect.digitHovered) { setVFO(gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval); } core::configManager.aquire(); diff --git a/core/src/gui/widgets/frequency_select.cpp b/core/src/gui/widgets/frequency_select.cpp index e10b5ed0..c50bbfc6 100644 --- a/core/src/gui/widgets/frequency_select.cpp +++ b/core/src/gui/widgets/frequency_select.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #ifndef IMGUI_DEFINE_MATH_OPERATORS @@ -127,6 +128,7 @@ void FrequencySelect::draw() { bool rightClick = ImGui::IsMouseClicked(ImGuiMouseButton_Right); int mw = ImGui::GetIO().MouseWheel; bool onDigit = false; + bool hovered = false; for (int i = 0; i < 12; i++) { onDigit = false; @@ -145,6 +147,7 @@ void FrequencySelect::draw() { onDigit = true; } if (onDigit) { + hovered = true; if (rightClick) { for (int j = i; j < 12; j++) { digits[j] = 0; @@ -157,6 +160,19 @@ void FrequencySelect::draw() { if (ImGui::IsKeyPressed(GLFW_KEY_DOWN)) { decrementDigit(i); } + if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && i > 0) { + double xpos, ypos; + glfwGetCursorPos(core::window, &xpos, &ypos); + float nxpos = (digitTopMaxs[i - 1].x + digitTopMins[i - 1].x) / 2.0f; + glfwSetCursorPos(core::window, nxpos, ypos); + + } + if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && i < 11) { + double xpos, ypos; + glfwGetCursorPos(core::window, &xpos, &ypos); + float nxpos = (digitTopMaxs[i + 1].x + digitTopMins[i + 1].x) / 2.0f; + glfwSetCursorPos(core::window, nxpos, ypos); + } if (mw != 0) { int count = abs(mw); for (int j = 0; j < count; j++) { @@ -166,6 +182,8 @@ void FrequencySelect::draw() { } } + digitHovered = hovered; + uint64_t freq = 0; for (int i = 0; i < 12; i++) { freq += digits[i] * pow(10, 11 - i); diff --git a/core/src/gui/widgets/frequency_select.h b/core/src/gui/widgets/frequency_select.h index 1a81a9f2..37833fbd 100644 --- a/core/src/gui/widgets/frequency_select.h +++ b/core/src/gui/widgets/frequency_select.h @@ -12,6 +12,7 @@ public: uint64_t frequency; bool frequencyChanged = false; + bool digitHovered = false; private: void onPosChange();