2021-08-15 16:47:44 +02:00
|
|
|
#include "main_ui.h"
|
|
|
|
|
#include "imgui/imgui_flags.h"
|
|
|
|
|
#include "imgui/imgui.h"
|
|
|
|
|
#include "processing.h"
|
2022-03-07 20:29:23 +01:00
|
|
|
#include "offline.h"
|
2022-03-30 15:41:23 +02:00
|
|
|
#include "settings.h"
|
|
|
|
|
#include "satdump_vars.h"
|
|
|
|
|
#include "core/config.h"
|
2022-05-02 18:59:03 +02:00
|
|
|
#include "core/style.h"
|
2023-12-31 16:49:23 -05:00
|
|
|
#include "core/backend.h"
|
2022-06-20 18:54:33 +02:00
|
|
|
#include "resources.h"
|
|
|
|
|
#include "common/widgets/markdown_helper.h"
|
2023-02-19 23:21:06 +01:00
|
|
|
#include "common/audio/audio_sink.h"
|
2023-05-20 22:40:36 +02:00
|
|
|
#include "imgui_notify/imgui_notify.h"
|
|
|
|
|
#include "notify_logger_sink.h"
|
2023-08-09 22:21:32 -04:00
|
|
|
#include "status_logger_sink.h"
|
2022-08-08 10:45:19 +02:00
|
|
|
|
2023-10-04 21:40:08 +02:00
|
|
|
#include "imgui/implot/implot.h"
|
|
|
|
|
|
2022-12-17 16:55:11 +01:00
|
|
|
// #define ENABLE_DEBUG_MAP
|
2022-08-11 12:25:30 +02:00
|
|
|
#ifdef ENABLE_DEBUG_MAP
|
|
|
|
|
#include "common/widgets/image_view.h"
|
2022-08-08 22:14:13 +02:00
|
|
|
float lat = 0, lon = 0, lat1 = 0, lon1 = 0;
|
2022-08-08 10:45:19 +02:00
|
|
|
int zoom = 0;
|
2022-08-08 22:14:13 +02:00
|
|
|
image::Image<uint8_t> img(800, 400, 3);
|
2022-08-08 10:45:19 +02:00
|
|
|
ImageViewWidget ivw;
|
2022-08-11 12:25:30 +02:00
|
|
|
#endif
|
2022-03-20 20:56:32 +01:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
namespace satdump
|
2021-08-15 16:47:44 +02:00
|
|
|
{
|
2022-05-07 18:16:24 +02:00
|
|
|
std::shared_ptr<RecorderApplication> recorder_app;
|
|
|
|
|
std::shared_ptr<ViewerApplication> viewer_app;
|
2022-04-11 16:26:40 +02:00
|
|
|
|
2022-04-24 12:43:34 +02:00
|
|
|
bool in_app = false; // true;
|
2024-01-06 08:24:56 -05:00
|
|
|
bool open_recorder;
|
2022-04-11 16:26:40 +02:00
|
|
|
|
2022-06-20 18:54:33 +02:00
|
|
|
widgets::MarkdownHelper credits_md;
|
|
|
|
|
|
2023-05-20 22:40:36 +02:00
|
|
|
std::shared_ptr<NotifyLoggerSink> notify_logger_sink;
|
2023-08-09 22:21:32 -04:00
|
|
|
std::shared_ptr<StatusLoggerSink> status_logger_sink;
|
2023-05-20 22:40:36 +02:00
|
|
|
|
2023-08-23 15:45:10 -04:00
|
|
|
void initMainUI(float device_scale)
|
2022-03-10 19:56:37 +01:00
|
|
|
{
|
2023-10-04 21:40:08 +02:00
|
|
|
ImPlot::CreateContext();
|
|
|
|
|
|
2023-02-19 23:21:06 +01:00
|
|
|
audio::registerSinks();
|
2022-03-10 19:56:37 +01:00
|
|
|
offline::setup();
|
2022-03-30 15:41:23 +02:00
|
|
|
settings::setup();
|
|
|
|
|
|
2023-08-23 15:45:10 -04:00
|
|
|
// Setup DPI/Theme
|
|
|
|
|
updateUI(device_scale);
|
2022-04-11 16:26:40 +02:00
|
|
|
|
2022-06-20 18:54:33 +02:00
|
|
|
// Load credits MD
|
|
|
|
|
std::ifstream ifs(resources::getResourcePath("credits.md"));
|
|
|
|
|
std::string credits_markdown((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
|
|
|
|
|
credits_md.set_md(credits_markdown);
|
|
|
|
|
|
2022-04-11 16:26:40 +02:00
|
|
|
registerApplications();
|
2022-04-12 20:18:44 +02:00
|
|
|
registerViewerHandlers();
|
|
|
|
|
|
2022-05-07 18:16:24 +02:00
|
|
|
recorder_app = std::make_shared<RecorderApplication>();
|
|
|
|
|
viewer_app = std::make_shared<ViewerApplication>();
|
2024-01-06 08:24:56 -05:00
|
|
|
open_recorder = satdump::config::main_cfg.contains("cli") && satdump::config::main_cfg["cli"].contains("start_recorder_device");
|
2023-05-20 22:40:36 +02:00
|
|
|
|
2023-10-04 21:40:08 +02:00
|
|
|
// Logger status bar sync
|
2023-08-10 12:03:26 -04:00
|
|
|
status_logger_sink = std::make_shared<StatusLoggerSink>();
|
2023-10-04 21:40:08 +02:00
|
|
|
if (status_logger_sink->is_shown())
|
2023-08-09 22:21:32 -04:00
|
|
|
logger->add_sink(status_logger_sink);
|
2023-11-19 16:22:39 -05:00
|
|
|
|
|
|
|
|
// Shut down the logger init buffer manually to prevent init warnings
|
|
|
|
|
// From showing as a toast, or in the product processor screen
|
|
|
|
|
completeLoggerInit();
|
|
|
|
|
|
|
|
|
|
// Logger notify sink
|
|
|
|
|
notify_logger_sink = std::make_shared<NotifyLoggerSink>();
|
|
|
|
|
logger->add_sink(notify_logger_sink);
|
2022-03-10 19:56:37 +01:00
|
|
|
}
|
2021-08-15 16:47:44 +02:00
|
|
|
|
2023-08-23 15:45:10 -04:00
|
|
|
void updateUI(float device_scale)
|
|
|
|
|
{
|
|
|
|
|
light_theme = config::main_cfg["user_interface"]["light_theme"]["value"].get<bool>();
|
|
|
|
|
float manual_dpi_scaling = config::main_cfg["user_interface"]["manual_dpi_scaling"]["value"].get<float>();
|
|
|
|
|
ui_scale = device_scale * manual_dpi_scaling;
|
2023-08-23 20:23:29 -04:00
|
|
|
ImGui::GetStyle() = ImGuiStyle();
|
2023-08-23 15:45:10 -04:00
|
|
|
ImGui::GetStyle().ScaleAllSizes(ui_scale);
|
|
|
|
|
|
|
|
|
|
if (light_theme)
|
|
|
|
|
style::setLightStyle();
|
|
|
|
|
else
|
|
|
|
|
style::setDarkStyle();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-08 16:35:54 +02:00
|
|
|
void exitMainUI()
|
|
|
|
|
{
|
2022-05-08 16:58:14 +02:00
|
|
|
recorder_app->save_settings();
|
2023-10-16 11:14:21 -04:00
|
|
|
viewer_app->save_settings();
|
|
|
|
|
config::saveUserConfig();
|
2022-12-17 16:55:11 +01:00
|
|
|
recorder_app.reset();
|
2023-10-16 11:14:21 -04:00
|
|
|
viewer_app.reset();
|
2022-05-08 16:35:54 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-31 16:49:23 -05:00
|
|
|
void renderMainUI()
|
2021-08-15 16:47:44 +02:00
|
|
|
{
|
2023-12-31 16:49:23 -05:00
|
|
|
std::pair<int, int> dims = backend::beginFrame();
|
2022-09-17 16:22:26 +02:00
|
|
|
// ImGui::ShowDemoWindow();
|
|
|
|
|
|
2022-05-07 18:16:24 +02:00
|
|
|
/*if (in_app)
|
2022-04-11 16:26:40 +02:00
|
|
|
{
|
|
|
|
|
ImGui::SetNextWindowPos({0, 0});
|
|
|
|
|
ImGui::SetNextWindowSize({(float)wwidth, (float)wheight});
|
2022-05-02 08:11:47 -07:00
|
|
|
ImGui::Begin("Main", NULL, NOWINDOW_FLAGS | ImGuiWindowFlags_NoDecoration);
|
2022-04-11 16:26:40 +02:00
|
|
|
current_app->draw();
|
|
|
|
|
ImGui::End();
|
2022-05-07 18:16:24 +02:00
|
|
|
}*/
|
2022-05-03 17:00:43 +02:00
|
|
|
/*else if (processing::is_processing)
|
2021-08-15 16:47:44 +02:00
|
|
|
{
|
2022-03-10 19:56:37 +01:00
|
|
|
processing::ui_call_list_mutex->lock();
|
|
|
|
|
float winheight = processing::ui_call_list->size() > 0 ? wheight / processing::ui_call_list->size() : wheight;
|
|
|
|
|
float currentPos = 0;
|
|
|
|
|
for (std::shared_ptr<ProcessingModule> module : *processing::ui_call_list)
|
|
|
|
|
{
|
|
|
|
|
ImGui::SetNextWindowPos({0, currentPos});
|
|
|
|
|
currentPos += winheight;
|
|
|
|
|
ImGui::SetNextWindowSize({(float)wwidth, (float)winheight});
|
|
|
|
|
module->drawUI(false);
|
|
|
|
|
}
|
|
|
|
|
processing::ui_call_list_mutex->unlock();
|
2022-05-03 17:00:43 +02:00
|
|
|
}*/
|
2022-05-07 18:16:24 +02:00
|
|
|
// else
|
2022-03-05 12:44:19 +01:00
|
|
|
{
|
2024-01-10 12:04:59 -05:00
|
|
|
bool main_ui_is_processing_selected = ImGuiUtils_OfflineProcessingSelected();
|
2023-08-10 12:03:26 -04:00
|
|
|
bool status_bar = status_logger_sink->is_shown();
|
|
|
|
|
if (status_bar && processing::is_processing && main_ui_is_processing_selected)
|
|
|
|
|
{
|
|
|
|
|
for (std::shared_ptr<ProcessingModule> module : *processing::ui_call_list)
|
|
|
|
|
{
|
|
|
|
|
std::string module_id = module->getIDM();
|
|
|
|
|
if (module_id == "products_processor")
|
|
|
|
|
{
|
|
|
|
|
status_bar = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-04 21:40:08 +02:00
|
|
|
if (status_bar)
|
2023-12-31 16:49:23 -05:00
|
|
|
dims.second -= status_logger_sink->draw();
|
2023-08-10 12:03:26 -04:00
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
ImGui::SetNextWindowPos({0, 0});
|
2024-01-10 12:04:59 -05:00
|
|
|
ImGui::SetNextWindowSize({(float)dims.first, (processing::is_processing && main_ui_is_processing_selected) ? -1.0f : (float)dims.second});
|
2023-11-20 14:18:52 -05:00
|
|
|
ImGui::Begin("SatDump UI", nullptr, NOWINDOW_FLAGS | ImGuiWindowFlags_NoDecoration);
|
2022-03-10 19:56:37 +01:00
|
|
|
if (ImGui::BeginTabBar("Main TabBar", ImGuiTabBarFlags_None))
|
2022-03-05 12:44:19 +01:00
|
|
|
{
|
2022-03-10 19:56:37 +01:00
|
|
|
if (ImGui::BeginTabItem("Offline processing"))
|
|
|
|
|
{
|
2022-05-03 17:00:43 +02:00
|
|
|
if (processing::is_processing)
|
|
|
|
|
{
|
|
|
|
|
// ImGui::BeginChild("OfflineProcessingChild");
|
|
|
|
|
processing::ui_call_list_mutex->lock();
|
2023-12-31 16:49:23 -05:00
|
|
|
int live_width = dims.first; // ImGui::GetWindowWidth();
|
|
|
|
|
int live_height = /*ImGui::GetWindowHeight()*/ dims.second - ImGui::GetCursorPos().y;
|
2022-05-03 17:00:43 +02:00
|
|
|
float winheight = processing::ui_call_list->size() > 0 ? live_height / processing::ui_call_list->size() : live_height;
|
|
|
|
|
float currentPos = ImGui::GetCursorPos().y;
|
2023-11-20 14:18:52 -05:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_TitleBg, ImGui::GetStyleColorVec4(ImGuiCol_TitleBgActive));
|
2022-05-03 17:00:43 +02:00
|
|
|
for (std::shared_ptr<ProcessingModule> module : *processing::ui_call_list)
|
|
|
|
|
{
|
|
|
|
|
ImGui::SetNextWindowPos({0, currentPos});
|
|
|
|
|
currentPos += winheight;
|
|
|
|
|
ImGui::SetNextWindowSize({(float)live_width, (float)winheight});
|
2023-06-06 11:20:21 +02:00
|
|
|
module->drawUI(false);
|
2022-05-03 17:00:43 +02:00
|
|
|
}
|
2023-11-20 14:18:52 -05:00
|
|
|
ImGui::PopStyleColor();
|
2022-05-03 17:00:43 +02:00
|
|
|
processing::ui_call_list_mutex->unlock();
|
|
|
|
|
// ImGui::EndChild();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-11-10 13:16:18 -05:00
|
|
|
ImGui::BeginChild("offlineprocessing", ImGui::GetContentRegionAvail());
|
2022-05-03 17:00:43 +02:00
|
|
|
offline::render();
|
2023-11-10 13:16:18 -05:00
|
|
|
ImGui::EndChild();
|
2022-05-03 17:00:43 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2024-01-06 08:24:56 -05:00
|
|
|
if (ImGui::BeginTabItem("Recorder", nullptr, open_recorder ? ImGuiTabItemFlags_SetSelected : ImGuiTabItemFlags_None))
|
2022-05-07 18:16:24 +02:00
|
|
|
{
|
2024-01-06 08:24:56 -05:00
|
|
|
open_recorder = false;
|
2022-05-07 18:16:24 +02:00
|
|
|
recorder_app->draw();
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
|
|
|
|
if (ImGui::BeginTabItem("Viewer"))
|
|
|
|
|
{
|
|
|
|
|
viewer_app->draw();
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2022-09-07 13:19:23 +02:00
|
|
|
#if 0
|
2022-04-11 16:26:40 +02:00
|
|
|
if (ImGui::BeginTabItem("Applications"))
|
|
|
|
|
{
|
2022-04-12 20:18:44 +02:00
|
|
|
// current_app->draw();
|
2022-05-07 18:16:24 +02:00
|
|
|
if (in_app)
|
2022-04-11 16:26:40 +02:00
|
|
|
{
|
2022-05-07 18:16:24 +02:00
|
|
|
// current_app->draw();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for (std::pair<const std::string, std::function<std::shared_ptr<Application>()>> &appEntry : application_registry)
|
2022-04-11 16:26:40 +02:00
|
|
|
{
|
2022-05-07 18:16:24 +02:00
|
|
|
if (ImGui::Button(appEntry.first.c_str()))
|
|
|
|
|
{
|
|
|
|
|
in_app = true;
|
|
|
|
|
// current_app = application_registry[appEntry.first]();
|
|
|
|
|
}
|
2022-04-11 16:26:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2022-09-07 13:19:23 +02:00
|
|
|
#endif
|
2022-03-30 15:41:23 +02:00
|
|
|
if (ImGui::BeginTabItem("Settings"))
|
|
|
|
|
{
|
2023-11-10 13:16:18 -05:00
|
|
|
ImGui::BeginChild("settings", ImGui::GetContentRegionAvail());
|
2022-03-30 15:41:23 +02:00
|
|
|
settings::render();
|
2023-11-10 13:16:18 -05:00
|
|
|
ImGui::EndChild();
|
2022-03-30 15:41:23 +02:00
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2023-10-13 16:19:24 -04:00
|
|
|
if (ImGui::BeginTabItem("About"))
|
2022-06-20 18:54:33 +02:00
|
|
|
{
|
2022-09-11 16:15:15 +02:00
|
|
|
ImGui::BeginChild("credits_md", ImGui::GetContentRegionAvail(), false, ImGuiWindowFlags_AlwaysVerticalScrollbar);
|
2022-06-20 18:54:33 +02:00
|
|
|
credits_md.render();
|
2022-09-11 16:15:15 +02:00
|
|
|
ImGui::EndChild();
|
2022-06-20 18:54:33 +02:00
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2022-08-11 12:25:30 +02:00
|
|
|
#ifdef ENABLE_DEBUG_MAP
|
2022-08-08 10:45:19 +02:00
|
|
|
if (ImGui::BeginTabItem("Map"))
|
|
|
|
|
{
|
2022-08-08 16:15:26 +02:00
|
|
|
tileMap tm;
|
2022-08-08 10:45:19 +02:00
|
|
|
ImGui::SetNextItemWidth(120);
|
|
|
|
|
ImGui::InputFloat("Latitude", &lat);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::SetNextItemWidth(120);
|
|
|
|
|
ImGui::InputFloat("Longitude", &lon);
|
2022-08-08 22:14:13 +02:00
|
|
|
ImGui::SetNextItemWidth(120);
|
|
|
|
|
ImGui::InputFloat("Latitude##1", &lat1);
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
ImGui::SetNextItemWidth(120);
|
|
|
|
|
ImGui::InputFloat("Longitude##1", &lon1);
|
2022-08-08 10:45:19 +02:00
|
|
|
ImGui::SetNextItemWidth(250);
|
|
|
|
|
ImGui::SliderInt("Zoom", &zoom, 0, 19);
|
|
|
|
|
if (ImGui::Button("Get tile from server"))
|
|
|
|
|
{
|
2022-08-11 12:25:30 +02:00
|
|
|
// mapTile tl(tm.downloadTile(tm.coorToTile({lat, lon}, zoom), zoom));
|
2022-08-10 18:30:38 +02:00
|
|
|
img = tm.getMapImage({lat, lon}, {lat1, lon1}, zoom);
|
2022-08-11 12:25:30 +02:00
|
|
|
ivw.update(img);
|
2022-08-08 10:45:19 +02:00
|
|
|
}
|
2022-08-08 22:14:13 +02:00
|
|
|
ivw.draw(ImVec2(800, 400));
|
2022-08-08 10:45:19 +02:00
|
|
|
ImGui::EndTabItem();
|
|
|
|
|
}
|
2022-08-11 12:25:30 +02:00
|
|
|
#endif
|
2022-03-05 12:44:19 +01:00
|
|
|
}
|
2022-03-10 19:56:37 +01:00
|
|
|
ImGui::EndTabBar();
|
2023-11-20 14:18:52 -05:00
|
|
|
ImGuiUtils_SendCurrentWindowToBack();
|
2022-03-10 19:56:37 +01:00
|
|
|
ImGui::End();
|
2022-03-05 12:44:19 +01:00
|
|
|
|
2023-01-30 12:12:04 +01:00
|
|
|
if (settings::show_imgui_demo)
|
|
|
|
|
ImGui::ShowDemoWindow();
|
2022-03-10 19:56:37 +01:00
|
|
|
}
|
2023-05-20 22:40:36 +02:00
|
|
|
|
|
|
|
|
// Render toasts on top of everything, at the end of your code!
|
|
|
|
|
// You should push style vars here
|
2023-09-13 15:27:42 -04:00
|
|
|
float notification_bgcolor = (light_theme ? 212.f : 43.f) / 255.f;
|
|
|
|
|
float notification_transparency = (light_theme ? 200.f : 100.f) / 255.f;
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.f);
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(notification_bgcolor, notification_bgcolor, notification_bgcolor, notification_transparency));
|
2023-10-31 20:18:35 -04:00
|
|
|
notify_logger_sink->notify_mutex.lock();
|
2023-09-13 15:27:42 -04:00
|
|
|
ImGui::RenderNotifications();
|
2023-10-31 20:18:35 -04:00
|
|
|
notify_logger_sink->notify_mutex.unlock();
|
2023-09-13 15:27:42 -04:00
|
|
|
ImGui::PopStyleVar(1);
|
2023-05-20 22:40:36 +02:00
|
|
|
ImGui::PopStyleColor(1);
|
2023-12-31 16:49:23 -05:00
|
|
|
|
|
|
|
|
backend::endFrame();
|
2022-03-05 12:44:19 +01:00
|
|
|
}
|
2022-03-10 19:56:37 +01:00
|
|
|
|
2022-03-30 15:41:23 +02:00
|
|
|
bool light_theme;
|
|
|
|
|
|
2022-03-10 19:56:37 +01:00
|
|
|
ctpl::thread_pool ui_thread_pool(8);
|
2023-06-26 16:16:56 +02:00
|
|
|
}
|