commit 10c9dd9
dalem
·
2026-02-08 00:27:48 +0000 UTC
parent b43133c
add lines
4 files changed,
+36,
-1
+1,
-0
1@@ -63,6 +63,7 @@ static const struct wld_renderer_impl wld_renderer_impl = {
2 .copy_region = &default_copy_region,
3 #endif
4 .draw_circle = &wld_draw_circle,
5+ .draw_line = &wld_draw_line,
6 .draw_text = &renderer_draw_text,
7 .flush = &renderer_flush,
8 .destroy = &renderer_destroy
+29,
-0
1@@ -188,6 +188,35 @@ wld_draw_circle(struct wld_renderer *renderer, uint32_t color,
2 }
3 }
4
5+EXPORT
6+void
7+wld_draw_line(struct wld_renderer *renderer, uint32_t color,
8+ int32_t x1, int32_t y1, int32_t x2, int32_t y2)
9+{
10+ int32_t dx = abs(x2-x1), sx = x1<x2 ? 1 : -1;
11+ int32_t dy = -abs(y2-y1), sy = y1<y2 ? 1 : -1;
12+ int32_t err = dx+dy, e2;
13+
14+ while(true) {
15+ renderer->impl->fill_rectangle(renderer, color, x1, y1, 1, 1);
16+
17+ if (x1==x2 && y1==y2)
18+ break;
19+
20+ e2 = 2*err;
21+
22+ if (e2 >= dy) {
23+ err += dy;
24+ x1 += sx;
25+ }
26+
27+ if (e2 <= dx) {
28+ err += dx;
29+ y1 += sy;
30+ }
31+ }
32+}
33+
34 EXPORT
35 void
36 wld_draw_text(struct wld_renderer *renderer,
+2,
-0
1@@ -110,6 +110,8 @@ struct wld_renderer_impl {
2 pixman_region32_t *region);
3 void (*draw_circle)(struct wld_renderer *renderer, uint32_t color,
4 int32_t x, int32_t y, uint32_t r, bool fill);
5+ void (*draw_line)(struct wld_renderer *renderer, uint32_t color,
6+ int32_t x1, int32_t y1, int32_t x2, int32_t y2);
7 void (*draw_text)(struct wld_renderer *renderer,
8 struct font *font, uint32_t color,
9 int32_t x, int32_t y, const char *text, uint32_t length,
M
wld.h
+4,
-1
1@@ -254,7 +254,10 @@ void wld_copy_region(struct wld_renderer *renderer,
2 int32_t dst_x, int32_t dst_y, pixman_region32_t *region);
3
4 void wld_draw_circle(struct wld_renderer *renderer, uint32_t color,
5- int32_t x, int32_t y, uint32_t r, bool fill);
6+ int32_t x, int32_t y, uint32_t r, bool fill);
7+
8+void wld_draw_line(struct wld_renderer *renderer, uint32_t color,
9+ int32_t x1, int32_t y1, int32_t x2, int32_t y2);
10
11 /**
12 * Draw a UTF-8 text string to the given buffer.