2023-08-09 22:21:32 -04:00
|
|
|
#include "status_logger_sink.h"
|
|
|
|
|
#include "imgui/imgui_internal.h"
|
2023-08-10 12:03:26 -04:00
|
|
|
#include "core/config.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()
|
|
|
|
|
{
|
2023-08-14 08:32:26 -04:00
|
|
|
slog::LogMsg welcome_message;
|
|
|
|
|
welcome_message.lvl = slog::LOG_INFO;
|
|
|
|
|
welcome_message.str = "Welcome to SatDump!";
|
|
|
|
|
receive(welcome_message);
|
|
|
|
|
|
|
|
|
|
show_bar = config::main_cfg["user_interface"]["status_bar"]["value"].get<bool>();
|
|
|
|
|
show_log = false;
|
2023-08-09 22:21:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusLoggerSink::~StatusLoggerSink()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 12:03:26 -04:00
|
|
|
bool StatusLoggerSink::is_shown()
|
|
|
|
|
{
|
2023-08-14 08:32:26 -04:00
|
|
|
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)
|
|
|
|
|
{
|
2023-08-14 08:32:26 -04:00
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
int height = 0;
|
|
|
|
|
if (ImGui::BeginViewportSideBar("##MainStatusBar", ImGui::GetMainViewport(), ImGuiDir_Down, ImGui::GetFrameHeight(),
|
|
|
|
|
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar)) {
|
|
|
|
|
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());
|
2023-08-14 08:32:26 -04:00
|
|
|
if (ImGui::IsItemClicked())
|
|
|
|
|
show_log = true;
|
|
|
|
|
|
2023-08-09 22:21:32 -04:00
|
|
|
height = ImGui::GetWindowHeight();
|
|
|
|
|
ImGui::EndMenuBar();
|
|
|
|
|
}
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 08:32:26 -04:00
|
|
|
if (show_log)
|
|
|
|
|
{
|
2023-08-14 21:00:21 -04:00
|
|
|
static ImVec2 last_size;
|
2023-08-14 08:32:26 -04:00
|
|
|
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;
|
|
|
|
|
|
2023-08-14 08:32:26 -04:00
|
|
|
ImGui::SetNextWindowBgAlpha(1.0);
|
|
|
|
|
ImGui::Begin("SatDump Log", &show_log, ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoCollapse);
|
|
|
|
|
if (ImGui::IsWindowFocused())
|
|
|
|
|
widgets::LoggerSinkWidget::draw();
|
|
|
|
|
else
|
|
|
|
|
show_log = false;
|
|
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-09 22:21:32 -04:00
|
|
|
return height;
|
|
|
|
|
}
|
|
|
|
|
}
|