Mercurial > molko
changeset 278:cc676046aac9
core: add sprite_scale function
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 15 Dec 2020 22:06:32 +0100 |
parents | 1d10983fc0d7 |
children | 5217c195c5b9 |
files | doc/docs/dev/api/core/sprite.md libmlk-core/core/sprite.c libmlk-core/core/sprite.h |
diffstat | 3 files changed, 35 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/docs/dev/api/core/sprite.md Sun Dec 13 11:25:11 2020 +0100 +++ b/doc/docs/dev/api/core/sprite.md Tue Dec 15 22:06:32 2020 +0100 @@ -73,13 +73,23 @@ ### sprite\_draw +Similar to [sprite_scale](#sprite_scale) but use sprite cell dimensions for +scaling. + +```c +bool +sprite_draw(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y) +``` + +### sprite_scale + Draw an individual cell from row `r` and column `c` at the coordinates `x`, `y` -from the sprite `sprite`. +from the sprite `sprite` and scale the image to dimensions `w`, `h`. !!! caution Argument `r` and `c` must be out of bounds. ```c bool -sprite_draw(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y) +sprite_scale(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y, unsigned int w, unsigned int h) ```
--- a/libmlk-core/core/sprite.c Sun Dec 13 11:25:11 2020 +0100 +++ b/libmlk-core/core/sprite.c Tue Dec 15 22:06:32 2020 +0100 @@ -49,6 +49,18 @@ bool sprite_draw(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y) { + return sprite_scale(sprite, r, c, x, y, sprite->cellw, sprite->cellh); +} + +bool +sprite_scale(const struct sprite *sprite, + unsigned int r, + unsigned int c, + int x, + int y, + unsigned int w, + unsigned int h) +{ assert(sprite_ok(sprite)); assert(r < sprite->nrows); assert(c < sprite->ncols); @@ -61,8 +73,8 @@ sprite->cellh, /* src height */ x, /* dst x */ y, /* dst y */ - sprite->cellw, /* dst width */ - sprite->cellh, /* dst height */ + w, /* dst width */ + h, /* dst height */ 0.0 /* angle */ ); }
--- a/libmlk-core/core/sprite.h Sun Dec 13 11:25:11 2020 +0100 +++ b/libmlk-core/core/sprite.h Tue Dec 15 22:06:32 2020 +0100 @@ -43,4 +43,13 @@ bool sprite_draw(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y); +bool +sprite_scale(const struct sprite *sprite, + unsigned int r, + unsigned int c, + int x, + int y, + unsigned int w, + unsigned int h); + #endif /* !MOLKO_CORE_SPRITE_H */