introduce support for coloring the frame behind a map location

Also includes support by paxed for polearm targeting using the
frame color.

Also renames USE_TILES to TILES_IN_GLYPHMAP which is a more
accurate description.

Not all window interfaces have full support for the color framing
of the background square yet.

MS-DOS needs further work (to bring it to both VESA and VGA, with
and without tiles.

Windows GUI is missing support.

X11 and Qt have been started, but may require further refinement.
This commit is contained in:
nhmall
2023-01-01 19:55:02 -05:00
parent 1972c8447f
commit 2fc0d25d45
38 changed files with 365 additions and 133 deletions

View File

@@ -460,11 +460,11 @@ cflags = -c -O $(INCLDIR) $(DLBFLG) $(CURSESDEF) -DSUPPRESS_GRAPHICS
LFLAGS =
# Debugging
#cflags = -g -c $(INCLDIR) $(DLBFLG) $(CURSESDEF) -DUSE_TILES
#cflags = -g -c $(INCLDIR) $(DLBFLG) $(CURSESDEF) -DTILES_IN_GLYPHMAP
#LFLAGS = -g
# Normal
cflags = -c -O $(INCLDIR) $(DLBFLG) $(CURSESDEF) -DUSE_TILES
cflags = -c -O $(INCLDIR) $(DLBFLG) $(CURSESDEF) -DTILES_IN_GLYPHMAP
LFLAGS =
#==========================================

View File

@@ -58,7 +58,7 @@ unsigned long sys_random_seed(void);
static char *getdta(void);
#endif
static unsigned int dos_ioctl(int, int, unsigned);
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
extern boolean pckeys(unsigned char, unsigned char); /* pckeys.c */
#endif
@@ -281,7 +281,7 @@ BIOSgetch(void)
else
ch = kpad[scan - KEYPADLO].normal;
}
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
/* Check for special interface manipulation keys */
if (pckeys(scan, shift)) {
ch = 0xFF;

View File

@@ -9,7 +9,7 @@
#include "hack.h"
#ifdef MSDOS
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
#include "wintty.h"
#include "pcvideo.h"
@@ -126,7 +126,7 @@ refresh(void)
vesa_refresh();
#endif
}
#endif /* USE_TILES */
#endif /* TILES_IN_GLYPHMAP */
#endif /* MSDOS */
/*pckeys.c*/

View File

@@ -12,7 +12,7 @@
#include "hack.h"
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
#if defined(__GO32__) || defined(__DJGPP__)
#include <unistd.h>
@@ -247,6 +247,6 @@ ReadPackedTileFile(int tilenum, char (*pta)[TILE_X])
return 0;
}
#endif
#endif /* USE_TILES */
#endif /* TILES_IN_GLYPHMAP */
/* pctiles.c */

View File

@@ -10,7 +10,7 @@
*
*/
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
#ifndef TILE_X
#define TILE_X 16
#endif
@@ -59,6 +59,6 @@ extern int ReadPlanarTileFile_O(int, struct overview_planar_cell_struct **);
#ifdef PACKED_FILE
extern int ReadPackedTileFile(int, char (*)[TILE_X]);
#endif
#endif /* USE_TILES */
#endif /* TILES_IN_GLYPHMAP */
/* pctiles.h */

View File

@@ -276,7 +276,7 @@ extern void vga_tty_end_screen(void);
extern void vga_tty_startup(int *, int *);
extern void vga_xputs(const char *, int, int);
extern void vga_xputc(char, int);
extern void vga_xputg(const glyph_info *);
extern void vga_xputg(const glyph_info *, const glyph_info *);
extern void vga_userpan(enum vga_pan_direction);
extern void vga_overview(boolean);
extern void vga_traditional(boolean);
@@ -305,7 +305,7 @@ extern void vesa_tty_end_screen(void);
extern void vesa_tty_startup(int *, int *);
extern void vesa_xputs(const char *, int, int);
extern void vesa_xputc(char, int);
extern void vesa_xputg(const glyph_info *);
extern void vesa_xputg(const glyph_info *, const glyph_info *);
extern void vesa_userpan(enum vga_pan_direction);
extern void vesa_overview(boolean);
extern void vesa_traditional(boolean);

View File

@@ -132,6 +132,7 @@ int attrib_text_normal; /* text mode normal attribute */
int attrib_gr_normal; /* graphics mode normal attribute */
int attrib_text_intense; /* text mode intense attribute */
int attrib_gr_intense; /* graphics mode intense attribute */
uint32 curframecolor = NO_COLOR; /* current background text color */
boolean traditional = FALSE; /* traditonal TTY character mode */
boolean inmap = FALSE; /* in the map window */
#ifdef TEXTCOLOR
@@ -165,7 +166,7 @@ clear_screen(void)
#endif
#ifdef SCREEN_VESA
} else if (iflags.usevesa) {
vesa_clear_screen(BACKGROUND_VGA_COLOR);
vesa_clear_screen(BACKGROUND_VESA_COLOR);
#endif
}
}
@@ -302,12 +303,14 @@ term_end_attr(int attr)
default:
g_attribute = iflags.grmode ? attrib_gr_normal : attrib_text_normal;
}
curframecolor = NO_COLOR;
}
void
term_end_color(void)
{
g_attribute = iflags.grmode ? attrib_gr_normal : attrib_text_normal;
curframecolor = NO_COLOR;
}
void
@@ -370,6 +373,19 @@ term_start_color(int color)
#endif
}
void
term_start_bgcolor(int bgcolor)
{
// pline("before bgcolor = %d, curframecolor = %d", bgcolor, curframecolor);
#ifdef TEXTCOLOR
if (!monoflag) {
if (bgcolor >= 0 && bgcolor < CLR_MAX)
curframecolor = bgcolor;
}
#endif
// pline("after bgcolor = %d, curframecolor = %d", bgcolor, curframecolor);
}
void
term_start_raw_bold(void)
{
@@ -577,8 +593,12 @@ xputc(int ch) /* write out character (and attribute) */
char attribute;
i = iflags.grmode ? attrib_gr_normal : attrib_text_normal;
attribute = (char) ((g_attribute == 0) ? i : g_attribute);
if (curframecolor != NO_COLOR) {
attribute |= ((ttycolors[curframecolor]) << 4);
}
if (!iflags.grmode) {
txt_xputc(ch, attribute);
#ifdef SCREEN_VGA
@@ -594,17 +614,17 @@ xputc(int ch) /* write out character (and attribute) */
}
/* write out a glyph picture at current location */
void xputg(const glyph_info *glyphinfo)
void xputg(const glyph_info *glyphinfo, const glyph_info *bkglyphinfo)
{
if (!iflags.grmode || !iflags.tile_view) {
(void) xputc((char) glyphinfo->ttychar);
#ifdef SCREEN_VGA
} else if (iflags.grmode && iflags.usevga) {
vga_xputg(glyphinfo);
vga_xputg(glyphinfo, bkglyphinfo);
#endif
#ifdef SCREEN_VESA
} else if (iflags.grmode && iflags.usevesa) {
vesa_xputg(glyphinfo);
vesa_xputg(glyphinfo, bkglyphinfo);
#endif
}
}

View File

@@ -22,7 +22,7 @@
extern int total_tiles_used, Tile_corr, Tile_unexplored; /* from tile.c */
struct VesaCharacter {
uint32 colour;
uint32 colour, bgcolour;
uint32 chr;
};
@@ -86,6 +86,7 @@ static struct map_struct {
uint32 attr;
unsigned special;
short int tileidx;
int framecolor;
} map[ROWNO][COLNO]; /* track the glyphs */
#define vesa_clearmap() \
@@ -95,6 +96,7 @@ static struct map_struct {
for (x = 0; x < COLNO; ++x) { \
map[y][x].glyph = GLYPH_UNEXPLORED; \
map[y][x].ch = glyph2ttychar(GLYPH_UNEXPLORED); \
map[y][x].framecolor = NO_COLOR; \
map[y][x].attr = 0; \
map[y][x].special = 0; \
map[y][x].tileidx = Tile_unexplored; \
@@ -667,10 +669,10 @@ vesa_xputc(char ch, int attr)
vesa_gotoloc(col, row);
}
#if defined(USE_TILES)
#if defined(TILES_IN_GLYPHMAP)
/* Place tile represent. a glyph at current location */
void
vesa_xputg(const glyph_info *glyphinfo)
vesa_xputg(const glyph_info *glyphinfo, const glyph_info *bkglyphinfo UNUSED)
{
int glyphnum = glyphinfo->glyph;
uint32 ch = (uchar) glyphinfo->ttychar;
@@ -701,6 +703,11 @@ vesa_xputg(const glyph_info *glyphinfo)
map[ry][col].special = special;
map[ry][col].tileidx = glyphinfo->gm.tileidx;
map[ry][col].attr = attr;
if (bkglyphinfo->framecolor != NO_COLOR) {
map[ry][col].framecolor = bkglyphinfo->framecolor;
}
if (iflags.traditional_view) {
vesa_WriteChar(ch, col, row, attr);
} else {
@@ -717,7 +724,7 @@ vesa_xputg(const glyph_info *glyphinfo)
++col;
vesa_gotoloc(col, row);
}
#endif /* USE_TILES */
#endif /* TILES_IN_GLYPHMAP */
/*
* Cursor location manipulation, and location information fetching
@@ -738,7 +745,7 @@ vesa_gotoloc(int col, int row)
currow = min(row, LI - 1);
}
#if defined(USE_TILES) && defined(CLIPPING)
#if defined(TILES_IN_GLYPHMAP) && defined(CLIPPING)
static void
vesa_cliparound(int x, int y)
{
@@ -857,7 +864,8 @@ vesa_redrawmap(void)
free(p_row);
}
#endif /* USE_TILES && CLIPPING */
#endif /* TILES_IN_GLYPHMAP && CLIPPING */
void
vesa_userpan(enum vga_pan_direction pan)
@@ -1030,7 +1038,7 @@ vesa_Init(void)
if (inited) return;
inited = TRUE;
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
/*
* Attempt to open the required tile files. If we can't
* don't perform the video mode switch, use TTY code instead.
@@ -1082,7 +1090,7 @@ vesa_Init(void)
windowprocs.wincap2 |= WC2_U_24BITCOLOR;
}
#endif
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
paletteptr = get_palette();
iflags.tile_view = TRUE;
iflags.over_view = FALSE;
@@ -1626,6 +1634,8 @@ vesa_flush_text(void)
chr_cache_size = 0;
}
extern uint32 curframecolor; /* video.c */
static void
vesa_WriteTextRow(int pixx, int pixy, struct VesaCharacter const *t_row,
unsigned t_row_width)
@@ -1637,6 +1647,7 @@ vesa_WriteTextRow(int pixx, int pixy, struct VesaCharacter const *t_row,
unsigned long offset = pixy * (unsigned long)vesa_scan_line + pixx * vesa_pixel_bytes;
unsigned char fg[4], bg[4];
#if 0
/* Preprocess the background color */
if (vesa_pixel_bytes == 1) {
bg[0] = BACKGROUND_VESA_COLOR;
@@ -1647,6 +1658,7 @@ vesa_WriteTextRow(int pixx, int pixy, struct VesaCharacter const *t_row,
bg[2] = (pix >> 16) & 0xFF;
bg[3] = (pix >> 24) & 0xFF;
}
#endif
/* First loop: draw one raster line of all row entries */
for (py = 0; py < (int) vesa_char_height; ++py) {
@@ -1655,6 +1667,17 @@ vesa_WriteTextRow(int pixx, int pixy, struct VesaCharacter const *t_row,
for (i = 0; i < t_row_width; ++i) {
uint32 chr = t_row[i].chr;
uint32 colour = t_row[i].colour;
/* background color */
if (vesa_pixel_bytes == 1) {
bg[0] = BACKGROUND_VESA_COLOR;
} else {
unsigned long pix = vesa_palette[t_row[i].bgcolour];
bg[0] = pix & 0xFF;
bg[1] = (pix >> 8) & 0xFF;
bg[2] = (pix >> 16) & 0xFF;
bg[3] = (pix >> 24) & 0xFF;
}
/* Preprocess the foreground color */
if (colour & 0x80000000) {
fg[0] = colour & 0xFF;
@@ -1910,7 +1933,7 @@ vesa_SetHardPalette(const struct Pixel *palette)
/* First, try the VESA palette function */
/* Set the tile set and text colors */
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
for (i = 0; i < FIRST_TEXT_COLOR; ++i) {
p2[i*4 + 0] = palette[i].b >> shift;
p2[i*4 + 1] = palette[i].g >> shift;
@@ -1937,7 +1960,7 @@ vesa_SetHardPalette(const struct Pixel *palette)
/* If that didn't work, use the original BIOS function */
if (regs.x.ax != 0x004F) {
/* Set the tile set and text colors */
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
for (i = 0; i < FIRST_TEXT_COLOR; ++i) {
p2[i*3 + 0] = palette[i].r >> shift;
p2[i*3 + 1] = palette[i].g >> shift;
@@ -1976,7 +1999,7 @@ vesa_SetSoftPalette(const struct Pixel *palette)
unsigned i;
/* Set the tile set and text colors */
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
if (palette != NULL) {
p = palette;
for (i = 0; i < FIRST_TEXT_COLOR; ++i) {

View File

@@ -143,7 +143,7 @@ extern int attrib_gr_normal; /* graphics mode normal attribute */
extern int attrib_text_intense; /* text mode intense attribute */
extern int attrib_gr_intense; /* graphics mode intense attribute */
extern boolean inmap; /* in the map window */
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
extern glyph_map glyphmap[MAX_GLYPH];
#endif
@@ -162,6 +162,7 @@ static struct map_struct {
int attr;
unsigned special;
short int tileidx;
uint32 framecolor;
} map[ROWNO][COLNO]; /* track the glyphs */
extern int total_tiles_used, Tile_corr, Tile_unexplored; /* from tile.c */
@@ -173,6 +174,7 @@ extern int total_tiles_used, Tile_corr, Tile_unexplored; /* from tile.c */
for (x = 0; x < COLNO; ++x) { \
map[y][x].glyph = GLYPH_UNEXPLORED; \
map[y][x].ch = glyph2ttychar(GLYPH_UNEXPLORED); \
map[y][x].framecolor = NO_COLOR; \
map[y][x].attr = 0; \
map[y][x].special = 0; \
map[y][x].tileidx = Tile_unexplored; \
@@ -361,10 +363,11 @@ void vga_xputc(char ch, int attr)
vga_gotoloc(col, row);
}
#if defined(USE_TILES)
#if defined(TILES_IN_GLYPHMAP)
/* Place tile represent. a glyph at current location */
void
vga_xputg(const glyph_info *glyphinfo)
vga_xputg(const glyph_info *glyphinfo,
const glyph_info *bkglyphinfo)
{
int glyphnum = glyphinfo->glyph;
uint32 ch = glyphinfo->ttychar;
@@ -399,6 +402,10 @@ vga_xputg(const glyph_info *glyphinfo)
attr = (g_attribute == 0) ? attrib_gr_normal : g_attribute;
map[ry][col].attr = attr;
map[ry][col].tileidx = glyphinfo->gm.tileidx;
if (bkglyphinfo->framecolor != NO_COLOR) {
map[ry][col].framecolor = bkglyphinfo->framecolor;
}
if (iflags.traditional_view) {
vga_WriteChar(ch, col, row, attr);
} else if (!iflags.over_view) {
@@ -416,7 +423,7 @@ vga_xputg(const glyph_info *glyphinfo)
++col;
vga_gotoloc(col, row);
}
#endif /* USE_TILES */
#endif /* TILES_IN_GLYPHMAP */
/*
* Cursor location manipulation, and location information fetching
@@ -437,7 +444,7 @@ vga_gotoloc(int col, int row)
currow = min(row, LI - 1);
}
#if defined(USE_TILES) && defined(CLIPPING)
#if defined(TILES_IN_GLYPHMAP) && defined(CLIPPING)
static void
vga_cliparound(int x, int y UNUSED)
{
@@ -506,7 +513,7 @@ vga_redrawmap(boolean clearfirst)
}
}
}
#endif /* USE_TILES && CLIPPING */
#endif /* TILES_IN_GLYPHMAP && CLIPPING */
void
vga_userpan(enum vga_pan_direction pan)
@@ -736,7 +743,7 @@ vga_Init(void)
int i;
const char *font_name;
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
const char *tile_file;
int tilefailure = 0;
/*
@@ -776,7 +783,7 @@ vga_Init(void)
windowprocs.win_cliparound = vga_cliparound;
/* vga_NoBorder(BACKGROUND_VGA_COLOR); */ /* Not needed after palette
mod */
#ifdef USE_TILES
#ifdef TILES_IN_GLYPHMAP
paletteptr = get_palette();
iflags.tile_view = TRUE;
iflags.over_view = FALSE;
@@ -930,6 +937,8 @@ vga_detect(void)
return 0;
}
extern int curframecolor; /* video.c */
/*
* Write character 'ch', at (x,y) and
* do it using the colour 'colour'.
@@ -944,16 +953,21 @@ vga_WriteChar(uint32 chr, int col, int row, int colour)
char __far *cp;
unsigned char fnt;
int actual_colour = vgacmap[colour];
int bgcolor;
int vplane;
unsigned char bitmap[ROWS_PER_CELL];
/* if (chr < ' ') chr = ' '; */ /* assumes ASCII set */
vga_GetBitmap(chr, bitmap);
if (curframecolor != NO_COLOR)
bgcolor = vgacmap[curframecolor];
else
bgcolor = BACKGROUND_VGA_COLOR;
x = min(col, (CO - 1)); /* min() used protection from callers */
pixy = min(row, (LI - 1)) * 16; /* assumes 8 x 16 char set */
vplane = ~actual_colour & ~BACKGROUND_VGA_COLOR & 0xF;
vplane = ~actual_colour & ~bgcolor & 0xF;
if (vplane != 0) {
egawriteplane(vplane);
for (i = 0; i < MAX_ROWS_PER_CELL; ++i) {
@@ -961,7 +975,7 @@ vga_WriteChar(uint32 chr, int col, int row, int colour)
WRITE_ABSOLUTE(cp, (char) 0x00);
}
}
vplane = actual_colour & ~BACKGROUND_VGA_COLOR & 0xF;
vplane = actual_colour & ~bgcolor & 0xF;
if (vplane != 0) {
egawriteplane(vplane);
for (i = 0; i < MAX_ROWS_PER_CELL; ++i) {
@@ -970,7 +984,7 @@ vga_WriteChar(uint32 chr, int col, int row, int colour)
WRITE_ABSOLUTE(cp, (char) fnt);
}
}
vplane = ~actual_colour & BACKGROUND_VGA_COLOR & 0xF;
vplane = ~actual_colour & bgcolor & 0xF;
if (vplane != 0) {
egawriteplane(vplane);
for (i = 0; i < MAX_ROWS_PER_CELL; ++i) {
@@ -979,7 +993,7 @@ vga_WriteChar(uint32 chr, int col, int row, int colour)
WRITE_ABSOLUTE(cp, (char) fnt);
}
}
vplane = actual_colour & BACKGROUND_VGA_COLOR & 0xF;
vplane = actual_colour & bgcolor & 0xF;
if (vplane != 0) {
egawriteplane(vplane);
for (i = 0; i < MAX_ROWS_PER_CELL; ++i) {

View File

@@ -155,7 +155,8 @@ override TARGET_AR = $(TOOLTOP1)/i586-pc-msdosdjgpp-gcc-ar
override TARGET_STUBEDIT = ../lib/djgpp/i586-pc-msdosdjgpp/bin/stubedit
MSDOS_TARGET_CFLAGS = -c -O -I../include -I../sys/msdos -I../win/share \
$(LUAINCL) -DDLB $(PDCURSESDEF) \
-DUSE_TILES -DCROSSCOMPILE -DCROSSCOMPILE_TARGET -DCROSS_TO_MSDOS \
-DTILES_IN_GLYPHMAP -DCROSSCOMPILE -DCROSSCOMPILE_TARGET \
-DCROSS_TO_MSDOS \
-Wall -Wextra -Wno-missing-field-initializers -Wreturn-type -Wunused \
-Wformat -Wswitch -Wshadow -Wwrite-strings \
-Wimplicit -Wimplicit-function-declaration -Wimplicit-int \

View File

@@ -2003,6 +2003,7 @@ clean:
# * -c (which is included in cflagsBuild) substituted with -Fo$@
# * "-o $@ " is removed
# * win/X11/Window.o commented due to conflict with pdcurses
# * win/share/cppregex.o commented out due to earlier rule
# * commented out $(TARGETPFX)tile.o: tile.c $(HACK_H)
# * commented out $(TARGETPFX)cppregex.o because it has its own rule already
# * $(TARGETPFX) becomes $(OTTY) in 1st batch with $(TTYDEF)

View File

@@ -86,6 +86,7 @@ typedef struct {
WORD attr;
long color24;
int color256idx;
const char *bkcolorseq;
const char *colorseq;
#endif /* VIRTUAL_TERMINAL_SEQUENCES */
} cell_t;
@@ -170,6 +171,7 @@ struct console_t {
WORD foreground;
WORD attr;
int current_nhcolor;
int current_nhbkcolor;
int current_nhattr[ATR_INVERSE+1];
COORD cursor;
HANDLE hConOut;
@@ -210,6 +212,7 @@ struct console_t {
(FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED), /* foreground */
0, /* attr */
0, /* current_nhcolor */
0, /* current_nhbkcolor */
#endif /* VIRTUAL_TERMINAL_SEQUENCES */
{FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
#ifndef VIRTUAL_TERMINAL_SEQUENCES
@@ -313,6 +316,7 @@ static INPUT_RECORD bogus_key;
#ifdef VIRTUAL_TERMINAL_SEQUENCES
long customcolors[CLR_MAX];
const char *esc_seq_colors[CLR_MAX];
const char *esc_seq_bkcolors[CLR_MAX];
struct rgbvalues {
int idx;
@@ -471,6 +475,8 @@ rgbtable_to_long(struct rgbvalues *tbl)
static void
init_custom_colors(void)
{
char bkcolorbuf[32];
customcolors[CLR_BLACK] = rgbtable_to_long(&rgbtable[131]);
customcolors[CLR_RED] = rgbtable_to_long(&rgbtable[5]);
customcolors[CLR_GREEN] = rgbtable_to_long(&rgbtable[31]);
@@ -507,6 +513,40 @@ init_custom_colors(void)
esc_seq_colors[CLR_BRIGHT_BLUE] = "\x1b[34m\x1b[94m";
esc_seq_colors[CLR_BRIGHT_MAGENTA] = "\x1b[35m\x1b[95m";
esc_seq_colors[CLR_BRIGHT_CYAN] = "\x1b[36m\x1b[96m";
/* Sprintf(tmp, "\033[%dm", ((color % 8) + 40)); */
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_BLACK % 8) + 40));
esc_seq_bkcolors[CLR_BLACK] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_RED % 8) + 40));
esc_seq_bkcolors[CLR_RED] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_GREEN % 8) + 40));
esc_seq_bkcolors[CLR_GREEN] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_YELLOW % 8) + 40));
esc_seq_bkcolors[CLR_YELLOW] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_BLUE % 8) + 40));
esc_seq_bkcolors[CLR_BLUE] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_MAGENTA % 8) + 40));
esc_seq_bkcolors[CLR_MAGENTA] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_CYAN % 8) + 40));
esc_seq_bkcolors[CLR_CYAN] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_WHITE % 8) + 40));
esc_seq_bkcolors[CLR_WHITE] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_BROWN % 8) + 40));
esc_seq_bkcolors[CLR_BROWN] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_GRAY % 8) + 40));
esc_seq_bkcolors[CLR_GRAY] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((NO_COLOR % 8) + 40));
esc_seq_bkcolors[NO_COLOR] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_ORANGE % 8) + 40));
esc_seq_bkcolors[CLR_ORANGE] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_BRIGHT_BLUE % 8) + 40));
esc_seq_bkcolors[CLR_BRIGHT_BLUE] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_BRIGHT_GREEN % 8) + 40));
esc_seq_bkcolors[CLR_BRIGHT_GREEN] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_BRIGHT_MAGENTA % 8) + 40));
esc_seq_bkcolors[CLR_BRIGHT_MAGENTA] = dupstr(bkcolorbuf);
Snprintf(bkcolorbuf, sizeof bkcolorbuf, "\x1b[%dm", ((CLR_BRIGHT_CYAN % 8) + 40));
esc_seq_bkcolors[CLR_BRIGHT_CYAN] = dupstr(bkcolorbuf);
}
void emit_start_bold(void);
@@ -715,18 +755,20 @@ DWORD error_result;
/* Console buffer flipping support */
#ifdef VIRTUAL_TERMINAL_SEQUENCES
enum do_flags {
do_utf8_content = 1,
do_wide_content = 2,
do_colorseq = 4,
do_color24 = 8,
do_newattr = 16
do_utf8_content = 0x01,
do_wide_content = 0x02,
do_colorseq = 0x04,
do_color24 = 0x08,
do_newattr = 0x10,
do_bkcolorseq = 0x20,
};
enum did_flags {
did_utf8_content = 1,
did_wide_content = 2,
did_colorseq = 4,
did_color24 = 8,
did_newattr = 16
did_utf8_content = 0x01,
did_wide_content = 0x02,
did_colorseq = 0x04,
did_color24 = 0x08,
did_newattr = 0x10,
did_bkcolorseq = 0x20,
};
static void
@@ -753,6 +795,8 @@ back_buffer_flip(void)
do_anything |= do_colorseq;
if (back->attr != front->attr)
do_anything |= do_newattr;
if (back->bkcolorseq != front->bkcolorseq)
do_anything |= do_bkcolorseq;
#ifdef UTF8_FROM_CORE
if (!SYMHANDLING(H_UTF8)) {
if (console.has_unicode
@@ -800,7 +844,15 @@ back_buffer_flip(void)
WriteConsoleA(console.hConOut, back->colorseq,
(int) strlen(back->colorseq), &unused,
&reserved);
} else {
}
if (back->bkcolorseq) {
did_anything |= did_bkcolorseq;
WriteConsoleA(console.hConOut, back->bkcolorseq,
(int) strlen(back->bkcolorseq), &unused,
&reserved);
}
if ((did_anything | (did_colorseq | did_bkcolorseq | did_color24)) == 0) {
did_anything &= ~(did_bkcolorseq | did_color24);
did_anything |= did_colorseq;
emit_default_color();
}
@@ -1276,6 +1328,7 @@ xputc_core(int ch)
/* this causes way too much performance degradation */
/* cell.color24 = customcolors[console.current_nhcolor]; */
cell.colorseq = esc_seq_colors[console.current_nhcolor];
cell.bkcolorseq = esc_seq_bkcolors[console.current_nhbkcolor];
cell.attr = console.attr;
// if (console.color24)
// __debugbreak();
@@ -1370,6 +1423,7 @@ g_putch(int in_ch)
#else
cell.attr = console.attr;
cell.colorseq = esc_seq_colors[console.current_nhcolor];
cell.bkcolorseq = esc_seq_bkcolors[console.current_nhbkcolor];
cell.color24 = console.color24 ? console.color24 : 0L;
cell.color256idx = 0;
wch[1] = 0;
@@ -1416,6 +1470,7 @@ g_pututf8(uint8 *sequence)
cell_t cell;
cell.attr = console.attr;
cell.colorseq = esc_seq_colors[console.current_nhcolor];
cell.bkcolorseq = esc_seq_bkcolors[console.current_nhbkcolor];
cell.color24 = console.color24 ? console.color24 : 0L;
cell.color256idx =console.color256idx ? console.color256idx : 0;
Snprintf((char *) cell.utf8str, sizeof cell.utf8str, "%s",
@@ -1718,6 +1773,17 @@ term_start_color(int color)
console.current_nhcolor = NO_COLOR;
}
void
term_start_bgcolor(int color)
{
#ifdef TEXTCOLOR
if (color >= 0 && color < CLR_MAX) {
console.current_nhbkcolor = color;
} else
#endif
console.current_nhbkcolor = NO_COLOR;
}
void
term_end_color(void)
{
@@ -1728,6 +1794,7 @@ term_end_color(void)
console.attr = (console.foreground | console.background);
#endif /* ! VIRTUAL_TERMINAL_SEQUENCES */
console.current_nhcolor = NO_COLOR;
console.current_nhbkcolor = NO_COLOR;
}
void
@@ -1849,7 +1916,7 @@ tty_utf8graphics_fixup(void)
/* the locale */
if (console.localestr)
free(console.localestr);
console.localestr = strdup(setlocale(LC_ALL, ".UTF8"));
console.localestr = dupstr(setlocale(LC_ALL, ".UTF8"));
/* the code page */
SetConsoleOutputCP(65001);
console.code_page = GetConsoleOutputCP();
@@ -1917,7 +1984,7 @@ tty_ibmgraphics_fixup(void)
if (localestr) {
if (console.localestr)
free(console.localestr);
console.localestr = strdup(localestr);
console.localestr = dupstr(localestr);
}
set_known_good_console_font();
/* the console mode */
@@ -2201,7 +2268,7 @@ restore_original_console_font(void)
if (tmplocalestr) {
if (console.localestr)
free(console.localestr);
console.localestr = strdup(tmplocalestr);
console.localestr = dupstr(tmplocalestr);
}
success = SetConsoleOutputCP(console.orig_code_page);
#endif /* VIRTUAL_TERMINAL_SEQUENCES */
@@ -2455,7 +2522,7 @@ void nethack_enter_consoletty(void)
if (localestr) {
if (console.localestr)
free(console.localestr);
console.localestr = strdup(localestr);
console.localestr = dupstr(localestr);
}
console.code_page = console.orig_code_page;
if (console.has_unicode) {