From d9d6f47f8a973d6f335c9bac8254d0b295dadac0 Mon Sep 17 00:00:00 2001 From: KonAki Date: Sun, 18 Oct 2026 04:26:33 +0800 Subject: konui: kon_uiImage --- kon/konui.c | 20 ++++++++++++++++++++ kon/konui.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/kon/konui.c b/kon/konui.c index ec7651e..6de6971 100644 --- a/kon/konui.c +++ b/kon/konui.c @@ -1011,3 +1011,23 @@ void kon_uiNextWidth(kon_ui_t *ui, int width) { ui->nextWidth = width; } + +void kon_uiImage(kon_ui_t *ui, kon_image *image, int width, int height) +{ + kon_rect_t r; + int x, y, tile = 8; + + if (width < 1) width = 1; + if (height < 1) height = 1; + r = kon_uiNextRect_(ui, width, height); + + for (y = 0; y < r.h; y += tile) { + for (x = 0; x < r.w; x += tile) { + int w = r.w - x < tile ? r.w - x : tile, h = r.h - y < tile ? r.h - y : tile; + + kon_fillRectangle(ui->fb, r.x + x, r.y + y, w, h, ((x + y) / tile) % 2 ? ui->theme.title : ui->theme.panel); + } + } + if (image) kon_drawImage(ui->fb, r.x, r.y, r.w, r.h, image); + kon_uiOutline_(ui, r, ui->theme.border); +} diff --git a/kon/konui.h b/kon/konui.h index c055b06..c4ea30f 100644 --- a/kon/konui.h +++ b/kon/konui.h @@ -131,6 +131,9 @@ int kon_uiTabs(kon_ui_t *ui, const char *const *labels, int count, int *current) int kon_uiTreeNode(kon_ui_t *ui, const char *label, int *open); void kon_uiIndent(kon_ui_t *ui, int amount); +/* a picture drawn at width x height pixels (scaled to it) on a checkerboard, so see through parts show. image can be NULL for just the board */ +void kon_uiImage(kon_ui_t *ui, kon_image *image, int width, int height); + void kon_uiSeparator(kon_ui_t *ui); void kon_uiSameLine(kon_ui_t *ui); -- cgit