Mercurial > molko
annotate src/core/message.h @ 67:7187c0d9b9c0
core: implement message action, closes #2467
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 27 Jan 2020 13:04:19 +0100 |
parents | da9b7462ab92 |
children | 53b217afe122 |
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 |
67
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
29 struct action; |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
30 struct font; |
62 | 31 struct texture; |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
32 |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
33 union event; |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
34 |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
36 * \brief Message flags. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
37 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
38 enum message_flags { |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
39 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
|
40 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
|
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 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
44 * \brief Message state. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
45 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
46 enum message_state { |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
47 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
|
48 MESSAGE_OPENING, /*!< Message animation is opening */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
49 MESSAGE_SHOWING, /*!< Message is displaying */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
50 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
|
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 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
54 * \brief Message object. |
62 | 55 * |
56 * This structure is used to display a message into the screen. It does not own | |
57 * 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
|
58 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
59 struct message { |
62 | 60 const char *text[6]; /*!< (RW) Lines of text to show */ |
61 struct texture *frame; /*!< (RW) Frame to use */ | |
62 struct texture *avatar; /*!< (RW) Optional avatar */ | |
63 struct font *font; /*!< (RW) Font to use */ | |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
64 unsigned long colors[2]; /*!< (RW) Normal/selected colors */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
65 unsigned int index; /*!< (RW) Line selected */ |
62 | 66 enum message_flags flags; /*!< (RW) Message flags */ |
67 enum message_state state; /*!< (RO) Current state */ | |
68 | |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
69 /*! \cond PRIVATE */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
70 |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
71 struct texture *textures[12]; |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
72 unsigned int elapsed; |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
73 int height[2]; |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
74 |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
75 /*! \endcond */ |
24
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 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
79 * 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
|
80 * elapsed time. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
81 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
82 * \pre msg != NULL |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 * \param msg the message |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
84 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
85 void |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
86 message_start(struct message *msg); |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
87 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
88 /** |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
89 * Handle input events. |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
90 * |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
91 * 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
|
92 * case of question. |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
93 * |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
94 * \pre msg != NULL |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
95 * \pre ev != NULL |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
96 * \param msg the message |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
97 * \param ev the event which occured |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
98 */ |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
99 void |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
100 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
|
101 |
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
102 /** |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
103 * 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
|
104 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
105 * \pre msg != NULL |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
106 * \param msg the message |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
107 * \param ticks the elapsed delay since last frame |
60
7266c750b649
core: simplify message
David Demelier <markand@malikania.fr>
parents:
59
diff
changeset
|
108 * \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
|
109 */ |
60
7266c750b649
core: simplify message
David Demelier <markand@malikania.fr>
parents:
59
diff
changeset
|
110 bool |
46
b815621df3e3
core: remove all fixed width integers, closes #2460
David Demelier <markand@malikania.fr>
parents:
24
diff
changeset
|
111 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
|
112 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
113 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
114 * Draw the message into the screen. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
115 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
116 * \pre msg != NULL |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
117 * \param msg the message |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
118 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
119 void |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
120 message_draw(struct message *msg); |
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 /** |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
123 * Start hiding the message. |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
124 * |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
125 * \pre msg != NULL |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
126 * \param msg the message |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
127 * \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
|
128 * finished! |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
129 */ |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
130 void |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
131 message_hide(struct message *msg); |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
132 |
62 | 133 /** |
134 * Destroy owned resources. | |
135 * | |
136 * \pre msg != NULL | |
137 * \param msg the message | |
138 */ | |
139 void | |
140 message_finish(struct message *msg); | |
141 | |
67
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
142 /** |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
143 * Convert message into an action. |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
144 * |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
145 * \pre msg != NULL |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
146 * \pre action != NULL |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
147 * \param msg the message to copy from |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
148 * \param action the action to fill |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
149 */ |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
150 void |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
151 message_action(const struct message *msg, struct action *action); |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
64
diff
changeset
|
152 |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
153 #endif /* !MOLKO_MESSAGE_H */ |