aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-10-01 18:34:07 +1000
committerquou <quou@disroot.org>2024-10-01 18:34:07 +1000
commit20311c69d2fd4315e3fecf731819d7eba3152871 (patch)
treeceb0776ac26f7f6f4683c5ec8ccfdb1d8661dfba
parentfbc6770df9234bf89b5e4fe3ae07af6f3ab96281 (diff)
debug rectangle drawing
-rw-r--r--plat.c41
-rw-r--r--plat.h8
2 files changed, 49 insertions, 0 deletions
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) {
diff --git a/plat.h b/plat.h
index 32f17f6..687106d 100644
--- a/plat.h
+++ b/plat.h
@@ -85,4 +85,12 @@ int btn_pressed(const App* a, Btn btn);
int btn_just_pressed(const App* a, Btn btn);
int btn_just_released(const App* a, Btn btn);
+void ren_debug_rect(
+ int x,
+ int y,
+ int w,
+ int h,
+ unsigned colour
+);
+
#endif