2023-02-22 09:09:33 +00:00
|
|
|
#include <imgui/imgui.cpp>
|
2023-01-23 08:44:16 +00:00
|
|
|
#include "../myimconfig.h"
|
|
|
|
|
|
|
|
#include "../log.h"
|
2023-03-07 11:02:18 +00:00
|
|
|
#include "../logcat_entry.h"
|
2023-01-23 08:44:16 +00:00
|
|
|
#include "../logcat_thread.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
2023-03-29 10:08:31 +00:00
|
|
|
void debug_window(LogcatThread& logcat_thread, LogcatEntries& logcat_entries) {
|
2023-01-23 08:44:16 +00:00
|
|
|
static bool show_demo_window = false;
|
|
|
|
static size_t add_log_entry_presses = 1;
|
|
|
|
static bool log_entry_every_second = false;
|
|
|
|
static float log_entry_every_second_delta;
|
|
|
|
|
|
|
|
if (show_demo_window) {
|
|
|
|
ImGui::ShowDemoWindow(&show_demo_window);
|
|
|
|
}
|
|
|
|
if (!ImGui::Begin("LogMeow Debug")) {
|
|
|
|
ImGui::End();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
|
|
|
ImGui::Checkbox("Show Dear ImGui Demo Window", &show_demo_window);
|
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::Button("Add Log Entry")) {
|
|
|
|
log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated via manual button press)");
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
// returns true when it's pressed
|
|
|
|
if (ImGui::Checkbox("Add log entry every second", &log_entry_every_second)) {
|
|
|
|
log_entry_every_second_delta = 0.0f;
|
|
|
|
}
|
|
|
|
if (ImGui::Button("Add Log Entry with Newlines")) {
|
|
|
|
log("The following should have five spaces: \"\n\n\n\n\n\"");
|
|
|
|
}
|
|
|
|
if (ImGui::Button("Test user assert")) {
|
|
|
|
IM_ASSERT_USER_ERROR(0, "User assert tested");
|
|
|
|
}
|
|
|
|
if (ImGui::Button("Request log entry from Logcat thread")) {
|
|
|
|
logcat_thread.debug_log_request.test_and_set();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log_entry_every_second) {
|
|
|
|
log_entry_every_second_delta += ImGui::GetIO().DeltaTime;
|
|
|
|
if (log_entry_every_second_delta >= 1.0f) {
|
|
|
|
log_entry_every_second_delta = 0.0f;
|
|
|
|
log(std::string("Debug log entry #") + std::to_string(add_log_entry_presses++) + " (activated by add log entry every second)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-07 11:02:18 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
if (ImGui::Button("Add test entry (w/ user)")) {
|
2023-03-30 14:24:01 +00:00
|
|
|
LogcatEntry entry = {
|
2023-03-07 11:02:18 +00:00
|
|
|
.buffer = Buffer::Main,
|
2023-03-30 14:24:01 +00:00
|
|
|
// time to be set later
|
2023-03-07 11:02:18 +00:00
|
|
|
.user = "blankie",
|
|
|
|
.pid = 69,
|
|
|
|
.tid = 420,
|
|
|
|
.priority = Priority::Error,
|
|
|
|
.tag = "blanket, inc.",
|
|
|
|
.message = "Failed to make blanket",
|
2023-03-30 14:24:01 +00:00
|
|
|
};
|
|
|
|
time_t entry_time = time(nullptr);
|
|
|
|
localtime_r(&entry_time, &entry.time);
|
|
|
|
logcat_entries.push_back(std::move(entry));
|
2023-03-07 11:02:18 +00:00
|
|
|
}
|
|
|
|
if (ImGui::Button("Add test entry (w/o user)")) {
|
2023-03-30 14:24:01 +00:00
|
|
|
LogcatEntry entry = {
|
2023-03-07 11:02:18 +00:00
|
|
|
.buffer = Buffer::Crash,
|
2023-03-30 14:24:01 +00:00
|
|
|
// time to be set later
|
2023-03-07 11:02:18 +00:00
|
|
|
.pid = 420,
|
|
|
|
.tid = 69,
|
|
|
|
.priority = Priority::Fatal,
|
|
|
|
.tag = "blanket, inc.",
|
|
|
|
.message = "Failed to invent blankets",
|
2023-03-30 14:24:01 +00:00
|
|
|
};
|
|
|
|
time_t entry_time = time(nullptr);
|
|
|
|
localtime_r(&entry_time, &entry.time);
|
|
|
|
logcat_entries.push_back(std::move(entry));
|
2023-03-07 11:02:18 +00:00
|
|
|
}
|
|
|
|
|
2023-01-23 08:44:16 +00:00
|
|
|
ImGui::End();
|
|
|
|
}
|