summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-04-16 13:40:40 +0200
committerkdx <kikoodx@paranoici.org>2023-04-16 13:40:40 +0200
commit5be9f675a51072dfbd8e01edc11c9aebcad0195e (patch)
tree5d41737952a708b989f253353b788021c7adb1c5
parent25b45b7354db9c9a36c56cf6aeee58dca02a1b73 (diff)
downloadpx-5be9f675a51072dfbd8e01edc11c9aebcad0195e.tar.gz
rect and rectfill
-rw-r--r--src/main.c3
-rw-r--r--src/px.c41
-rw-r--r--src/px.h6
3 files changed, 50 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 2d8f351..beee27a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
diff --git a/src/px.c b/src/px.c
index 629a7de..3ca7077 100644
--- a/src/px.c
+++ b/src/px.c
@@ -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);
diff --git a/src/px.h b/src/px.h
index e32f079..7fe0765 100644
--- a/src/px.h
+++ b/src/px.h
@@ -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__})