comparison libmlk-core/core/animation.h @ 243:71b3b7036de7

misc: lot of cleanups, - prefix libraries with libmlk, - move assets from source directories closes #2520, - prefix header guards closes #2519
author David Demelier <markand@malikania.fr>
date Sat, 28 Nov 2020 22:37:30 +0100
parents libcore/core/animation.h@604fad63bd9c
children c4da052c0def
comparison
equal deleted inserted replaced
242:4c24604efcab 243:71b3b7036de7
1 /*
2 * animation.h -- basic animations
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_CORE_ANIMATION_H
20 #define MOLKO_CORE_ANIMATION_H
21
22 /**
23 * \file animation.h
24 * \brief Basic animations.
25 * \ingroup drawing
26 */
27
28 #include <stdbool.h>
29
30 struct drawable;
31 struct sprite;
32
33 /**
34 * \brief Animation object
35 */
36 struct animation {
37 struct sprite *sprite; /*!< (+&) Sprite to use. */
38 unsigned int row; /*!< (-) Current row. */
39 unsigned int column; /*!< (-) Current column. */
40 unsigned int delay; /*!< (-) Delay between frames. */
41 unsigned int elapsed; /*!< (-) Elapsed time since last frame. */
42 };
43
44 /**
45 * Initialize the animation.
46 *
47 * The animation does not take sprite ownership, it must be valid until
48 * animation is no longer used.
49 *
50 * \pre an != NULL
51 * \pre sprite != NULL
52 * \param an the animation
53 * \param sprite the sprite to use
54 * \param delay the delay between frames in milliseconds
55 */
56 void
57 animation_init(struct animation *an, struct sprite *sprite, unsigned int delay);
58
59 /**
60 * Start an animation.
61 *
62 * \pre an != NULL
63 * \param an the animation
64 */
65 void
66 animation_start(struct animation *an);
67
68 /**
69 * Tells if the animation has completed.
70 *
71 * \pre an != NULL
72 * \param an the animation
73 * \return True if the animation shown all images.
74 */
75 bool
76 animation_completed(const struct animation *an);
77
78 /**
79 * Update the animation.
80 *
81 * You must call this function at each loop iteration to update the animation
82 * frame depending on its delay.
83 *
84 * \pre an != NULL
85 * \param an the animation
86 * \param ticks the elapsed ticks since the last call
87 * \return True if the animation is complete.
88 */
89 bool
90 animation_update(struct animation *an, unsigned int ticks);
91
92 /**
93 * Draw the animation.
94 *
95 * \pre an != NULL && !animation_completed(an)
96 * \param an the animation
97 * \param x the X coordinate
98 * \param y the Y coordinate
99 * \return False in case of rendering error.
100 */
101 bool
102 animation_draw(const struct animation *an, int x, int y);
103
104 /**
105 * Create a drawable from an animation.
106 *
107 * The animation must be kept alive until the drawable is used.
108 *
109 * The dw->data member will be set to the animation pointer and can be
110 * safely used by the user for custom drawable operation if needed.
111 *
112 * The dw->finish member isn't used and can be re-used by the user.
113 *
114 * \pre an != NULL
115 * \pre dw != NULL
116 * \param an the animation
117 * \param dw the drawable
118 * \param x x position on screen
119 * \param y y position on screen
120 * \post dw->data contains an
121 * \post dw->update contains an update function
122 * \post dw->draw contains a drawing function
123 * \post dw->finish is NULL
124 */
125 void
126 animation_drawable(struct animation *an, struct drawable *dw, int x, int y);
127
128 #endif /* !MOLKO_CORE_ANIMATION_H */