prettier colors

This commit is contained in:
silverweed 2024-07-11 14:27:19 +02:00
parent b9a490d8cc
commit c032d60f9e
6 changed files with 59 additions and 21 deletions

View file

@ -12,5 +12,5 @@ Size=1775,680
[Window][Hex View] [Window][Hex View]
Pos=91,62 Pos=91,62
Size=986,681 Size=1002,939

View file

@ -1,7 +1,8 @@
struct App_State { struct App_State {
Window_Data win_data; Window_Data win_data;
User_Input user_input; User_Input user_input;
RNTuple_Info *rntinfo; RNTuple_Info rntinfo;
Viewer_Settings vsettings;
FILE *inspected_file; FILE *inspected_file;
u8 *inspected_fmem; u8 *inspected_fmem;

View file

@ -1,26 +1,38 @@
internal internal
u32 mem_edit_bg_color_fn(const u8 *data, u64 off, const void *user_data) u32 mem_edit_bg_color_fn(const u8 *data, u64 off, const void *user_data)
{ {
const RNTuple_Info *ntinfo = reinterpret_cast<const RNTuple_Info *>(user_data); 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
if (ntinfo->header.start <= off && off <= ntinfo->header.end())
return IM_COL32(200, 0, 50, 255);
if (ntinfo->footer.start <= off && off <= ntinfo->footer.end())
return IM_COL32(50, 0, 200, 255);
return IM_COL32(0, 0, 0, 0); return IM_COL32(0, 0, 0, 0);
} }
internal internal
MemoryEditor make_memory_editor(const RNTuple_Info &ntpl_info) MemoryEditor make_memory_editor(const App_State &app)
{ {
MemoryEditor mem_edit; MemoryEditor mem_edit;
// mem_edit.ReadOnly = true; // mem_edit.ReadOnly = true;
mem_edit.Cols = 32; mem_edit.Cols = 32;
mem_edit.OptShowDataPreview = true;
mem_edit.BgColorFn = mem_edit_bg_color_fn; mem_edit.BgColorFn = mem_edit_bg_color_fn;
mem_edit.BgColorFnUserData = &ntpl_info; mem_edit.BgColorFnUserData = &app;
return mem_edit; return mem_edit;
} }
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;
}
internal internal
void update_and_render(Arena *arena, App_State &app, f32 delta_time) void update_and_render(Arena *arena, App_State &app, f32 delta_time)
{ {
@ -41,12 +53,25 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time)
sprintf(&text_buf[2 * i], "%02X", app.inspected_fmem[i]); sprintf(&text_buf[2 * i], "%02X", app.inspected_fmem[i]);
text_buf[text_buf_size] = 0; text_buf[text_buf_size] = 0;
if (ImGui::Begin("main")) { const auto main_win_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDecoration;
if (ImGui::Begin("main", nullptr, main_win_flags)) {
ImGui::Text("Inspecting RNTuple '%s' (%s)", app.ntpl_name, ImGui::Text("Inspecting RNTuple '%s' (%s)", app.ntpl_name,
(const char *)rntuple_description(scratch.arena, app.rntinfo->anchor)); (const char *)rntuple_description(scratch.arena, app.rntinfo.anchor));
ImGui::Separator();
static MemoryEditor mem_edit = make_memory_editor(*app.rntinfo); {
mem_edit.DrawWindow("Hex View", app.inspected_fmem, app.inspected_file_size); 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();
}
ImGui::End(); ImGui::End();
} }

10
src/render.h Normal file
View file

@ -0,0 +1,10 @@
struct Viewer_Settings {
float col_header[3];
float col_footer[3];
};
struct Edit_Bg_Color_Data {
RNTuple_Info *ntinfo;
Viewer_Settings vsettings;
};

View file

@ -10,9 +10,9 @@ String8 rntuple_description(Arena *arena, const RNTuple &anchor)
} }
internal internal
RNTuple_Info *get_rntuple_info(Arena *arena, const char *fname, const char *ntpl_name) RNTuple_Info get_rntuple_info(Arena *arena, const char *fname, const char *ntpl_name)
{ {
RNTuple_Info *info = arena_push_zeroed<RNTuple_Info>(arena); RNTuple_Info info = {};
// Open the TFile // Open the TFile
TFile *tfile = TFile::Open(fname, "READ"); TFile *tfile = TFile::Open(fname, "READ");
@ -25,11 +25,11 @@ RNTuple_Info *get_rntuple_info(Arena *arena, const char *fname, const char *ntpl
// Get the RNTuple information // Get the RNTuple information
const RNTuple *anchor = tfile->Get<RNTuple>(ntpl_name); const RNTuple *anchor = tfile->Get<RNTuple>(ntpl_name);
if (anchor) { if (anchor) {
info->anchor = *anchor; info.anchor = *anchor;
info->header.start = anchor->GetSeekHeader(); info.header.start = anchor->GetSeekHeader();
info->header.len = anchor->GetNBytesHeader(); info.header.len = anchor->GetNBytesHeader();
info->footer.start = anchor->GetSeekFooter(); info.footer.start = anchor->GetSeekFooter();
info->footer.len = anchor->GetNBytesFooter(); info.footer.len = anchor->GetNBytesFooter();
} else { } else {
fprintf(stderr, "RNTuple '%s' not found in %s.\n", ntpl_name, fname); fprintf(stderr, "RNTuple '%s' not found in %s.\n", ntpl_name, fname);
} }

View file

@ -24,6 +24,7 @@
#include "str.h" #include "str.h"
#include "rntuple.h" #include "rntuple.h"
#include "window.h" #include "window.h"
#include "render.h"
#include "app_state.h" #include "app_state.h"
// @Platform // @Platform
@ -143,6 +144,7 @@ int main(int argc, char **argv)
app.ntpl_name = ntpl_name; app.ntpl_name = ntpl_name;
app.rntinfo = get_rntuple_info(arena, fname, ntpl_name); app.rntinfo = get_rntuple_info(arena, fname, ntpl_name);
app.vsettings = make_viewer_settings();
// Start main loop // Start main loop
run_main_loop(window, arena, app); run_main_loop(window, arena, app);