|
21 | 21 |
|
22 | 22 | #include "v3_ctrl.h"
|
23 | 23 |
|
| 24 | +static int in_color = 0; |
| 25 | +static int color8 = 0; |
| 26 | +#define TRANS_STYLE(x) ( !color8 ? (x) : ((x)&0x7)|(((x)&0x70)>>1)) |
| 27 | + |
24 | 28 | static int use_curses = 0;
|
25 | 29 | static int debug_enable = 0;
|
26 | 30 |
|
@@ -117,9 +121,9 @@ static int handle_char_set(struct character_msg * msg) {
|
117 | 121 | return -1;
|
118 | 122 | }
|
119 | 123 |
|
120 |
| - wattron(console.win, COLOR_PAIR(msg->style)); |
| 124 | + if (in_color) {wattron(console.win, COLOR_PAIR(TRANS_STYLE(msg->style)));} |
121 | 125 | mvwaddch(console.win, msg->y, msg->x, c);
|
122 |
| - wattroff(console.win, COLOR_PAIR(msg->style)); |
| 126 | + if (in_color) {wattroff(console.win, COLOR_PAIR(TRANS_STYLE(msg->style)));} |
123 | 127 |
|
124 | 128 | } else {
|
125 | 129 | //stdout text display
|
@@ -403,10 +407,59 @@ int check_terminal_size (void)
|
403 | 407 | static void
|
404 | 408 | init_colors (void)
|
405 | 409 | {
|
| 410 | + unsigned short i; |
| 411 | + |
| 412 | + if (!has_colors()) { |
| 413 | + fprintf(stderr,"No color support\n"); |
| 414 | + in_color=0; |
| 415 | + color8=0; |
| 416 | + return; |
| 417 | + } |
| 418 | + |
406 | 419 | start_color();
|
407 |
| - int i; |
408 |
| - for (i = 0; i < 0x100; i++) { |
409 |
| - init_pair(i, i & 0xf, (i >> 4) & 0xf); |
| 420 | + |
| 421 | + if (can_change_color() && COLORS>=16 && COLOR_PAIRS>=256) { |
| 422 | + fprintf(stderr, "Modifyable color support with enough colors available\n"); |
| 423 | + // initialize first 16 colors to be the PC colors |
| 424 | + // then create all the pairings |
| 425 | + for (i=0;i<16;i++) { |
| 426 | + unsigned short red, green, blue, intens; |
| 427 | + // i = IRGB (4 bits) |
| 428 | + intens = i>>3 & 0x1; |
| 429 | + red = i>>2 & 0x1; |
| 430 | + green = i>>1 & 0x1; |
| 431 | + blue = i>>0 & 0x1; |
| 432 | + init_color(i, 500*(red+intens), 500*(blue+intens), 500*(green+intens)); |
| 433 | + } |
| 434 | + for (i=0;i<256;i++) { |
| 435 | + init_pair(i, i & 0xf, (i >> 4) & 0xf); |
| 436 | + } |
| 437 | + in_color = 1; |
| 438 | + color8 = 0; |
| 439 | + return; |
| 440 | + } else { |
| 441 | + if (COLORS!=8 || COLOR_PAIRS<64) { |
| 442 | + fprintf(stderr,"Insufficient number of fixed colors (%d) or color pairs (%d)\n",COLORS,COLOR_PAIRS); |
| 443 | + in_color = 0; |
| 444 | + color8 = 0; |
| 445 | + return; |
| 446 | + } |
| 447 | + // We have only the low-intensity colors available, so |
| 448 | + // map just to these |
| 449 | + fprintf(stderr,"Only 8 color standard palette available\n"); |
| 450 | + for (i=0;i<64;i++) { |
| 451 | + // VGA color order: black, blue, green, cyan, red, magenta, brown, gray |
| 452 | + // curses color order: black, red, green, yellow, blue, magenta, cyan, white |
| 453 | + short map[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; |
| 454 | + unsigned short fg, bg; |
| 455 | + // discard intensity bit |
| 456 | + bg = (i>>3 & 0x7); |
| 457 | + fg = i & 0x7; |
| 458 | + init_pair(i, map[fg], map[bg]); |
| 459 | + } |
| 460 | + in_color = 1; |
| 461 | + color8 = 1; |
| 462 | + return; |
410 | 463 | }
|
411 | 464 | }
|
412 | 465 |
|
@@ -468,7 +521,8 @@ int main(int argc, char* argv[]) {
|
468 | 521 | scrollok(console.win, 1);
|
469 | 522 |
|
470 | 523 | erase();
|
471 |
| - init_colors(); |
| 524 | + init_colors(); |
| 525 | + //abort(); |
472 | 526 | }
|
473 | 527 |
|
474 | 528 | /*
|
|
0 commit comments