144 lines
5.1 KiB
C
144 lines
5.1 KiB
C
////////////////////////////////////////////////////////////
|
|
//~ Console
|
|
|
|
UI_Box *PP_BuildDebugConsole(b32 minimized)
|
|
{
|
|
/* TODO: Remove this whole thing */
|
|
__prof;
|
|
PP_SharedUserState *g = &PP_shared_user_state;
|
|
TempArena scratch = BeginScratchNoConflict();
|
|
|
|
// i32 console_level = minimized ? LogLevel_Success : LogLevel_Debug;
|
|
i32 console_level = LogLevel_Debug;
|
|
|
|
u32 colors[LogLevel_Count][2] = ZI;
|
|
SetBytes(colors, 0xFF, sizeof(colors));
|
|
/* Debug colors */
|
|
colors[LogLevel_Debug][0] = Rgb32F(0.4, 0.1, 0.4);
|
|
colors[LogLevel_Debug][1] = Rgb32F(0.5, 0.2, 0.5);
|
|
/* Info colors */
|
|
colors[LogLevel_Info][0] = Rgb32F(0.4, 0.4, 0.4);
|
|
colors[LogLevel_Info][1] = Rgb32F(0.5, 0.5, 0.5);
|
|
/* Success colors */
|
|
colors[LogLevel_Success][0] = Rgb32F(0.1, 0.3, 0.1);
|
|
colors[LogLevel_Success][1] = Rgb32F(0.2, 0.4, 0.2);
|
|
/* Warning colors */
|
|
colors[LogLevel_Warning][0] = Rgb32F(0.4, 0.4, 0.1);
|
|
colors[LogLevel_Warning][1] = Rgb32F(0.5, 0.5, 0.2);
|
|
/* Error colors */
|
|
colors[LogLevel_Error][0] = Rgb32F(0.4, 0.1, 0.1);
|
|
colors[LogLevel_Error][1] = Rgb32F(0.5, 0.2, 0.2);
|
|
|
|
i64 max_time_ns = I64Max;
|
|
i64 fade_time_ns = max_time_ns;
|
|
if (minimized)
|
|
{
|
|
max_time_ns = NsFromSeconds(10);
|
|
fade_time_ns = max_time_ns;
|
|
}
|
|
f32 fade_curve = 0.5;
|
|
|
|
i64 now_ns = TimeNs();
|
|
UI_Box *console_box = 0;
|
|
{
|
|
UI_SetNext(Border, 0);
|
|
if (minimized)
|
|
{
|
|
UI_SetNext(BackgroundColor, 0);
|
|
UI_SetNext(Width, UI_PIX(500, 0));
|
|
UI_SetNext(Height, UI_FIT(1));
|
|
}
|
|
else
|
|
{
|
|
UI_SetNext(BackgroundColor, Rgba32F(1, 1, 1, 0.02));
|
|
UI_SetNext(Width, UI_FILL(1, 0));
|
|
UI_SetNext(Height, UI_FIT(1));
|
|
}
|
|
console_box = UI_BuildColumn(Lit("Console box"));
|
|
UI_PushCP(console_box);
|
|
{
|
|
/* Gather display logs */
|
|
u64 max = 20;
|
|
u64 display_count = 0;
|
|
LogEvent *display_logs = PushStructs(scratch.arena, LogEvent, max);
|
|
{
|
|
b32 done = 0;
|
|
if (minimized)
|
|
{
|
|
max = 5;
|
|
}
|
|
LogEventsArray logs = GetLogEvents();
|
|
for (u64 i = logs.count; i-- > 0 && display_count < max && !done;)
|
|
{
|
|
LogEvent ev = logs.logs[i];
|
|
if (ev.time_ns > (now_ns - max_time_ns))
|
|
{
|
|
if (ev.level <= console_level)
|
|
{
|
|
display_logs[display_count] = ev;
|
|
++display_count;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
done = 1;
|
|
}
|
|
}
|
|
}
|
|
/* Display logs in reverse */
|
|
for (u64 i = display_count; i-- > 0;)
|
|
{
|
|
LogEvent log = display_logs[i];
|
|
f32 opacity = 0.75;
|
|
f32 lin = 1.0 - ClampF64((f64)(now_ns - log.time_ns) / (f64)fade_time_ns, 0, 1);
|
|
opacity *= PowF32(lin, fade_curve);
|
|
String text = log.msg;
|
|
if (!minimized)
|
|
{
|
|
DateTime datetime = log.datetime;
|
|
text = StringF(
|
|
scratch.arena,
|
|
"[%F:%F:%F.%F] %F",
|
|
FmtUintZ(datetime.hour, 2),
|
|
FmtUintZ(datetime.minute, 2),
|
|
FmtUintZ(datetime.second, 2),
|
|
FmtUintZ(datetime.milliseconds, 3),
|
|
FmtString(text));
|
|
}
|
|
UI_PushCP(0);
|
|
{
|
|
UI_Push(Tint, Alpha32F(0xFFFFFFFF, opacity));
|
|
{
|
|
u32 color = colors[log.level][log.level_id % 2];
|
|
UI_Push(BackgroundColor, color);
|
|
UI_Push(Width, UI_FILL(1, 0));
|
|
UI_Push(Height, UI_FNT(1.5, 1));
|
|
UI_Push(BorderColor, Rgba32F(0.25, 0.25, 0.25, 1));
|
|
UI_Push(Rounding, UI_RPIX(0));
|
|
UI_Push(Border, 1);
|
|
UI_Push(ChildAlignment, UI_Alignment_Left);
|
|
UI_PushCP(UI_BuildRow(Zstr));
|
|
{
|
|
// UI_SetNext(Height, UI_PIX(100, 0));
|
|
UI_BuildSpacer(UI_PIX(10, 0));
|
|
UI_Push(BackgroundColor, 0);
|
|
UI_Push(Border, 0);
|
|
UI_Push(Text, text);
|
|
UI_Push(Width, UI_FILL(1, 0));
|
|
UI_Push(Height, UI_FIT(1));
|
|
UI_Push(Flags, UI_BoxFlag_DrawText);
|
|
UI_BuildBox(Zstr);
|
|
}
|
|
UI_PopCP();
|
|
}
|
|
}
|
|
UI_PopCP();
|
|
}
|
|
}
|
|
UI_PopCP();
|
|
}
|
|
|
|
EndScratch(scratch);
|
|
return console_box;
|
|
}
|