Mercurial > molko
changeset 167:b9b826cd9832
core: texture_(scale|draw) now return a bool
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 20 Oct 2020 14:58:51 +0200 |
parents | e8c3ea4fe5d2 |
children | aab824406d3d |
files | libcore/core/texture.c libcore/core/texture.h |
diffstat | 2 files changed, 17 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/libcore/core/texture.c Tue Oct 20 14:54:14 2020 +0200 +++ b/libcore/core/texture.c Tue Oct 20 14:58:51 2020 +0200 @@ -48,12 +48,10 @@ bool texture_ok(const struct texture *tex) { - assert(tex); - - return tex->handle && tex->w && tex->h; + return tex && tex->handle && tex->w && tex->h; } -void +bool texture_draw(struct texture *tex, int x, int y) { assert(tex); @@ -65,10 +63,13 @@ .h = tex->h }; - SDL_RenderCopy(RENDERER(), tex->handle, NULL, &dst); + if (SDL_RenderCopy(RENDERER(), tex->handle, NULL, &dst) < 0) + return error_sdl(); + + return true; } -void +bool texture_scale(struct texture *tex, int src_x, int src_y, @@ -93,7 +94,10 @@ .h = dst_h }; - SDL_RenderCopyEx(RENDERER(), tex->handle, &src, &dst, angle, NULL, SDL_FLIP_NONE); + if (SDL_RenderCopyEx(RENDERER(), tex->handle, &src, &dst, angle, NULL, SDL_FLIP_NONE) < 0) + return error_sdl(); + + return true; } void
--- a/libcore/core/texture.h Tue Oct 20 14:54:14 2020 +0200 +++ b/libcore/core/texture.h Tue Oct 20 14:58:51 2020 +0200 @@ -56,9 +56,8 @@ * This function simply checks if the texture is initialized and has non-null * dimensions. * - * \pre tex != NULL - * \param tex the texture to check - * \return True if the texture is initialized + * \param tex the texture to check (may be NULL) + * \return True if the texture is properly initialized. */ bool texture_ok(const struct texture *tex); @@ -70,8 +69,9 @@ * \param tex the texture * \param x the X coordinate * \param y the Y coordinate + * \return False in case of rendering error. */ -void +bool texture_draw(struct texture *tex, int x, int y); /** @@ -88,8 +88,9 @@ * \param dst_w the destination rectangle width * \param dst_h the destination rectangle height * \param angle the angle + * \return False in case of rendering error. */ -void +bool texture_scale(struct texture *tex, int src_x, int src_y,