mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-11-10 04:37:37 +01:00
Backend abstraction
This commit is contained in:
parent
3c19081561
commit
9969ce018b
@ -7,6 +7,9 @@ else()
|
|||||||
set(CMAKE_INSTALL_PREFIX "/usr")
|
set(CMAKE_INSTALL_PREFIX "/usr")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Backends
|
||||||
|
option(OPT_BACKEND_GLFW "Use the GLFW backend" ON)
|
||||||
|
|
||||||
# Compatibility Options
|
# Compatibility Options
|
||||||
option(OPT_OVERRIDE_STD_FILESYSTEM "Use a local version of std::filesystem on systems that don't have it yet" OFF)
|
option(OPT_OVERRIDE_STD_FILESYSTEM "Use a local version of std::filesystem on systems that don't have it yet" OFF)
|
||||||
|
|
||||||
|
@ -17,8 +17,13 @@ if (MSVC)
|
|||||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# Configure backend sources
|
||||||
|
if (OPT_BACKEND_GLFW)
|
||||||
|
file(GLOB_RECURSE BACKEND_SRC "backends/glfw/*.cpp" "backends/glfw/*.c")
|
||||||
|
endif (OPT_BACKEND_GLFW)
|
||||||
|
|
||||||
# Add code to dyn lib
|
# Add code to dyn lib
|
||||||
add_library(sdrpp_core SHARED ${SRC})
|
add_library(sdrpp_core SHARED ${SRC} ${BACKEND_SRC})
|
||||||
|
|
||||||
# Set compiler options
|
# Set compiler options
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
@ -36,6 +41,25 @@ target_compile_definitions(sdrpp_core PUBLIC INSTALL_PREFIX="${CMAKE_INSTALL_PRE
|
|||||||
target_include_directories(sdrpp_core PUBLIC "src/")
|
target_include_directories(sdrpp_core PUBLIC "src/")
|
||||||
target_include_directories(sdrpp_core PUBLIC "src/imgui")
|
target_include_directories(sdrpp_core PUBLIC "src/imgui")
|
||||||
|
|
||||||
|
# Configure backend includes and libraries
|
||||||
|
if (OPT_BACKEND_GLFW)
|
||||||
|
target_include_directories(sdrpp_core PUBLIC "backends/glfw")
|
||||||
|
target_include_directories(sdrpp_core PUBLIC "backends/glfw/imgui")
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
# GLFW3
|
||||||
|
find_package(glfw3 CONFIG REQUIRED)
|
||||||
|
target_link_libraries(sdrpp_core PUBLIC glfw)
|
||||||
|
else()
|
||||||
|
find_package(PkgConfig)
|
||||||
|
pkg_check_modules(GLFW3 REQUIRED glfw3)
|
||||||
|
|
||||||
|
target_include_directories(sdrpp_core PUBLIC ${GLFW3_INCLUDE_DIRS})
|
||||||
|
target_link_directories(sdrpp_core PUBLIC ${GLFW3_LIBRARY_DIRS})
|
||||||
|
target_link_libraries(sdrpp_core PUBLIC ${GLFW3_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
endif (OPT_BACKEND_GLFW)
|
||||||
|
|
||||||
# Link to libcorrect
|
# Link to libcorrect
|
||||||
if (USE_INTERNAL_LIBCORRECT)
|
if (USE_INTERNAL_LIBCORRECT)
|
||||||
target_include_directories(sdrpp_core PUBLIC "libcorrect/include")
|
target_include_directories(sdrpp_core PUBLIC "libcorrect/include")
|
||||||
|
301
core/backends/glfw/backend.cpp
Normal file
301
core/backends/glfw/backend.cpp
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
#include <backend.h>
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "imgui_impl_glfw.h"
|
||||||
|
#include "imgui_impl_opengl3.h"
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <utils/opengl_include_code.h>
|
||||||
|
#include <version.h>
|
||||||
|
#include <core.h>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <stb_image.h>
|
||||||
|
#include <stb_image_resize.h>
|
||||||
|
#include <gui/gui.h>
|
||||||
|
|
||||||
|
namespace backend {
|
||||||
|
const char* OPENGL_VERSIONS_GLSL[] = {
|
||||||
|
"#version 120",
|
||||||
|
"#version 300 es",
|
||||||
|
"#version 120"
|
||||||
|
};
|
||||||
|
|
||||||
|
const int OPENGL_VERSIONS_MAJOR[] = {
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2
|
||||||
|
};
|
||||||
|
|
||||||
|
const int OPENGL_VERSIONS_MINOR[] = {
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
};
|
||||||
|
|
||||||
|
const bool OPENGL_VERSIONS_IS_ES[] = {
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
#define OPENGL_VERSION_COUNT (sizeof(OPENGL_VERSIONS_GLSL) / sizeof(char*))
|
||||||
|
|
||||||
|
bool maximized = false;
|
||||||
|
bool fullScreen = false;
|
||||||
|
int winHeight;
|
||||||
|
int winWidth;
|
||||||
|
bool _maximized = maximized;
|
||||||
|
int fsWidth, fsHeight, fsPosX, fsPosY;
|
||||||
|
int _winWidth, _winHeight;
|
||||||
|
GLFWwindow* window;
|
||||||
|
GLFWmonitor* monitor;
|
||||||
|
|
||||||
|
static void glfw_error_callback(int error, const char* description) {
|
||||||
|
spdlog::error("Glfw Error {0}: {1}", error, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void maximized_callback(GLFWwindow* window, int n) {
|
||||||
|
if (n == GLFW_TRUE) {
|
||||||
|
maximized = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
maximized = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int init(std::string resDir) {
|
||||||
|
// Load config
|
||||||
|
core::configManager.acquire();
|
||||||
|
winWidth = core::configManager.conf["windowSize"]["w"];
|
||||||
|
winHeight = core::configManager.conf["windowSize"]["h"];
|
||||||
|
maximized = core::configManager.conf["maximized"];
|
||||||
|
fullScreen = core::configManager.conf["fullscreen"];
|
||||||
|
core::configManager.release();
|
||||||
|
|
||||||
|
// Setup window
|
||||||
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
|
if (!glfwInit()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// GL 3.2 + GLSL 150
|
||||||
|
const char* glsl_version = "#version 150";
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
||||||
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
|
||||||
|
|
||||||
|
// Create window with graphics context
|
||||||
|
monitor = glfwGetPrimaryMonitor();
|
||||||
|
window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
|
||||||
|
if (window == NULL)
|
||||||
|
return 1;
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
#else
|
||||||
|
const char* glsl_version = "#version 120";
|
||||||
|
monitor = NULL;
|
||||||
|
for (int i = 0; i < OPENGL_VERSION_COUNT; i++) {
|
||||||
|
glsl_version = OPENGL_VERSIONS_GLSL[i];
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, OPENGL_VERSIONS_IS_ES[i] ? GLFW_OPENGL_ES_API : GLFW_OPENGL_API);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_VERSIONS_MAJOR[i]);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_VERSIONS_MINOR[i]);
|
||||||
|
|
||||||
|
// Create window with graphics context
|
||||||
|
monitor = glfwGetPrimaryMonitor();
|
||||||
|
window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
|
||||||
|
if (window == NULL) {
|
||||||
|
spdlog::info("OpenGL {0}.{1} {2}was not supported", OPENGL_VERSIONS_MAJOR[i], OPENGL_VERSIONS_MINOR[i], OPENGL_VERSIONS_IS_ES[i] ? "ES " : "");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
spdlog::info("Using OpenGL {0}.{1}{2}", OPENGL_VERSIONS_MAJOR[i], OPENGL_VERSIONS_MINOR[i], OPENGL_VERSIONS_IS_ES[i] ? " ES" : "");
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Add callback for max/min if GLFW supports it
|
||||||
|
#if (GLFW_VERSION_MAJOR == 3) && (GLFW_VERSION_MINOR >= 3)
|
||||||
|
if (maximized) {
|
||||||
|
glfwMaximizeWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwSetWindowMaximizeCallback(window, maximized_callback);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Load app icon
|
||||||
|
if (!std::filesystem::is_regular_file(resDir + "/icons/sdrpp.png")) {
|
||||||
|
spdlog::error("Icon file '{0}' doesn't exist!", resDir + "/icons/sdrpp.png");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLFWimage icons[10];
|
||||||
|
icons[0].pixels = stbi_load(((std::string)(resDir + "/icons/sdrpp.png")).c_str(), &icons[0].width, &icons[0].height, 0, 4);
|
||||||
|
icons[1].pixels = (unsigned char*)malloc(16 * 16 * 4);
|
||||||
|
icons[1].width = icons[1].height = 16;
|
||||||
|
icons[2].pixels = (unsigned char*)malloc(24 * 24 * 4);
|
||||||
|
icons[2].width = icons[2].height = 24;
|
||||||
|
icons[3].pixels = (unsigned char*)malloc(32 * 32 * 4);
|
||||||
|
icons[3].width = icons[3].height = 32;
|
||||||
|
icons[4].pixels = (unsigned char*)malloc(48 * 48 * 4);
|
||||||
|
icons[4].width = icons[4].height = 48;
|
||||||
|
icons[5].pixels = (unsigned char*)malloc(64 * 64 * 4);
|
||||||
|
icons[5].width = icons[5].height = 64;
|
||||||
|
icons[6].pixels = (unsigned char*)malloc(96 * 96 * 4);
|
||||||
|
icons[6].width = icons[6].height = 96;
|
||||||
|
icons[7].pixels = (unsigned char*)malloc(128 * 128 * 4);
|
||||||
|
icons[7].width = icons[7].height = 128;
|
||||||
|
icons[8].pixels = (unsigned char*)malloc(196 * 196 * 4);
|
||||||
|
icons[8].width = icons[8].height = 196;
|
||||||
|
icons[9].pixels = (unsigned char*)malloc(256 * 256 * 4);
|
||||||
|
icons[9].width = icons[9].height = 256;
|
||||||
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[1].pixels, 16, 16, 16 * 4, 4);
|
||||||
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[2].pixels, 24, 24, 24 * 4, 4);
|
||||||
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[3].pixels, 32, 32, 32 * 4, 4);
|
||||||
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[4].pixels, 48, 48, 48 * 4, 4);
|
||||||
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[5].pixels, 64, 64, 64 * 4, 4);
|
||||||
|
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[6].pixels, 96, 96, 96 * 4, 4);
|
||||||
|
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);
|
||||||
|
stbi_image_free(icons[0].pixels);
|
||||||
|
for (int i = 1; i < 10; i++) {
|
||||||
|
free(icons[i].pixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup Dear ImGui context
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
(void)io;
|
||||||
|
io.IniFilename = NULL;
|
||||||
|
|
||||||
|
// Setup Platform/Renderer bindings
|
||||||
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
|
|
||||||
|
if (!ImGui_ImplOpenGL3_Init(glsl_version)) {
|
||||||
|
// If init fail, try to fall back on GLSL 1.2
|
||||||
|
spdlog::warn("Could not init using OpenGL with normal GLSL version, falling back to GLSL 1.2");
|
||||||
|
if (!ImGui_ImplOpenGL3_Init("#version 120")) {
|
||||||
|
spdlog::error("Failed to initialize OpenGL with GLSL 1.2");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set window size and fullscreen state
|
||||||
|
glfwGetWindowSize(window, &_winWidth, &_winHeight);
|
||||||
|
if (fullScreen) {
|
||||||
|
spdlog::info("Fullscreen: ON");
|
||||||
|
fsWidth = _winWidth;
|
||||||
|
fsHeight = _winHeight;
|
||||||
|
glfwGetWindowPos(window, &fsPosX, &fsPosY);
|
||||||
|
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
|
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything went according to plan
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginFrame() {
|
||||||
|
// Start the Dear ImGui frame
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
ImGui_ImplGlfw_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
void render(bool vsync) {
|
||||||
|
// Rendering
|
||||||
|
ImGui::Render();
|
||||||
|
int display_w, display_h;
|
||||||
|
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||||
|
glViewport(0, 0, display_w, display_h);
|
||||||
|
glClearColor(gui::themeManager.clearColor.x, gui::themeManager.clearColor.y, gui::themeManager.clearColor.z, gui::themeManager.clearColor.w);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
|
glfwSwapInterval(vsync);
|
||||||
|
glfwSwapBuffers(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void getMouseScreenPos(double& x, double& y) {
|
||||||
|
glfwGetCursorPos(window, &x, &y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMouseScreenPos(double x, double y) {
|
||||||
|
glfwSetCursorPos(window, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int renderLoop() {
|
||||||
|
// Main loop
|
||||||
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
glfwPollEvents();
|
||||||
|
|
||||||
|
beginFrame();
|
||||||
|
|
||||||
|
if (_maximized != maximized) {
|
||||||
|
_maximized = maximized;
|
||||||
|
core::configManager.acquire();
|
||||||
|
core::configManager.conf["maximized"] = _maximized;
|
||||||
|
if (!maximized) {
|
||||||
|
glfwSetWindowSize(window, core::configManager.conf["windowSize"]["w"], core::configManager.conf["windowSize"]["h"]);
|
||||||
|
}
|
||||||
|
core::configManager.release(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwGetWindowSize(window, &_winWidth, &_winHeight);
|
||||||
|
|
||||||
|
if (ImGui::IsKeyPressed(GLFW_KEY_F11)) {
|
||||||
|
fullScreen = !fullScreen;
|
||||||
|
if (fullScreen) {
|
||||||
|
spdlog::info("Fullscreen: ON");
|
||||||
|
fsWidth = _winWidth;
|
||||||
|
fsHeight = _winHeight;
|
||||||
|
glfwGetWindowPos(window, &fsPosX, &fsPosY);
|
||||||
|
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
|
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, 0);
|
||||||
|
core::configManager.acquire();
|
||||||
|
core::configManager.conf["fullscreen"] = true;
|
||||||
|
core::configManager.release();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
spdlog::info("Fullscreen: OFF");
|
||||||
|
glfwSetWindowMonitor(window, nullptr, fsPosX, fsPosY, fsWidth, fsHeight, 0);
|
||||||
|
core::configManager.acquire();
|
||||||
|
core::configManager.conf["fullscreen"] = false;
|
||||||
|
core::configManager.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((_winWidth != winWidth || _winHeight != winHeight) && !maximized && _winWidth > 0 && _winHeight > 0) {
|
||||||
|
winWidth = _winWidth;
|
||||||
|
winHeight = _winHeight;
|
||||||
|
core::configManager.acquire();
|
||||||
|
core::configManager.conf["windowSize"]["w"] = winWidth;
|
||||||
|
core::configManager.conf["windowSize"]["h"] = winHeight;
|
||||||
|
core::configManager.release(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (winWidth > 0 && winHeight > 0) {
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||||
|
ImGui::SetNextWindowSize(ImVec2(_winWidth, _winHeight));
|
||||||
|
gui::mainWindow.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int end() {
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
glfwDestroyWindow(window);
|
||||||
|
glfwTerminate();
|
||||||
|
|
||||||
|
return 0; // TODO: Int really needed?
|
||||||
|
}
|
||||||
|
}
|
24
core/backends/glfw/keybinds.h
Normal file
24
core/backends/glfw/keybinds.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#define KB_KEY_HOME GLFW_KEY_HOME
|
||||||
|
#define KB_KEY_MENU GLFW_KEY_MENU
|
||||||
|
#define KB_KEY_END GLFW_KEY_END
|
||||||
|
#define KB_KEY_ESC GLFW_KEY_ESCAPE
|
||||||
|
#define KB_KEY_PG_UP GLFW_KEY_PAGE_UP
|
||||||
|
#define KB_KEY_PG_DOWN GLFW_KEY_PAGE_DOWN
|
||||||
|
|
||||||
|
#define KB_KEY_ENTER GLFW_KEY_ENTER
|
||||||
|
#define KB_KEY_KP_ENTER GLFW_KEY_KP_ENTER
|
||||||
|
#define KB_KEY_DEL GLFW_KEY_DELETE
|
||||||
|
#define KB_KEY_BACKSPACE GLFW_KEY_BACKSPACE
|
||||||
|
|
||||||
|
#define KB_KEY_LEFT GLFW_KEY_LEFT
|
||||||
|
#define KB_KEY_RIGHT GLFW_KEY_RIGHT
|
||||||
|
#define KB_KEY_UP GLFW_KEY_UP
|
||||||
|
#define KB_KEY_DOWN GLFW_KEY_DOWN
|
||||||
|
|
||||||
|
#define KB_KEY_LCTRL GLFW_KEY_LEFT_CONTROL
|
||||||
|
#define KB_KEY_RCTRL GLFW_KEY_RIGHT_CONTROL
|
||||||
|
#define KB_KEY_LSHIFT GLFW_KEY_LEFT_SHIFT
|
||||||
|
#define KB_KEY_RSHIFT GLFW_KEY_RIGHT_SHIFT
|
12
core/src/backend.h
Normal file
12
core/src/backend.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace backend {
|
||||||
|
int init(std::string resDir);
|
||||||
|
void beginFrame();
|
||||||
|
void render(bool vsync = true);
|
||||||
|
void getMouseScreenPos(double& x, double& y);
|
||||||
|
void setMouseScreenPos(double x, double y);
|
||||||
|
int renderLoop();
|
||||||
|
int end();
|
||||||
|
}
|
@ -3,7 +3,6 @@
|
|||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "imgui_impl_opengl3.h"
|
#include "imgui_impl_opengl3.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <gui/main_window.h>
|
#include <gui/main_window.h>
|
||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
@ -14,10 +13,10 @@
|
|||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <core.h>
|
#include <core.h>
|
||||||
#include <glfw_window.h>
|
|
||||||
#include <options.h>
|
#include <options.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <gui/menus/theme.h>
|
#include <gui/menus/theme.h>
|
||||||
|
#include <backend.h>
|
||||||
|
|
||||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||||
#include <stb_image_resize.h>
|
#include <stb_image_resize.h>
|
||||||
@ -36,37 +35,10 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char* OPENGL_VERSIONS_GLSL[] = {
|
|
||||||
"#version 120",
|
|
||||||
"#version 300 es",
|
|
||||||
"#version 120"
|
|
||||||
};
|
|
||||||
|
|
||||||
const int OPENGL_VERSIONS_MAJOR[] = {
|
|
||||||
3,
|
|
||||||
3,
|
|
||||||
2
|
|
||||||
};
|
|
||||||
|
|
||||||
const int OPENGL_VERSIONS_MINOR[] = {
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
1
|
|
||||||
};
|
|
||||||
|
|
||||||
const bool OPENGL_VERSIONS_IS_ES[] = {
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
#define OPENGL_VERSION_COUNT (sizeof(OPENGL_VERSIONS_GLSL) / sizeof(char*))
|
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
ConfigManager configManager;
|
ConfigManager configManager;
|
||||||
ModuleManager moduleManager;
|
ModuleManager moduleManager;
|
||||||
ModuleComManager modComManager;
|
ModuleComManager modComManager;
|
||||||
GLFWwindow* window;
|
|
||||||
|
|
||||||
void setInputSampleRate(double samplerate) {
|
void setInputSampleRate(double samplerate) {
|
||||||
// Forward this to the server
|
// Forward this to the server
|
||||||
@ -84,22 +56,6 @@ namespace core {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool maximized = false;
|
|
||||||
bool fullScreen = false;
|
|
||||||
|
|
||||||
static void glfw_error_callback(int error, const char* description) {
|
|
||||||
spdlog::error("Glfw Error {0}: {1}", error, description);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void maximized_callback(GLFWwindow* window, int n) {
|
|
||||||
if (n == GLFW_TRUE) {
|
|
||||||
maximized = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
maximized = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// main
|
// main
|
||||||
int sdrpp_main(int argc, char* argv[]) {
|
int sdrpp_main(int argc, char* argv[]) {
|
||||||
spdlog::info("SDR++ v" VERSION_STR);
|
spdlog::info("SDR++ v" VERSION_STR);
|
||||||
@ -268,7 +224,6 @@ int sdrpp_main(int argc, char* argv[]) {
|
|||||||
core::configManager.load(defConfig);
|
core::configManager.load(defConfig);
|
||||||
core::configManager.enableAutoSave();
|
core::configManager.enableAutoSave();
|
||||||
|
|
||||||
|
|
||||||
core::configManager.acquire();
|
core::configManager.acquire();
|
||||||
// Fix missing elements in config
|
// Fix missing elements in config
|
||||||
for (auto const& item : defConfig.items()) {
|
for (auto const& item : defConfig.items()) {
|
||||||
@ -297,16 +252,11 @@ int sdrpp_main(int argc, char* argv[]) {
|
|||||||
core::configManager.conf["moduleInstances"][_name] = newMod;
|
core::configManager.conf["moduleInstances"][_name] = newMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
fullScreen = core::configManager.conf["fullscreen"];
|
|
||||||
|
|
||||||
core::configManager.release(true);
|
core::configManager.release(true);
|
||||||
|
|
||||||
if (options::opts.serverMode) { return server::main(); }
|
if (options::opts.serverMode) { return server::main(); }
|
||||||
|
|
||||||
core::configManager.acquire();
|
core::configManager.acquire();
|
||||||
int winWidth = core::configManager.conf["windowSize"]["w"];
|
|
||||||
int winHeight = core::configManager.conf["windowSize"]["h"];
|
|
||||||
maximized = core::configManager.conf["maximized"];
|
|
||||||
std::string resDir = core::configManager.conf["resourcesDirectory"];
|
std::string resDir = core::configManager.conf["resourcesDirectory"];
|
||||||
json bandColors = core::configManager.conf["bandColors"];
|
json bandColors = core::configManager.conf["bandColors"];
|
||||||
core::configManager.release();
|
core::configManager.release();
|
||||||
@ -318,123 +268,13 @@ int sdrpp_main(int argc, char* argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup window
|
// Initialize backend
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
int biRes = backend::init(resDir);
|
||||||
if (!glfwInit()) {
|
if (biRes < 0) { return biRes; }
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
// GL 3.2 + GLSL 150
|
|
||||||
const char* glsl_version = "#version 150";
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
|
|
||||||
|
|
||||||
// Create window with graphics context
|
|
||||||
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
|
|
||||||
core::window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
|
|
||||||
if (core::window == NULL)
|
|
||||||
return 1;
|
|
||||||
glfwMakeContextCurrent(core::window);
|
|
||||||
#else
|
|
||||||
const char* glsl_version = "#version 120";
|
|
||||||
GLFWmonitor* monitor = NULL;
|
|
||||||
for (int i = 0; i < OPENGL_VERSION_COUNT; i++) {
|
|
||||||
glsl_version = OPENGL_VERSIONS_GLSL[i];
|
|
||||||
glfwWindowHint(GLFW_CLIENT_API, OPENGL_VERSIONS_IS_ES[i] ? GLFW_OPENGL_ES_API : GLFW_OPENGL_API);
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_VERSIONS_MAJOR[i]);
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_VERSIONS_MINOR[i]);
|
|
||||||
|
|
||||||
// Create window with graphics context
|
|
||||||
monitor = glfwGetPrimaryMonitor();
|
|
||||||
core::window = glfwCreateWindow(winWidth, winHeight, "SDR++ v" VERSION_STR " (Built at " __TIME__ ", " __DATE__ ")", NULL, NULL);
|
|
||||||
if (core::window == NULL) {
|
|
||||||
spdlog::info("OpenGL {0}.{1} {2}was not supported", OPENGL_VERSIONS_MAJOR[i], OPENGL_VERSIONS_MINOR[i], OPENGL_VERSIONS_IS_ES[i] ? "ES " : "");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
spdlog::info("Using OpenGL {0}.{1}{2}", OPENGL_VERSIONS_MAJOR[i], OPENGL_VERSIONS_MINOR[i], OPENGL_VERSIONS_IS_ES[i] ? " ES" : "");
|
|
||||||
glfwMakeContextCurrent(core::window);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Add callback for max/min if GLFW supports it
|
|
||||||
#if (GLFW_VERSION_MAJOR == 3) && (GLFW_VERSION_MINOR >= 3)
|
|
||||||
if (maximized) {
|
|
||||||
glfwMaximizeWindow(core::window);
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwSetWindowMaximizeCallback(core::window, maximized_callback);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Load app icon
|
|
||||||
if (!std::filesystem::is_regular_file(resDir + "/icons/sdrpp.png")) {
|
|
||||||
spdlog::error("Icon file '{0}' doesn't exist!", resDir + "/icons/sdrpp.png");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
GLFWimage icons[10];
|
|
||||||
icons[0].pixels = stbi_load(((std::string)(resDir + "/icons/sdrpp.png")).c_str(), &icons[0].width, &icons[0].height, 0, 4);
|
|
||||||
icons[1].pixels = (unsigned char*)malloc(16 * 16 * 4);
|
|
||||||
icons[1].width = icons[1].height = 16;
|
|
||||||
icons[2].pixels = (unsigned char*)malloc(24 * 24 * 4);
|
|
||||||
icons[2].width = icons[2].height = 24;
|
|
||||||
icons[3].pixels = (unsigned char*)malloc(32 * 32 * 4);
|
|
||||||
icons[3].width = icons[3].height = 32;
|
|
||||||
icons[4].pixels = (unsigned char*)malloc(48 * 48 * 4);
|
|
||||||
icons[4].width = icons[4].height = 48;
|
|
||||||
icons[5].pixels = (unsigned char*)malloc(64 * 64 * 4);
|
|
||||||
icons[5].width = icons[5].height = 64;
|
|
||||||
icons[6].pixels = (unsigned char*)malloc(96 * 96 * 4);
|
|
||||||
icons[6].width = icons[6].height = 96;
|
|
||||||
icons[7].pixels = (unsigned char*)malloc(128 * 128 * 4);
|
|
||||||
icons[7].width = icons[7].height = 128;
|
|
||||||
icons[8].pixels = (unsigned char*)malloc(196 * 196 * 4);
|
|
||||||
icons[8].width = icons[8].height = 196;
|
|
||||||
icons[9].pixels = (unsigned char*)malloc(256 * 256 * 4);
|
|
||||||
icons[9].width = icons[9].height = 256;
|
|
||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[1].pixels, 16, 16, 16 * 4, 4);
|
|
||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[2].pixels, 24, 24, 24 * 4, 4);
|
|
||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[3].pixels, 32, 32, 32 * 4, 4);
|
|
||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[4].pixels, 48, 48, 48 * 4, 4);
|
|
||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[5].pixels, 64, 64, 64 * 4, 4);
|
|
||||||
stbir_resize_uint8(icons[0].pixels, icons[0].width, icons[0].height, icons[0].width * 4, icons[6].pixels, 96, 96, 96 * 4, 4);
|
|
||||||
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(core::window, 10, icons);
|
|
||||||
stbi_image_free(icons[0].pixels);
|
|
||||||
for (int i = 1; i < 10; i++) {
|
|
||||||
free(icons[i].pixels);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
ImGui::CreateContext();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
(void)io;
|
|
||||||
io.IniFilename = NULL;
|
|
||||||
|
|
||||||
// Setup Platform/Renderer bindings
|
|
||||||
ImGui_ImplGlfw_InitForOpenGL(core::window, true);
|
|
||||||
|
|
||||||
if (!ImGui_ImplOpenGL3_Init(glsl_version)) {
|
|
||||||
// If init fail, try to fall back on GLSL 1.2
|
|
||||||
spdlog::warn("Could not init using OpenGL with normal GLSL version, falling back to GLSL 1.2");
|
|
||||||
if (!ImGui_ImplOpenGL3_Init("#version 120")) {
|
|
||||||
spdlog::error("Failed to initialize OpenGL with GLSL 1.2");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!style::loadFonts(resDir)) { return -1; }
|
if (!style::loadFonts(resDir)) { return -1; }
|
||||||
thememenu::init(resDir);
|
thememenu::init(resDir);
|
||||||
|
|
||||||
LoadingScreen::setWindow(core::window);
|
|
||||||
|
|
||||||
LoadingScreen::show("Loading icons");
|
LoadingScreen::show("Loading icons");
|
||||||
spdlog::info("Loading icons");
|
spdlog::info("Loading icons");
|
||||||
if (!icons::load(resDir)) { return -1; }
|
if (!icons::load(resDir)) { return -1; }
|
||||||
@ -447,110 +287,20 @@ int sdrpp_main(int argc, char* argv[]) {
|
|||||||
spdlog::info("Loading band plans color table");
|
spdlog::info("Loading band plans color table");
|
||||||
bandplan::loadColorTable(bandColors);
|
bandplan::loadColorTable(bandColors);
|
||||||
|
|
||||||
bool _maximized = maximized;
|
|
||||||
int fsWidth, fsHeight, fsPosX, fsPosY;
|
|
||||||
int _winWidth, _winHeight;
|
|
||||||
glfwGetWindowSize(core::window, &_winWidth, &_winHeight);
|
|
||||||
|
|
||||||
if (fullScreen) {
|
|
||||||
spdlog::info("Fullscreen: ON");
|
|
||||||
fsWidth = _winWidth;
|
|
||||||
fsHeight = _winHeight;
|
|
||||||
glfwGetWindowPos(core::window, &fsPosX, &fsPosY);
|
|
||||||
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
|
||||||
glfwSetWindowMonitor(core::window, monitor, 0, 0, mode->width, mode->height, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
gui::mainWindow.init();
|
gui::mainWindow.init();
|
||||||
|
|
||||||
spdlog::info("Ready.");
|
spdlog::info("Ready.");
|
||||||
|
|
||||||
// Main loop
|
// Run render loop (TODO: CHECK RETURN VALUE)
|
||||||
while (!glfwWindowShouldClose(core::window)) {
|
backend::renderLoop();
|
||||||
glfwPollEvents();
|
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
|
||||||
ImGui_ImplGlfw_NewFrame();
|
|
||||||
ImGui::NewFrame();
|
|
||||||
|
|
||||||
//ImGui::ShowDemoWindow();
|
|
||||||
|
|
||||||
if (_maximized != maximized) {
|
|
||||||
_maximized = maximized;
|
|
||||||
core::configManager.acquire();
|
|
||||||
core::configManager.conf["maximized"] = _maximized;
|
|
||||||
if (!maximized) {
|
|
||||||
glfwSetWindowSize(core::window, core::configManager.conf["windowSize"]["w"], core::configManager.conf["windowSize"]["h"]);
|
|
||||||
}
|
|
||||||
core::configManager.release(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
glfwGetWindowSize(core::window, &_winWidth, &_winHeight);
|
|
||||||
|
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_F11)) {
|
|
||||||
fullScreen = !fullScreen;
|
|
||||||
if (fullScreen) {
|
|
||||||
spdlog::info("Fullscreen: ON");
|
|
||||||
fsWidth = _winWidth;
|
|
||||||
fsHeight = _winHeight;
|
|
||||||
glfwGetWindowPos(core::window, &fsPosX, &fsPosY);
|
|
||||||
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
|
||||||
glfwSetWindowMonitor(core::window, monitor, 0, 0, mode->width, mode->height, 0);
|
|
||||||
core::configManager.acquire();
|
|
||||||
core::configManager.conf["fullscreen"] = true;
|
|
||||||
core::configManager.release();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
spdlog::info("Fullscreen: OFF");
|
|
||||||
glfwSetWindowMonitor(core::window, nullptr, fsPosX, fsPosY, fsWidth, fsHeight, 0);
|
|
||||||
core::configManager.acquire();
|
|
||||||
core::configManager.conf["fullscreen"] = false;
|
|
||||||
core::configManager.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((_winWidth != winWidth || _winHeight != winHeight) && !maximized && _winWidth > 0 && _winHeight > 0) {
|
|
||||||
winWidth = _winWidth;
|
|
||||||
winHeight = _winHeight;
|
|
||||||
core::configManager.acquire();
|
|
||||||
core::configManager.conf["windowSize"]["w"] = winWidth;
|
|
||||||
core::configManager.conf["windowSize"]["h"] = winHeight;
|
|
||||||
core::configManager.release(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (winWidth > 0 && winHeight > 0) {
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
|
||||||
ImGui::SetNextWindowSize(ImVec2(_winWidth, _winHeight));
|
|
||||||
gui::mainWindow.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rendering
|
|
||||||
ImGui::Render();
|
|
||||||
int 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(gui::themeManager.clearColor.x, gui::themeManager.clearColor.y, gui::themeManager.clearColor.z, gui::themeManager.clearColor.w);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
||||||
|
|
||||||
glfwSwapInterval(1); // Enable vsync
|
|
||||||
glfwSwapBuffers(core::window);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Shut down all modules
|
// Shut down all modules
|
||||||
for (auto& [name, mod] : core::moduleManager.modules) {
|
for (auto& [name, mod] : core::moduleManager.modules) {
|
||||||
mod.end();
|
mod.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Terminate backend (TODO: CHECK RETURN VALUE)
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
backend::end();
|
||||||
ImGui_ImplGlfw_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
glfwDestroyWindow(core::window);
|
|
||||||
glfwTerminate();
|
|
||||||
|
|
||||||
sigpath::signalPath.stop();
|
sigpath::signalPath.stop();
|
||||||
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <module.h>
|
|
||||||
|
|
||||||
namespace core {
|
|
||||||
SDRPP_EXPORT GLFWwindow* window;
|
|
||||||
};
|
|
@ -7,20 +7,13 @@
|
|||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
#include <credits.h>
|
#include <credits.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
|
#include <backend.h>
|
||||||
|
|
||||||
namespace LoadingScreen {
|
namespace LoadingScreen {
|
||||||
GLFWwindow* _win;
|
|
||||||
|
|
||||||
void setWindow(GLFWwindow* win) {
|
|
||||||
_win = win;
|
|
||||||
}
|
|
||||||
|
|
||||||
void show(std::string msg) {
|
void show(std::string msg) {
|
||||||
glfwPollEvents();
|
backend::beginFrame();
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
|
||||||
ImGui_ImplGlfw_NewFrame();
|
|
||||||
|
|
||||||
ImGui::NewFrame();
|
|
||||||
ImGui::Begin("Main", NULL, WINDOW_FLAGS);
|
ImGui::Begin("Main", NULL, WINDOW_FLAGS);
|
||||||
|
|
||||||
|
|
||||||
@ -46,14 +39,6 @@ namespace LoadingScreen {
|
|||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
ImGui::Render();
|
backend::render(false);
|
||||||
int display_w, display_h;
|
|
||||||
glfwGetFramebufferSize(_win, &display_w, &display_h);
|
|
||||||
glViewport(0, 0, display_w, display_h);
|
|
||||||
glClearColor(gui::themeManager.clearColor.x, gui::themeManager.clearColor.y, gui::themeManager.clearColor.z, gui::themeManager.clearColor.w);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
||||||
|
|
||||||
glfwSwapBuffers(_win);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,9 +2,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
namespace LoadingScreen {
|
namespace LoadingScreen {
|
||||||
void setWindow(GLFWwindow* win);
|
|
||||||
void show(std::string msg);
|
void show(std::string msg);
|
||||||
};
|
};
|
@ -4,7 +4,6 @@
|
|||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "imgui_impl_opengl3.h"
|
#include "imgui_impl_opengl3.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
#include <gui/widgets/waterfall.h>
|
#include <gui/widgets/waterfall.h>
|
||||||
@ -31,6 +30,7 @@
|
|||||||
#include <gui/colormaps.h>
|
#include <gui/colormaps.h>
|
||||||
#include <gui/widgets/snr_meter.h>
|
#include <gui/widgets/snr_meter.h>
|
||||||
#include <gui/tuner.h>
|
#include <gui/tuner.h>
|
||||||
|
#include <keybinds.h>
|
||||||
|
|
||||||
void MainWindow::init() {
|
void MainWindow::init() {
|
||||||
LoadingScreen::show("Initializing UI");
|
LoadingScreen::show("Initializing UI");
|
||||||
@ -355,7 +355,7 @@ void MainWindow::draw() {
|
|||||||
|
|
||||||
// To Bar
|
// To Bar
|
||||||
ImGui::PushID(ImGui::GetID("sdrpp_menu_btn"));
|
ImGui::PushID(ImGui::GetID("sdrpp_menu_btn"));
|
||||||
if (ImGui::ImageButton(icons::MENU, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(GLFW_KEY_MENU, false)) {
|
if (ImGui::ImageButton(icons::MENU, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(KB_KEY_MENU, false)) {
|
||||||
showMenu = !showMenu;
|
showMenu = !showMenu;
|
||||||
core::configManager.acquire();
|
core::configManager.acquire();
|
||||||
core::configManager.conf["showMenu"] = showMenu;
|
core::configManager.conf["showMenu"] = showMenu;
|
||||||
@ -369,14 +369,14 @@ void MainWindow::draw() {
|
|||||||
if (playButtonLocked && !tmpPlaySate) { style::beginDisabled(); }
|
if (playButtonLocked && !tmpPlaySate) { style::beginDisabled(); }
|
||||||
if (playing) {
|
if (playing) {
|
||||||
ImGui::PushID(ImGui::GetID("sdrpp_stop_btn"));
|
ImGui::PushID(ImGui::GetID("sdrpp_stop_btn"));
|
||||||
if (ImGui::ImageButton(icons::STOP, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(GLFW_KEY_END, false)) {
|
if (ImGui::ImageButton(icons::STOP, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(KB_KEY_END, false)) {
|
||||||
setPlayState(false);
|
setPlayState(false);
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
else { // TODO: Might need to check if there even is a device
|
else { // TODO: Might need to check if there even is a device
|
||||||
ImGui::PushID(ImGui::GetID("sdrpp_play_btn"));
|
ImGui::PushID(ImGui::GetID("sdrpp_play_btn"));
|
||||||
if (ImGui::ImageButton(icons::PLAY, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(GLFW_KEY_END, false)) {
|
if (ImGui::ImageButton(icons::PLAY, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5) || ImGui::IsKeyPressed(KB_KEY_END, false)) {
|
||||||
setPlayState(true);
|
setPlayState(true);
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
@ -439,7 +439,7 @@ void MainWindow::draw() {
|
|||||||
if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) {
|
if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) {
|
||||||
showCredits = false;
|
showCredits = false;
|
||||||
}
|
}
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_ESCAPE)) {
|
if (ImGui::IsKeyPressed(KB_KEY_ESC)) {
|
||||||
showCredits = false;
|
showCredits = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,12 +557,12 @@ void MainWindow::draw() {
|
|||||||
if (!lockWaterfallControls) {
|
if (!lockWaterfallControls) {
|
||||||
// Handle arrow keys
|
// Handle arrow keys
|
||||||
if (vfo != NULL && (gui::waterfall.mouseInFFT || gui::waterfall.mouseInWaterfall)) {
|
if (vfo != NULL && (gui::waterfall.mouseInFFT || gui::waterfall.mouseInWaterfall)) {
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_LEFT) && !gui::freqSelect.digitHovered) {
|
if (ImGui::IsKeyPressed(KB_KEY_LEFT) && !gui::freqSelect.digitHovered) {
|
||||||
double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset - vfo->snapInterval;
|
double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset - vfo->snapInterval;
|
||||||
nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval;
|
nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval;
|
||||||
tuner::tune(tuningMode, gui::waterfall.selectedVFO, nfreq);
|
tuner::tune(tuningMode, gui::waterfall.selectedVFO, nfreq);
|
||||||
}
|
}
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && !gui::freqSelect.digitHovered) {
|
if (ImGui::IsKeyPressed(KB_KEY_RIGHT) && !gui::freqSelect.digitHovered) {
|
||||||
double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval;
|
double nfreq = gui::waterfall.getCenterFrequency() + vfo->generalOffset + vfo->snapInterval;
|
||||||
nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval;
|
nfreq = roundl(nfreq / vfo->snapInterval) * vfo->snapInterval;
|
||||||
tuner::tune(tuningMode, gui::waterfall.selectedVFO, nfreq);
|
tuner::tune(tuningMode, gui::waterfall.selectedVFO, nfreq);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <gui/main_window.h>
|
#include <gui/main_window.h>
|
||||||
#include <signal_path/signal_path.h>
|
#include <signal_path/signal_path.h>
|
||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
|
#include <keybinds.h>
|
||||||
|
|
||||||
namespace displaymenu {
|
namespace displaymenu {
|
||||||
bool showWaterfall;
|
bool showWaterfall;
|
||||||
@ -89,7 +90,7 @@ namespace displaymenu {
|
|||||||
|
|
||||||
void draw(void* ctx) {
|
void draw(void* ctx) {
|
||||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||||
bool homePressed = ImGui::IsKeyPressed(GLFW_KEY_HOME, false);
|
bool homePressed = ImGui::IsKeyPressed(KB_KEY_HOME, false);
|
||||||
if (ImGui::Checkbox("Show Waterfall##_sdrpp", &showWaterfall) || homePressed) {
|
if (ImGui::Checkbox("Show Waterfall##_sdrpp", &showWaterfall) || homePressed) {
|
||||||
if (homePressed) { showWaterfall = !showWaterfall; }
|
if (homePressed) { showWaterfall = !showWaterfall; }
|
||||||
showWaterfall ? gui::waterfall.showWaterfall() : gui::waterfall.hideWaterfall();
|
showWaterfall ? gui::waterfall.showWaterfall() : gui::waterfall.hideWaterfall();
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <glfw_window.h>
|
#include <backend.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <keybinds.h>
|
||||||
|
|
||||||
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
#ifndef IMGUI_DEFINE_MATH_OPERATORS
|
||||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||||
@ -87,9 +87,9 @@ void FrequencySelect::decrementDigit(int i) {
|
|||||||
|
|
||||||
void FrequencySelect::moveCursorToDigit(int i) {
|
void FrequencySelect::moveCursorToDigit(int i) {
|
||||||
double xpos, ypos;
|
double xpos, ypos;
|
||||||
glfwGetCursorPos(core::window, &xpos, &ypos);
|
backend::getMouseScreenPos(xpos, ypos);
|
||||||
float nxpos = (digitTopMaxs[i].x + digitTopMins[i].x) / 2.0f;
|
double nxpos = (digitTopMaxs[i].x + digitTopMins[i].x) / 2.0;
|
||||||
glfwSetCursorPos(core::window, nxpos, ypos);
|
backend::setMouseScreenPos(nxpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrequencySelect::draw() {
|
void FrequencySelect::draw() {
|
||||||
@ -165,23 +165,23 @@ void FrequencySelect::draw() {
|
|||||||
}
|
}
|
||||||
if (onDigit) {
|
if (onDigit) {
|
||||||
hovered = true;
|
hovered = true;
|
||||||
if (rightClick || (ImGui::IsKeyPressed(GLFW_KEY_DELETE) || ImGui::IsKeyPressed(GLFW_KEY_ENTER) || ImGui::IsKeyPressed(GLFW_KEY_KP_ENTER))) {
|
if (rightClick || (ImGui::IsKeyPressed(KB_KEY_DEL) || ImGui::IsKeyPressed(KB_KEY_ENTER) || ImGui::IsKeyPressed(KB_KEY_KP_ENTER))) {
|
||||||
for (int j = i; j < 12; j++) {
|
for (int j = i; j < 12; j++) {
|
||||||
digits[j] = 0;
|
digits[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
frequencyChanged = true;
|
frequencyChanged = true;
|
||||||
}
|
}
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_UP)) {
|
if (ImGui::IsKeyPressed(KB_KEY_UP)) {
|
||||||
incrementDigit(i);
|
incrementDigit(i);
|
||||||
}
|
}
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_DOWN)) {
|
if (ImGui::IsKeyPressed(KB_KEY_DOWN)) {
|
||||||
decrementDigit(i);
|
decrementDigit(i);
|
||||||
}
|
}
|
||||||
if ((ImGui::IsKeyPressed(GLFW_KEY_LEFT) || ImGui::IsKeyPressed(GLFW_KEY_BACKSPACE)) && i > 0) {
|
if ((ImGui::IsKeyPressed(KB_KEY_LEFT) || ImGui::IsKeyPressed(KB_KEY_BACKSPACE)) && i > 0) {
|
||||||
moveCursorToDigit(i - 1);
|
moveCursorToDigit(i - 1);
|
||||||
}
|
}
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_RIGHT) && i < 11) {
|
if (ImGui::IsKeyPressed(KB_KEY_RIGHT) && i < 11) {
|
||||||
moveCursorToDigit(i + 1);
|
moveCursorToDigit(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
#include <imutils.h>
|
#include <imutils.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <volk/volk.h>
|
#include <volk/volk.h>
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
|
#include <keybinds.h>
|
||||||
|
|
||||||
float DEFAULT_COLOR_MAP[][3] = {
|
float DEFAULT_COLOR_MAP[][3] = {
|
||||||
{ 0x00, 0x00, 0x20 },
|
{ 0x00, 0x00, 0x20 },
|
||||||
@ -387,8 +387,8 @@ namespace ImGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the left and right keys are pressed while hovering the freq scale, move it too
|
// If the left and right keys are pressed while hovering the freq scale, move it too
|
||||||
bool leftKeyPressed = ImGui::IsKeyPressed(GLFW_KEY_LEFT);
|
bool leftKeyPressed = ImGui::IsKeyPressed(KB_KEY_LEFT);
|
||||||
if ((leftKeyPressed || ImGui::IsKeyPressed(GLFW_KEY_RIGHT)) && mouseInFreq) {
|
if ((leftKeyPressed || ImGui::IsKeyPressed(KB_KEY_RIGHT)) && mouseInFreq) {
|
||||||
viewOffset += leftKeyPressed ? (viewBandwidth / 20.0) : (-viewBandwidth / 20.0);
|
viewOffset += leftKeyPressed ? (viewBandwidth / 20.0) : (-viewBandwidth / 20.0);
|
||||||
|
|
||||||
if (viewOffset + (viewBandwidth / 2.0) > wholeBandwidth / 2.0) {
|
if (viewOffset + (viewBandwidth / 2.0) > wholeBandwidth / 2.0) {
|
||||||
@ -435,7 +435,7 @@ namespace ImGui {
|
|||||||
|
|
||||||
ImGui::TextUnformatted(name.c_str());
|
ImGui::TextUnformatted(name.c_str());
|
||||||
|
|
||||||
if (ImGui::IsKeyDown(GLFW_KEY_LEFT_CONTROL) || ImGui::IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) {
|
if (ImGui::IsKeyDown(KB_KEY_LCTRL) || ImGui::IsKeyDown(KB_KEY_RCTRL)) {
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
printAndScale(_vfo->generalOffset + centerFreq, buf);
|
printAndScale(_vfo->generalOffset + centerFreq, buf);
|
||||||
ImGui::Text("Frequency: %sHz", buf);
|
ImGui::Text("Frequency: %sHz", buf);
|
||||||
@ -461,7 +461,7 @@ namespace ImGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle Page Up to cycle through VFOs
|
// Handle Page Up to cycle through VFOs
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_PAGE_UP) && selVfo != NULL) {
|
if (ImGui::IsKeyPressed(KB_KEY_PG_UP) && selVfo != NULL) {
|
||||||
std::string next = (--vfos.end())->first;
|
std::string next = (--vfos.end())->first;
|
||||||
std::string lowest = "";
|
std::string lowest = "";
|
||||||
double lowestOffset = INFINITY;
|
double lowestOffset = INFINITY;
|
||||||
@ -484,7 +484,7 @@ namespace ImGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle Page Down to cycle through VFOs
|
// Handle Page Down to cycle through VFOs
|
||||||
if (ImGui::IsKeyPressed(GLFW_KEY_PAGE_DOWN) && selVfo != NULL) {
|
if (ImGui::IsKeyPressed(KB_KEY_PG_DOWN) && selVfo != NULL) {
|
||||||
std::string next = (--vfos.end())->first;
|
std::string next = (--vfos.end())->first;
|
||||||
std::string highest = "";
|
std::string highest = "";
|
||||||
double highestOffset = -INFINITY;
|
double highestOffset = -INFINITY;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <gui/file_dialogs.h>
|
#include <gui/file_dialogs.h>
|
||||||
#include <utils/freq_formatting.h>
|
#include <utils/freq_formatting.h>
|
||||||
#include <gui/dialogs/dialog_box.h>
|
#include <gui/dialogs/dialog_box.h>
|
||||||
|
#include <keybinds.h>
|
||||||
|
|
||||||
SDRPP_MOD_INFO{
|
SDRPP_MOD_INFO{
|
||||||
/* Name: */ "frequency_manager",
|
/* Name: */ "frequency_manager",
|
||||||
@ -497,8 +498,8 @@ private:
|
|||||||
|
|
||||||
if (ImGui::Selectable((name + "##_freq_mgr_bkm_name_" + _this->name).c_str(), &bm.selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SelectOnClick)) {
|
if (ImGui::Selectable((name + "##_freq_mgr_bkm_name_" + _this->name).c_str(), &bm.selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SelectOnClick)) {
|
||||||
// if shift or control isn't pressed, deselect all others
|
// if shift or control isn't pressed, deselect all others
|
||||||
if (!ImGui::IsKeyDown(GLFW_KEY_LEFT_SHIFT) && !ImGui::IsKeyDown(GLFW_KEY_RIGHT_SHIFT) &&
|
if (!ImGui::IsKeyDown(KB_KEY_LSHIFT) && !ImGui::IsKeyDown(KB_KEY_RSHIFT) &&
|
||||||
!ImGui::IsKeyDown(GLFW_KEY_LEFT_CONTROL) && !ImGui::IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) {
|
!ImGui::IsKeyDown(KB_KEY_LCTRL) && !ImGui::IsKeyDown(KB_KEY_RCTRL)) {
|
||||||
for (auto& [_name, _bm] : _this->bookmarks) {
|
for (auto& [_name, _bm] : _this->bookmarks) {
|
||||||
if (name == _name) { continue; }
|
if (name == _name) { continue; }
|
||||||
_bm.selected = false;
|
_bm.selected = false;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <gui/gui.h>
|
#include <gui/gui.h>
|
||||||
#include <sched_task.h>
|
#include <sched_task.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <keybinds.h>
|
||||||
|
|
||||||
SDRPP_MOD_INFO{
|
SDRPP_MOD_INFO{
|
||||||
/* Name: */ "scheduler",
|
/* Name: */ "scheduler",
|
||||||
@ -100,8 +101,8 @@ private:
|
|||||||
|
|
||||||
if (ImGui::Selectable((name + "##_freq_mgr_bkm_name_" + _this->name).c_str(), &bm.selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SelectOnClick)) {
|
if (ImGui::Selectable((name + "##_freq_mgr_bkm_name_" + _this->name).c_str(), &bm.selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SelectOnClick)) {
|
||||||
// if shift or control isn't pressed, deselect all others
|
// if shift or control isn't pressed, deselect all others
|
||||||
if (!ImGui::IsKeyDown(GLFW_KEY_LEFT_SHIFT) && !ImGui::IsKeyDown(GLFW_KEY_RIGHT_SHIFT) &&
|
if (!ImGui::IsKeyDown(KB_KEY_LSHIFT) && !ImGui::IsKeyDown(KB_KEY_RSHIFT) &&
|
||||||
!ImGui::IsKeyDown(GLFW_KEY_LEFT_CONTROL) && !ImGui::IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) {
|
!ImGui::IsKeyDown(KB_KEY_LCTRL) && !ImGui::IsKeyDown(KB_KEY_RCTRL)) {
|
||||||
for (auto& [_name, _bm] : _this->tasks) {
|
for (auto& [_name, _bm] : _this->tasks) {
|
||||||
if (name == _name) { continue; }
|
if (name == _name) { continue; }
|
||||||
_bm.selected = false;
|
_bm.selected = false;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <gui/style.h>
|
#include <gui/style.h>
|
||||||
#include <sched_action.h>
|
#include <sched_action.h>
|
||||||
|
#include <keybinds.h>
|
||||||
|
|
||||||
class Task {
|
class Task {
|
||||||
public:
|
public:
|
||||||
@ -77,8 +78,8 @@ public:
|
|||||||
|
|
||||||
if (ImGui::Selectable((act->getName() + "##scheduler_task_actions_entry").c_str(), &act->selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SelectOnClick)) {
|
if (ImGui::Selectable((act->getName() + "##scheduler_task_actions_entry").c_str(), &act->selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_SelectOnClick)) {
|
||||||
// if shift or control isn't pressed, deselect all others
|
// if shift or control isn't pressed, deselect all others
|
||||||
if (!ImGui::IsKeyDown(GLFW_KEY_LEFT_SHIFT) && !ImGui::IsKeyDown(GLFW_KEY_RIGHT_SHIFT) &&
|
if (!ImGui::IsKeyDown(KB_KEY_LSHIFT) && !ImGui::IsKeyDown(KB_KEY_RSHIFT) &&
|
||||||
!ImGui::IsKeyDown(GLFW_KEY_LEFT_CONTROL) && !ImGui::IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) {
|
!ImGui::IsKeyDown(KB_KEY_LCTRL) && !ImGui::IsKeyDown(KB_KEY_RCTRL)) {
|
||||||
int _id = 0;
|
int _id = 0;
|
||||||
for (auto& _act : actions) {
|
for (auto& _act : actions) {
|
||||||
if (_id == id) { continue; }
|
if (_id == id) { continue; }
|
||||||
|
Loading…
Reference in New Issue
Block a user