Mercurial > molko
comparison src/libmlk-rpg/rpg/message.c @ 391:9334b420c975
rpg: don't use fixed size messages
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 15 Feb 2022 20:35:23 +0100 |
parents | 460c78706989 |
children | 73eabfd50410 |
comparison
equal
deleted
inserted
replaced
390:ae2dcf40c1eb | 391:9334b420c975 |
---|---|
84 { | 84 { |
85 assert(msg); | 85 assert(msg); |
86 | 86 |
87 unsigned int maxw = 0, w = 0; | 87 unsigned int maxw = 0, w = 0; |
88 | 88 |
89 for (size_t i = 0; i < MESSAGE_LINES_MAX; ++i) { | 89 for (size_t i = 0; i < msg->linesz; ++i) { |
90 if (!msg->text[i]) | 90 if (!msg->lines[i]) |
91 continue; | 91 continue; |
92 if (font_query(THEME(msg)->fonts[THEME_FONT_INTERFACE], msg->text[i], &w, NULL) < 0) | 92 if (font_query(THEME(msg)->fonts[THEME_FONT_INTERFACE], msg->lines[i], &w, NULL) < 0) |
93 panic(); | 93 panic(); |
94 if (w > maxw) | 94 if (w > maxw) |
95 maxw = w; | 95 maxw = w; |
96 } | 96 } |
97 | 97 |
104 assert(msg); | 104 assert(msg); |
105 | 105 |
106 const struct theme *th = THEME(msg); | 106 const struct theme *th = THEME(msg); |
107 const unsigned int lh = font_height(th->fonts[THEME_FONT_INTERFACE]); | 107 const unsigned int lh = font_height(th->fonts[THEME_FONT_INTERFACE]); |
108 | 108 |
109 return (th->padding * 2) + (MESSAGE_LINES_MAX * lh) + ((MESSAGE_LINES_MAX - 1) * msg->spacing); | 109 return (th->padding * 2) + (msg->linesz * lh) + ((msg->linesz - 1) * msg->spacing); |
110 } | 110 } |
111 | 111 |
112 static void | 112 static void |
113 draw_lines(const struct message *msg) | 113 draw_lines(const struct message *msg) |
114 { | 114 { |
120 * We need a copy of the current theme because we will alter the label | 120 * We need a copy of the current theme because we will alter the label |
121 * color depending on the selection. | 121 * color depending on the selection. |
122 */ | 122 */ |
123 theme_shallow(&theme, THEME(msg)); | 123 theme_shallow(&theme, THEME(msg)); |
124 | 124 |
125 for (int i = 0; i < MESSAGE_LINES_MAX; ++i) { | 125 for (size_t i = 0; i < msg->linesz; ++i) { |
126 if (!msg->text[i]) | 126 if (!msg->lines[i]) |
127 continue; | 127 continue; |
128 if (font_query(theme.fonts[THEME_FONT_INTERFACE], msg->text[i], &lw, &lh) < 0) | 128 if (font_query(theme.fonts[THEME_FONT_INTERFACE], msg->lines[i], &lw, &lh) < 0) |
129 panic(); | 129 panic(); |
130 | 130 |
131 label.theme = &theme; | 131 label.theme = &theme; |
132 label.x = theme.padding; | 132 label.x = theme.padding; |
133 label.y = theme.padding + (i * (lh + msg->spacing)); | 133 label.y = theme.padding + (i * (lh + msg->spacing)); |
134 label.text = msg->text[i]; | 134 label.text = msg->lines[i]; |
135 label.flags = LABEL_FLAGS_SHADOW; | 135 label.flags = LABEL_FLAGS_SHADOW; |
136 | 136 |
137 if (label.x + lw > msg->w) | 137 if (label.x + lw > msg->w) |
138 tracef(_("message width too small: %u < %u"), msg->w, min_width(msg)); | 138 tracef(_("message width too small: %u < %u"), msg->w, min_width(msg)); |
139 if (label.y + lh > msg->h) | 139 if (label.y + lh > msg->h) |
200 case KEY_UP: | 200 case KEY_UP: |
201 if (msg->index > 0) | 201 if (msg->index > 0) |
202 msg->index--; | 202 msg->index--; |
203 break; | 203 break; |
204 case KEY_DOWN: | 204 case KEY_DOWN: |
205 if (msg->index < 5 && msg->text[msg->index + 1]) | 205 if (msg->index + 1 < msg->linesz && msg->lines[msg->index + 1]) |
206 msg->index++; | 206 msg->index++; |
207 break; | 207 break; |
208 case KEY_ENTER: | 208 case KEY_ENTER: |
209 msg->state = msg->flags & MESSAGE_FLAGS_FADEOUT | 209 msg->state = msg->flags & MESSAGE_FLAGS_FADEOUT |
210 ? MESSAGE_STATE_HIDING | 210 ? MESSAGE_STATE_HIDING |