From: nhmall Date: Mon, 2 Jan 2023 01:05:03 +0000 (-0500) Subject: add some curses support for coloring of map frame X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=095e4ffe31bdfbe9665ea366d4d01a4feea58ff9;p=nethack add some curses support for coloring of map frame --- diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index 3d370e872..c20aad69a 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -812,7 +812,7 @@ curses_print_glyph( winid wid, coordxy x, coordxy y, const glyph_info *glyphinfo, - const glyph_info *bkglyphinfo UNUSED) + const glyph_info *bkglyphinfo) { int glyph; int ch; @@ -861,12 +861,15 @@ curses_print_glyph( if (SYMHANDLING(H_UTF8) && glyphinfo->gm.u && glyphinfo->gm.u->utf8str) { - curses_putch(wid, x, y, ch, glyphinfo->gm.u, color, attr); + curses_putch(wid, x, y, ch, glyphinfo->gm.u, color, + bkglyphinfo->framecolor, attr); } else { - curses_putch(wid, x, y, ch, NULL, color, attr); + curses_putch(wid, x, y, ch, NULL, color, + bkglyphinfo->framecolor, attr); } #else - curses_putch(wid, x, y, ch, color, attr); + curses_putch(wid, x, y, ch, color, + bkglyphinfo->framecolor, attr); #endif } diff --git a/win/curses/curswins.c b/win/curses/curswins.c index 51c504f32..b24255b5c 100644 --- a/win/curses/curswins.c +++ b/win/curses/curswins.c @@ -35,6 +35,7 @@ typedef struct nhwd { typedef struct nhchar { int ch; /* character */ int color; /* color info for character */ + int framecolor; /* background color info for character */ int attr; /* attributes of character */ struct unicode_representation *unicode_representation; } nethack_char; @@ -370,9 +371,9 @@ void #ifdef ENHANCED_SYMBOLS curses_putch(winid wid, int x, int y, int ch, struct unicode_representation *unicode_representation, - int color, int attr) + int color, int framecolor, int attr) #else -curses_putch(winid wid, int x, int y, int ch, int color, int attr) +curses_putch(winid wid, int x, int y, int ch, int color, int framecolor, int attr) #endif { static boolean map_initted = FALSE; @@ -396,6 +397,7 @@ curses_putch(winid wid, int x, int y, int ch, int color, int attr) --x; /* map column [0] is not used; draw column [1] in first screen col */ map[y][x].ch = ch; map[y][x].color = color; + map[y][x].framecolor = framecolor; map[y][x].attr = attr; #ifdef ENHANCED_SYMBOLS map[y][x].unicode_representation = unicode_representation; @@ -595,10 +597,39 @@ is_main_window(winid wid) /* Unconditionally write a single character to a window at the given coordinates without a refresh. Currently only used for the map. */ +static int +get_framecolor(int nhcolor, int framecolor) +{ + boolean hicolor = (COLORS >= 16), adj_framecolor = framecolor; + static int framecolors[16][8] = { + { 0, 16, 8, 32, 17, 40, 48, 0 }, { 1, 18, 9, 33, 19, 41, 49, 1 }, + { 2, 20, 10, 34, 21, 42, 50, 2 }, { 3, 22, 11, 35, 23, 43, 51, 3 }, + { 4, 24, 12, 36, 25, 44, 52, 4 }, { 5, 26, 13, 37, 27, 45, 53, 5 }, + { 6, 28, 14, 38, 29, 46, 54, 6 }, { 0, 30, 15, 72, 31, 88, 56, 0 }, + { 0, 30, 15, 39, 31, 47, 55, 0 }, { 1, 18, 9, 73, 19, 89, 57, 121 }, + { 2, 20, 10, 74, 21, 90, 58, 122 }, { 2, 22, 11, 75, 23, 91, 59, 123 }, + { 4, 24, 12, 76, 25, 44, 60, 124 }, { 5, 26, 13, 77, 27, 93, 61, 125 }, + { 6, 28, 14, 78, 29, 94, 62, 126 }, { 0, 30, 15, 79, 31, 95, 63, 127 }, + }; + + if (framecolor < 16 && framecolor >= 8) + adj_framecolor = framecolor - 8; + return ((nhcolor < (hicolor ? 16 : 8) && adj_framecolor < 8) + ? framecolors[nhcolor][adj_framecolor] + : nhcolor); +} + static void write_char(WINDOW * win, int x, int y, nethack_char nch) { - curses_toggle_color_attr(win, nch.color, nch.attr, ON); + int curscolor = nch.color, cursattr = nch.attr; + + if (nch.framecolor != NO_COLOR) { + curscolor = get_framecolor(nch.color, nch.framecolor); + if (nch.attr == A_REVERSE) + cursattr = A_NORMAL; /* hilited pet looks odd otherwise */ + } + curses_toggle_color_attr(win, curscolor, cursattr, ON); #if defined(CURSES_UNICODE) && defined(ENHANCED_SYMBOLS) if ((nch.unicode_representation && nch.unicode_representation->utf8str) || SYMHANDLING(H_IBM)) { @@ -670,7 +701,7 @@ write_char(WINDOW * win, int x, int y, nethack_char nch) #else mvwaddch(win, y, x, nch.ch); #endif - curses_toggle_color_attr(win, nch.color, nch.attr, OFF); + curses_toggle_color_attr(win, curscolor, cursattr, OFF); } diff --git a/win/curses/curswins.h b/win/curses/curswins.h index ea599a338..589e81bb0 100644 --- a/win/curses/curswins.h +++ b/win/curses/curswins.h @@ -23,9 +23,11 @@ void curses_del_wid(winid wid); void curs_destroy_all_wins(void); #ifdef ENHANCED_SYMBOLS void curses_putch(winid wid, int x, int y, int ch, - struct unicode_representation *ur, int color, int attrs); + struct unicode_representation *ur, int color, + int framecolor, int attrs); #else -void curses_putch(winid wid, int x, int y, int ch, int color, int attrs); +void curses_putch(winid wid, int x, int y, int ch, int color, + int framecolor, int attrs); #endif void curses_get_window_xy(winid wid, int *x, int *y); boolean curses_window_has_border(winid wid);