OSDN Git Service

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