From 22d18a9e5850c4eb45ebbc129507fc2dbb5b13bc Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Tue, 22 Dec 2020 22:39:24 +0100 Subject: [PATCH] new directory system on linux --- core/src/core.cpp | 13 +++++++++++-- core/src/gui/icons.cpp | 27 ++++++++++++++++++--------- core/src/gui/icons.h | 2 +- core/src/gui/main_window.cpp | 7 ++++--- core/src/gui/style.cpp | 32 ++++++++++++++++++++++++-------- core/src/gui/style.h | 5 +++-- core/src/options.cpp | 2 +- 7 files changed, 62 insertions(+), 26 deletions(-) diff --git a/core/src/core.cpp b/core/src/core.cpp index a567ad3..2d6728b 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -117,6 +117,14 @@ int sdrpp_main(int argc, char *argv[]) { defConfig["windowSize"]["h"] = 720; defConfig["windowSize"]["w"] = 1280; +#ifdef _WIN32 + defConfig["modulesDirectory"] = "./modules"; + defConfig["resourcesDirectory"] = "./res"; +#else + defConfig["modulesDirectory"] = "/usr/lib/sdrpp/plugins"; + defConfig["resourcesDirectory"] = "/usr/share/sdrpp"; +#endif + // Load config spdlog::info("Loading config"); core::configManager.setPath(options::opts.root + "/config.json"); @@ -138,6 +146,7 @@ int sdrpp_main(int argc, char *argv[]) { 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"]; core::configManager.release(); // Create window with graphics context @@ -198,13 +207,13 @@ int sdrpp_main(int argc, char *argv[]) { ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init("#version 150"); - style::setDarkStyle(); + if (!style::setDarkStyle(resDir)) { return -1; } LoadingScreen::setWindow(window); LoadingScreen::show("Loading icons"); spdlog::info("Loading icons"); - icons::load(); + if (!icons::load(resDir)) { return -1; } LoadingScreen::show("Loading band plans"); spdlog::info("Loading band plans"); diff --git a/core/src/gui/icons.cpp b/core/src/gui/icons.cpp index a2f0f97..2cd776c 100644 --- a/core/src/gui/icons.cpp +++ b/core/src/gui/icons.cpp @@ -6,6 +6,8 @@ #define STB_IMAGE_IMPLEMENTATION #include +#include +#include namespace icons { ImTextureID LOGO; @@ -31,14 +33,21 @@ namespace icons { return texId; } - void load() { - LOGO = (ImTextureID)(uintptr_t)loadTexture(options::opts.root + "/res/icons/sdrpp.png"); - PLAY = (ImTextureID)(uintptr_t)loadTexture(options::opts.root + "/res/icons/play.png"); - STOP = (ImTextureID)(uintptr_t)loadTexture(options::opts.root + "/res/icons/stop.png"); - MENU = (ImTextureID)(uintptr_t)loadTexture(options::opts.root + "/res/icons/menu.png"); - MUTED = (ImTextureID)(uintptr_t)loadTexture(options::opts.root + "/res/icons/muted.png"); - UNMUTED = (ImTextureID)(uintptr_t)loadTexture(options::opts.root + "/res/icons/unmuted.png"); - NORMAL_TUNING = (ImTextureID)(uintptr_t)loadTexture(options::opts.root + "/res/icons/normal_tuning.png"); - CENTER_TUNING = (ImTextureID)(uintptr_t)loadTexture(options::opts.root + "/res/icons/center_tuning.png"); + bool load(std::string resDir) { + if (!std::filesystem::is_directory(resDir)) { + spdlog::error("Inavlid resource directory: {0}", resDir); + return false; + } + + LOGO = (ImTextureID)(uintptr_t)loadTexture(resDir + "/icons/sdrpp.png"); + PLAY = (ImTextureID)(uintptr_t)loadTexture(resDir + "/icons/play.png"); + STOP = (ImTextureID)(uintptr_t)loadTexture(resDir + "/icons/stop.png"); + MENU = (ImTextureID)(uintptr_t)loadTexture(resDir + "/icons/menu.png"); + MUTED = (ImTextureID)(uintptr_t)loadTexture(resDir + "/icons/muted.png"); + UNMUTED = (ImTextureID)(uintptr_t)loadTexture(resDir + "/icons/unmuted.png"); + NORMAL_TUNING = (ImTextureID)(uintptr_t)loadTexture(resDir + "/icons/normal_tuning.png"); + CENTER_TUNING = (ImTextureID)(uintptr_t)loadTexture(resDir + "/icons/center_tuning.png"); + + return true; } } \ No newline at end of file diff --git a/core/src/gui/icons.h b/core/src/gui/icons.h index 74c4a84..a307254 100644 --- a/core/src/gui/icons.h +++ b/core/src/gui/icons.h @@ -14,5 +14,5 @@ namespace icons { extern ImTextureID CENTER_TUNING; GLuint loadTexture(std::string path); - void load(); + bool load(std::string resDir); } \ No newline at end of file diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index efde3a9..dec5754 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -120,6 +120,7 @@ void windowInit() { core::configManager.aquire(); gui::menu.order = core::configManager.conf["menuOrder"].get>(); + std::string modulesDir = core::configManager.conf["modulesDirectory"]; core::configManager.release(); gui::menu.registerEntry("Source", sourecmenu::draw, NULL); @@ -144,8 +145,8 @@ void windowInit() { spdlog::info("Loading modules"); // Load modules from /module directory - if (std::filesystem::is_directory(options::opts.root + "/modules")) { - for (const auto & file : std::filesystem::directory_iterator(options::opts.root + "/modules")) { + if (std::filesystem::is_directory(modulesDir)) { + for (const auto & file : std::filesystem::directory_iterator(modulesDir)) { std::string path = file.path().generic_string(); if (file.path().extension().generic_string() != SDRPP_MOD_EXTENTSION) { continue; @@ -157,7 +158,7 @@ void windowInit() { } } else { - spdlog::warn("Module directory {0} does not exist, not loading modules from directory"); + spdlog::warn("Module directory {0} does not exist, not loading modules from directory", modulesDir); } // Read module config diff --git a/core/src/gui/style.cpp b/core/src/gui/style.cpp index 35fbca8..6ba917b 100644 --- a/core/src/gui/style.cpp +++ b/core/src/gui/style.cpp @@ -3,13 +3,20 @@ #include #include #include +#include +#include namespace style { ImFont* baseFont; ImFont* bigFont; ImFont* hugeFont; - void setDefaultStyle() { + bool setDefaultStyle(std::string resDir) { + if (!std::filesystem::is_directory(resDir)) { + spdlog::error("Inavlid resource directory: {0}", resDir); + return false; + } + ImGui::GetStyle().WindowRounding = 0.0f; ImGui::GetStyle().ChildRounding = 0.0f; ImGui::GetStyle().FrameRounding = 0.0f; @@ -17,19 +24,26 @@ namespace style { ImGui::GetStyle().PopupRounding = 0.0f; ImGui::GetStyle().ScrollbarRounding = 0.0f; - baseFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(options::opts.root + "/res/fonts/Roboto-Medium.ttf")).c_str(), 16.0f); - bigFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(options::opts.root + "/res/fonts/Roboto-Medium.ttf")).c_str(), 42.0f); - hugeFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(options::opts.root + "/res/fonts/Roboto-Medium.ttf")).c_str(), 128.0f); + baseFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 16.0f); + bigFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 42.0f); + hugeFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 128.0f); ImGui::StyleColorsDark(); //ImGui::StyleColorsLight(); + + return true; } void testtt() { ImGui::StyleColorsLight(); } - void setDarkStyle() { + bool setDarkStyle(std::string resDir) { + if (!std::filesystem::is_directory(resDir)) { + spdlog::error("Inavlid resource directory: {0}", resDir); + return false; + } + ImGui::GetStyle().WindowRounding = 0.0f; ImGui::GetStyle().ChildRounding = 0.0f; ImGui::GetStyle().FrameRounding = 0.0f; @@ -37,9 +51,9 @@ namespace style { ImGui::GetStyle().PopupRounding = 0.0f; ImGui::GetStyle().ScrollbarRounding = 0.0f; - baseFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(options::opts.root + "/res/fonts/Roboto-Medium.ttf")).c_str(), 16.0f); - bigFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(options::opts.root + "/res/fonts/Roboto-Medium.ttf")).c_str(), 42.0f); - hugeFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(options::opts.root + "/res/fonts/Roboto-Medium.ttf")).c_str(), 128.0f); + baseFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 16.0f); + bigFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 42.0f); + hugeFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 128.0f); ImGui::StyleColorsDark(); @@ -89,6 +103,8 @@ namespace style { colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); colors[ImGuiCol_NavHighlight] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); + + return true; } void beginDisabled() { diff --git a/core/src/gui/style.h b/core/src/gui/style.h index c76f81c..28a82f6 100644 --- a/core/src/gui/style.h +++ b/core/src/gui/style.h @@ -1,13 +1,14 @@ #pragma once #include +#include namespace style { extern ImFont* baseFont; extern ImFont* bigFont; extern ImFont* hugeFont; - void setDefaultStyle(); - void setDarkStyle(); + bool setDefaultStyle(std::string resDir); + bool setDarkStyle(std::string resDir); void beginDisabled(); void endDisabled(); void testtt(); diff --git a/core/src/options.cpp b/core/src/options.cpp index 6e8ba81..2841a50 100644 --- a/core/src/options.cpp +++ b/core/src/options.cpp @@ -8,7 +8,7 @@ namespace options { #ifdef _WIN32 opts.root = "."; #else - opts.root = "~/.sdrpp/"; + opts.root = "~/.config/sdrpp"; #endif }