satdump/src-interface/status_logger_sink.cpp

123 lines
4.4 KiB
C++
Raw Permalink Normal View History

2023-08-09 22:21:32 -04:00
#include "status_logger_sink.h"
2024-01-26 22:45:55 -05:00
#include "common/imgui_utils.h"
2025-07-08 17:42:18 +01:00
#include "core/config.h"
2025-07-14 21:21:55 +02:00
#include "core/plugin.h"
2025-07-14 20:22:56 +02:00
#include "imgui/imgui.h"
2025-07-08 17:42:18 +01:00
#include "imgui/imgui_internal.h"
2025-07-14 21:21:55 +02:00
#include "main_ui.h"
2025-07-14 20:22:56 +02:00
#include "utils/time.h"
2023-08-09 22:21:32 -04:00
2023-08-10 22:14:39 -04:00
SATDUMP_DLL extern float ui_scale;
2023-08-09 22:21:32 -04:00
namespace satdump
{
StatusLoggerSink::StatusLoggerSink()
{
2025-06-08 16:57:37 +02:00
show_bar = satdump_cfg.main_cfg["user_interface"]["status_bar"]["value"].get<bool>();
show_log = false;
2025-07-14 21:21:55 +02:00
eventBus->register_handler<SetIsProcessingEvent>([this](const SetIsProcessingEvent &) { processing_tasks_n++; });
eventBus->register_handler<SetIsDoneProcessingEvent>(
[this](const SetIsDoneProcessingEvent &)
{
processing_tasks_n--;
if (processing_tasks_n < 0)
processing_tasks_n = 0;
});
2023-08-09 22:21:32 -04:00
}
2025-07-08 17:42:18 +01:00
StatusLoggerSink::~StatusLoggerSink() {}
2023-08-09 22:21:32 -04:00
2025-07-08 17:42:18 +01:00
bool StatusLoggerSink::is_shown() { return show_bar; }
2023-08-10 12:03:26 -04:00
2023-08-09 22:21:32 -04:00
void StatusLoggerSink::receive(slog::LogMsg log)
{
widgets::LoggerSinkWidget::receive(log);
2023-08-09 22:21:32 -04:00
if (log.lvl >= slog::LOG_INFO)
{
if (log.lvl == slog::LOG_INFO)
2023-08-10 12:03:26 -04:00
lvl = "Info";
2023-08-09 22:21:32 -04:00
else if (log.lvl == slog::LOG_WARN)
2023-08-10 12:03:26 -04:00
lvl = "Warning";
2023-08-09 22:21:32 -04:00
else if (log.lvl == slog::LOG_ERROR)
2023-08-10 12:03:26 -04:00
lvl = "Error";
else if (log.lvl == slog::LOG_CRIT)
lvl = "Critical";
2023-08-09 22:21:32 -04:00
else
2023-08-10 12:03:26 -04:00
lvl = "";
2023-08-09 22:21:32 -04:00
str = log.str;
}
}
int StatusLoggerSink::draw()
{
2024-01-26 22:45:55 -05:00
// Check if status bar should be drawn
if (!show_bar)
return 0;
2025-07-08 17:42:18 +01:00
// if (processing::is_processing && ImGuiUtils_OfflineProcessingSelected())
// for (std::shared_ptr<pipeline::ProcessingModule> module : *processing::ui_call_list)
// if (module->getIDM() == "products_processor")
// return 0; TODOREWORK
2024-01-26 22:45:55 -05:00
// Draw status bar
2023-08-09 22:21:32 -04:00
int height = 0;
if (ImGui::BeginViewportSideBar("##MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, ImGui::GetFrameHeight(),
2025-07-08 17:42:18 +01:00
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoNavFocus))
2024-01-26 22:45:55 -05:00
{
if (ImGui::BeginMenuBar())
{
2023-08-10 12:03:26 -04:00
ImGui::TextUnformatted(lvl.c_str());
2023-08-10 22:14:39 -04:00
ImGui::SameLine(75 * ui_scale);
2023-08-10 12:03:26 -04:00
ImGui::Separator();
ImGui::TextDisabled("%s", str.c_str());
if (ImGui::IsItemClicked())
show_log = true;
2023-08-09 22:21:32 -04:00
height = ImGui::GetWindowHeight();
2025-07-14 21:49:19 +02:00
ImGui::SetCursorPosX(ImGui::GetWindowSize().x * 0.75);
ImGui::Separator();
2023-08-09 22:21:32 -04:00
ImGui::EndMenuBar();
}
2025-07-14 20:22:56 +02:00
// TODOREWORK
2025-07-14 21:21:55 +02:00
if (processing_tasks_n > 0)
2025-07-14 20:22:56 +02:00
{
size_t pos = getTime() * 200;
size_t offset = ImGui::GetWindowSize().x * 0.75 - 200 * ui_scale;
auto p1 = ImGui::GetWindowPos();
p1.x += offset + pos % (size_t)(ImGui::GetWindowSize().x * 0.25 + 200 * ui_scale);
for (int i = 0; i < 10; i++)
{
int xpos1 = p1.x + (i * 6) * ui_scale;
int xpos2 = p1.x + (i * 6 + 3) * ui_scale;
if (xpos1 >= ImGui::GetWindowSize().x * 0.75)
ImGui::GetForegroundDrawList()->AddRectFilled(ImVec2(xpos1, p1.y), ImVec2(xpos2, p1.y + height), ImGui::GetColorU32(ImGuiCol_CheckMark));
}
}
2023-08-09 22:21:32 -04:00
ImGui::End();
}
if (show_log)
{
2023-08-14 21:00:21 -04:00
static ImVec2 last_size;
ImVec2 display_size = ImGui::GetIO().DisplaySize;
2023-08-14 21:00:21 -04:00
bool did_resize = display_size.x != last_size.x || display_size.y != last_size.y;
ImGui::SetNextWindowSize(ImVec2(display_size.x, (display_size.y * 0.3) - height), did_resize ? ImGuiCond_Always : ImGuiCond_Appearing);
ImGui::SetNextWindowPos(ImVec2(0, display_size.y * 0.7), did_resize ? ImGuiCond_Always : ImGuiCond_Appearing, ImVec2(0, 0));
last_size = display_size;
ImGui::SetNextWindowBgAlpha(1.0);
ImGui::Begin("SatDump Log", &show_log, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoCollapse);
widgets::LoggerSinkWidget::draw();
ImGui::End();
}
2023-08-09 22:21:32 -04:00
return height;
}
2025-07-08 17:42:18 +01:00
} // namespace satdump