comparison libcore/core/sprite.h @ 121:789b23e01f52

misc: reorganize hierarchy, closes #2490
author David Demelier <markand@malikania.fr>
date Mon, 05 Oct 2020 13:25:06 +0200
parents src/core/sprite.h@ed72843a7194
children 365e40e92800
comparison
equal deleted inserted replaced
120:b3429b26d60d 121:789b23e01f52
1 /*
2 * sprite.h -- image sprites
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MOLKO_SPRITE_H
20 #define MOLKO_SPRITE_H
21
22 /**
23 * \file sprite.h
24 * \brief Image sprites.
25 * \ingroup drawing
26 */
27
28 struct texture;
29
30 /**
31 * \brief Sprite structure.
32 */
33 struct sprite {
34 struct texture *texture; /*!< Texture to access (RO) */
35 unsigned int cellw; /*!< Width per cell (RW) */
36 unsigned int cellh; /*!< Height per cell (RW) */
37 unsigned int nrows; /*!< Number of rows (RW) */
38 unsigned int ncols; /*!< Number of columns (RW) */
39 };
40
41 /**
42 * Initialize a sprite.
43 *
44 * The sprite does not take ownership of texture and must be valid until the
45 * sprite is no longer used.
46 *
47 * This function is only provided as convenience, user may initialize the
48 * sprite by itself if wanted.
49 *
50 * The fields `nrows' and `ncols' will be determined automatically from the
51 * texture size.
52 *
53 * \pre sprite != NULL
54 * \pre tex != NULL && texture_ok(tex)
55 * \param sprite the sprite to initialize
56 * \param tex the texture
57 * \param cellw the width per cell in pixels
58 * \param cellh the height per cell in pixels
59 */
60 void
61 sprite_init(struct sprite *sprite,
62 struct texture *tex,
63 unsigned int cellw,
64 unsigned int cellh);
65
66 /**
67 * Draw the sprite component from row `r' and column `c'.
68 *
69 * \pre sprite != NULL
70 * \param sprite the sprite to draw
71 * \param r the row number
72 * \param c the column number
73 * \param x the X destination
74 * \param y the Y destination
75 * \warning No bounds checking
76 */
77 void
78 sprite_draw(struct sprite *sprite, unsigned int r, unsigned int c, int x, int y);
79
80 #endif /* !MOLKO_SPRITE_H */