adjustment of win32 console colours (trunk only)

Allow config file entries to adjust win32 console colours.

The following entries in a config file are examples:
OPTIONS=palette:black-0-0-0
OPTIONS=palette:red-210-0-0
OPTIONS=palette:green-80-200-0
OPTIONS=palette:brown-180-100-0
OPTIONS=palette:blue-0-0-200
OPTIONS=palette:magenta-128-0-128
OPTIONS=palette:cyan-50-180-180
OPTIONS=palette:gray-192-192-192
OPTIONS=palette:dark gray-100-100-100
OPTIONS=palette:orange-255-128-0
OPTIONS=palette:bright green-0-255-0
OPTIONS=palette:yellow-255-255-0
OPTIONS=palette:bright blue-100-100-240
OPTIONS=palette:bright magenta-255-0-255
OPTIONS=palette:bright cyan-0-255-255
OPTIONS=palette:white-255-255-255

This uses an undocumented way to adjust the console
colours in a win32 console application. The method and
code snippet used comes from www.catch22.net by James Brown.

This page:
      http://www.catch22.net/about.asp
states the following:
"you do not have to pay anything to use the software, and there are no
 licencing terms for any sourcecode that you may download from this site.
This means you can freely use any sourcecode or portions of code in
your applications, whether they be free software or professional, retail
products."
This commit is contained in:
nethack.allison
2006-09-03 04:17:09 +00:00
parent 7ba02dda00
commit 817cae4518
4 changed files with 410 additions and 6 deletions

View File

@@ -311,8 +311,14 @@ static struct Comp_Opt
{ "packorder", "the inventory order of the items in your pack",
MAXOCLASSES, SET_IN_GAME },
#ifdef CHANGE_COLOR
{ "palette", "palette (00c/880/-fff is blue/yellow/reverse white)",
{ "palette",
# ifndef WIN32CON
"palette (00c/880/-fff is blue/yellow/reverse white)",
15 , SET_IN_GAME },
# else
"palette (adjust an RGB color in palette (color-R-G-B)",
15 , SET_IN_FILE },
# endif
# if defined(MAC)
{ "hicolor", "same as palette, only order is reversed",
15, SET_IN_FILE },
@@ -1445,7 +1451,9 @@ boolean tinitial, tfrom_file;
) {
int color_number, color_incr;
#ifndef WIN32CON
if (duplicate) complain_about_duplicate(opts,1);
#endif
# ifdef MAC
if (match_optname(opts, "hicolor", 3, TRUE)) {
if (negated) {
@@ -1466,6 +1474,10 @@ boolean tinitial, tfrom_file;
}
# endif
if ((op = string_for_opt(opts, FALSE)) != (char *)0) {
# ifdef WIN32CON
if (!alternative_palette(op))
badoption(opts);
# else
char *pt = op;
int cnt, tmp, reverse;
long rgb;
@@ -1481,21 +1493,21 @@ boolean tinitial, tfrom_file;
}
while (cnt-- > 0) {
if (*pt && *pt != '/') {
# ifdef AMIGA
# ifdef AMIGA
rgb <<= 4;
# else
# else
rgb <<= 8;
# endif
# endif
tmp = *(pt++);
if (isalpha(tmp)) {
tmp = (tmp + 9) & 0xf; /* Assumes ASCII... */
} else {
tmp &= 0xf; /* Digits in ASCII too... */
}
# ifndef AMIGA
# ifndef AMIGA
/* Add an extra so we fill f -> ff and 0 -> 00 */
rgb += tmp << 4;
# endif
# endif
rgb += tmp;
}
}
@@ -1505,6 +1517,7 @@ boolean tinitial, tfrom_file;
change_color(color_number, rgb, reverse);
color_number += color_incr;
}
# endif /* !WIN32CON */
}
if (!initial) {
need_redraw = TRUE;