From 7bf9f5c5fc7cd8422070866744734fdcd937fbc8 Mon Sep 17 00:00:00 2001 From: kdx Date: Fri, 1 Sep 2023 23:03:08 +0200 Subject: spr center flag --- src/px.c | 11 +++++++++-- src/px.h | 3 ++- 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. */ -- cgit v1.2.3