2024-07-10 19:47:37 +00:00
|
|
|
internal
|
2024-07-11 12:00:43 +00:00
|
|
|
u32 mem_edit_bg_color_fn(const u8 *data, u64 off, const void *user_data)
|
|
|
|
{
|
2024-07-11 12:27:19 +00:00
|
|
|
const App_State *app = reinterpret_cast<const App_State *>(user_data);
|
|
|
|
|
|
|
|
#define COL(c) (ImColor((c)[0], (c)[1], (c)[2]))
|
|
|
|
if (app->rntinfo.header.start <= off && off <= app->rntinfo.header.end()) return COL(app->vsettings.col_header);
|
|
|
|
if (app->rntinfo.footer.start <= off && off <= app->rntinfo.footer.end()) return COL(app->vsettings.col_footer);
|
|
|
|
#undef COL
|
2024-07-11 12:00:43 +00:00
|
|
|
|
|
|
|
return IM_COL32(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal
|
2024-07-11 12:27:19 +00:00
|
|
|
MemoryEditor make_memory_editor(const App_State &app)
|
2024-07-10 19:41:48 +00:00
|
|
|
{
|
|
|
|
MemoryEditor mem_edit;
|
|
|
|
// mem_edit.ReadOnly = true;
|
|
|
|
mem_edit.Cols = 32;
|
2024-07-11 12:27:19 +00:00
|
|
|
mem_edit.OptShowDataPreview = true;
|
2024-07-11 12:00:43 +00:00
|
|
|
mem_edit.BgColorFn = mem_edit_bg_color_fn;
|
2024-07-11 12:27:19 +00:00
|
|
|
mem_edit.BgColorFnUserData = &app;
|
2024-07-10 19:41:48 +00:00
|
|
|
return mem_edit;
|
|
|
|
}
|
|
|
|
|
2024-07-11 12:27:19 +00:00
|
|
|
Viewer_Settings make_viewer_settings()
|
|
|
|
{
|
|
|
|
Viewer_Settings settings {};
|
|
|
|
#define COL(c, r, g, b) settings.c[0] = r/255.0, settings.c[1] = g/255.0, settings.c[2] = b/255.0
|
|
|
|
COL(col_header, 150, 0, 50);
|
|
|
|
COL(col_footer, 50, 0, 150);
|
|
|
|
#undef COL
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2024-07-10 19:47:37 +00:00
|
|
|
internal
|
|
|
|
void update_and_render(Arena *arena, App_State &app, f32 delta_time)
|
2024-07-10 17:38:16 +00:00
|
|
|
{
|
2024-07-11 12:00:43 +00:00
|
|
|
(void)delta_time;
|
|
|
|
|
2024-07-10 17:38:16 +00:00
|
|
|
ImGui::SetNextWindowPos({ 0, 0 });
|
|
|
|
ImGui::SetNextWindowSize({ (f32)app.win_data.width, (f32)app.win_data.height });
|
2024-07-10 18:11:42 +00:00
|
|
|
|
|
|
|
Temp scratch = temp_begin(arena);
|
|
|
|
defer { temp_end(scratch); };
|
|
|
|
|
2024-07-11 12:00:43 +00:00
|
|
|
const u64 inspected_max_size = 2048;
|
|
|
|
u64 text_buf_size = min(app.inspected_file_size * 2, inspected_max_size);
|
2024-07-10 19:41:48 +00:00
|
|
|
char *text_buf = arena_push_array_no_zero<char>(scratch.arena, text_buf_size + 1);
|
2024-07-11 12:00:43 +00:00
|
|
|
// Convert file content to human readable
|
|
|
|
// @Speed: maybe do this only when the file changes
|
2024-07-10 19:41:48 +00:00
|
|
|
for (u64 i = 0; i < text_buf_size / 2; ++i)
|
2024-07-10 20:30:49 +00:00
|
|
|
sprintf(&text_buf[2 * i], "%02X", app.inspected_fmem[i]);
|
2024-07-10 19:41:48 +00:00
|
|
|
text_buf[text_buf_size] = 0;
|
2024-07-10 18:11:42 +00:00
|
|
|
|
2024-07-11 12:27:19 +00:00
|
|
|
const auto main_win_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDecoration;
|
|
|
|
if (ImGui::Begin("main", nullptr, main_win_flags)) {
|
2024-07-11 12:00:43 +00:00
|
|
|
ImGui::Text("Inspecting RNTuple '%s' (%s)", app.ntpl_name,
|
2024-07-11 12:27:19 +00:00
|
|
|
(const char *)rntuple_description(scratch.arena, app.rntinfo.anchor));
|
|
|
|
ImGui::Separator();
|
|
|
|
|
|
|
|
{
|
|
|
|
static MemoryEditor mem_edit = make_memory_editor(app);
|
|
|
|
ImGui::BeginTable("Hex View", 2);
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
mem_edit.DrawContents(app.inspected_fmem, app.inspected_file_size);
|
|
|
|
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::ColorEdit3("Header", app.vsettings.col_header, ImGuiColorEditFlags_NoInputs);
|
|
|
|
ImGui::ColorEdit3("Footer", app.vsettings.col_footer, ImGuiColorEditFlags_NoInputs);
|
|
|
|
|
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
2024-07-11 12:00:43 +00:00
|
|
|
|
2024-07-10 17:38:16 +00:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
}
|