ENHANCED_SYMBOLS: store all CLR_ colors specially

The 0x1000000 bit (NH_BASIC_COLOR bit) was used to mark
CLR_BLACK when storing it in u->ucolor. Now, all of the basic CLR_*
colors are stored that way.

The NH_BASIC_COLOR bit indicates that the value in u->ucolor is
not an rgb value, rather it is one of the 0-15 basic NetHack colors.
The window-ports need to strip the NH_BASIC_COLOR bit off before using
it for color changes.
This commit is contained in:
nhmall
2024-03-03 18:31:11 -05:00
parent 3fb35e390b
commit 6619d10d90
10 changed files with 103 additions and 69 deletions

View File

@@ -629,28 +629,28 @@ start: Enhanced1
S_expl_ml: U+258f # LEFT ONE EIGHTH BLOCK
S_expl_mr: U+2595 # RIGHT ONE EIGHTH BLOCK
S_expl_bc: U+2581 # LOWER ONE EIGHTH BLOCK
G_vwall_sokoban: U+2502/0-0-190
G_hwall_sokoban: U+2500/0-0-190
G_tlcorn_sokoban: U+250c/0-0-190
G_trcorn_sokoban: U+2510/0-0-190
G_blcorn_sokoban: U+2514/0-0-190
G_brcorn_sokoban: U+2518/0-0-190
G_crwall_sokoban: U+253C/0-0-190
G_tuwall_sokoban: U+2534/0-0-190
G_tdwall_sokoban: U+252C/0-0-190
G_tlwall_sokoban: U+2524/0-0-190
G_trwall_sokoban: U+251C/0-0-190
G_vwall_gehennom: U+2502/190-0-0
G_hwall_gehennom: U+2500/190-0-0
G_tlcorn_gehennom: U+250c/190-0-0
G_trcorn_gehennom: U+2510/190-0-0
G_blcorn_gehennom: U+2514/190-0-0
G_brcorn_gehennom: U+2518/190-0-0
G_crwall_gehennom: U+253C/190-0-0
G_tuwall_gehennom: U+2534/190-0-0
G_tdwall_gehennom: U+252C/190-0-0
G_tlwall_gehennom: U+2524/190-0-0
G_trwall_gehennom: U+251C/190-0-0
G_vwall_sokoban: U+2502/blue
G_hwall_sokoban: U+2500/blue
G_tlcorn_sokoban: U+250c/blue
G_trcorn_sokoban: U+2510/blue
G_blcorn_sokoban: U+2514/blue
G_brcorn_sokoban: U+2518/blue
G_crwall_sokoban: U+253C/blue
G_tuwall_sokoban: U+2534/blue
G_tdwall_sokoban: U+252C/blue
G_tlwall_sokoban: U+2524/blue
G_trwall_sokoban: U+251C/blue
G_vwall_gehennom: U+2502/red
G_hwall_gehennom: U+2500/red
G_tlcorn_gehennom: U+250c/red
G_trcorn_gehennom: U+2510/red
G_blcorn_gehennom: U+2514/red
G_brcorn_gehennom: U+2518/red
G_crwall_gehennom: U+253C/red
G_tuwall_gehennom: U+2534/red
G_tdwall_gehennom: U+252C/red
G_tlwall_gehennom: U+2524/red
G_trwall_gehennom: U+251C/red
G_vwall_knox: U+2502/150-75-0
G_hwall_knox: U+2500/150-75-0
G_tlcorn_knox: U+250c/150-75-0

View File

@@ -54,6 +54,8 @@
#define DRAGON_SILVER CLR_BRIGHT_CYAN
#define HI_ZAP CLR_BRIGHT_BLUE
#define NH_BASIC_COLOR 0x1000000
enum nhcolortype { no_color, nh_color, rgb_color };
struct nethack_color {

View File

@@ -293,13 +293,13 @@ extern const char *attr2attrname(int);
extern void basic_menu_colors(boolean);
extern boolean add_menu_coloring_parsed(const char *, int, int);
extern const char *clr2colorname(int);
extern int match_str2clr(char *) NONNULLARG1;
extern int match_str2clr(char *, boolean) NONNULLARG1;
extern int match_str2attr(const char *, boolean) NONNULLARG1;
extern boolean add_menu_coloring(char *) NONNULLARG1;
extern void free_one_menu_coloring(int);
extern void free_menu_coloring(void);
extern int count_menucolors(void);
extern int32 check_enhanced_colors(const char *) NONNULLARG1;
extern int32 check_enhanced_colors(char *) NONNULLARG1;
/* ### cmd.c ### */

View File

@@ -2780,7 +2780,7 @@ parse_status_hl2(char (*s)[QBUFSZ], boolean from_configfile)
else if (a == ATR_NONE)
disp_attrib = HL_NONE;
else {
int c = match_str2clr(subfields[i]);
int c = match_str2clr(subfields[i], FALSE);
if (c >= CLR_MAX || coloridx != -1) {
config_error_add("bad color '%d %d'", c, coloridx);
@@ -3052,7 +3052,7 @@ parse_condition(char (*s)[QBUFSZ], int sidx)
gc.cond_hilites[HL_ATTCLR_BLINK] &= ~conditions_bitmask;
gc.cond_hilites[HL_ATTCLR_INVERSE] &= ~conditions_bitmask;
} else {
int k = match_str2clr(subfields[i]);
int k = match_str2clr(subfields[i], FALSE);
if (k >= CLR_MAX) {
config_error_add("bad color %d", k);

View File

@@ -62,22 +62,22 @@ static const struct attr_names attrnames[] = {
/* { colortyp, tableindex, rgbindx, name, hexval, r, g, b }, */
static struct nethack_color colortable[] = {
{ nh_color, 0, 0, "black", "#000000", 0, 0, 0 },
{ nh_color, 1, 0, "red", "#FF0000", 255, 0, 0 },
{ nh_color, 2, 0, "green", "#228B22", 34, 139, 34 },
{ nh_color, 3, 0, "brown", "#A52A2A", 165, 42, 42 },
{ nh_color, 4, 0, "blue", "#0000FF", 0, 0, 255 },
{ nh_color, 5, 0, "magenta", "#FF00FF", 255, 0, 255 },
{ nh_color, 6, 0, "cyan", "#00FFFF", 0, 255, 255 },
{ nh_color, 7, 0, "gray", "#808080", 128, 128, 128 },
{ no_color, 8, 0, "nocolor", "#000000", 0, 0, 0 },
{ nh_color, 9, 0, "orange", "#FFA500", 255, 165, 0 },
{ nh_color, 10, 0, "bright-green", "#008000", 0, 128, 0 },
{ nh_color, 11, 0, "yellow", "#FFFF00", 255, 255, 0 },
{ nh_color, 12, 0, "bright-blue", "#ADD8E6", 173, 216, 230 },
{ nh_color, 13, 0, "bright-magenta", "#9370DB", 147, 112, 219 },
{ nh_color, 14, 0, "light-cyan", "#E0FFFF", 224, 255, 255 },
{ nh_color, 15, 0, "white", "#FFFFFF", 255, 255, 255 },
{ nh_color, 0, 0, "black", "", 0, 0, 0 },
{ nh_color, 1, 0, "red", "", 255, 0, 0 },
{ nh_color, 2, 0, "green", "", 34, 139, 34 },
{ nh_color, 3, 0, "brown", "", 165, 42, 42 },
{ nh_color, 4, 0, "blue", "", 0, 0, 255 },
{ nh_color, 5, 0, "magenta", "", 255, 0, 255 },
{ nh_color, 6, 0, "cyan", "", 0, 255, 255 },
{ nh_color, 7, 0, "gray", "", 128, 128, 128 },
{ no_color, 8, 0, "nocolor", "", 0, 0, 0 },
{ nh_color, 9, 0, "orange", "", 255, 165, 0 },
{ nh_color, 10, 0, "bright-green", "", 0, 128, 0 },
{ nh_color, 11, 0, "yellow", "", 255, 255, 0 },
{ nh_color, 12, 0, "bright-blue", "", 173, 216, 230 },
{ nh_color, 13, 0, "bright-magenta", "", 147, 112, 219 },
{ nh_color, 14, 0, "light-cyan", "", 224, 255, 255 },
{ nh_color, 15, 0, "white", "", 255, 255, 255 },
{ rgb_color, 16, 0, "maroon", "#800000", 128, 0, 0 },
{ rgb_color, 17, 1, "dark-red", "#8B0000", 139, 0, 0 },
{ rgb_color, 18, 2, "brown", "#A52A2A", 165, 42, 42 },
@@ -222,7 +222,12 @@ static struct nethack_color colortable[] = {
int32
colortable_to_int32(struct nethack_color *cte)
{
int32 clr = (cte->r << 16) | (cte->g << 8) | cte->b;
int32 clr = NO_COLOR | NH_BASIC_COLOR;
if (cte->colortyp == rgb_color)
clr = (cte->r << 16) | (cte->g << 8) | cte->b;
else if (cte->colortyp == nh_color)
clr = cte->tableindex | NH_BASIC_COLOR;
return clr;
}
@@ -253,13 +258,13 @@ color_attr_parse_str(color_attr *ca, char *str)
if (amp) {
amp++;
c = match_str2clr(buf);
c = match_str2clr(buf, FALSE);
a = match_str2attr(amp, TRUE);
/* FIXME: match_str2clr & match_str2attr give config_error_add(),
so this is useless */
if (c >= CLR_MAX && a == -1) {
/* try other way around */
c = match_str2clr(amp);
c = match_str2clr(amp, FALSE);
a = match_str2attr(buf, TRUE);
}
if (c >= CLR_MAX || a == -1)
@@ -268,7 +273,7 @@ color_attr_parse_str(color_attr *ca, char *str)
/* one param only */
tmp = match_str2attr(buf, FALSE);
if (tmp == -1) {
tmp = match_str2clr(buf);
tmp = match_str2clr(buf, FALSE);
if (tmp >= CLR_MAX)
return FALSE;
c = tmp;
@@ -327,7 +332,7 @@ clr2colorname(int clr)
}
int
match_str2clr(char *str)
match_str2clr(char *str, boolean suppress_msg)
{
int i, c = CLR_MAX;
@@ -344,7 +349,8 @@ match_str2clr(char *str)
c = atoi(str);
if (c < 0 || c >= CLR_MAX) {
config_error_add("Unknown color '%.60s'", str);
if (!suppress_msg)
config_error_add("Unknown color '%.60s'", str);
c = CLR_MAX; /* "none of the above" */
}
return c;
@@ -608,7 +614,7 @@ add_menu_coloring(char *tmpstr) /* never Null but could be empty */
if ((amp = strchr(tmps, '&')) != 0)
*amp = '\0';
c = match_str2clr(tmps);
c = match_str2clr(tmps, FALSE);
if (c >= CLR_MAX)
return FALSE;
@@ -695,15 +701,19 @@ count_menucolors(void)
* buf is NONNULLARG1
*/
int32
check_enhanced_colors(const char *buf)
check_enhanced_colors(char *buf)
{
int c;
int32 retcolor = -1, color;
for (c = 0; c < SIZE(colortable); ++c) {
if (!strcmpi(buf, colortable[c].name))
return colortable_to_int32(&colortable[c]);
if ((color = match_str2clr(buf, TRUE)) != CLR_MAX) {
retcolor = color | NH_BASIC_COLOR;
} else {
for (color = 0; color < SIZE(colortable); ++color) {
if (!strcmpi(buf, colortable[color].name))
retcolor = colortable_to_int32(&colortable[color]);
}
}
return -1;
return retcolor;
}

View File

@@ -49,10 +49,11 @@ static int glyph_find_core(const char *id, struct find_struct *findwhat);
static char *fix_glyphname(char *str);
static int32_t rgbstr_to_int32(const char *rgbstr);
boolean closest_color(uint32_t lcolor, uint32_t *closecolor, int *clridx);
static const long nonzero_black = 0x1000000;
static int color_distance(uint32_t, uint32_t);
static boolean onlyhexdigits(const char *buf);
static const long nonzero_black = CLR_BLACK | NH_BASIC_COLOR;
static void
to_custom_symset_entry_callback(int glyph, struct find_struct *findwhat)
{

View File

@@ -587,7 +587,12 @@ void NetHackQtMapViewport::PrintGlyph(int x, int y,
&& glyphinfo->gm.u->utf8str) {
Glyphttychar(x, y) = glyphinfo->gm.u->utf32ch;
if (glyphinfo->gm.u->ucolor != 0) {
Glyphcolor(x, y) = glyphinfo->gm.u->ucolor | 0x80000000;
if ((glyphinfo->gm.u->ucolor & NH_BASIC_COLOR) == 0) {
Glyphcolor(x, y) = glyphinfo->gm.u->ucolor | 0x80000000;
} else {
Glyphcolor(x, y) =
(uint32) glyphinfo->gm.u->ucolor & ~NH_BASIC_COLOR;
}
}
}
#endif

View File

@@ -133,6 +133,12 @@ X11_print_glyph(
color = glyphinfo->gm.sym.color;
special = glyphinfo->gm.glyphflags;
ch = glyph_char(glyphinfo);
#ifdef ENHANCED_SYMBOLS
if (SYMHANDLING(H_UTF8) && glyphinfo->gm.u != NULL
&& glyphinfo->gm.u->ucolor != 0
&& (glyphinfo->gm.u->ucolor & NH_BASIC_COLOR) != 0)
color = glyphinfo->gm.u->ucolor & ~NH_BASIC_COLOR;
#endif
if (special != map_info->tile_map.glyphs[y][x].glyphflags) {
map_info->tile_map.glyphs[y][x].glyphflags = special;
@@ -156,11 +162,12 @@ X11_print_glyph(
color += colordif;
#ifdef ENHANCED_SYMBOLS
if (SYMHANDLING(H_UTF8) && glyphinfo->gm.u != NULL
&& glyphinfo->gm.u->ucolor != 0) {
color = glyphinfo->gm.u->ucolor | 0x80000000;
if (colordif != 0) {
color |= 0x40000000;
}
&& glyphinfo->gm.u->ucolor != 0
&& (glyphinfo->gm.u->ucolor & NH_BASIC_COLOR) == 0) {
color = glyphinfo->gm.u->ucolor | 0x80000000;
if (colordif != 0) {
color |= 0x40000000;
}
}
#endif
if (*co_ptr != color) {

View File

@@ -3844,9 +3844,13 @@ tty_print_glyph(
&& !calling_from_update_inventory
#endif
&& glyphinfo->gm.u && glyphinfo->gm.u->ucolor) {
term_start_24bitcolor(glyphinfo->gm.u);
color24bit_on = TRUE;
colordone = TRUE;
if ((glyphinfo->gm.u->ucolor & NH_BASIC_COLOR) == 0) {
term_start_24bitcolor(glyphinfo->gm.u);
color24bit_on = TRUE;
colordone = TRUE;
} else {
color = glyphinfo->gm.u->ucolor & ~NH_BASIC_COLOR;
}
}
#endif
if (!colordone) {

View File

@@ -978,10 +978,15 @@ paintGlyph(PNHMapWindow data, int i, int j, RECT * rect)
&& glyphinfo->gm.u->utf8str) {
ch = glyphinfo->gm.u->utf32ch;
if (glyphinfo->gm.u->ucolor != 0) {
rgbcolor = RGB(
(glyphinfo->gm.u->ucolor >> 16) & 0xFF,
(glyphinfo->gm.u->ucolor >> 8) & 0xFF,
(glyphinfo->gm.u->ucolor >> 0) & 0xFF);
if ((glyphinfo->gm.u->ucolor & NH_BASIC_COLOR) == 0) {
rgbcolor = RGB(
(glyphinfo->gm.u->ucolor >> 16) & 0xFF,
(glyphinfo->gm.u->ucolor >> 8) & 0xFF,
(glyphinfo->gm.u->ucolor >> 0) & 0xFF);
} else {
color = (int) (glyphinfo->gm.u->ucolor & ~NH_BASIC_COLOR);
rgbcolor = nhcolor_to_RGB(color);
}
}
}
#endif