1 /* File: z-term.h */ 2 3 #ifndef INCLUDED_Z_TERM_H 4 #define INCLUDED_Z_TERM_H 5 6 #include "../common/h-basic.h" 7 8 9 10 /* 11 * A term_win is a "window" for a Term 12 * 13 * - Cursor Useless/Visible codes 14 * - Cursor Location (see "Useless") 15 * 16 * - Array[h] -- Access to the attribute array 17 * - Array[h] -- Access to the character array 18 * 19 * - Array[h*w] -- Attribute array 20 * - Array[h*w] -- Character array 21 * 22 * Note that the attr/char pair at (x,y) is a[y][x]/c[y][x] 23 * and that the row of attr/chars at (0,y) is a[y]/c[y] 24 */ 25 26 typedef struct term_win term_win; 27 28 struct term_win 29 { 30 bool cu, cv; 31 byte cx, cy; 32 33 byte **a; 34 char **c; 35 36 byte *va; 37 char *vc; 38 }; 39 40 41 42 /* 43 * An actual "term" structure 44 * 45 * - Extra info (used by application) 46 * 47 * - Extra data (used by implementation) 48 * 49 * 50 * - Flag "active_flag" 51 * This "term" is "active" 52 * 53 * - Flag "mapped_flag" 54 * This "term" is "mapped" 55 * 56 * - Flag "total_erase" 57 * This "term" should be fully erased 58 * 59 * - Flag "icky_corner" 60 * This "term" has an "icky" corner grid 61 * 62 * - Flag "soft_cursor" 63 * This "term" uses a "software" cursor 64 * 65 * - Flag "always_pict" 66 * Use the "Term_pict()" routine for all text 67 * 68 * - Flag "higher_pict" 69 * Use the "Term_pict()" routine for special text 70 * 71 * - Flag "always_text" 72 * Use the "Term_text()" routine for invisible text 73 * 74 * - Flag "never_bored" 75 * Never call the "TERM_XTRA_BORED" action 76 * 77 * - Flag "never_frosh" 78 * Never call the "TERM_XTRA_FROSH" action 79 * 80 * 81 * - Value "attr_blank" 82 * Use this "attr" value for "blank" grids 83 * 84 * - Value "char_blank" 85 * Use this "char" value for "blank" grids 86 * 87 * 88 * - Ignore this pointer 89 * 90 * - Keypress Queue -- various data 91 * 92 * - Keypress Queue -- pending keys 93 * 94 * 95 * - Window Width (max 255) 96 * - Window Height (max 255) 97 * 98 * - Minimum modified row 99 * - Maximum modified row 100 * 101 * - Minimum modified column (per row) 102 * - Maximum modified column (per row) 103 * 104 * 105 * - Displayed screen image 106 * - Requested screen image 107 * 108 * - Temporary screen image 109 * - Memorized screen image 110 * 111 * 112 * - Hook for init-ing the term 113 * - Hook for nuke-ing the term 114 * 115 * - Hook for user actions 116 * 117 * - Hook for extra actions 118 * 119 * - Hook for placing the cursor 120 * 121 * - Hook for drawing some blank spaces 122 * 123 * - Hook for drawing a special character 124 * 125 * - Hook for drawing a string of characters 126 */ 127 128 typedef struct term term; 129 130 struct term 131 { 132 vptr user; 133 134 vptr data; 135 136 bool active_flag; 137 bool mapped_flag; 138 bool total_erase; 139 bool icky_corner; 140 bool soft_cursor; 141 bool always_pict; 142 bool higher_pict; 143 bool always_text; 144 bool never_bored; 145 bool never_frosh; 146 147 byte attr_blank; 148 char char_blank; 149 150 char *key_queue; 151 152 s32b key_head; 153 s32b key_tail; 154 s32b key_length; 155 s32b key_size; 156 s32b key_size_orig; 157 158 byte wid; 159 byte hgt; 160 161 byte y1; 162 byte y2; 163 164 byte *x1; 165 byte *x2; 166 167 term_win *old; 168 term_win *scr; 169 170 // term_win *tmp; 171 term_win *mem[4]; 172 173 void (*init_hook)(term *t); 174 void (*nuke_hook)(term *t); 175 176 errr (*user_hook)(int n); 177 178 errr (*xtra_hook)(int n, int v); 179 180 errr (*curs_hook)(int x, int y); 181 182 errr (*wipe_hook)(int x, int y, int n); 183 184 errr (*pict_hook)(int x, int y, byte a, char c); 185 186 errr (*text_hook)(int x, int y, int n, byte a, cptr s); 187 }; 188 189 190 191 192 193 194 195 /**** Available Constants ****/ 196 197 198 /* 199 * Definitions for the "actions" of "Term_xtra()" 200 * 201 * These values may be used as the first parameter of "Term_xtra()", 202 * with the second parameter depending on the "action" itself. Many 203 * of the actions shown below are optional on at least one platform. 204 * 205 * The "TERM_XTRA_EVENT" action uses "v" to "wait" for an event 206 * The "TERM_XTRA_SHAPE" action uses "v" to "show" the cursor 207 * The "TERM_XTRA_FROSH" action uses "v" for the index of the row 208 * The "TERM_XTRA_SOUND" action uses "v" for the index of a sound 209 * The "TERM_XTRA_ALIVE" action uses "v" to "activate" (or "close") 210 * The "TERM_XTRA_LEVEL" action uses "v" to "resume" (or "suspend") 211 * The "TERM_XTRA_DELAY" action uses "v" as a "millisecond" value 212 * 213 * The other actions do not need a "v" code, so "zero" is used. 214 */ 215 #define TERM_XTRA_EVENT 1 /* Process some pending events */ 216 #define TERM_XTRA_FLUSH 2 /* Flush all pending events */ 217 #define TERM_XTRA_CLEAR 3 /* Clear the entire window */ 218 #define TERM_XTRA_SHAPE 4 /* Set cursor shape (optional) */ 219 #define TERM_XTRA_FROSH 5 /* Flush one row (optional) */ 220 #define TERM_XTRA_FRESH 6 /* Flush all rows (optional) */ 221 #define TERM_XTRA_NOISE 7 /* Make a noise (optional) */ 222 #define TERM_XTRA_SOUND 8 /* Make a sound (optional) */ 223 #define TERM_XTRA_BORED 9 /* Handle stuff when bored (optional) */ 224 #define TERM_XTRA_REACT 10 /* React to global changes (optional) */ 225 #define TERM_XTRA_ALIVE 11 /* Change the "hard" level (optional) */ 226 #define TERM_XTRA_LEVEL 12 /* Change the "soft" level (optional) */ 227 #define TERM_XTRA_DELAY 13 /* Delay some milliseconds (optional) */ 228 229 230 /**** Available Variables ****/ 231 232 extern term *Term; 233 234 235 /**** Available Functions ****/ 236 237 extern errr Term_user(int n); 238 extern errr Term_xtra(int n, int v); 239 240 extern errr Term_fresh(void); 241 extern errr Term_set_cursor(int v); 242 extern errr Term_gotoxy(int x, int y); 243 extern errr Term_draw(int x, int y, byte a, char c); 244 extern errr Term_addch(byte a, char c); 245 extern errr Term_addstr(int n, byte a, cptr s); 246 extern errr Term_putch(int x, int y, byte a, char c); 247 extern errr Term_putstr(int x, int y, int n, byte a, char *s); 248 extern errr Term_erase(int x, int y, int n); 249 extern errr Term_clear(void); 250 extern errr Term_redraw(void); 251 252 extern errr Term_get_cursor(int *v); 253 extern errr Term_get_size(int *w, int *h); 254 extern errr Term_locate(int *x, int *y); 255 extern errr Term_what(int x, int y, byte *a, char *c); 256 257 extern errr Term_flush(void); 258 extern errr Term_keypress(int k); 259 extern errr Term_key_push(int k); 260 extern errr Term_inkey(char *ch, bool wait, bool take); 261 262 extern errr Term_save(void); 263 extern errr Term_load(void); 264 extern errr Term_switch(int screen); 265 266 extern errr Term_resize(int w, int h); 267 268 extern errr Term_activate(term *t); 269 270 extern errr term_nuke(term *t); 271 extern errr term_init(term *t, int w, int h, int k); 272 273 extern byte flick_colour(byte attr); 274 extern void flicker(void); 275 276 277 #endif 278 279