From f680ab5c3798b730e2e4efb7363ca15074e0499e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 11 Aug 2024 01:07:00 +0200 Subject: fix incorrect sprite_set_height, add sprite_set_width --- include/mgl/graphics/sprite.h | 2 ++ src/graphics/sprite.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/mgl/graphics/sprite.h b/include/mgl/graphics/sprite.h index 9e4ebc7..c37ee39 100644 --- a/include/mgl/graphics/sprite.h +++ b/include/mgl/graphics/sprite.h @@ -27,6 +27,8 @@ void mgl_sprite_set_rotation(mgl_sprite *self, float degrees); void mgl_sprite_set_origin(mgl_sprite *self, mgl_vec2f origin); /* This only has an effect if the sprite has a texture set */ void mgl_sprite_set_size(mgl_sprite *self, mgl_vec2f size); +/* This only has an effect if the sprite has a texture set. Scales height in proportion */ +void mgl_sprite_set_width(mgl_sprite *self, float width); /* This only has an effect if the sprite has a texture set. Scales width in proportion */ void mgl_sprite_set_height(mgl_sprite *self, float height); /* Texture size multiplied by the sprite scaling */ diff --git a/src/graphics/sprite.c b/src/graphics/sprite.c index 613ec4c..ce2566e 100644 --- a/src/graphics/sprite.c +++ b/src/graphics/sprite.c @@ -40,14 +40,22 @@ void mgl_sprite_set_size(mgl_sprite *self, mgl_vec2f size) { self->scale.y = size.y / (float)self->texture->height; } -void mgl_sprite_set_height(mgl_sprite *self, float height) { +void mgl_sprite_set_width(mgl_sprite *self, float width) { if(!self->texture) return; - self->scale.x = height / (float)self->texture->width; + self->scale.x = width / (float)self->texture->width; self->scale.y = self->scale.x; } +void mgl_sprite_set_height(mgl_sprite *self, float height) { + if(!self->texture) + return; + + self->scale.y = height / (float)self->texture->height; + self->scale.x = self->scale.y; +} + mgl_vec2f mgl_sprite_get_size(const mgl_sprite *self) { if(self->texture) { return (mgl_vec2f){ (float)self->texture->width * self->scale.x, (float)self->texture->height * self->scale.y }; -- cgit v1.2.3