neuwld

patched neuwld library (tracked)
git clone https://git.daat.foo/neuwld.git
Log | Files | Refs | README | LICENSE

commit 10c9dd9acae668be7786327b12fd22e7304f3fc6
parent b43133ce0f6fc7dfe59682527710ca4721417978
Author: dalem <lain@dalem.foo>
Date:   Sun,  8 Feb 2026 01:27:48 +0100

add lines

Diffstat:
Minterface/renderer.h | 1+
Mrenderer.c | 29+++++++++++++++++++++++++++++
Mwld-private.h | 2++
Mwld.h | 5++++-
4 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/interface/renderer.h b/interface/renderer.h @@ -63,6 +63,7 @@ static const struct wld_renderer_impl wld_renderer_impl = { .copy_region = &default_copy_region, #endif .draw_circle = &wld_draw_circle, + .draw_line = &wld_draw_line, .draw_text = &renderer_draw_text, .flush = &renderer_flush, .destroy = &renderer_destroy diff --git a/renderer.c b/renderer.c @@ -190,6 +190,35 @@ wld_draw_circle(struct wld_renderer *renderer, uint32_t color, EXPORT void +wld_draw_line(struct wld_renderer *renderer, uint32_t color, + int32_t x1, int32_t y1, int32_t x2, int32_t y2) +{ + int32_t dx = abs(x2-x1), sx = x1<x2 ? 1 : -1; + int32_t dy = -abs(y2-y1), sy = y1<y2 ? 1 : -1; + int32_t err = dx+dy, e2; + + while(true) { + renderer->impl->fill_rectangle(renderer, color, x1, y1, 1, 1); + + if (x1==x2 && y1==y2) + break; + + e2 = 2*err; + + if (e2 >= dy) { + err += dy; + x1 += sx; + } + + if (e2 <= dx) { + err += dx; + y1 += sy; + } + } +} + +EXPORT +void wld_draw_text(struct wld_renderer *renderer, struct wld_font *font_base, uint32_t color, int32_t x, int32_t y, const char *text, uint32_t length, diff --git a/wld-private.h b/wld-private.h @@ -110,6 +110,8 @@ struct wld_renderer_impl { pixman_region32_t *region); void (*draw_circle)(struct wld_renderer *renderer, uint32_t color, int32_t x, int32_t y, uint32_t r, bool fill); + void (*draw_line)(struct wld_renderer *renderer, uint32_t color, + int32_t x1, int32_t y1, int32_t x2, int32_t y2); void (*draw_text)(struct wld_renderer *renderer, struct font *font, uint32_t color, int32_t x, int32_t y, const char *text, uint32_t length, diff --git a/wld.h b/wld.h @@ -254,7 +254,10 @@ void wld_copy_region(struct wld_renderer *renderer, int32_t dst_x, int32_t dst_y, pixman_region32_t *region); void wld_draw_circle(struct wld_renderer *renderer, uint32_t color, - int32_t x, int32_t y, uint32_t r, bool fill); + int32_t x, int32_t y, uint32_t r, bool fill); + +void wld_draw_line(struct wld_renderer *renderer, uint32_t color, + int32_t x1, int32_t y1, int32_t x2, int32_t y2); /** * Draw a UTF-8 text string to the given buffer.