diff options
author | kdx <kikoodx@paranoici.org> | 2023-04-16 13:40:40 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-04-16 13:40:40 +0200 |
commit | 5be9f675a51072dfbd8e01edc11c9aebcad0195e (patch) | |
tree | 5d41737952a708b989f253353b788021c7adb1c5 | |
parent | 25b45b7354db9c9a36c56cf6aeee58dca02a1b73 (diff) | |
download | px-5be9f675a51072dfbd8e01edc11c9aebcad0195e.tar.gz |
rect and rectfill
-rw-r--r-- | src/main.c | 3 | ||||
-rw-r--r-- | src/px.c | 41 | ||||
-rw-r--r-- | src/px.h | 6 |
3 files changed, 50 insertions, 0 deletions
@@ -35,6 +35,9 @@ main(void) pxCls(1); + pxRectfill(112, 112, x, y, 10); + pxRect(16, 16, x, y, 11); + pxPalt(); pxSpr(&spr, x, y); @@ -82,6 +82,47 @@ pxPget(int x, int y) } void +pxRect(int x0, int y0, int x1, int y1, PxCol col) +{ + if (x0 > x1) { + x0 ^= x1; + x1 ^= x0; + x0 ^= x1; + } + if (y0 > y1) { + y0 ^= y1; + y1 ^= y0; + y0 ^= y1; + } + for (int x = x0; x <= x1; x++) { + pxPset(x, y0, col); + pxPset(x, y1, col); + } + for (int y = y0; y <= y1; y++) { + pxPset(x0, y, col); + pxPset(x1, y, col); + } +} + +void +pxRectfill(int x0, int y0, int x1, int y1, PxCol col) +{ + if (x0 > x1) { + x0 ^= x1; + x1 ^= x0; + x0 ^= x1; + } + if (y0 > y1) { + y0 ^= y1; + y1 ^= y0; + y0 ^= y1; + } + for (int y = y0; y <= y1; y++) + for (int x = x0; x <= x1; x++) + pxPset(x, y, col); +} + +void _pxSpr(const PxSprArgs *args) { int w = (args->w < 0) ? (args->spr->w) : (args->w); @@ -57,6 +57,12 @@ void pxPset(int x, int y, PxCol c); /* Get a pixel. */ PxCol pxPget(int x, int y); +/* Draw empty rectangle. */ +void pxRect(int x0, int y0, int x1, int y1, PxCol col); + +/* Draw filled rectangle. */ +void pxRectfill(int x0, int y0, int x1, int y1, PxCol col); + /* Draw sprite. */ #define pxSpr(...) _pxSpr(&(const PxSprArgs){ \ .ix=0, .iy=0, .w=-1, .h=-1, ._=0, __VA_ARGS__}) |