From 20311c69d2fd4315e3fecf731819d7eba3152871 Mon Sep 17 00:00:00 2001 From: quou Date: Tue, 1 Oct 2024 18:34:07 +1000 Subject: debug rectangle drawing --- plat.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'plat.c') diff --git a/plat.c b/plat.c index cc351ff..ef84eda 100644 --- a/plat.c +++ b/plat.c @@ -15,6 +15,31 @@ int btn_just_released(const App* a, Btn btn) { return a->btn_states[btn] & btn_state_just_released; } +typedef struct { + int x, y, w, h; + unsigned col; +} Debug_Rect; + +#define max_debug_rects 128 +Debug_Rect debug_rects[max_debug_rects]; +int debug_rect_count; + +void ren_debug_rect( + int x, + int y, + int w, + int h, + unsigned colour +) { + Debug_Rect* r = &debug_rects[debug_rect_count++]; + assert(debug_rect_count < max_debug_rects); + r->x = x; + r->y = y; + r->w = w; + r->h = h; + r->col = colour; +} + #ifdef plat_posix #define _POSIX_SOURCE #define _GNU_SOURCE @@ -419,6 +444,22 @@ void app_rencpy( sx, sy, w, h ); +#ifdef DEBUG + for (sj = 0; sj < debug_rect_count; sj++) { + const Debug_Rect* dr = &debug_rects[sj]; + XSetForeground(i->d, i->gc, dr->col); + XFillRectangle( + i->d, + i->wi, + i->gc, + dr->x * s, + dr->y * s, + dr->w * s, + dr->h * s + ); + } +#endif + debug_rect_count = 0; } void app_end(App* a) { -- cgit v1.2.3-54-g00ecf