| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include "angband.h" |
| 21 |
#include "buildid.h" |
| 22 |
#include "cmds.h" |
| 23 |
#include "cave.h" |
| 24 |
#include "ui-command.h" |
| 25 |
#include "ui-display.h" |
| 26 |
#include "ui-prefs.h" |
| 27 |
|
| 28 |
#ifdef USE_GCU |
| 29 |
#include "main.h" |
| 30 |
#ifdef _WIN32 |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include <io.h> |
| 36 |
#define PLATFORM_WRITE _write |
| 37 |
#else |
| 38 |
#define PLATFORM_WRITE write |
| 39 |
#endif |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#define term System_term |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#ifdef USE_NCURSES |
| 50 |
# ifdef HAVE_STDbool_H |
| 51 |
# define NCURSES_ENABLE_STDbool_H 0 |
| 52 |
# endif |
| 53 |
|
| 54 |
|
| 55 |
# define _XOPEN_SOURCE_EXTENDED 1 |
| 56 |
|
| 57 |
# include <ncurses.h> |
| 58 |
#else |
| 59 |
# include <curses.h> |
| 60 |
#endif |
| 61 |
|
| 62 |
#include <term.h> |
| 63 |
|
| 64 |
#undef term |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
#define USE_TPOSIX |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
#if defined(WIN32_CONSOLE_MODE) |
| 78 |
# undef USE_TPOSIX |
| 79 |
_stdcall void Sleep(int); |
| 80 |
#define usleep(v) Sleep(v / 1000) |
| 81 |
#endif |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
#ifdef USE_TPOSIX |
| 87 |
# include <termios.h> |
| 88 |
#endif |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
#define USE_CURS_SET |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
#ifdef USE_TPOSIX |
| 108 |
|
| 109 |
static struct termios norm_termios; |
| 110 |
static struct termios game_termios; |
| 111 |
|
| 112 |
#endif |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
static char *termtype; |
| 118 |
static bool loaded_terminfo; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
struct rect_s |
| 124 |
{ |
| 125 |
int x, y; |
| 126 |
int cx, cy; |
| 127 |
}; |
| 128 |
typedef struct rect_s rect_t, *rect_ptr; |
| 129 |
|
| 130 |
|
| 131 |
static rect_t rect(int x, int y, int cx, int cy) |
| 132 |
{ |
| 133 |
rect_t r; |
| 134 |
r.x = x; |
| 135 |
r.y = y; |
| 136 |
r.cx = cx; |
| 137 |
r.cy = cy; |
| 138 |
return r; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
typedef struct term_data { |
| 145 |
term t; |
| 146 |
rect_t r; |
| 147 |
WINDOW *win; |
| 148 |
} term_data; |
| 149 |
|
| 150 |
|
| 151 |
#define MAX_TERM_DATA 6 |
| 152 |
|
| 153 |
|
| 154 |
#define MIN_TERM0_LINES 24 |
| 155 |
#define MIN_TERM0_COLS 80 |
| 156 |
|
| 157 |
|
| 158 |
#define COMFY_SUBTERM_LINES 5 |
| 159 |
#define COMFY_SUBTERM_COLS 40 |
| 160 |
|
| 161 |
|
| 162 |
static term_data data[MAX_TERM_DATA]; |
| 163 |
|
| 164 |
|
| 165 |
static int active = 0; |
| 166 |
|
| 167 |
#ifdef A_COLOR |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
#ifndef A_BRIGHT |
| 174 |
# define A_BRIGHT A_BOLD |
| 175 |
#endif |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
static int can_use_color = false; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
static int colortable[BASIC_COLORS]; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
static int same_colortable[BASIC_COLORS]; |
| 192 |
|
| 193 |
|
| 194 |
static bool bold_extended = false; |
| 195 |
static bool use_default_background = false; |
| 196 |
static bool keep_terminal_colors = false; |
| 197 |
static int term_count = 1; |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
static int bg_color = COLOR_BLACK; |
| 203 |
|
| 204 |
|
| 205 |
#define PAIR_WHITE 0 |
| 206 |
#define PAIR_RED 1 |
| 207 |
#define PAIR_GREEN 2 |
| 208 |
#define PAIR_YELLOW 3 |
| 209 |
#define PAIR_BLUE 4 |
| 210 |
#define PAIR_MAGENTA 5 |
| 211 |
#define PAIR_CYAN 6 |
| 212 |
#define PAIR_BLACK 7 |
| 213 |
#define PAIR_WHITE_WHITE 8 |
| 214 |
#define PAIR_RED_RED 9 |
| 215 |
#define PAIR_GREEN_GREEN 10 |
| 216 |
#define PAIR_YELLOW_YELLOW 11 |
| 217 |
#define PAIR_BLUE_BLUE 12 |
| 218 |
#define PAIR_MAGENTA_MAGENTA 13 |
| 219 |
#define PAIR_CYAN_CYAN 14 |
| 220 |
#define PAIR_BLACK_BLACK 15 |
| 221 |
|
| 222 |
#endif |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
static void keymap_norm(void) { |
| 228 |
#ifdef USE_TPOSIX |
| 229 |
(void)tcsetattr(0, TCSAFLUSH, &norm_termios); |
| 230 |
#endif |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
static void keymap_game(void) { |
| 238 |
#ifdef USE_TPOSIX |
| 239 |
|
| 240 |
(void)tcsetattr(0, TCSAFLUSH, &game_termios); |
| 241 |
#endif |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
static void keymap_norm_prepare(void) { |
| 249 |
#ifdef USE_TPOSIX |
| 250 |
|
| 251 |
tcgetattr(0, &norm_termios); |
| 252 |
#endif |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
static void keymap_game_prepare(void) { |
| 260 |
#ifdef USE_TPOSIX |
| 261 |
|
| 262 |
tcgetattr(0, &game_termios); |
| 263 |
|
| 264 |
|
| 265 |
game_termios.c_cc[VINTR] = (char)3; |
| 266 |
|
| 267 |
|
| 268 |
game_termios.c_cc[VSUSP] = (char)26; |
| 269 |
|
| 270 |
#ifdef VDSUSP |
| 271 |
|
| 272 |
game_termios.c_cc[VDSUSP] = (char)-1; |
| 273 |
#endif |
| 274 |
|
| 275 |
|
| 276 |
game_termios.c_cc[VQUIT] = (char)-1; |
| 277 |
game_termios.c_cc[VERASE] = (char)-1; |
| 278 |
game_termios.c_cc[VKILL] = (char)-1; |
| 279 |
game_termios.c_cc[VEOF] = (char)-1; |
| 280 |
game_termios.c_cc[VEOL] = (char)-1; |
| 281 |
|
| 282 |
|
| 283 |
game_termios.c_cc[VMIN] = 1; |
| 284 |
game_termios.c_cc[VTIME] = 0; |
| 285 |
|
| 286 |
|
| 287 |
game_termios.c_iflag &= ~IXON; |
| 288 |
#endif |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
static errr Term_xtra_gcu_alive(int v) { |
| 296 |
if (!v) { |
| 297 |
|
| 298 |
int x, y; |
| 299 |
|
| 300 |
|
| 301 |
keymap_norm(); |
| 302 |
|
| 303 |
|
| 304 |
nocbreak(); |
| 305 |
echo(); |
| 306 |
nl(); |
| 307 |
|
| 308 |
|
| 309 |
Term_xtra(TERM_XTRA_SHAPE, 1); |
| 310 |
|
| 311 |
|
| 312 |
refresh(); |
| 313 |
|
| 314 |
|
| 315 |
getyx(stdscr, y, x); |
| 316 |
|
| 317 |
|
| 318 |
mvcur(y, x, LINES - 1, 0); |
| 319 |
|
| 320 |
|
| 321 |
endwin(); |
| 322 |
|
| 323 |
|
| 324 |
fflush(stdout); |
| 325 |
|
| 326 |
} else { |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
cbreak(); |
| 331 |
noecho(); |
| 332 |
nonl(); |
| 333 |
|
| 334 |
|
| 335 |
keymap_game(); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
return 0; |
| 340 |
} |
| 341 |
|
| 342 |
const char help_gcu[] = "Text mode, subopts\n" |
| 343 |
" -B Use brighter bold characters\n" |
| 344 |
" -D Use terminal default background color\n" |
| 345 |
" -K Keep terminal's color table when changing colors\n" |
| 346 |
" -nN Use N terminals (up to 6)"; |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
#ifdef MSYS2_ENCODING_WORKAROUND |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
static size_t Term_mbcs_gcu_msys2(wchar_t *dest, const char *src, int n) |
| 381 |
{ |
| 382 |
size_t nout = (n > 0) ? n : 0; |
| 383 |
size_t count = 0; |
| 384 |
|
| 385 |
while (1) { |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
uint32_t decoded = 0xfffd; |
| 393 |
|
| 394 |
if (((unsigned int) *src & 0x80) == 0) { |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
if (*src == 0) { |
| 400 |
if (dest && count < nout) { |
| 401 |
dest[count] = 0; |
| 402 |
} |
| 403 |
break; |
| 404 |
} |
| 405 |
decoded = *src; |
| 406 |
++src; |
| 407 |
} else if (((unsigned int) *src & 0xe0) == 0xc0) { |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
uint32_t part = ((uint32_t) *src & 0x1f) << 6; |
| 413 |
|
| 414 |
++src; |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
if (((unsigned int) *src & 0xc0) == 0x80 |
| 420 |
&& part > 0x40) { |
| 421 |
decoded = part + ((uint32_t) *src & 0x3f); |
| 422 |
++src; |
| 423 |
} |
| 424 |
} else if (((unsigned int) *src & 0xf0) == 0xe0) { |
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
uint32_t part = ((uint32_t) *src & 0xf) << 12; |
| 430 |
|
| 431 |
++src; |
| 432 |
if (((unsigned int) *src & 0xc0) == 0x80) { |
| 433 |
part += ((uint32_t) *src & 0x3f) << 6; |
| 434 |
++src; |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
if (((unsigned int) *src & 0xc0) == 0x80 |
| 442 |
&& part >= 0x800 |
| 443 |
&& (part & 0xf800) != 0xd800) { |
| 444 |
decoded = part |
| 445 |
+ ((uint32_t) *src & 0x3f); |
| 446 |
++src; |
| 447 |
} |
| 448 |
} |
| 449 |
} else if (((unsigned int) *src & 0xf8) == 0xf0) { |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
uint32_t part = ((uint32_t) *src & 0x7) << 18; |
| 455 |
|
| 456 |
++src; |
| 457 |
if (((unsigned int) *src & 0xc0) == 0x80) { |
| 458 |
part += ((uint32_t) * src & 0x3f) << 12; |
| 459 |
++src; |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
if (((unsigned int) *src & 0xc0) == 0x80 |
| 467 |
&& part >= 0x10000 |
| 468 |
&& (part & 0xff0000) |
| 469 |
<= 0x100000) { |
| 470 |
part += ((uint32_t) *src & 0x3f) << 6; |
| 471 |
++src; |
| 472 |
if (((unsigned int) *src & 0xc0) |
| 473 |
== 0x80) { |
| 474 |
decoded = part |
| 475 |
+ ((uint32_t) *src |
| 476 |
& 0x3f); |
| 477 |
++src; |
| 478 |
} |
| 479 |
} |
| 480 |
} |
| 481 |
} else { |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
++src; |
| 487 |
} |
| 488 |
if (dest && count < nout) { |
| 489 |
if (decoded >= 0x10000) { |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
assert(decoded <= 0x10FFFF); |
| 495 |
dest[count] = (wchar_t) 0xfffd; |
| 496 |
} else { |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
assert(decoded < 0xd800 || decoded > 0xdfff); |
| 502 |
dest[count] = (wchar_t) decoded; |
| 503 |
} |
| 504 |
} |
| 505 |
++count; |
| 506 |
} |
| 507 |
return count; |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
static int Term_wctomb_gcu_msys2(char *s, wchar_t wchar) |
| 523 |
{ |
| 524 |
if ((unsigned int) wchar <= 0x7f) { |
| 525 |
*s = wchar; |
| 526 |
return 1; |
| 527 |
} |
| 528 |
if ((unsigned int) wchar < 0x7ff) { |
| 529 |
*s++ = 0xc0 + (((unsigned int) wchar & 0x7c0) >> 6); |
| 530 |
*s++ = 0x80 + ((unsigned int) wchar & 0x3f); |
| 531 |
return 2; |
| 532 |
} |
| 533 |
|
| 534 |
if ((unsigned int) wchar >= 0xd800 && (unsigned int) wchar <= 0xdfff) { |
| 535 |
return -1; |
| 536 |
} |
| 537 |
*s++ = 0xe0 + (((unsigned int) wchar & 0xf000) >> 12); |
| 538 |
*s++ = 0x80 + (((unsigned int) wchar & 0xfc0) >> 6); |
| 539 |
*s++ = 0x80 + ((unsigned int) wchar & 0x3f); |
| 540 |
return 3; |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
static int Term_iswprint_gcu_msys2(wint_t wc) |
| 551 |
{ |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
return utf32_isprint((uint32_t) wc); |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
static int Term_wcsz_gcu_msys2(void) |
| 564 |
{ |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
return 3; |
| 570 |
} |
| 571 |
|
| 572 |
#endif |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
static void Term_init_gcu(term *t) { |
| 578 |
term_data *td = (term_data *)(t->data); |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
wrefresh(stdscr); |
| 585 |
|
| 586 |
|
| 587 |
if (active++ != 0) return; |
| 588 |
|
| 589 |
#if defined(USE_NCURSES) && defined(KEY_MOUSE) |
| 590 |
|
| 591 |
mousemask(ALL_MOUSE_EVENTS, NULL); |
| 592 |
#endif |
| 593 |
|
| 594 |
|
| 595 |
wclear(td->win); |
| 596 |
|
| 597 |
|
| 598 |
wmove(td->win, 0, 0); |
| 599 |
|
| 600 |
|
| 601 |
wrefresh(td->win); |
| 602 |
|
| 603 |
|
| 604 |
keymap_game(); |
| 605 |
|
| 606 |
#ifdef MSYS2_ENCODING_WORKAROUND |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
text_mbcs_hook = Term_mbcs_gcu_msys2; |
| 612 |
text_wctomb_hook = Term_wctomb_gcu_msys2; |
| 613 |
text_wcsz_hook = Term_wcsz_gcu_msys2; |
| 614 |
text_iswprint_hook = Term_iswprint_gcu_msys2; |
| 615 |
#endif |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
static void Term_nuke_gcu(term *t) { |
| 623 |
int x, y; |
| 624 |
term_data *td = (term_data *)(t->data); |
| 625 |
|
| 626 |
|
| 627 |
delwin(td->win); |
| 628 |
|
| 629 |
|
| 630 |
if (--active != 0) return; |
| 631 |
|
| 632 |
|
| 633 |
Term_xtra(TERM_XTRA_SHAPE, 1); |
| 634 |
|
| 635 |
#ifdef A_COLOR |
| 636 |
|
| 637 |
start_color(); |
| 638 |
#endif |
| 639 |
|
| 640 |
|
| 641 |
getyx(stdscr, y, x); |
| 642 |
|
| 643 |
|
| 644 |
mvcur(y, x, LINES - 1, 0); |
| 645 |
|
| 646 |
|
| 647 |
refresh(); |
| 648 |
|
| 649 |
|
| 650 |
endwin(); |
| 651 |
|
| 652 |
|
| 653 |
fflush(stdout); |
| 654 |
|
| 655 |
|
| 656 |
keymap_norm(); |
| 657 |
} |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
static void balance_dimension(int *size, int *start, int term_group_index, |
| 677 |
int term_group_count, int window_size, int min_term0_size, |
| 678 |
int comfy_subterm_size) { |
| 679 |
|
| 680 |
|
| 681 |
int subterm_group_count = term_group_count - 1; |
| 682 |
|
| 683 |
if (term_group_index == 0) { |
| 684 |
|
| 685 |
*size = MAX(min_term0_size, window_size - subterm_group_count*(min_term0_size + 1)); |
| 686 |
*start = 0; |
| 687 |
} else if (term_group_index == term_group_count - 1) { |
| 688 |
|
| 689 |
if (window_size <= min_term0_size + subterm_group_count*(comfy_subterm_size + 1)) { |
| 690 |
|
| 691 |
|
| 692 |
*size = (window_size - min_term0_size - subterm_group_count) / subterm_group_count; |
| 693 |
if (window_size > min_term0_size + subterm_group_count + *size * subterm_group_count) |
| 694 |
(*size)++; |
| 695 |
} else { |
| 696 |
*size = MIN(min_term0_size, window_size - min_term0_size - comfy_subterm_size*(subterm_group_count - 1) - subterm_group_count); |
| 697 |
} |
| 698 |
*start = window_size - *size; |
| 699 |
} else { |
| 700 |
|
| 701 |
if (window_size <= subterm_group_count*(min_term0_size + 1) + comfy_subterm_size) { |
| 702 |
|
| 703 |
*size = MIN(comfy_subterm_size, (window_size - min_term0_size - subterm_group_count) / subterm_group_count); |
| 704 |
} else { |
| 705 |
*size = MIN(min_term0_size, window_size - subterm_group_count*(min_term0_size + 1)); |
| 706 |
} |
| 707 |
*start = 1 + MAX(min_term0_size, window_size - subterm_group_count*(min_term0_size + 1)); |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
static void get_gcu_term_size(int i, int *rows, int *cols, int *y, int *x) { |
| 717 |
bool is_wide = (10 * LINES < 3 * COLS); |
| 718 |
int term_rows = 1; |
| 719 |
int term_cols = 1; |
| 720 |
int term_row_index = 0; |
| 721 |
int term_col_index = 0; |
| 722 |
|
| 723 |
assert(i < term_count); |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
if (is_wide) { |
| 733 |
while (term_rows*(term_rows + 1) < term_count) term_rows++; |
| 734 |
while (term_cols*term_cols < term_count) term_cols++; |
| 735 |
if (term_count == 3) { |
| 736 |
term_rows = 1; |
| 737 |
term_cols = 3; |
| 738 |
} |
| 739 |
term_col_index = i % term_cols; |
| 740 |
term_row_index = (int)(i / term_cols); |
| 741 |
} else { |
| 742 |
while (term_rows*term_rows < term_count) term_rows++; |
| 743 |
while (term_cols*(term_cols + 1) < term_count) term_cols++; |
| 744 |
if (term_count == 3) { |
| 745 |
term_rows = 3; |
| 746 |
term_cols = 1; |
| 747 |
} |
| 748 |
term_col_index = (int)(i / term_rows); |
| 749 |
term_row_index = i % term_rows; |
| 750 |
} |
| 751 |
|
| 752 |
if (LINES < MIN_TERM0_LINES + 2 * (term_rows - 1) || |
| 753 |
COLS < MIN_TERM0_COLS + 2 * (term_cols - 1)) { |
| 754 |
term_rows = term_cols = term_count = 1; |
| 755 |
if (i != 0) { |
| 756 |
*rows = *cols = *y = *x = 0; |
| 757 |
} |
| 758 |
term_col_index = term_row_index = 0; |
| 759 |
} |
| 760 |
|
| 761 |
balance_dimension(cols, x, term_col_index, term_cols, COLS, MIN_TERM0_COLS, COMFY_SUBTERM_COLS); |
| 762 |
balance_dimension(rows, y, term_row_index, term_rows, LINES, MIN_TERM0_LINES, COMFY_SUBTERM_LINES); |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
static void do_gcu_resize(void) { |
| 770 |
int i, rows, cols, y, x; |
| 771 |
term *old_t = Term; |
| 772 |
|
| 773 |
for (i = 0; i < term_count; i++) { |
| 774 |
|
| 775 |
Term_activate(&data[i].t); |
| 776 |
|
| 777 |
|
| 778 |
get_gcu_term_size(i, &rows, &cols, &y, &x); |
| 779 |
if (wresize(data[i].win, rows, cols) == OK) |
| 780 |
Term_resize(cols, rows); |
| 781 |
|
| 782 |
|
| 783 |
Term_activate(old_t); |
| 784 |
} |
| 785 |
do_cmd_redraw(); |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
static errr Term_xtra_gcu_event(int v) { |
| 793 |
int i, j, k, mods=0; |
| 794 |
|
| 795 |
if (v) { |
| 796 |
|
| 797 |
|
| 798 |
halfdelay(2); |
| 799 |
i = getch(); |
| 800 |
while (i == ERR) { |
| 801 |
i = getch(); |
| 802 |
idle_update(); |
| 803 |
} |
| 804 |
cbreak(); |
| 805 |
} else { |
| 806 |
|
| 807 |
nodelay(stdscr, true); |
| 808 |
|
| 809 |
|
| 810 |
i = getch(); |
| 811 |
|
| 812 |
|
| 813 |
nodelay(stdscr, false); |
| 814 |
|
| 815 |
|
| 816 |
if (i == ERR) return (1); |
| 817 |
if (i == EOF) return (1); |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
#ifdef USE_NCURSES |
| 822 |
if (i == KEY_RESIZE) { |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
halfdelay(10); |
| 827 |
do { |
| 828 |
i = getch(); |
| 829 |
} while (i == KEY_RESIZE); |
| 830 |
cbreak(); |
| 831 |
do_gcu_resize(); |
| 832 |
if (i == ERR) return (1); |
| 833 |
} |
| 834 |
#endif |
| 835 |
|
| 836 |
#if defined(USE_NCURSES) && defined(KEY_MOUSE) |
| 837 |
if (i == KEY_MOUSE) { |
| 838 |
MEVENT m; |
| 839 |
if (getmouse(&m) != OK) return (0); |
| 840 |
|
| 841 |
int b = 0; |
| 842 |
if (m.bstate & BUTTON1_CLICKED) b = 1; |
| 843 |
else if (m.bstate & BUTTON2_CLICKED) b = 2; |
| 844 |
else if (m.bstate & BUTTON3_CLICKED) b = 3; |
| 845 |
else if (m.bstate & BUTTON4_CLICKED) b = 4; |
| 846 |
if (m.bstate & BUTTON_SHIFT) b |= (KC_MOD_SHIFT << 4); |
| 847 |
if (m.bstate & BUTTON_CTRL) b |= (KC_MOD_CONTROL << 4); |
| 848 |
if (m.bstate & BUTTON_ALT) b |= (KC_MOD_ALT << 4); |
| 849 |
|
| 850 |
if (b != 0) Term_mousepress(m.x, m.y, b); |
| 851 |
return (0); |
| 852 |
} |
| 853 |
#endif |
| 854 |
|
| 855 |
|
| 856 |
#if 0 |
| 857 |
printw("key %d", i); |
| 858 |
wrefresh(stdscr); |
| 859 |
#endif |
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
if (i == 27) { |
| 874 |
nodelay(stdscr, true); |
| 875 |
j = getch(); |
| 876 |
switch (j) { |
| 877 |
case 'O': { |
| 878 |
k = getch(); |
| 879 |
switch (k) { |
| 880 |
|
| 881 |
case 'q': i = '1'; break; |
| 882 |
case 'r': i = '2'; break; |
| 883 |
case 's': i = '3'; break; |
| 884 |
case 't': i = '4'; break; |
| 885 |
case 'u': i = '5'; break; |
| 886 |
case 'v': i = '6'; break; |
| 887 |
case 'w': i = '7'; break; |
| 888 |
case 'x': i = '8'; break; |
| 889 |
case 'y': i = '9'; break; |
| 890 |
|
| 891 |
|
| 892 |
case ERR: break; |
| 893 |
default: ungetch(k); ungetch(j); |
| 894 |
} |
| 895 |
break; |
| 896 |
} |
| 897 |
|
| 898 |
|
| 899 |
case ERR: break; |
| 900 |
default: ungetch(j); |
| 901 |
} |
| 902 |
nodelay(stdscr, false); |
| 903 |
} |
| 904 |
|
| 905 |
#ifdef KEY_DOWN |
| 906 |
|
| 907 |
switch (i) { |
| 908 |
case KEY_DOWN: i = ARROW_DOWN; break; |
| 909 |
case KEY_UP: i = ARROW_UP; break; |
| 910 |
case KEY_LEFT: i = ARROW_LEFT; break; |
| 911 |
case KEY_RIGHT: i = ARROW_RIGHT; break; |
| 912 |
case KEY_DC: i = KC_DELETE; break; |
| 913 |
case KEY_BACKSPACE: i = KC_BACKSPACE; break; |
| 914 |
case KEY_ENTER: i = KC_ENTER; mods |= KC_MOD_KEYPAD; break; |
| 915 |
case 9: i = KC_TAB; break; |
| 916 |
case 13: i = KC_ENTER; break; |
| 917 |
case 27: i = ESCAPE; break; |
| 918 |
|
| 919 |
|
| 920 |
case 0xFC: i = '0'; break; |
| 921 |
case 0xFD: i = '.'; break; |
| 922 |
case 0xC0: i = '\b'; break; |
| 923 |
case 0xDF: i = '1'; break; |
| 924 |
case 0xF5: i = '3'; break; |
| 925 |
case 0xE9: i = '5'; break; |
| 926 |
case 0xC1: i = '7'; break; |
| 927 |
case 0xF4: i = '9'; break; |
| 928 |
|
| 929 |
default: { |
| 930 |
if (i < KEY_MIN) break; |
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
if (i >= 252) i = KEY_F(63) - (i - 252); |
| 937 |
if (i >= ARROW_DOWN) i += 4; |
| 938 |
|
| 939 |
i = 128 + (i & 127); |
| 940 |
break; |
| 941 |
} |
| 942 |
} |
| 943 |
#endif |
| 944 |
|
| 945 |
|
| 946 |
Term_keypress(i, mods); |
| 947 |
|
| 948 |
|
| 949 |
return (0); |
| 950 |
} |
| 951 |
|
| 952 |
static int scale_color(int i, int j, int scale) { |
| 953 |
return (angband_color_table[i][j] * (scale - 1) + 127) / 255; |
| 954 |
} |
| 955 |
|
| 956 |
static int create_color(int i, int scale) { |
| 957 |
int r = scale_color(i, 1, scale); |
| 958 |
int g = scale_color(i, 2, scale); |
| 959 |
int b = scale_color(i, 3, scale); |
| 960 |
int rgb = 16 + scale * scale * r + scale * g + b; |
| 961 |
|
| 962 |
|
| 963 |
if (r == g && g == b) { |
| 964 |
if (b == 0) rgb = 0; |
| 965 |
if (b == scale) rgb = 15; |
| 966 |
} |
| 967 |
|
| 968 |
return rgb; |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
static void handle_extended_color_tables(void) { |
| 976 |
#ifdef A_COLOR |
| 977 |
if (COLORS == 256 || COLORS == 88) { |
| 978 |
int isbold = bold_extended ? A_BRIGHT : A_NORMAL; |
| 979 |
int i; |
| 980 |
|
| 981 |
if (keep_terminal_colors) { |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
int scale = COLORS == 256 ? 6 : 4; |
| 998 |
|
| 999 |
bg_color = create_color(COLOUR_DARK, scale); |
| 1000 |
for (i = 0; i < BASIC_COLORS; i++) { |
| 1001 |
int fg = create_color(i, scale); |
| 1002 |
init_pair(i + 1, fg, bg_color); |
| 1003 |
colortable[i] = COLOR_PAIR(i + 1) | isbold; |
| 1004 |
init_pair(BASIC_COLORS + i, fg, fg); |
| 1005 |
same_colortable[i] = |
| 1006 |
COLOR_PAIR(BASIC_COLORS + i) | isbold; |
| 1007 |
} |
| 1008 |
} else { |
| 1009 |
bg_color = 0; |
| 1010 |
for (i = 0; i < BASIC_COLORS; i++) { |
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
init_color(i, |
| 1016 |
(angband_color_table[i][1] * 1001) / 256, |
| 1017 |
(angband_color_table[i][2] * 1001) / 256, |
| 1018 |
(angband_color_table[i][3] * 1001) / 256); |
| 1019 |
init_pair(i + 1, i, bg_color); |
| 1020 |
colortable[i] = COLOR_PAIR(i + 1) | isbold; |
| 1021 |
init_pair(BASIC_COLORS + i, i, i); |
| 1022 |
same_colortable[i] = |
| 1023 |
COLOR_PAIR(BASIC_COLORS + i) | isbold; |
| 1024 |
} |
| 1025 |
} |
| 1026 |
|
| 1027 |
for (i = 0; i < term_count; ++i) { |
| 1028 |
if (data[i].win) { |
| 1029 |
wbkgdset(data[i].win, ' ' | |
| 1030 |
colortable[COLOUR_DARK]); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
if (data[0].win) { |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
chtype term0_bkg = getbkgd(data[0].win); |
| 1040 |
|
| 1041 |
if (getbkgd(stdscr) != term0_bkg) { |
| 1042 |
wbkgd(stdscr, term0_bkg); |
| 1043 |
wrefresh(stdscr); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
} |
| 1047 |
#endif |
| 1048 |
} |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
static errr Term_xtra_gcu(int n, int v) { |
| 1055 |
term_data *td = (term_data *)(Term->data); |
| 1056 |
|
| 1057 |
|
| 1058 |
switch (n) { |
| 1059 |
|
| 1060 |
case TERM_XTRA_CLEAR: touchwin(td->win); wclear(td->win); return 0; |
| 1061 |
|
| 1062 |
|
| 1063 |
case TERM_XTRA_NOISE: PLATFORM_WRITE(1, "\007", 1); return 0; |
| 1064 |
|
| 1065 |
|
| 1066 |
case TERM_XTRA_FRESH: wrefresh(td->win); return 0; |
| 1067 |
|
| 1068 |
#ifdef USE_CURS_SET |
| 1069 |
|
| 1070 |
case TERM_XTRA_SHAPE: curs_set(v); return 0; |
| 1071 |
#endif |
| 1072 |
|
| 1073 |
|
| 1074 |
case TERM_XTRA_ALIVE: return Term_xtra_gcu_alive(v); |
| 1075 |
|
| 1076 |
|
| 1077 |
case TERM_XTRA_EVENT: return Term_xtra_gcu_event(v); |
| 1078 |
|
| 1079 |
|
| 1080 |
case TERM_XTRA_FLUSH: while (!Term_xtra_gcu_event(false)); return 0; |
| 1081 |
|
| 1082 |
|
| 1083 |
case TERM_XTRA_DELAY: if (v > 0) usleep(1000 * v); return 0; |
| 1084 |
|
| 1085 |
|
| 1086 |
case TERM_XTRA_REACT: handle_extended_color_tables(); return 0; |
| 1087 |
} |
| 1088 |
|
| 1089 |
|
| 1090 |
return 1; |
| 1091 |
} |
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
static errr Term_curs_gcu(int x, int y) { |
| 1098 |
term_data *td = (term_data *)(Term->data); |
| 1099 |
wmove(td->win, y, x); |
| 1100 |
return 0; |
| 1101 |
} |
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
static errr Term_wipe_gcu(int x, int y, int n) { |
| 1109 |
term_data *td = (term_data *)(Term->data); |
| 1110 |
|
| 1111 |
wmove(td->win, y, x); |
| 1112 |
|
| 1113 |
if (x + n >= td->t.wid) { |
| 1114 |
|
| 1115 |
wclrtoeol(td->win); |
| 1116 |
} else { |
| 1117 |
|
| 1118 |
if (can_use_color) { |
| 1119 |
wattrset(td->win, colortable[COLOUR_DARK] | A_NORMAL); |
| 1120 |
} |
| 1121 |
whline(td->win, ' ', n); |
| 1122 |
if (can_use_color) { |
| 1123 |
wattrset(td->win, A_NORMAL); |
| 1124 |
} |
| 1125 |
} |
| 1126 |
|
| 1127 |
return 0; |
| 1128 |
} |
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
static errr Term_text_gcu(int x, int y, int n, int a, const wchar_t *s) { |
| 1135 |
term_data *td = (term_data *)(Term->data); |
| 1136 |
|
| 1137 |
#ifdef A_COLOR |
| 1138 |
if (can_use_color) { |
| 1139 |
|
| 1140 |
|
| 1141 |
int attr = a & 127; |
| 1142 |
|
| 1143 |
|
| 1144 |
bool reversed = a > 127; |
| 1145 |
|
| 1146 |
int color; |
| 1147 |
|
| 1148 |
|
| 1149 |
if (a / MULT_BG == BG_SAME) { |
| 1150 |
color = same_colortable[attr]; |
| 1151 |
} else { |
| 1152 |
color = colortable[attr]; |
| 1153 |
} |
| 1154 |
|
| 1155 |
|
| 1156 |
int mode; |
| 1157 |
if (reversed && (color & A_BRIGHT)) |
| 1158 |
mode = (color & ~A_BRIGHT) | A_BLINK | A_REVERSE; |
| 1159 |
else if (reversed) |
| 1160 |
mode = color | A_REVERSE; |
| 1161 |
else |
| 1162 |
mode = color | A_NORMAL; |
| 1163 |
|
| 1164 |
wattrset(td->win, mode); |
| 1165 |
mvwaddnwstr(td->win, y, x, s, n); |
| 1166 |
wattrset(td->win, A_NORMAL); |
| 1167 |
return 0; |
| 1168 |
} |
| 1169 |
#endif |
| 1170 |
|
| 1171 |
mvwaddnwstr(td->win, y, x, s, n); |
| 1172 |
return 0; |
| 1173 |
} |
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
static errr term_data_init_gcu(term_data *td, int rows, int cols, int y, int x) |
| 1181 |
{ |
| 1182 |
term *t = &td->t; |
| 1183 |
|
| 1184 |
|
| 1185 |
td->win = newwin(rows, cols, y, x); |
| 1186 |
|
| 1187 |
|
| 1188 |
if (!td->win) |
| 1189 |
quit("Failed to setup curses window."); |
| 1190 |
|
| 1191 |
|
| 1192 |
term_init(t, cols, rows, 256); |
| 1193 |
|
| 1194 |
|
| 1195 |
t->icky_corner = true; |
| 1196 |
|
| 1197 |
|
| 1198 |
t->complex_input = true; |
| 1199 |
|
| 1200 |
|
| 1201 |
t->init_hook = Term_init_gcu; |
| 1202 |
t->nuke_hook = Term_nuke_gcu; |
| 1203 |
|
| 1204 |
|
| 1205 |
t->text_hook = Term_text_gcu; |
| 1206 |
t->wipe_hook = Term_wipe_gcu; |
| 1207 |
t->curs_hook = Term_curs_gcu; |
| 1208 |
t->xtra_hook = Term_xtra_gcu; |
| 1209 |
|
| 1210 |
|
| 1211 |
t->data = td; |
| 1212 |
|
| 1213 |
|
| 1214 |
Term_activate(t); |
| 1215 |
|
| 1216 |
|
| 1217 |
return (0); |
| 1218 |
} |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
static errr term_data_init(term_data *td) |
| 1224 |
{ |
| 1225 |
return term_data_init_gcu(td, td->r.cy, td->r.cx, td->r.y, td->r.x); |
| 1226 |
} |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
static int _parse_size_list(const char *arg, int sizes[], int max) |
| 1232 |
{ |
| 1233 |
int i = 0; |
| 1234 |
const char *start = arg; |
| 1235 |
const char *stop = arg; |
| 1236 |
|
| 1237 |
for (;;) |
| 1238 |
{ |
| 1239 |
if (!*stop || !isdigit(*stop)) |
| 1240 |
{ |
| 1241 |
if (i >= max) break; |
| 1242 |
if (*start == '*') |
| 1243 |
sizes[i] = 255; |
| 1244 |
else |
| 1245 |
{ |
| 1246 |
|
| 1247 |
|
| 1248 |
sizes[i] = atoi(start); |
| 1249 |
} |
| 1250 |
i++; |
| 1251 |
if (!*stop || *stop != ',') break; |
| 1252 |
|
| 1253 |
stop++; |
| 1254 |
start = stop; |
| 1255 |
} |
| 1256 |
else |
| 1257 |
stop++; |
| 1258 |
} |
| 1259 |
return i; |
| 1260 |
} |
| 1261 |
|
| 1262 |
|
| 1263 |
static void hook_quit(const char *str) { |
| 1264 |
int i; |
| 1265 |
|
| 1266 |
for (i = 0; i < term_count; i++) { |
| 1267 |
if (angband_term[i]) { |
| 1268 |
term_nuke(angband_term[i]); |
| 1269 |
} |
| 1270 |
} |
| 1271 |
endwin(); |
| 1272 |
} |
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
errr init_gcu(int argc, char **argv) { |
| 1283 |
int i; |
| 1284 |
|
| 1285 |
|
| 1286 |
termtype = getenv("TERM"); |
| 1287 |
loaded_terminfo = termtype && tgetent(0, termtype) == 1; |
| 1288 |
|
| 1289 |
|
| 1290 |
for (i = 1; i < argc; i++) { |
| 1291 |
if (prefix(argv[i], "-B")) { |
| 1292 |
bold_extended = true; |
| 1293 |
} else if (prefix(argv[i], "-n")) { |
| 1294 |
term_count = atoi(&argv[i][2]); |
| 1295 |
if (term_count > MAX_TERM_DATA) term_count = MAX_TERM_DATA; |
| 1296 |
else if (term_count < 1) term_count = 1; |
| 1297 |
} else if (prefix(argv[i], "-D")) { |
| 1298 |
use_default_background = true; |
| 1299 |
} else if (streq(argv[i], "-K")) { |
| 1300 |
keep_terminal_colors = true; |
| 1301 |
} |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
keymap_norm_prepare(); |
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
if (!getenv("ESCDELAY")) { |
| 1310 |
#if _POSIX_C_SOURCE < 200112L |
| 1311 |
static char escdelbuf[80] = "ESCDELAY=20"; |
| 1312 |
putenv(escdelbuf); |
| 1313 |
#else |
| 1314 |
setenv("ESCDELAY", "20", 1); |
| 1315 |
#endif |
| 1316 |
} |
| 1317 |
|
| 1318 |
|
| 1319 |
if (initscr() == NULL) return (-1); |
| 1320 |
|
| 1321 |
|
| 1322 |
quit_aux = hook_quit; |
| 1323 |
|
| 1324 |
|
| 1325 |
if (LINES < MIN_TERM0_LINES || COLS < MIN_TERM0_COLS) |
| 1326 |
quit("Angband needs at least an 80x24 'curses' screen"); |
| 1327 |
|
| 1328 |
#ifdef A_COLOR |
| 1329 |
|
| 1330 |
can_use_color = ((start_color() != ERR) && has_colors() && |
| 1331 |
(COLORS >= 8) && (COLOR_PAIRS >= 8)); |
| 1332 |
if (!can_change_color()) keep_terminal_colors = true; |
| 1333 |
|
| 1334 |
#ifdef HAVE_USE_DEFAULT_COLORS |
| 1335 |
|
| 1336 |
if (use_default_background && use_default_colors() == OK) bg_color = -1; |
| 1337 |
#endif |
| 1338 |
|
| 1339 |
|
| 1340 |
if (can_use_color) { |
| 1341 |
|
| 1342 |
|
| 1343 |
init_pair(PAIR_RED, COLOR_RED, bg_color); |
| 1344 |
init_pair(PAIR_GREEN, COLOR_GREEN, bg_color); |
| 1345 |
init_pair(PAIR_YELLOW, COLOR_YELLOW, bg_color); |
| 1346 |
init_pair(PAIR_BLUE, COLOR_BLUE, bg_color); |
| 1347 |
init_pair(PAIR_MAGENTA, COLOR_MAGENTA, bg_color); |
| 1348 |
init_pair(PAIR_CYAN, COLOR_CYAN, bg_color); |
| 1349 |
init_pair(PAIR_BLACK, COLOR_BLACK, bg_color); |
| 1350 |
|
| 1351 |
|
| 1352 |
init_pair(PAIR_WHITE_WHITE, COLOR_WHITE, COLOR_WHITE); |
| 1353 |
init_pair(PAIR_RED_RED, COLOR_RED, COLOR_RED); |
| 1354 |
init_pair(PAIR_GREEN_GREEN, COLOR_GREEN, COLOR_GREEN); |
| 1355 |
init_pair(PAIR_YELLOW_YELLOW, COLOR_YELLOW, COLOR_YELLOW); |
| 1356 |
init_pair(PAIR_BLUE_BLUE, COLOR_BLUE, COLOR_BLUE); |
| 1357 |
init_pair(PAIR_MAGENTA_MAGENTA, COLOR_MAGENTA, COLOR_MAGENTA); |
| 1358 |
init_pair(PAIR_CYAN_CYAN, COLOR_CYAN, COLOR_CYAN); |
| 1359 |
init_pair(PAIR_BLACK_BLACK, COLOR_BLACK, COLOR_BLACK); |
| 1360 |
|
| 1361 |
|
| 1362 |
colortable[COLOUR_DARK] = (COLOR_PAIR(PAIR_BLACK)); |
| 1363 |
colortable[COLOUR_WHITE] = (COLOR_PAIR(PAIR_WHITE) | A_BRIGHT); |
| 1364 |
colortable[COLOUR_SLATE] = (COLOR_PAIR(PAIR_WHITE)); |
| 1365 |
colortable[COLOUR_ORANGE] = (COLOR_PAIR(PAIR_YELLOW) | A_BRIGHT); |
| 1366 |
colortable[COLOUR_RED] = (COLOR_PAIR(PAIR_RED)); |
| 1367 |
colortable[COLOUR_GREEN] = (COLOR_PAIR(PAIR_GREEN)); |
| 1368 |
colortable[COLOUR_BLUE] = (COLOR_PAIR(PAIR_BLUE)); |
| 1369 |
colortable[COLOUR_UMBER] = (COLOR_PAIR(PAIR_YELLOW)); |
| 1370 |
colortable[COLOUR_L_DARK] = (COLOR_PAIR(PAIR_BLACK) | A_BRIGHT); |
| 1371 |
colortable[COLOUR_L_WHITE] = (COLOR_PAIR(PAIR_WHITE)); |
| 1372 |
colortable[COLOUR_L_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA)); |
| 1373 |
colortable[COLOUR_YELLOW] = (COLOR_PAIR(PAIR_YELLOW) | A_BRIGHT); |
| 1374 |
colortable[COLOUR_L_RED] = (COLOR_PAIR(PAIR_MAGENTA) | A_BRIGHT); |
| 1375 |
colortable[COLOUR_L_GREEN] = (COLOR_PAIR(PAIR_GREEN) | A_BRIGHT); |
| 1376 |
colortable[COLOUR_L_BLUE] = (COLOR_PAIR(PAIR_BLUE) | A_BRIGHT); |
| 1377 |
colortable[COLOUR_L_UMBER] = (COLOR_PAIR(PAIR_YELLOW)); |
| 1378 |
|
| 1379 |
colortable[COLOUR_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA)); |
| 1380 |
colortable[COLOUR_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA)); |
| 1381 |
colortable[COLOUR_TEAL] = (COLOR_PAIR(PAIR_CYAN)); |
| 1382 |
colortable[COLOUR_MUD] = (COLOR_PAIR(PAIR_YELLOW)); |
| 1383 |
colortable[COLOUR_L_YELLOW] = (COLOR_PAIR(PAIR_YELLOW | A_BRIGHT)); |
| 1384 |
colortable[COLOUR_MAGENTA] = (COLOR_PAIR(PAIR_MAGENTA | A_BRIGHT)); |
| 1385 |
colortable[COLOUR_L_TEAL] = (COLOR_PAIR(PAIR_CYAN) | A_BRIGHT); |
| 1386 |
colortable[COLOUR_L_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA) | A_BRIGHT); |
| 1387 |
colortable[COLOUR_L_PINK] = (COLOR_PAIR(PAIR_MAGENTA) | A_BRIGHT); |
| 1388 |
colortable[COLOUR_MUSTARD] = (COLOR_PAIR(PAIR_YELLOW)); |
| 1389 |
colortable[COLOUR_BLUE_SLATE] = (COLOR_PAIR(PAIR_BLUE)); |
| 1390 |
colortable[COLOUR_DEEP_L_BLUE] = (COLOR_PAIR(PAIR_BLUE)); |
| 1391 |
|
| 1392 |
same_colortable[COLOUR_DARK] = (COLOR_PAIR(PAIR_BLACK_BLACK)); |
| 1393 |
same_colortable[COLOUR_WHITE] = (COLOR_PAIR(PAIR_WHITE_WHITE) | A_BRIGHT); |
| 1394 |
same_colortable[COLOUR_SLATE] = (COLOR_PAIR(PAIR_WHITE_WHITE)); |
| 1395 |
same_colortable[COLOUR_ORANGE] = (COLOR_PAIR(PAIR_YELLOW_YELLOW) | A_BRIGHT); |
| 1396 |
same_colortable[COLOUR_RED] = (COLOR_PAIR(PAIR_RED_RED)); |
| 1397 |
same_colortable[COLOUR_GREEN] = (COLOR_PAIR(PAIR_GREEN_GREEN)); |
| 1398 |
same_colortable[COLOUR_BLUE] = (COLOR_PAIR(PAIR_BLUE_BLUE)); |
| 1399 |
same_colortable[COLOUR_UMBER] = (COLOR_PAIR(PAIR_YELLOW_YELLOW)); |
| 1400 |
same_colortable[COLOUR_L_DARK] = (COLOR_PAIR(PAIR_BLACK_BLACK) | A_BRIGHT); |
| 1401 |
same_colortable[COLOUR_L_WHITE] = (COLOR_PAIR(PAIR_WHITE_WHITE)); |
| 1402 |
same_colortable[COLOUR_L_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA_MAGENTA)); |
| 1403 |
same_colortable[COLOUR_YELLOW] = (COLOR_PAIR(PAIR_YELLOW_YELLOW) | A_BRIGHT); |
| 1404 |
same_colortable[COLOUR_L_RED] = (COLOR_PAIR(PAIR_MAGENTA_MAGENTA) | A_BRIGHT); |
| 1405 |
same_colortable[COLOUR_L_GREEN] = (COLOR_PAIR(PAIR_GREEN_GREEN) | A_BRIGHT); |
| 1406 |
same_colortable[COLOUR_L_BLUE] = (COLOR_PAIR(PAIR_BLUE_BLUE) | A_BRIGHT); |
| 1407 |
same_colortable[COLOUR_L_UMBER] = (COLOR_PAIR(PAIR_YELLOW_YELLOW)); |
| 1408 |
|
| 1409 |
same_colortable[COLOUR_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA_MAGENTA)); |
| 1410 |
same_colortable[COLOUR_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA_MAGENTA)); |
| 1411 |
same_colortable[COLOUR_TEAL] = (COLOR_PAIR(PAIR_CYAN_CYAN)); |
| 1412 |
same_colortable[COLOUR_MUD] = (COLOR_PAIR(PAIR_YELLOW_YELLOW)); |
| 1413 |
same_colortable[COLOUR_L_YELLOW] = (COLOR_PAIR(PAIR_YELLOW_YELLOW) | A_BRIGHT); |
| 1414 |
same_colortable[COLOUR_MAGENTA] = (COLOR_PAIR(PAIR_MAGENTA_MAGENTA) | A_BRIGHT); |
| 1415 |
same_colortable[COLOUR_L_TEAL] = (COLOR_PAIR(PAIR_CYAN_CYAN) | A_BRIGHT); |
| 1416 |
same_colortable[COLOUR_L_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA_MAGENTA) | A_BRIGHT); |
| 1417 |
same_colortable[COLOUR_L_PINK] = (COLOR_PAIR(PAIR_MAGENTA_MAGENTA) | A_BRIGHT); |
| 1418 |
same_colortable[COLOUR_MUSTARD] = (COLOR_PAIR(PAIR_YELLOW)); |
| 1419 |
same_colortable[COLOUR_BLUE_SLATE] = (COLOR_PAIR(PAIR_BLUE)); |
| 1420 |
same_colortable[COLOUR_DEEP_L_BLUE] = (COLOR_PAIR(PAIR_BLUE)); |
| 1421 |
handle_extended_color_tables(); |
| 1422 |
} |
| 1423 |
#endif |
| 1424 |
|
| 1425 |
|
| 1426 |
nodelay(stdscr, false); |
| 1427 |
|
| 1428 |
|
| 1429 |
cbreak(); |
| 1430 |
noecho(); |
| 1431 |
nonl(); |
| 1432 |
raw(); |
| 1433 |
|
| 1434 |
|
| 1435 |
keypad(stdscr, true); |
| 1436 |
|
| 1437 |
|
| 1438 |
keymap_game_prepare(); |
| 1439 |
|
| 1440 |
|
| 1441 |
if (term_count > 1) |
| 1442 |
{ |
| 1443 |
int rows, cols, y, x; |
| 1444 |
int next_win = 0; |
| 1445 |
for (i = 0; i < term_count; i++) { |
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
get_gcu_term_size(i, &rows, &cols, &y, &x); |
| 1450 |
|
| 1451 |
|
| 1452 |
if (rows <= 0 || cols <= 0) continue; |
| 1453 |
|
| 1454 |
|
| 1455 |
term_data_init_gcu(&data[next_win], rows, cols, y, x); |
| 1456 |
|
| 1457 |
|
| 1458 |
angband_term[next_win] = &data[next_win].t; |
| 1459 |
|
| 1460 |
|
| 1461 |
next_win++; |
| 1462 |
} |
| 1463 |
} |
| 1464 |
else |
| 1465 |
|
| 1466 |
|
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
{ |
| 1493 |
rect_t remaining = rect(0, 0, COLS, LINES); |
| 1494 |
int spacer_cx = 1; |
| 1495 |
int spacer_cy = 1; |
| 1496 |
int next_term = 1; |
| 1497 |
int term_ct = 1; |
| 1498 |
|
| 1499 |
for (i = 1; i < argc; i++) |
| 1500 |
{ |
| 1501 |
if (streq(argv[i], "-spacer")) |
| 1502 |
{ |
| 1503 |
char *pe, *ystr; |
| 1504 |
long lv; |
| 1505 |
|
| 1506 |
i++; |
| 1507 |
if (i >= argc) |
| 1508 |
quit("Missing size specifier for -spacer"); |
| 1509 |
lv = strtol(argv[i], &pe, 10); |
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
if (pe == argv[i] || *pe != 'x' || lv <= INT_MIN || |
| 1516 |
lv >= INT_MAX) { |
| 1517 |
quit_fmt("Invalid specification for -spacer; got %s", |
| 1518 |
argv[i]); |
| 1519 |
} |
| 1520 |
spacer_cx = (int)lv; |
| 1521 |
ystr = pe + 1; |
| 1522 |
lv = strtol(ystr, &pe, 10); |
| 1523 |
if (pe == ystr || !contains_only_spaces(pe) || |
| 1524 |
lv <= INT_MIN || lv >= INT_MAX) { |
| 1525 |
quit_fmt("Invalid specification for -spacer; got %s", |
| 1526 |
argv[i]); |
| 1527 |
} |
| 1528 |
spacer_cy = (int)lv; |
| 1529 |
} |
| 1530 |
else if (streq(argv[i], "-right") || streq(argv[i], "-left")) |
| 1531 |
{ |
| 1532 |
const char *arg, *tmp; |
| 1533 |
bool left = streq(argv[i], "-left"); |
| 1534 |
int cx, cys[MAX_TERM_DATA] = {0}, ct, j, x, y; |
| 1535 |
|
| 1536 |
i++; |
| 1537 |
if (i >= argc) |
| 1538 |
quit(format("Missing size specifier for -%s", left ? "left" : "right")); |
| 1539 |
|
| 1540 |
arg = argv[i]; |
| 1541 |
tmp = strchr(arg, 'x'); |
| 1542 |
if (!tmp) |
| 1543 |
quit(format("Expected something like -%s 60x27,* for two %s hand terminals of 60 columns, the first 27 lines and the second whatever is left.", left ? "left" : "right", left ? "left" : "right")); |
| 1544 |
cx = atoi(arg); |
| 1545 |
remaining.cx -= cx; |
| 1546 |
if (left) |
| 1547 |
{ |
| 1548 |
x = remaining.x; |
| 1549 |
y = remaining.y; |
| 1550 |
remaining.x += cx; |
| 1551 |
} |
| 1552 |
else |
| 1553 |
{ |
| 1554 |
x = remaining.x + remaining.cx; |
| 1555 |
y = remaining.y; |
| 1556 |
} |
| 1557 |
remaining.cx -= spacer_cx; |
| 1558 |
if (left) |
| 1559 |
remaining.x += spacer_cx; |
| 1560 |
|
| 1561 |
tmp++; |
| 1562 |
ct = _parse_size_list(tmp, cys, MAX_TERM_DATA); |
| 1563 |
for (j = 0; j < ct; j++) |
| 1564 |
{ |
| 1565 |
int cy = cys[j]; |
| 1566 |
if (y + cy > remaining.y + remaining.cy) |
| 1567 |
cy = remaining.y + remaining.cy - y; |
| 1568 |
if (next_term >= MAX_TERM_DATA) |
| 1569 |
quit(format("Too many terminals. Only %d are allowed.", MAX_TERM_DATA)); |
| 1570 |
if (cy <= 0) |
| 1571 |
{ |
| 1572 |
quit(format("Out of bounds in -%s: %d is too large (%d rows max for this strip)", |
| 1573 |
left ? "left" : "right", cys[j], remaining.cy)); |
| 1574 |
} |
| 1575 |
data[next_term++].r = rect(x, y, cx, cy); |
| 1576 |
y += cy + spacer_cy; |
| 1577 |
term_ct++; |
| 1578 |
} |
| 1579 |
} |
| 1580 |
else if (streq(argv[i], "-top") || streq(argv[i], "-bottom")) |
| 1581 |
{ |
| 1582 |
const char *arg, *tmp; |
| 1583 |
bool top = streq(argv[i], "-top"); |
| 1584 |
int cy, cxs[MAX_TERM_DATA] = {0}, ct, j, x, y; |
| 1585 |
|
| 1586 |
i++; |
| 1587 |
if (i >= argc) |
| 1588 |
quit(format("Missing size specifier for -%s", top ? "top" : "bottom")); |
| 1589 |
|
| 1590 |
arg = argv[i]; |
| 1591 |
tmp = strchr(arg, 'x'); |
| 1592 |
if (!tmp) |
| 1593 |
quit(format("Expected something like -%s *x7 for a single %s terminal of 7 lines using as many columns as are available.", top ? "top" : "bottom", top ? "top" : "bottom")); |
| 1594 |
tmp++; |
| 1595 |
cy = atoi(tmp); |
| 1596 |
ct = _parse_size_list(arg, cxs, MAX_TERM_DATA); |
| 1597 |
|
| 1598 |
remaining.cy -= cy; |
| 1599 |
if (top) |
| 1600 |
{ |
| 1601 |
x = remaining.x; |
| 1602 |
y = remaining.y; |
| 1603 |
remaining.y += cy; |
| 1604 |
} |
| 1605 |
else |
| 1606 |
{ |
| 1607 |
x = remaining.x; |
| 1608 |
y = remaining.y + remaining.cy; |
| 1609 |
} |
| 1610 |
remaining.cy -= spacer_cy; |
| 1611 |
if (top) |
| 1612 |
remaining.y += spacer_cy; |
| 1613 |
|
| 1614 |
tmp++; |
| 1615 |
for (j = 0; j < ct; j++) |
| 1616 |
{ |
| 1617 |
int cx = cxs[j]; |
| 1618 |
if (x + cx > remaining.x + remaining.cx) |
| 1619 |
cx = remaining.x + remaining.cx - x; |
| 1620 |
if (next_term >= MAX_TERM_DATA) |
| 1621 |
quit(format("Too many terminals. Only %d are allowed.", MAX_TERM_DATA)); |
| 1622 |
if (cx <= 0) |
| 1623 |
{ |
| 1624 |
quit(format("Out of bounds in -%s: %d is too large (%d cols max for this strip)", |
| 1625 |
top ? "top" : "bottom", cxs[j], remaining.cx)); |
| 1626 |
} |
| 1627 |
data[next_term++].r = rect(x, y, cx, cy); |
| 1628 |
x += cx + spacer_cx; |
| 1629 |
term_ct++; |
| 1630 |
} |
| 1631 |
} |
| 1632 |
} |
| 1633 |
|
| 1634 |
|
| 1635 |
if (remaining.cx < MIN_TERM0_COLS || remaining.cy < MIN_TERM0_LINES) |
| 1636 |
quit(format("Failed: angband needs an %dx%d map screen, not %dx%d", MIN_TERM0_COLS, MIN_TERM0_LINES, remaining.cx, remaining.cy)); |
| 1637 |
data[0].r = remaining; |
| 1638 |
term_data_init(&data[0]); |
| 1639 |
angband_term[0] = Term; |
| 1640 |
|
| 1641 |
|
| 1642 |
for (next_term = 1; next_term < term_ct; next_term++) |
| 1643 |
{ |
| 1644 |
term_data_init(&data[next_term]); |
| 1645 |
angband_term[next_term] = Term; |
| 1646 |
} |
| 1647 |
} |
| 1648 |
|
| 1649 |
|
| 1650 |
Term_activate(&data[0].t); |
| 1651 |
|
| 1652 |
|
| 1653 |
term_screen = &data[0].t; |
| 1654 |
|
| 1655 |
|
| 1656 |
return (0); |
| 1657 |
} |
| 1658 |
|
| 1659 |
#endif |