diff libcore/core/sprite.h @ 166:e8c3ea4fe5d2

core: add sprite_ok function, closes #2505
author David Demelier <markand@malikania.fr>
date Tue, 20 Oct 2020 14:54:14 +0200
parents b386d25832c8
children eb0a7ab71023
line wrap: on
line diff
--- a/libcore/core/sprite.h	Mon Oct 19 08:10:21 2020 +0200
+++ b/libcore/core/sprite.h	Tue Oct 20 14:54:14 2020 +0200
@@ -23,8 +23,28 @@
  * \file sprite.h
  * \brief Image sprites.
  * \ingroup drawing
+ *
+ * The sprite is a module to help rendering a large image that is split into
+ * individual parts. This improves memory usage as several images are loaded
+ * in a unique one instead of individual parts.
+ *
+ * Example of sprite.
+ *
+ * ```
+ * +---+---+---+
+ * | 0 | 1 | 2 |
+ * +---+---+---+
+ * | 3 | 4 | 5 |
+ * +---+---+---+
+ * ```
+ *
+ * If an image is designed like this grid, it contains three columns and 2 rows.
+ *
+ * \note The image may not contain space, margins or padding within each cell.
  */
 
+#include <stdbool.h>
+
 struct texture;
 
 /**
@@ -64,15 +84,25 @@
             unsigned int cellh);
 
 /**
+ * Tells if the sprite has a texture and isn't null sized.
+ *
+ * \param sprite the sprite to check (may be NULL)
+ * \return True if it is initialized correctly
+ */
+bool
+sprite_ok(const struct sprite *sprite);
+
+/**
  * Draw the sprite component from row `r' and column `c'.
  *
+ * \pre r < sprite->nrows
+ * \pre c < sprite->ncols
  * \pre sprite != NULL
  * \param sprite the sprite to draw
  * \param r the row number
  * \param c the column number
  * \param x the X destination
  * \param y the Y destination
- * \warning No bounds checking
  */
 void
 sprite_draw(struct sprite *sprite, unsigned int r, unsigned int c, int x, int y);