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