From 3a141f98c21809baa84dd698b00174d8074f9a73 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sun, 6 Jun 2021 11:33:08 +0200 Subject: Add draw_filled_rect function --- src/renderer.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/renderer.c') diff --git a/src/renderer.c b/src/renderer.c index 2b1f0d2..773d50b 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -26,7 +26,7 @@ static u32 dirty_tiles[21] = {0}; IWRAM_CODE void -draw_pixel(size_t x, size_t y, u8 color) { +draw_pixel(size_t x, size_t y, u8 clr) { BOUNDCHECK_SCREEN(x, y); // Find row position for the given x/y coordinates. @@ -38,7 +38,7 @@ draw_pixel(size_t x, size_t y, u8 color) { // Update backbuffer. size_t shift = start_col * sizeof(u32); - BACKBUF[pos] = (BACKBUF[pos] & ~(0xF << shift)) | color << shift; + BACKBUF[pos] = (BACKBUF[pos] & ~(0xF << shift)) | clr << shift; // Mark tile as dirty. dirty_tiles[tile_y] |= 1 << tile_x; @@ -129,7 +129,7 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { if (dx >= dy) { // Positive slope. int diff = 2 * dy - dx; - for (int i = 0; i <= dx; ++i) { + for (size_t i = 0; i <= dx; ++i) { draw_pixel(x, y, clr); if (diff >= 0) { y += y_step; @@ -141,7 +141,7 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { } else { // Negative slope. int diff = 2 * dx - dy; - for (int i = 0; i <= dy; ++i) { + for (size_t i = 0; i <= dy; ++i) { draw_pixel(x, y, clr); if (diff >= 0) { x += x_step; @@ -251,6 +251,21 @@ draw_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { } } +IWRAM_CODE +void +draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) { + BOUNDCHECK_SCREEN(x0, y0); + BOUNDCHECK_SCREEN(x1, y1); + + size_t dx = x1 - x0; + size_t dy = y1 - y0; + size_t n_rect = MIN(dx, dy); + n_rect = n_rect / 2 + 1; + for (size_t i = 0; i < n_rect; i++) { + draw_rect(x0 + i, y0 + i, x1 - i, y1 - i, clr); + } +} + IWRAM_CODE void draw_tile(size_t x, size_t y, Tile *tile, bool merge) { -- cgit v1.2.1