aboutsummaryrefslogtreecommitdiffstats
path: root/src/renderer.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-06-06 11:33:08 +0200
committerBad Diode <bd@badd10de.dev>2021-06-06 11:33:08 +0200
commit3a141f98c21809baa84dd698b00174d8074f9a73 (patch)
tree959187cf4e071f221d2a94e8a7f56b64052ea7a1 /src/renderer.c
parent781ab3f0f32ea3db697f2c77e17099b243c3ed29 (diff)
downloadstepper-3a141f98c21809baa84dd698b00174d8074f9a73.tar.gz
stepper-3a141f98c21809baa84dd698b00174d8074f9a73.zip
Add draw_filled_rect function
Diffstat (limited to 'src/renderer.c')
-rw-r--r--src/renderer.c23
1 files changed, 19 insertions, 4 deletions
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};
26 26
27IWRAM_CODE 27IWRAM_CODE
28void 28void
29draw_pixel(size_t x, size_t y, u8 color) { 29draw_pixel(size_t x, size_t y, u8 clr) {
30 BOUNDCHECK_SCREEN(x, y); 30 BOUNDCHECK_SCREEN(x, y);
31 31
32 // Find row position for the given x/y coordinates. 32 // Find row position for the given x/y coordinates.
@@ -38,7 +38,7 @@ draw_pixel(size_t x, size_t y, u8 color) {
38 38
39 // Update backbuffer. 39 // Update backbuffer.
40 size_t shift = start_col * sizeof(u32); 40 size_t shift = start_col * sizeof(u32);
41 BACKBUF[pos] = (BACKBUF[pos] & ~(0xF << shift)) | color << shift; 41 BACKBUF[pos] = (BACKBUF[pos] & ~(0xF << shift)) | clr << shift;
42 42
43 // Mark tile as dirty. 43 // Mark tile as dirty.
44 dirty_tiles[tile_y] |= 1 << tile_x; 44 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) {
129 if (dx >= dy) { 129 if (dx >= dy) {
130 // Positive slope. 130 // Positive slope.
131 int diff = 2 * dy - dx; 131 int diff = 2 * dy - dx;
132 for (int i = 0; i <= dx; ++i) { 132 for (size_t i = 0; i <= dx; ++i) {
133 draw_pixel(x, y, clr); 133 draw_pixel(x, y, clr);
134 if (diff >= 0) { 134 if (diff >= 0) {
135 y += y_step; 135 y += y_step;
@@ -141,7 +141,7 @@ draw_line(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
141 } else { 141 } else {
142 // Negative slope. 142 // Negative slope.
143 int diff = 2 * dx - dy; 143 int diff = 2 * dx - dy;
144 for (int i = 0; i <= dy; ++i) { 144 for (size_t i = 0; i <= dy; ++i) {
145 draw_pixel(x, y, clr); 145 draw_pixel(x, y, clr);
146 if (diff >= 0) { 146 if (diff >= 0) {
147 x += x_step; 147 x += x_step;
@@ -253,6 +253,21 @@ draw_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
253 253
254IWRAM_CODE 254IWRAM_CODE
255void 255void
256draw_filled_rect(size_t x0, size_t y0, size_t x1, size_t y1, u8 clr) {
257 BOUNDCHECK_SCREEN(x0, y0);
258 BOUNDCHECK_SCREEN(x1, y1);
259
260 size_t dx = x1 - x0;
261 size_t dy = y1 - y0;
262 size_t n_rect = MIN(dx, dy);
263 n_rect = n_rect / 2 + 1;
264 for (size_t i = 0; i < n_rect; i++) {
265 draw_rect(x0 + i, y0 + i, x1 - i, y1 - i, clr);
266 }
267}
268
269IWRAM_CODE
270void
256draw_tile(size_t x, size_t y, Tile *tile, bool merge) { 271draw_tile(size_t x, size_t y, Tile *tile, bool merge) {
257 BOUNDCHECK_SCREEN(x, y); 272 BOUNDCHECK_SCREEN(x, y);
258 273