1 #include "term/screen-processor.h"
2 #include "io/input-key-acceptor.h"
3 #include "locale/japanese.h"
4 #include "term/term-color-types.h"
5 #include "view/display-messages.h"
6 #include "world/world.h"
9 * Hack -- prevent "accidents" in "screen_save()" or "screen_load()"
11 static int screen_depth = 0;
16 void move_cursor(int row, int col)
18 term_gotoxy(col, row);
22 * Flush all input chars. Actually, remember the flush,
23 * and do a "special flush" before the next "inkey()".
25 * This is not only more efficient, but also necessary to make sure
26 * that various "inkey()" codes are not "lost" along the way.
34 * Save the screen, and increase the "icky" depth.
36 * This function must match exactly one call to "screen_load()".
44 w_ptr->character_icky_depth++;
49 * Load the screen, and decrease the "icky" depth.
51 * This function must match exactly one call to "screen_save()".
53 void screen_load(ScreenLoadOptType opt)
58 case ScreenLoadOptType::ONE:
60 w_ptr->character_icky_depth--;
64 case ScreenLoadOptType::ALL:
66 w_ptr->character_icky_depth -= static_cast<byte>(screen_depth);
76 * Display a string on the screen using an attribute.
78 * At the given location, using the given attribute, if allowed,
79 * add the given string. Do not clear the line.
81 void c_put_str(TERM_COLOR attr, std::string_view sv, TERM_LEN row, TERM_LEN col)
83 term_putstr(col, row, -1, attr, sv);
87 * As above, but in "white"
89 void put_str(std::string_view sv, TERM_LEN row, TERM_LEN col)
91 term_putstr(col, row, -1, TERM_WHITE, sv);
95 * Display a string on the screen using an attribute, and clear
96 * to the end of the line.
98 void c_prt(TERM_COLOR attr, std::string_view sv, TERM_LEN row, TERM_LEN col)
100 term_erase(col, row, 255);
101 term_addstr(-1, attr, sv);
105 * As above, but in "white"
107 void prt(std::string_view sv, TERM_LEN row, TERM_LEN col)
110 c_prt(TERM_WHITE, sv, row, col);
113 static std::vector<std::pair<TERM_COLOR, char>> c_roff_wrap(int x, int y, int w, const char *s)
119 std::vector<std::pair<TERM_COLOR, char>> wrap_chars;
122 if (_(iskanji(*s), false)) {
124 /* 行頭が行頭禁則文字になるときは、その1つ前の語で改行 */
125 if (is_kinsoku({ s, 2 })) {
128 term_what(x - 2, y, &a, &c);
129 wrap_chars.emplace_back(a, c);
130 term_what(x - 1, y, &a, &c);
131 wrap_chars.emplace_back(a, c);
136 for (auto i = 0; i < x; i++) {
139 term_what(i, y, &a, &c);
144 } else if (_(iskanji(c), false)) {
149 wrap_chars.emplace_back(a, c);
154 term_erase(wrap_col, y, 255);
159 * Print some (colored) text to the screen at the current cursor position,
160 * automatically "wrapping" existing text (at spaces) when necessary to
161 * avoid placing any text into the last column, and clearing every line
162 * before placing any text in that line. Also, allow "newline" to force
163 * a "wrap" to the next line. Advance the cursor as needed so sequential
164 * calls to this function will work correctly.
166 * Once this function has been called, the cursor should not be moved
167 * until all the related "c_roff()" calls to the window are complete.
169 * This function will correctly handle any width up to the maximum legal
170 * value of 256, though it works best for a standard 80 character width.
172 void c_roff(TERM_COLOR a, std::string_view str)
175 (void)term_get_size(&w, &h);
178 (void)term_locate(&x, &y);
180 if (y == h - 1 && x > w - 3) {
184 for (auto s = str.begin(); s != str.end(); ++s) {
185 const auto is_kanji = _(iskanji(*s), false);
189 term_erase(0, y + 1, 255);
195 const auto ch = (is_kanji || isprint(*s)) ? *s : ' ';
197 if ((x >= ((is_kanji) ? w - 2 : w - 1)) && (ch != ' ')) {
198 const auto wrap_chars = c_roff_wrap(x, y, w, &*s);
205 term_erase(0, y, 255);
206 for (const auto &[ca, cv] : wrap_chars) {
209 x = wrap_chars.size();
212 term_addch(_((a | 0x10), a), ch);
216 term_addch((a | 0x20), *s);
226 * As above, but in "white"
228 void roff(std::string_view str)
231 c_roff(TERM_WHITE, str);
235 * Clear part of the screen
237 void clear_from(int row)
239 for (int y = row; y < game_term->hgt; y++) {
240 TermOffsetSetter tos(0, std::nullopt);
241 term_erase(0, y, 255);