Mercurial > molko
annotate libmlk-rpg/mlk/rpg/message.c @ 622:ec334c61bb81
rpg: simplify message
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 22 Aug 2023 22:25:34 +0200 |
parents | ed1d3244ed57 |
children | 3cb1860d9f11 |
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.c -- message dialog |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 * |
445
773a082f0b91
misc: update copyright years
David Demelier <markand@malikania.fr>
parents:
441
diff
changeset
|
4 * Copyright (c) 2020-2023 David Demelier <markand@malikania.fr> |
24
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 #include <assert.h> |
67
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
65
diff
changeset
|
20 #include <stdlib.h> |
7187c0d9b9c0
core: implement message action, closes #2467
David Demelier <markand@malikania.fr>
parents:
65
diff
changeset
|
21 #include <string.h> |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
22 |
585 | 23 #include <mlk/core/err.h> |
431
8f59201dc76b
core: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
411
diff
changeset
|
24 #include <mlk/core/event.h> |
8f59201dc76b
core: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
411
diff
changeset
|
25 #include <mlk/core/font.h> |
8f59201dc76b
core: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
411
diff
changeset
|
26 #include <mlk/core/maths.h> |
8f59201dc76b
core: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
411
diff
changeset
|
27 #include <mlk/core/painter.h> |
8f59201dc76b
core: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
411
diff
changeset
|
28 #include <mlk/core/panic.h> |
8f59201dc76b
core: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
411
diff
changeset
|
29 #include <mlk/core/sprite.h> |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
30 #include <mlk/core/texture.h> |
431
8f59201dc76b
core: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
411
diff
changeset
|
31 #include <mlk/core/trace.h> |
8f59201dc76b
core: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
411
diff
changeset
|
32 #include <mlk/core/util.h> |
148
c577c15df07f
misc: split libraries, closes #2496
David Demelier <markand@malikania.fr>
parents:
146
diff
changeset
|
33 |
433
862b15c3a3ae
ui: cleanup hierarchy
David Demelier <markand@malikania.fr>
parents:
431
diff
changeset
|
34 #include <mlk/ui/align.h> |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
35 #include <mlk/ui/ui.h> |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
36 #include <mlk/ui/ui_p.h> |
148
c577c15df07f
misc: split libraries, closes #2496
David Demelier <markand@malikania.fr>
parents:
146
diff
changeset
|
37 |
28
783841af4033
core: implement painter API, closes #2451 @1h
David Demelier <markand@malikania.fr>
parents:
24
diff
changeset
|
38 #include "message.h" |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
39 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
40 static inline struct mlk_message_style * |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
41 get_style(struct mlk_message *msg) |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
42 { |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
43 return msg->style ? msg->style : mlk_message_style; |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
44 } |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
45 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
46 static inline struct mlk_font * |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
47 get_font(struct mlk_message *msg) |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
48 { |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
49 return MLK__STYLE_FONT(get_style(msg)->font, MLK_UI_FONT_INTERFACE); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
50 } |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
51 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
52 static unsigned int |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
53 min_width(struct mlk_message_style *style, struct mlk_message *msg) |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
54 { |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
55 struct mlk_font *font; |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
56 unsigned int maxw = 0, w = 0; |
486 | 57 int err; |
158
e8d2740703df
ui: make message auto-spacing lines
David Demelier <markand@malikania.fr>
parents:
157
diff
changeset
|
58 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
59 font = MLK__STYLE_FONT(style->font, MLK_UI_FONT_INTERFACE); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
60 |
391
9334b420c975
rpg: don't use fixed size messages
David Demelier <markand@malikania.fr>
parents:
378
diff
changeset
|
61 for (size_t i = 0; i < msg->linesz; ++i) { |
9334b420c975
rpg: don't use fixed size messages
David Demelier <markand@malikania.fr>
parents:
378
diff
changeset
|
62 if (!msg->lines[i]) |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
63 continue; |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
64 if ((err = mlk_font_query(font, msg->lines[i], &w, NULL)) < 0) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
65 return err; |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
66 if (w > maxw) |
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
67 maxw = w; |
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
68 } |
158
e8d2740703df
ui: make message auto-spacing lines
David Demelier <markand@malikania.fr>
parents:
157
diff
changeset
|
69 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
70 return (style->padding * 2) + maxw; |
158
e8d2740703df
ui: make message auto-spacing lines
David Demelier <markand@malikania.fr>
parents:
157
diff
changeset
|
71 } |
e8d2740703df
ui: make message auto-spacing lines
David Demelier <markand@malikania.fr>
parents:
157
diff
changeset
|
72 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
73 static unsigned int |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
74 min_height(struct mlk_message_style *style, struct mlk_message *msg) |
158
e8d2740703df
ui: make message auto-spacing lines
David Demelier <markand@malikania.fr>
parents:
157
diff
changeset
|
75 { |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
76 assert(msg); |
158
e8d2740703df
ui: make message auto-spacing lines
David Demelier <markand@malikania.fr>
parents:
157
diff
changeset
|
77 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
78 struct mlk_font *font; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
79 unsigned int lh; |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
80 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
81 font = MLK__STYLE_FONT(style->font, MLK_UI_FONT_INTERFACE); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
82 lh = mlk_font_height(font); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
83 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
84 return (style->padding * 2) + (msg->linesz * lh) + ((msg->linesz - 1) * style->padding); |
158
e8d2740703df
ui: make message auto-spacing lines
David Demelier <markand@malikania.fr>
parents:
157
diff
changeset
|
85 } |
e8d2740703df
ui: make message auto-spacing lines
David Demelier <markand@malikania.fr>
parents:
157
diff
changeset
|
86 |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
87 static void |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
88 draw_frame(struct mlk_message *msg) |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
89 { |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
90 struct mlk_message_style *style = get_style(msg); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
91 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
92 mlk_painter_set_color(style->border); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
93 mlk_painter_draw_rectangle(0, 0, msg->w, msg->h); |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
94 mlk_painter_set_color(style->background); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
95 mlk_painter_draw_rectangle( |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
96 style->border_size, |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
97 style->border_size, |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
98 msg->w - (style->border_size * 2), |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
99 msg->h - (style->border_size * 2) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
100 ); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
101 } |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
102 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
103 static void |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
104 draw_lines(struct mlk_message *msg) |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
105 { |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
106 struct mlk_message_style *style; |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
107 struct mlk_font *font; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
108 struct mlk_texture texture; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
109 unsigned long color; |
547
c7664b679a95
misc: remove error codes for now
David Demelier <markand@malikania.fr>
parents:
535
diff
changeset
|
110 int x, y; |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
111 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
112 style = get_style(msg); |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
113 font = get_font(msg); |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
114 |
391
9334b420c975
rpg: don't use fixed size messages
David Demelier <markand@malikania.fr>
parents:
378
diff
changeset
|
115 for (size_t i = 0; i < msg->linesz; ++i) { |
9334b420c975
rpg: don't use fixed size messages
David Demelier <markand@malikania.fr>
parents:
378
diff
changeset
|
116 if (!msg->lines[i]) |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
117 continue; |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
118 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
119 if ((msg->flags & MLK_MESSAGE_FLAGS_QUESTION) && msg->index == i) |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
120 color = style->color_selected; |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
121 else |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
122 color = style->color; |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
123 |
547
c7664b679a95
misc: remove error codes for now
David Demelier <markand@malikania.fr>
parents:
535
diff
changeset
|
124 if (mlk_font_render(font, &texture, msg->lines[i], color) < 0) { |
c7664b679a95
misc: remove error codes for now
David Demelier <markand@malikania.fr>
parents:
535
diff
changeset
|
125 mlk_tracef("unable to render message text", mlk_err()); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
126 continue; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
127 } |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
128 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
129 x = style->padding; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
130 y = style->padding + (i * (texture.h + style->padding)); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
131 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
132 if (x + texture.w > msg->w) |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
133 mlk_tracef("message width too small: %u < %u", msg->w, min_width(style, msg)); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
134 if (y + texture.h > msg->h) |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
135 mlk_tracef("message height too small: %u < %u", msg->h, min_height(style, msg)); |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
136 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
137 mlk_texture_draw(&texture, x, y); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
138 mlk_texture_finish(&texture); |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
139 } |
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
140 } |
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
141 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
142 static int |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
143 query(struct mlk_message_style *self, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
144 struct mlk_message *msg, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
145 unsigned int *w, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
146 unsigned int *h) |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
147 { |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
148 if (w) |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
149 *w = min_width(self, msg); |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
150 if (h) |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
151 *h = min_height(self, msg); |
535 | 152 |
153 return 0; | |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
154 } |
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
155 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
156 static void |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
157 update(struct mlk_message_style *self, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
158 struct mlk_message *msg, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
159 unsigned int ticks) |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
160 { |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
161 (void)self; |
64
da9b7462ab92
core: implement question, closes #2464 @2h
David Demelier <markand@malikania.fr>
parents:
62
diff
changeset
|
162 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
163 const struct mlk_message_style *style = MLK__STYLE(msg, mlk_message_style); |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
164 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
165 msg->elapsed += ticks; |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
166 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
167 switch (msg->state) { |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
168 case MLK_MESSAGE_STATE_OPENING: |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
169 msg->scale = (double)msg->elapsed / (double)style->speed; |
100
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
170 |
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
171 if (msg->scale > 1) |
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
172 msg->scale = 1; |
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
173 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
174 if (msg->elapsed >= style->speed) { |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
175 msg->state = MLK_MESSAGE_STATE_SHOWING; |
62 | 176 msg->elapsed = 0; |
177 } | |
178 | |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
179 break; |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
180 case MLK_MESSAGE_STATE_SHOWING: |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
181 /* Do automatically switch state if requested by the user. */ |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
182 if (msg->flags & MLK_MESSAGE_FLAGS_AUTOMATIC && msg->elapsed >= style->timeout) { |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
183 msg->state = msg->flags & MLK_MESSAGE_FLAGS_FADEOUT |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
184 ? MLK_MESSAGE_STATE_HIDING |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
185 : MLK_MESSAGE_STATE_NONE; |
62 | 186 msg->elapsed = 0; |
187 } | |
188 | |
189 break; | |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
190 case MLK_MESSAGE_STATE_HIDING: |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
191 msg->scale = 1 - (double)msg->elapsed / (double)style->speed; |
100
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
192 |
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
193 if (msg->scale < 0) |
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
194 msg->scale = 0; |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
195 if (msg->elapsed >= style->speed) { |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
196 msg->state = MLK_MESSAGE_STATE_NONE; |
62 | 197 msg->elapsed = 0; |
198 } | |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
199 |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
200 break; |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
201 default: |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
202 break; |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
203 } |
60
7266c750b649
core: simplify message
David Demelier <markand@malikania.fr>
parents:
59
diff
changeset
|
204 |
99
4ac71ac10c9f
core: start adding some UI elements
David Demelier <markand@malikania.fr>
parents:
97
diff
changeset
|
205 } |
4ac71ac10c9f
core: start adding some UI elements
David Demelier <markand@malikania.fr>
parents:
97
diff
changeset
|
206 |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
207 static void |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
208 draw(struct mlk_message_style *self, struct mlk_message *msg) |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
209 { |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
210 (void)self; |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
211 |
472
bc5483849614
core: texture -> mlk_texture
David Demelier <markand@malikania.fr>
parents:
465
diff
changeset
|
212 struct mlk_texture tex; |
486 | 213 int x, y, err; |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
214 unsigned int w, h; |
100
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
215 |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
216 if (msg->w == 0 || msg->h == 0) { |
473
02b16dd49b54
core: trace -> mlk_trace
David Demelier <markand@malikania.fr>
parents:
472
diff
changeset
|
217 mlk_tracef("message has null dimensions"); |
159
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
218 return; |
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
219 } |
e05a792f6910
ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents:
158
diff
changeset
|
220 |
486 | 221 if ((err = mlk_texture_new(&tex, msg->w, msg->h)) < 0) |
547
c7664b679a95
misc: remove error codes for now
David Demelier <markand@malikania.fr>
parents:
535
diff
changeset
|
222 mlk_panic(); |
100
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
223 |
457
04797b35565c
core: painter -> mlk_painter
David Demelier <markand@malikania.fr>
parents:
451
diff
changeset
|
224 MLK_PAINTER_BEGIN(&tex); |
100
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
225 draw_frame(msg); |
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
226 draw_lines(msg); |
457
04797b35565c
core: painter -> mlk_painter
David Demelier <markand@malikania.fr>
parents:
451
diff
changeset
|
227 MLK_PAINTER_END(); |
100
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
228 |
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
229 /* Compute scaling. */ |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
230 w = msg->w * msg->scale; |
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
231 h = msg->h * msg->scale; |
100
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
232 |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
233 /* Centerize within its drawing area. */ |
487
f2d3c5a97884
ui: align -> mlk_align
David Demelier <markand@malikania.fr>
parents:
486
diff
changeset
|
234 mlk_align(MLK_ALIGN_CENTER, &x, &y, w, h, msg->x, msg->y, msg->w, msg->h); |
100
ef9135c34505
message: improve rendering and add example
David Demelier <markand@malikania.fr>
parents:
99
diff
changeset
|
235 |
140
453651d76f7c
core: upgrade message in terms of customization
David Demelier <markand@malikania.fr>
parents:
136
diff
changeset
|
236 /* Draw and clear. */ |
472
bc5483849614
core: texture -> mlk_texture
David Demelier <markand@malikania.fr>
parents:
465
diff
changeset
|
237 mlk_texture_scale(&tex, 0, 0, msg->w, msg->h, x, y, w, h, 0); |
bc5483849614
core: texture -> mlk_texture
David Demelier <markand@malikania.fr>
parents:
465
diff
changeset
|
238 mlk_texture_finish(&tex); |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
239 } |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
240 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
241 // TODO: add dark variant. |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
242 struct mlk_message_style mlk_message_style_dark = { |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
243 .background = MLK_UI_COLOR_BG, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
244 .border = MLK_UI_COLOR_BORDER, |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
245 .border_size = MLK_UI_BORDER, |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
246 .color = MLK_UI_COLOR_TEXT, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
247 .color_selected = MLK_UI_COLOR_SELECTED, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
248 .padding = MLK_UI_PADDING, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
249 .timeout = MLK_MESSAGE_TIMEOUT_DEFAULT, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
250 .speed = MLK_MESSAGE_SPEED_DEFAULT, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
251 .query = query, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
252 .update = update, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
253 .draw = draw |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
254 }; |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
255 |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
256 struct mlk_message_style mlk_message_style_light = { |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
257 .background = MLK_UI_COLOR_BG, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
258 .border = MLK_UI_COLOR_BORDER, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
259 .border_size = MLK_UI_BORDER, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
260 .color = MLK_UI_COLOR_TEXT, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
261 .color_selected = MLK_UI_COLOR_SELECTED, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
262 .padding = MLK_UI_PADDING, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
263 .timeout = MLK_MESSAGE_TIMEOUT_DEFAULT, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
264 .speed = MLK_MESSAGE_SPEED_DEFAULT, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
265 .query = query, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
266 .update = update, |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
267 .draw = draw |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
268 }; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
269 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
270 struct mlk_message_style *mlk_message_style = &mlk_message_style_light; |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
271 |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
272 void |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
273 mlk_message_start(struct mlk_message *msg) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
274 { |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
275 assert(msg); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
276 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
277 struct mlk_message_style *style = MLK__STYLE(msg, mlk_message_style); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
278 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
279 if ((msg->flags & (MLK_MESSAGE_FLAGS_FADEIN | MLK_MESSAGE_FLAGS_FADEOUT)) && style->speed == 0) |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
280 mlk_tracef("message has animation but zero delay"); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
281 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
282 msg->elapsed = 0; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
283 msg->scale = msg->flags & MLK_MESSAGE_FLAGS_FADEIN ? 0.0 : 1.0; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
284 msg->state = msg->flags & MLK_MESSAGE_FLAGS_FADEIN |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
285 ? MLK_MESSAGE_STATE_OPENING |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
286 : MLK_MESSAGE_STATE_SHOWING; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
287 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
288 if (msg->flags & MLK_MESSAGE_FLAGS_AUTOMATIC && style->timeout == 0) |
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
289 mlk_tracef("message is automatic but has zero timeout"); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
290 } |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
291 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
292 int |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
293 mlk_message_query(struct mlk_message *msg, unsigned int *w, unsigned int *h) |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
294 { |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
295 assert(msg); |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
296 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
297 return MLK__STYLE_CALL(msg->style, mlk_message_style, query, msg, w, h); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
298 } |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
299 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
300 void |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
301 mlk_message_handle(struct mlk_message *msg, const union mlk_event *ev) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
302 { |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
303 assert(msg); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
304 assert(ev); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
305 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
306 /* Skip if the message animation hasn't complete. */ |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
307 if (msg->state != MLK_MESSAGE_STATE_SHOWING) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
308 return; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
309 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
310 /* Only keyboard event are valid. */ |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
311 if (ev->type != MLK_EVENT_KEYDOWN || msg->state == MLK_MESSAGE_STATE_NONE) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
312 return; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
313 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
314 switch (ev->key.key) { |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
315 case MLK_KEY_UP: |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
316 if (msg->index > 0) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
317 msg->index--; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
318 break; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
319 case MLK_KEY_DOWN: |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
320 if (msg->index + 1 < msg->linesz && msg->lines[msg->index + 1]) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
321 msg->index++; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
322 break; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
323 case MLK_KEY_ENTER: |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
324 msg->state = msg->flags & MLK_MESSAGE_FLAGS_FADEOUT |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
325 ? MLK_MESSAGE_STATE_HIDING |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
326 : MLK_MESSAGE_STATE_NONE; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
327 msg->elapsed = 0; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
328 break; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
329 default: |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
330 break; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
331 } |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
332 } |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
333 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
334 int |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
335 mlk_message_update(struct mlk_message *msg, unsigned int ticks) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
336 { |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
337 assert(msg); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
338 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
339 MLK__STYLE_CALL(msg->style, mlk_message_style, update, msg, ticks); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
340 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
341 return msg->state == MLK_MESSAGE_STATE_NONE; |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
342 } |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
343 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
344 void |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
345 mlk_message_draw(struct mlk_message *msg) |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
346 { |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
347 assert(msg); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
348 |
622
ec334c61bb81
rpg: simplify message
David Demelier <markand@malikania.fr>
parents:
603
diff
changeset
|
349 MLK__STYLE_CALL(msg->style, mlk_message_style, draw, msg); |
534
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
350 } |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
351 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
352 void |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
353 mlk_message_hide(struct mlk_message *msg) |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
354 { |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
355 assert(msg); |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
356 |
88e9bd420a28
rpg: add delegate/style support to mlk_message
David Demelier <markand@malikania.fr>
parents:
505
diff
changeset
|
357 msg->state = MLK_MESSAGE_STATE_HIDING; |
24
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
358 msg->elapsed = 0; |
4a06503641eb
core: start basic implementation of dialog, continue #2449 @2h
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
359 } |