4 * Copyright (c) 1997 Ben Harrison
6 * This software may be copied and distributed for educational, research,
7 * and not for profit purposes provided that this copyright and statement
8 * are included in all such copies.
11 #include "system/angband.h"
12 #include "system/h-basic.h"
16 #include <string_view>
21 * @brief A term_win is a "window" for a Term
25 static std::unique_ptr<term_win> create(TERM_LEN w, TERM_LEN h);
26 std::unique_ptr<term_win> clone() const;
27 void resize(TERM_LEN w, TERM_LEN h);
29 bool cu{}, cv{}; //!< Cursor Useless / Visible codes
30 TERM_LEN cx{}, cy{}; //!< Cursor Location (see "Useless")
32 std::vector<std::vector<TERM_COLOR>> a; //!< Array[h*w] -- Attribute array
33 std::vector<std::vector<char>> c; //!< Array[h*w] -- Character array
35 std::vector<std::vector<TERM_COLOR>> ta; //!< Note that the attr pair at(x, y) is a[y][x]
36 std::vector<std::vector<char>> tc; //!< Note that the char pair at(x, y) is c[y][x]
39 term_win(TERM_LEN w, TERM_LEN h);
43 * @brief term実装構造体 / An actual "term" structure
46 vptr user{}; //!< Extra "user" info (used by application)
47 vptr data{}; //!< Extra "data" info (used by implementation)
49 bool user_flag{}; //!< Flag "user_flag" An extra "user" flag (used by application)
50 bool data_flag{}; //!< Flag "data_flag" An extra "data" flag (used by implementation)
52 bool active_flag{}; //!< Flag "active_flag" This "term" is "active"
53 bool mapped_flag{}; //!< Flag "mapped_flag" This "term" is "mapped"
54 bool total_erase{}; //!< Flag "total_erase" This "term" should be fully erased
55 bool fixed_shape{}; //!< Flag "fixed_shape" This "term" is not allowed to resize
56 bool icky_corner{}; //!< Flag "icky_corner" This "term" has an "icky" corner grid
57 bool soft_cursor{}; //!< Flag "soft_cursor" This "term" uses a "software" cursor
58 bool always_pict{}; //!< Flag "always_pict" Use the "Term_pict()" routine for all text
59 bool higher_pict{}; //!< Flag "higher_pict" Use the "Term_pict()" routine for special text
60 bool always_text{}; //!< Flag "always_text" Use the "Term_text()" routine for invisible text
61 bool unused_flag{}; //!< Flag "unused_flag" Reserved for future use
62 bool never_bored{}; //!< Flag "never_bored" Never call the "TERM_XTRA_BORED" action
63 bool never_frosh{}; //!< Flag "never_frosh" Never call the "TERM_XTRA_FROSH" action
64 bool never_fresh{}; //!< Flag "never_fresh" Never redraw the Term
66 byte attr_blank{}; //!< Value "attr_blank" Use this "attr" value for "blank" grids
67 char char_blank{}; //!< Value "char_blank" Use this "char" value for "blank" grids
69 std::vector<char> key_queue; //!< Keypress Queue -- various data / Keypress Queue -- pending keys
75 TERM_LEN wid{}; //!< Window Width(max 255)
76 TERM_LEN hgt{}; //!< Window Height(max 255)
78 std::optional<TERM_LEN> centered_wid{};
79 std::optional<TERM_LEN> centered_hgt{};
84 TERM_LEN y1{}; //!< Minimum modified row
85 TERM_LEN y2{}; //!< Maximum modified row
87 std::vector<TERM_LEN> x1; //!< Minimum modified column(per row)
88 std::vector<TERM_LEN> x2; //!< Maximum modified column(per row)
90 std::unique_ptr<term_win> old; //!< Displayed screen image
91 std::unique_ptr<term_win> scr; //!< Requested screen image
93 std::unique_ptr<term_win> tmp; //!< Temporary screen image
94 std::stack<std::unique_ptr<term_win>> mem_stack; //!< Memorized screen image stack
96 void (*init_hook)(term_type *t){}; //!< Hook for init - ing the term
97 void (*nuke_hook)(term_type *t){}; //!< Hook for nuke - ing the term
99 errr (*user_hook)(int n){}; //!< ユーザ設定項目実装部 / Hook for user actions
100 errr (*xtra_hook)(int n, int v){}; //!< 拡張機能実装部 / Hook for extra actions
101 errr (*curs_hook)(TERM_LEN x, TERM_LEN y){}; //!< カーソル描画実装部 / Hook for placing the cursor
102 errr (*bigcurs_hook)(TERM_LEN x, TERM_LEN y){}; //!< 大型タイル時カーソル描画実装部 / Hook for placing the cursor on bigtile mode
103 errr (*wipe_hook)(TERM_LEN x, TERM_LEN y, int n){}; //!< 指定座標テキスト消去実装部 / Hook for drawing some blank spaces
104 errr (*text_hook)(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, concptr s){}; //!< テキスト描画実装部 / Hook for drawing a string of chars using an attr
105 void (*resize_hook)(void){}; //!< 画面リサイズ実装部
106 errr (*pict_hook)(TERM_LEN x, TERM_LEN y, int n, const TERM_COLOR *ap, concptr cp, const TERM_COLOR *tap,
107 concptr tcp){}; //!< タイル描画実装部 / Hook for drawing a sequence of special attr / char pairs
109 // std::unique_ptr をメンバに持つため、コピーはできない。
110 // コピーコンストラクタ/コピー代入演算子が暗黙に削除されたという
111 // MSVCの警告を避けるためコンストラクタ等を明示的に定義する。
112 term_type() = default;
113 ~term_type() = default;
114 term_type(const term_type &) = delete;
115 term_type &operator=(const term_type &) = delete;
116 term_type(term_type &&) = default;
117 term_type &operator=(term_type &&) = default;
120 class TermOffsetSetter {
122 TermOffsetSetter(std::optional<TERM_LEN> x, std::optional<TERM_LEN> y);
124 TermOffsetSetter(const TermOffsetSetter &) = delete;
125 TermOffsetSetter &operator=(const TermOffsetSetter &) = delete;
126 TermOffsetSetter(TermOffsetSetter &&) = delete;
127 TermOffsetSetter &operator=(TermOffsetSetter &&) = delete;
131 TERM_LEN orig_offset_x;
132 TERM_LEN orig_offset_y;
135 class TermCenteredOffsetSetter {
137 TermCenteredOffsetSetter(std::optional<TERM_LEN> width, std::optional<TERM_LEN> height);
138 ~TermCenteredOffsetSetter();
139 TermCenteredOffsetSetter(const TermCenteredOffsetSetter &) = delete;
140 TermCenteredOffsetSetter &operator=(const TermCenteredOffsetSetter &) = delete;
141 TermCenteredOffsetSetter(TermCenteredOffsetSetter &&) = delete;
142 TermCenteredOffsetSetter &operator=(TermCenteredOffsetSetter &&) = delete;
145 std::optional<TermOffsetSetter> tos;
147 std::optional<TERM_LEN> orig_centered_wid;
148 std::optional<TERM_LEN> orig_centered_hgt;
151 /**** Available Constants ****/
154 * Definitions for the "actions" of "term_xtra()"
156 * These values may be used as the first parameter of "term_xtra()",
157 * with the second parameter depending on the "action" itself. Many
158 * of the actions shown below are optional on at least one platform.
160 * The "TERM_XTRA_EVENT" action uses "v" to "wait" for an event
161 * The "TERM_XTRA_SHAPE" action uses "v" to "show" the cursor
162 * The "TERM_XTRA_FROSH" action uses "v" for the index of the row
163 * The "TERM_XTRA_SOUND" action uses "v" for the index of a sound
164 * The "TERM_XTRA_ALIVE" action uses "v" to "activate" (or "close")
165 * The "TERM_XTRA_LEVEL" action uses "v" to "resume" (or "suspend")
166 * The "TERM_XTRA_DELAY" action uses "v" as a "millisecond" value
168 * The other actions do not need a "v" code, so "zero" is used.
170 #define TERM_XTRA_EVENT 1 /* Process some pending events */
171 #define TERM_XTRA_FLUSH 2 /* Flush all pending events */
172 #define TERM_XTRA_CLEAR 3 /* Clear the entire window */
173 #define TERM_XTRA_SHAPE 4 /* Set cursor shape (optional) */
174 #define TERM_XTRA_FROSH 5 /* Flush one row (optional) */
175 #define TERM_XTRA_FRESH 6 /* Flush all rows (optional) */
176 #define TERM_XTRA_NOISE 7 /* Make a noise (optional) */
177 #define TERM_XTRA_SOUND 8 /* Make a sound (optional) */
178 #define TERM_XTRA_BORED 9 /* Handle stuff when bored (optional) */
179 #define TERM_XTRA_REACT 10 /* React to global changes (optional) */
180 #define TERM_XTRA_ALIVE 11 /* Change the "hard" level (optional) */
181 #define TERM_XTRA_LEVEL 12 /* Change the "soft" level (optional) */
182 #define TERM_XTRA_DELAY 13 /* Delay some milliseconds (optional) */
183 #define TERM_XTRA_MUSIC_BASIC 14 /* Play a music(basic) (optional) */
184 #define TERM_XTRA_MUSIC_DUNGEON 15 /* Play a music(dungeon) (optional) */
185 #define TERM_XTRA_MUSIC_QUEST 16 /* Play a music(quest) (optional) */
186 #define TERM_XTRA_MUSIC_TOWN 17 /* Play a music(floor) (optional) */
187 #define TERM_XTRA_MUSIC_MONSTER 18 /* Play a music(monster) (optional) */
188 #define TERM_XTRA_MUSIC_MUTE 19
189 #define TERM_XTRA_SCENE 20 /* React to scene changes (optional) */
191 /**** Available Variables ****/
192 extern term_type *game_term;
194 errr term_user(int n);
195 errr term_xtra(int n, int v);
197 void term_queue_char(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c, TERM_COLOR ta, char tc);
198 void term_queue_bigchar(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c, TERM_COLOR ta, char tc);
199 void term_queue_line(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR *a, char *c, TERM_COLOR *ta, char *tc);
201 errr term_fresh(void);
202 errr term_fresh_force(void);
203 errr term_set_cursor(int v);
204 errr term_gotoxy(TERM_LEN x, TERM_LEN y);
205 errr term_draw(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c);
206 errr term_addch(TERM_COLOR a, char c);
207 errr term_add_bigch(TERM_COLOR a, char c);
208 errr term_addstr(int n, TERM_COLOR a, std::string_view sv);
209 errr term_putch(TERM_LEN x, TERM_LEN y, TERM_COLOR a, char c);
210 errr term_putstr(TERM_LEN x, TERM_LEN y, int n, TERM_COLOR a, std::string_view sv);
211 errr term_erase(TERM_LEN x, TERM_LEN y, std::optional<int> n_opt = std::nullopt);
212 errr term_clear(void);
213 errr term_redraw(void);
214 errr term_redraw_section(TERM_LEN x1, TERM_LEN y1, TERM_LEN x2, TERM_LEN y2);
216 errr term_get_cursor(int *v);
217 std::pair<int, int> term_get_size();
218 errr term_locate(TERM_LEN *x, TERM_LEN *y);
219 errr term_what(TERM_LEN x, TERM_LEN y, TERM_COLOR *a, char *c);
221 errr term_flush(void);
222 errr term_key_push(int k);
223 errr term_inkey(char *ch, bool wait, bool take);
225 errr term_save(void);
226 errr term_load(bool load_all);
228 errr term_exchange(void);
230 errr term_resize(TERM_LEN w, TERM_LEN h);
232 errr term_activate(term_type *t);
234 errr term_init(term_type *t, TERM_LEN w, TERM_LEN h, int k);
237 errr term_putstr_v(TERM_LEN x, TERM_LEN y, int n, byte a, concptr s);
241 errr term_nuke(term_type *t);