new directory system on linux

This commit is contained in:
Ryzerth 2020-12-22 22:39:24 +01:00
parent d1a8425d43
commit 22d18a9e58
7 changed files with 62 additions and 26 deletions

View File

@ -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");

View File

@ -6,6 +6,8 @@
#define STB_IMAGE_IMPLEMENTATION
#include <imgui/stb_image.h>
#include <filesystem>
#include <spdlog/spdlog.h>
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;
}
}

View File

@ -14,5 +14,5 @@ namespace icons {
extern ImTextureID CENTER_TUNING;
GLuint loadTexture(std::string path);
void load();
bool load(std::string resDir);
}

View File

@ -120,6 +120,7 @@ void windowInit() {
core::configManager.aquire();
gui::menu.order = core::configManager.conf["menuOrder"].get<std::vector<std::string>>();
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

View File

@ -3,13 +3,20 @@
#include <imgui_internal.h>
#include <config.h>
#include <options.h>
#include <spdlog/spdlog.h>
#include <filesystem>
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() {

View File

@ -1,13 +1,14 @@
#pragma once
#include <imgui.h>
#include <string>
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();

View File

@ -8,7 +8,7 @@ namespace options {
#ifdef _WIN32
opts.root = ".";
#else
opts.root = "~/.sdrpp/";
opts.root = "~/.config/sdrpp";
#endif
}