eco2d/code/game/source/debug_ui_widgets.c

63 lines
2.0 KiB
C
Raw Normal View History

2021-05-13 12:17:44 +00:00
#include "debug_ui.h"
#include "raylib.h"
#include "platform.h"
#include "profiler.h"
//~ NOTE(zaklaus): helpers
static inline debug_draw_result
DrawFloat(float xpos, float ypos, float val) {
char const *text = TextFormat("%.02f\n", val);
UIDrawText(text, xpos, ypos, DBG_FONT_SIZE, RAYWHITE);
return (debug_draw_result){.x = xpos + UIMeasureText(text, DBG_FONT_SIZE), .y = ypos + DBG_FONT_SPACING};
}
static inline debug_draw_result
2021-05-13 19:42:31 +00:00
DrawColoredText(float xpos, float ypos, char const *text, Color color) {
2021-05-13 12:17:44 +00:00
assert(text);
2021-05-13 19:42:31 +00:00
UIDrawText(text, xpos, ypos, DBG_FONT_SIZE, color);
2021-05-13 12:17:44 +00:00
return (debug_draw_result){.x = xpos + UIMeasureText(text, DBG_FONT_SIZE), .y = ypos + DBG_FONT_SPACING};
}
2021-05-13 12:36:07 +00:00
static inline debug_draw_result
2021-05-13 19:42:31 +00:00
DrawFormattedText(float xpos, float ypos, char const *text) {
return DrawColoredText(xpos, ypos, text, RAYWHITE);
2021-05-13 12:36:07 +00:00
}
2021-05-13 12:17:44 +00:00
//~ NOTE(zaklaus): widgets
2021-05-13 14:37:53 +00:00
static inline debug_draw_result
DrawUnmeasuredTime(debug_item *it, float xpos, float ypos) {
(void)it;
float total_time = profiler_delta(PROF_TOTAL_TIME);
float acc_time = profiler_delta(PROF_MAIN_LOOP);
return DrawFormattedText(xpos, ypos, TextFormat("%.02f ms", (total_time-acc_time) * 1000.0f));
}
2021-05-13 12:17:44 +00:00
static inline debug_draw_result
DrawDeltaTime(debug_item *it, float xpos, float ypos) {
(void)it;
float dt = GetFrameTime();
return DrawFormattedText(xpos, ypos, TextFormat("%.02f (%.02f fps)", dt * 1000.0f, 1.0f/dt));
}
static inline debug_draw_result
DrawZoom(debug_item *it, float xpos, float ypos) {
(void)it;
return DrawFloat(xpos, ypos, platform_zoom_get());
}
static inline debug_draw_result
DrawLiteral(debug_item *it, float xpos, float ypos) {
assert(it->text);
return DrawFormattedText(xpos, ypos, it->text);
}
static inline debug_draw_result
DrawProfilerDelta(debug_item *it, float xpos, float ypos) {
float dt = profiler_delta(it->val);
return DrawFormattedText(xpos, ypos, TextFormat("%s: %.02f ms", profiler_name(it->val), dt * 1000.0f));
}