1 #include "term/screen-processor.h"
2 #include "io/input-key-acceptor.h"
3 #include "term/term-color-types.h"
4 #include "view/display-messages.h"
5 #include "world/world.h"
8 * Hack -- prevent "accidents" in "screen_save()" or "screen_load()"
10 static int screen_depth = 0;
15 void move_cursor(int row, int col)
17 term_gotoxy(col, row);
21 * Flush all input chars. Actually, remember the flush,
22 * and do a "special flush" before the next "inkey()".
24 * This is not only more efficient, but also necessary to make sure
25 * that various "inkey()" codes are not "lost" along the way.
33 * Save the screen, and increase the "icky" depth.
35 * This function must match exactly one call to "screen_load()".
43 w_ptr->character_icky_depth++;
48 * Load the screen, and decrease the "icky" depth.
50 * This function must match exactly one call to "screen_save()".
52 void screen_load(ScreenLoadOptType opt)
57 case ScreenLoadOptType::ONE:
59 w_ptr->character_icky_depth--;
63 case ScreenLoadOptType::ALL:
65 w_ptr->character_icky_depth -= static_cast<byte>(screen_depth);
75 * Display a string on the screen using an attribute.
77 * At the given location, using the given attribute, if allowed,
78 * add the given string. Do not clear the line.
80 void c_put_str(TERM_COLOR attr, std::string_view sv, TERM_LEN row, TERM_LEN col)
82 term_putstr(col, row, -1, attr, sv);
86 * As above, but in "white"
88 void put_str(std::string_view sv, TERM_LEN row, TERM_LEN col)
90 term_putstr(col, row, -1, TERM_WHITE, sv);
94 * Display a string on the screen using an attribute, and clear
95 * to the end of the line.
97 void c_prt(TERM_COLOR attr, std::string_view sv, TERM_LEN row, TERM_LEN col)
99 term_erase(col, row, 255);
100 term_addstr(-1, attr, sv);
104 * As above, but in "white"
106 void prt(std::string_view sv, TERM_LEN row, TERM_LEN col)
109 c_prt(TERM_WHITE, sv, row, col);
113 * Print some (colored) text to the screen at the current cursor position,
114 * automatically "wrapping" existing text (at spaces) when necessary to
115 * avoid placing any text into the last column, and clearing every line
116 * before placing any text in that line. Also, allow "newline" to force
117 * a "wrap" to the next line. Advance the cursor as needed so sequential
118 * calls to this function will work correctly.
120 * Once this function has been called, the cursor should not be moved
121 * until all the related "c_roff()" calls to the window are complete.
123 * This function will correctly handle any width up to the maximum legal
124 * value of 256, though it works best for a standard 80 character width.
126 void c_roff(TERM_COLOR a, std::string_view str)
129 (void)term_get_size(&w, &h);
132 (void)term_locate(&x, &y);
134 if (y == h - 1 && x > w - 3) {
138 for (auto s = str.data(); *s != '\0'; ++s) {
141 int k_flag = iskanji(*s);
150 term_erase(x, y, 255);
155 ch = ((k_flag || isprint(*s)) ? *s : ' ');
157 ch = (isprint(*s) ? *s : ' ');
161 if ((x >= ((k_flag) ? w - 2 : w - 1)) && (ch != ' '))
163 if ((x >= w - 1) && (ch != ' '))
167 const int end_col = x - 1;
177 for (i = 0; i <= end_col; i++) {
178 term_what(i, y, &av[i], &cv[i]);
184 if (iskanji(cv[i])) {
187 term_what(i, y, &av[i], &cv[i]);
195 /* 文頭が「。」「、」等になるときは、その1つ前の語で改行 */
196 if (strncmp(s, "。", 2) == 0 || strncmp(s, "、", 2) == 0) {
197 term_what(x - 1, y, &av[x - 1], &cv[x - 1]);
198 term_what(x - 2, y, &av[x - 2], &cv[x - 2]);
208 term_erase(n, y, 255);
215 term_erase(x, y, 255);
216 for (i = n; i <= end_col; i++) {
222 term_addch(av[i], cv[i]);
230 term_addch((byte)(a | 0x10), ch);
240 term_addch((byte)(a | 0x20), ch);
251 * As above, but in "white"
253 void roff(std::string_view str)
256 c_roff(TERM_WHITE, str);
260 * Clear part of the screen
262 void clear_from(int row)
264 for (int y = row; y < game_term->hgt; y++) {
265 term_erase(0, y, 255);