summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-09-01 23:03:08 +0200
committerkdx <kikoodx@paranoici.org>2023-09-01 23:03:08 +0200
commit7bf9f5c5fc7cd8422070866744734fdcd937fbc8 (patch)
tree37b1eff50382e67131258690407ae2efb68fc3a3
parent4ea628b8c6d500a803ed0c2c7d12718f57b41fa1 (diff)
downloadpx-7bf9f5c5fc7cd8422070866744734fdcd937fbc8.tar.gz
spr center flag
-rw-r--r--src/px.c11
-rw-r--r--src/px.h3
2 files changed, 11 insertions, 3 deletions
diff --git a/src/px.c b/src/px.c
index 5281432..d7c8650 100644
--- a/src/px.c
+++ b/src/px.c
@@ -220,10 +220,17 @@ _pxSpr(const PxSprArgs *args)
int h = (args->h < 0) ? (int)(args->spr->h) : (args->h);
h = pxMin(h, args->spr->h - args->iy);
+ int ox = args->x;
+ int oy = args->y;
+ if (args->center) {
+ ox -= w / 2;
+ oy -= h / 2;
+ }
+
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
- const int dx = x + args->x;
- const int dy = y + args->y;
+ const int dx = x + ox;
+ const int dy = y + oy;
int ix = args->ix + ((args->flip_x)
? (w - x - 1)
: (x));
diff --git a/src/px.h b/src/px.h
index 1d08bd1..3d0db03 100644
--- a/src/px.h
+++ b/src/px.h
@@ -34,6 +34,7 @@ typedef struct {
int h;
bool flip_x;
bool flip_y;
+ bool center;
} PxSprArgs;
typedef struct {
@@ -94,7 +95,7 @@ void pxLine(int x0, int y0, int x1, int y1, PxCol col);
/* Draw sprite. */
#define pxSpr(...) _pxSpr(&(const PxSprArgs){ \
.x=0, .y=0, .ix=0, .iy=0, .w=-1, .h=-1, .flip_x=false, .flip_x=false, \
- ._=0, __VA_ARGS__})
+ .center=false, ._=0, __VA_ARGS__})
void _pxSpr(const PxSprArgs *args);
/* Bind palette index to new color. */