Mercurial > molko
annotate src/core/message.h @ 64:da9b7462ab92
core: implement question, closes #2464 @2h
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 23 Jan 2020 20:44:01 +0100 |
parents | d07acc6ee4d9 |
children | 7187c0d9b9c0 |
rev | line source |
---|---|
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 /* |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
2 * message.h -- message dialog |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 * Permission to use, copy, modify, and/or distribute this software for any |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 * purpose with or without fee is hereby granted, provided that the above |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 * copyright notice and this permission notice appear in all copies. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
19 #ifndef MOLKO_MESSAGE_H |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 #define MOLKO_MESSAGE_H |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
21 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
22 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 * \file message.h |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
24 * \brief Message dialog. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
25 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
26 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
27 #include <stdbool.h> |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
28 |
62 | 29 struct texture; |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
30 struct font; |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
31 |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
32 union event; |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
33 |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
34 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 * \brief Message flags. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
36 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
37 enum message_flags { |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
38 MESSAGE_AUTOMATIC = (1 << 0), /*!< Will automatically change state by itself. */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
39 MESSAGE_QUESTION = (1 << 1) /*!< The message is a question. */ |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
40 }; |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
41 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
42 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
43 * \brief Message state. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
44 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
45 enum message_state { |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
46 MESSAGE_NONE, /*!< Message hasn't start yet or is finished */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
47 MESSAGE_OPENING, /*!< Message animation is opening */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
48 MESSAGE_SHOWING, /*!< Message is displaying */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
49 MESSAGE_HIDING /*!< Message animation for hiding */ |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
50 }; |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
51 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
52 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 * \brief Message object. |
62 | 54 * |
55 * This structure is used to display a message into the screen. It does not own | |
56 * any user properties and therefore must exist while using it. | |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
57 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
58 struct message { |
62 | 59 const char *text[6]; /*!< (RW) Lines of text to show */ |
60 struct texture *frame; /*!< (RW) Frame to use */ | |
61 struct texture *avatar; /*!< (RW) Optional avatar */ | |
62 struct font *font; /*!< (RW) Font to use */ | |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
63 unsigned long colors[2]; /*!< (RW) Normal/selected colors */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
64 unsigned int index; /*!< (RW) Line selected */ |
62 | 65 enum message_flags flags; /*!< (RW) Message flags */ |
66 enum message_state state; /*!< (RO) Current state */ | |
67 | |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
68 /*! \cond PRIVATE */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
69 |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
70 struct texture *textures[12]; |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
71 unsigned int elapsed; |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
72 int height[2]; |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
73 |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
74 /*! \endcond */ |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
75 }; |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
76 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
77 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
78 * Start opening the message. This function will reset the message state and |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
79 * elapsed time. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
80 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
81 * \pre msg != NULL |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
82 * \param msg the message |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
84 void |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
85 message_start(struct message *msg); |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
86 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
87 /** |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
88 * Handle input events. |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
89 * |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
90 * This function will alter state of the message and change its selection in |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
91 * case of question. |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
92 * |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
93 * \pre msg != NULL |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
94 * \pre ev != NULL |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
95 * \param msg the message |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
96 * \param ev the event which occured |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
97 */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
98 void |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
99 message_handle(struct message *msg, const union event *ev); |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
100 |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
101 /** |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
102 * Update the message state and elapsed time.. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
103 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
104 * \pre msg != NULL |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
105 * \param msg the message |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
106 * \param ticks the elapsed delay since last frame |
60
7266c750b649
core: simplify message
David Demelier <markand@malikania.fr>
parents:
59
diff
changeset
|
107 * \return true if it has finished |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
108 */ |
60
7266c750b649
core: simplify message
David Demelier <markand@malikania.fr>
parents:
59
diff
changeset
|
109 bool |
46
b815621df3e3
core: remove all fixed width integers, closes #2460
David Demelier <markand@malikania.fr>
parents:
24
diff
changeset
|
110 message_update(struct message *msg, unsigned int ticks); |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
111 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
112 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
113 * Draw the message into the screen. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
114 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
115 * \pre msg != NULL |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
116 * \param msg the message |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
117 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
118 void |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
119 message_draw(struct message *msg); |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
120 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
121 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
122 * Start hiding the message. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
123 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
124 * \pre msg != NULL |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
125 * \param msg the message |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
126 * \note You should still continue to draw the message as the animation is not |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
127 * finished! |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
128 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
129 void |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
130 message_hide(struct message *msg); |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
131 |
62 | 132 /** |
133 * Destroy owned resources. | |
134 * | |
135 * \pre msg != NULL | |
136 * \param msg the message | |
137 */ | |
138 void | |
139 message_finish(struct message *msg); | |
140 | |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
141 #endif /* !MOLKO_MESSAGE_H */ |