Curses: simplify color handling

The map frame (background) colors were all over the place; the
code should be much cleaner now, and still work exactly the same
as before.

I tested this with terminals with 8, 16, and 256 COLORS.
This commit is contained in:
Pasi Kallinen
2024-03-15 20:36:56 +02:00
parent 96a74ccfbf
commit 243f6410d2
3 changed files with 47 additions and 81 deletions
+16 -9
View File
@@ -78,6 +78,7 @@ curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff)
color = NONE;
int curses_color;
boolean use_bold = FALSE;
/* if color is disabled, just show attribute */
if ((win == mapwin) ? !iflags.wc_color
@@ -93,7 +94,7 @@ curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff)
return;
}
if (color == 0) { /* make black fg visible */
if (color == CLR_BLACK) { /* make black fg visible */
# ifdef USE_DARKGRAY
if (iflags.wc2_darkgray) {
if (COLORS > 16) {
@@ -105,17 +106,23 @@ curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff)
# endif/* USE_DARKGRAY */
color = CLR_BLUE;
}
curses_color = color + 1;
if (COLORS < 16) {
if (curses_color > 8 && curses_color < 17)
curses_color -= 8;
else if (curses_color > (17 + 16))
curses_color -= 16;
/* convert NetHack's 16 colors to 8 colors + BOLD */
int fg = color % 16;
int bg = color / 16;
if (fg > 7)
use_bold = TRUE;
curses_color = (8 * (bg % 8)) + (fg % 8) + 1;
} else {
curses_color = color + 1;
}
if (onoff == ON) { /* Turn on color/attributes */
if (color != NONE) {
if ((((color > 7) && (color < 17)) ||
(color > 17 + 17)) && (COLORS < 16)) {
if (use_bold) {
wattron(win, A_BOLD);
}
wattron(win, COLOR_PAIR(curses_color));
@@ -127,7 +134,7 @@ curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff)
} else { /* Turn off color/attributes */
if (color != NONE) {
if ((color > 7) && (COLORS < 16)) {
if (use_bold) {
wattroff(win, A_BOLD);
}
# ifdef USE_DARKGRAY