tty/wintty.c w/o TEXTCOLOR
With TEXTCOLOR disabled, compiler warnings about term_start_color()
and term_end_color() not being declared were followed by link failure
because they weren't available.
This tries to simplify color handling in the tty status code without
resorting to #if TEXTCOLOR (the proper fix, but somewhat intrusive).
For the usual case where TEXTCOLOR is defined, there were instances
of
if (color != NO_COLOR && color != CLR_MAX)
term_start_color();
...
if (color != NO_COLOR)
term_end_color();
and also of
if (color != NO_COLOR)
term_start_color();
...
if (color != NO_COLOR)
term_end_color();
I've changed both types to be
if (color != NO_COLOR && color != CLR_MAX)
term_start_color();
...
if (color != NO_COLOR && color != CLR_MAX)
term_end_color();
so that start/end pairing will always be consistent.
Also, ((color_and_attr & 0xFF00) >> 8) might not work as intended if
using 16-bit int and color_and_attr happened to have its sign bit set.
Change to ((color_and_attr >> 8) & 0x00FF) to ensure just the desired
bits.
Also also, a couple more formatting bits.
This commit is contained in:
+44
-44
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.6 wintty.c $NHDT-Date: 1526382995 2018/05/15 11:16:35 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.164 $ */
|
/* NetHack 3.6 wintty.c $NHDT-Date: 1526429383 2018/05/16 00:09:43 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.166 $ */
|
||||||
/* Copyright (c) David Cohrs, 1991 */
|
/* Copyright (c) David Cohrs, 1991 */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -3493,7 +3493,9 @@ const char *fieldnames[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef STATUS_HILITES
|
#ifdef STATUS_HILITES
|
||||||
|
#ifdef TEXTCOLOR
|
||||||
STATIC_DCL int FDECL(condcolor, (long, unsigned long *));
|
STATIC_DCL int FDECL(condcolor, (long, unsigned long *));
|
||||||
|
#endif
|
||||||
STATIC_DCL int FDECL(condattr, (long, unsigned long *));
|
STATIC_DCL int FDECL(condattr, (long, unsigned long *));
|
||||||
static unsigned long *tty_colormasks;
|
static unsigned long *tty_colormasks;
|
||||||
static long tty_condition_bits;
|
static long tty_condition_bits;
|
||||||
@@ -3624,13 +3626,13 @@ tty_status_init()
|
|||||||
* the textual gold amount without the leading "$:" the port will
|
* the textual gold amount without the leading "$:" the port will
|
||||||
* have to skip past ':' in the passed "ptr" for the BL_GOLD case.
|
* have to skip past ':' in the passed "ptr" for the BL_GOLD case.
|
||||||
* -- color is an unsigned int.
|
* -- color is an unsigned int.
|
||||||
* color_index = color & 0x00FF; CLR_* value
|
* color_index = color & 0x00FF; CLR_* value
|
||||||
* attribute = color & 0xFF00 >> 8; BL_* values
|
* attribute = (color >> 8) & 0x00FF; HL_ATTCLR_* mask
|
||||||
* This holds the color and attribute that the field should
|
* This holds the color and attribute that the field should
|
||||||
* be displayed in.
|
* be displayed in.
|
||||||
* This is relevant for everything except BL_CONDITION fldindex.
|
* This is relevant for everything except BL_CONDITION fldindex.
|
||||||
* If fldindex is BL_CONDITION, this parameter should be ignored,
|
* If fldindex is BL_CONDITION, this parameter should be ignored,
|
||||||
* as condition hilighting is done via the next colormasks
|
* as condition highlighting is done via the next colormasks
|
||||||
* parameter instead.
|
* parameter instead.
|
||||||
*
|
*
|
||||||
* -- colormasks - pointer to cond_hilites[] array of colormasks.
|
* -- colormasks - pointer to cond_hilites[] array of colormasks.
|
||||||
@@ -3653,16 +3655,15 @@ unsigned long *colormasks;
|
|||||||
char *text = (char *) ptr;
|
char *text = (char *) ptr;
|
||||||
char *lastchar = (char *) 0;
|
char *lastchar = (char *) 0;
|
||||||
char *fval = (char *) 0;
|
char *fval = (char *) 0;
|
||||||
boolean do_color = FALSE;
|
|
||||||
boolean force_update = FALSE;
|
boolean force_update = FALSE;
|
||||||
|
|
||||||
#ifdef TEXTCOLOR
|
|
||||||
do_color = TRUE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fldidx != BL_FLUSH && !status_activefields[fldidx])
|
if (fldidx != BL_FLUSH && !status_activefields[fldidx])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifndef TEXTCOLOR
|
||||||
|
color = (color & ~0x00FF) | NO_COLOR;
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (fldidx) {
|
switch (fldidx) {
|
||||||
case BL_FLUSH:
|
case BL_FLUSH:
|
||||||
force_update = TRUE;
|
force_update = TRUE;
|
||||||
@@ -3680,8 +3681,8 @@ unsigned long *colormasks;
|
|||||||
Sprintf(status_vals[fldidx],
|
Sprintf(status_vals[fldidx],
|
||||||
status_fieldfmt[fldidx] ? status_fieldfmt[fldidx] : "%s",
|
status_fieldfmt[fldidx] ? status_fieldfmt[fldidx] : "%s",
|
||||||
text);
|
text);
|
||||||
tty_status[NOW][fldidx].color = do_color ? (color & 0x00FF) : NO_COLOR;
|
tty_status[NOW][fldidx].color = (color & 0x00FF);
|
||||||
tty_status[NOW][fldidx].attr = (color & 0xFF00) >> 8;
|
tty_status[NOW][fldidx].attr = ((color >> 8) & 0x00FF);
|
||||||
tty_status[NOW][fldidx].lth = strlen(status_vals[fldidx]);
|
tty_status[NOW][fldidx].lth = strlen(status_vals[fldidx]);
|
||||||
tty_status[NOW][fldidx].valid = TRUE;
|
tty_status[NOW][fldidx].valid = TRUE;
|
||||||
tty_status[NOW][fldidx].dirty = TRUE;
|
tty_status[NOW][fldidx].dirty = TRUE;
|
||||||
@@ -3690,11 +3691,10 @@ unsigned long *colormasks;
|
|||||||
|
|
||||||
/* The core botl engine sends a single blank to the window port
|
/* The core botl engine sends a single blank to the window port
|
||||||
for carrying-capacity when its unused. Let's suppress that */
|
for carrying-capacity when its unused. Let's suppress that */
|
||||||
if (tty_status[NOW][fldidx].lth == 1
|
if (tty_status[NOW][fldidx].lth == 1 && status_vals[fldidx][0] == ' ') {
|
||||||
&& status_vals[fldidx][0] == ' ') {
|
status_vals[fldidx][0] = '\0';
|
||||||
status_vals[fldidx][0] = '\0';
|
tty_status[NOW][fldidx].lth = 0;
|
||||||
tty_status[NOW][fldidx].lth = 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* default processing above was required before these */
|
/* default processing above was required before these */
|
||||||
switch (fldidx) {
|
switch (fldidx) {
|
||||||
@@ -3702,7 +3702,7 @@ unsigned long *colormasks;
|
|||||||
if (iflags.wc2_hitpointbar) {
|
if (iflags.wc2_hitpointbar) {
|
||||||
/* Special additional processing for hitpointbar */
|
/* Special additional processing for hitpointbar */
|
||||||
hpbar_percent = percent;
|
hpbar_percent = percent;
|
||||||
hpbar_color = do_color ? (color & 0x00FF) : NO_COLOR;
|
hpbar_color = (color & 0x00FF);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BL_LEVELDESC:
|
case BL_LEVELDESC:
|
||||||
@@ -3721,7 +3721,7 @@ unsigned long *colormasks;
|
|||||||
tty_status[NOW][fldidx].lth += 2; /* '[' and ']' */
|
tty_status[NOW][fldidx].lth += 2; /* '[' and ']' */
|
||||||
break;
|
break;
|
||||||
case BL_GOLD:
|
case BL_GOLD:
|
||||||
tty_status[NOW][fldidx].lth -= 9; /* \GXXXXNNNN counts as 1 */
|
tty_status[NOW][fldidx].lth -= (10 - 1); /* \GXXXXNNNN counts as 1 */
|
||||||
break;
|
break;
|
||||||
case BL_CAP:
|
case BL_CAP:
|
||||||
fval = status_vals[fldidx];
|
fval = status_vals[fldidx];
|
||||||
@@ -4007,11 +4007,17 @@ unsigned long *bmarray;
|
|||||||
|
|
||||||
if (bm && bmarray)
|
if (bm && bmarray)
|
||||||
for (i = 0; i < CLR_MAX; ++i) {
|
for (i = 0; i < CLR_MAX; ++i) {
|
||||||
if (bmarray[i] && (bm & bmarray[i]))
|
if ((bm & bmarray[i]) != 0)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return NO_COLOR;
|
return NO_COLOR;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
/* might need something more elaborate if some compiler complains that
|
||||||
|
the condition where this gets used always has the same value */
|
||||||
|
#define condcolor(bm,bmarray) NO_COLOR
|
||||||
|
#define term_start_color(color) /*empty*/
|
||||||
|
#define term_end_color(color) /*empty*/
|
||||||
#endif /* TEXTCOLOR */
|
#endif /* TEXTCOLOR */
|
||||||
|
|
||||||
STATIC_OVL int
|
STATIC_OVL int
|
||||||
@@ -4024,8 +4030,8 @@ unsigned long *bmarray;
|
|||||||
|
|
||||||
if (bm && bmarray) {
|
if (bm && bmarray) {
|
||||||
for (i = HL_ATTCLR_DIM; i < BL_ATTCLR_MAX; ++i) {
|
for (i = HL_ATTCLR_DIM; i < BL_ATTCLR_MAX; ++i) {
|
||||||
if (bmarray[i] && (bm & bmarray[i])) {
|
if ((bm & bmarray[i]) != 0) {
|
||||||
switch(i) {
|
switch (i) {
|
||||||
case HL_ATTCLR_DIM:
|
case HL_ATTCLR_DIM:
|
||||||
attr |= HL_DIM;
|
attr |= HL_DIM;
|
||||||
break;
|
break;
|
||||||
@@ -4086,13 +4092,6 @@ render_status(VOID_ARGS)
|
|||||||
long mask = 0L;
|
long mask = 0L;
|
||||||
int i, c, row, attrmask = 0;
|
int i, c, row, attrmask = 0;
|
||||||
struct WinDesc *cw = 0;
|
struct WinDesc *cw = 0;
|
||||||
boolean do_color =
|
|
||||||
#ifdef TEXTCOLOR
|
|
||||||
TRUE
|
|
||||||
#else
|
|
||||||
FALSE
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
struct tty_status_fields *nullfield = (struct tty_status_fields *) 0;
|
struct tty_status_fields *nullfield = (struct tty_status_fields *) 0;
|
||||||
|
|
||||||
if (WIN_STATUS == WIN_ERR
|
if (WIN_STATUS == WIN_ERR
|
||||||
@@ -4139,11 +4138,10 @@ render_status(VOID_ARGS)
|
|||||||
if (iflags.hilite_delta) {
|
if (iflags.hilite_delta) {
|
||||||
attrmask = condattr(mask, tty_colormasks);
|
attrmask = condattr(mask, tty_colormasks);
|
||||||
Begin_Attr(attrmask);
|
Begin_Attr(attrmask);
|
||||||
if (do_color) {
|
coloridx = condcolor(mask, tty_colormasks);
|
||||||
coloridx = condcolor(mask, tty_colormasks);
|
if (coloridx != NO_COLOR
|
||||||
if (coloridx != NO_COLOR)
|
&& coloridx != CLR_MAX)
|
||||||
term_start_color(coloridx);
|
term_start_color(coloridx);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (x >= cw->cols && !truncation_expected)
|
if (x >= cw->cols && !truncation_expected)
|
||||||
impossible(
|
impossible(
|
||||||
@@ -4152,15 +4150,19 @@ render_status(VOID_ARGS)
|
|||||||
tty_putstatusfield(nullfield, condtext, x, y);
|
tty_putstatusfield(nullfield, condtext, x, y);
|
||||||
x += (int) strlen(condtext);
|
x += (int) strlen(condtext);
|
||||||
if (iflags.hilite_delta) {
|
if (iflags.hilite_delta) {
|
||||||
if (do_color && coloridx != NO_COLOR)
|
if (coloridx != NO_COLOR
|
||||||
|
&& coloridx != CLR_MAX)
|
||||||
term_end_color();
|
term_end_color();
|
||||||
End_Attr(attrmask);
|
End_Attr(attrmask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (x >= cw->cols) {
|
if (x >= cw->cols) {
|
||||||
if (!truncation_expected)
|
static unsigned once_only = 0;
|
||||||
paniclog("render_status()", " unexpected truncation.");
|
|
||||||
|
if (!truncation_expected && !once_only++)
|
||||||
|
paniclog(
|
||||||
|
"render_status()", " unexpected truncation.");
|
||||||
x = cw->cols - 1;
|
x = cw->cols - 1;
|
||||||
}
|
}
|
||||||
tty_curs(WIN_STATUS, x, y);
|
tty_curs(WIN_STATUS, x, y);
|
||||||
@@ -4175,15 +4177,14 @@ render_status(VOID_ARGS)
|
|||||||
if (iflags.hilite_delta) {
|
if (iflags.hilite_delta) {
|
||||||
/* multiple attributes can be in effect concurrently */
|
/* multiple attributes can be in effect concurrently */
|
||||||
Begin_Attr(attridx);
|
Begin_Attr(attridx);
|
||||||
if (do_color && coloridx != NO_COLOR
|
if (coloridx != NO_COLOR && coloridx != CLR_MAX)
|
||||||
&& coloridx != CLR_MAX)
|
|
||||||
term_start_color(coloridx);
|
term_start_color(coloridx);
|
||||||
}
|
}
|
||||||
/* decode_mixed() due to GOLD glyph */
|
/* decode_mixed() due to GOLD glyph */
|
||||||
tty_putstatusfield(nullfield,
|
tty_putstatusfield(nullfield,
|
||||||
decode_mixed(buf, text), x, y);
|
decode_mixed(buf, text), x, y);
|
||||||
if (iflags.hilite_delta) {
|
if (iflags.hilite_delta) {
|
||||||
if (do_color && coloridx != NO_COLOR)
|
if (coloridx != NO_COLOR && coloridx != CLR_MAX)
|
||||||
term_end_color();
|
term_end_color();
|
||||||
End_Attr(attridx);
|
End_Attr(attridx);
|
||||||
}
|
}
|
||||||
@@ -4216,13 +4217,13 @@ render_status(VOID_ARGS)
|
|||||||
}
|
}
|
||||||
if (iflags.hilite_delta) {
|
if (iflags.hilite_delta) {
|
||||||
tty_putstatusfield(nullfield, "[", x++, y);
|
tty_putstatusfield(nullfield, "[", x++, y);
|
||||||
if (do_color && hpbar_color != NO_COLOR)
|
if (hpbar_color != NO_COLOR && coloridx != CLR_MAX)
|
||||||
term_start_color(hpbar_color);
|
term_start_color(hpbar_color);
|
||||||
term_start_attr(ATR_INVERSE);
|
term_start_attr(ATR_INVERSE);
|
||||||
tty_putstatusfield(nullfield, bar, x, y);
|
tty_putstatusfield(nullfield, bar, x, y);
|
||||||
x += (int) strlen(bar);
|
x += (int) strlen(bar);
|
||||||
term_end_attr(ATR_INVERSE);
|
term_end_attr(ATR_INVERSE);
|
||||||
if (do_color && hpbar_color != NO_COLOR)
|
if (hpbar_color != NO_COLOR && coloridx != CLR_MAX)
|
||||||
term_end_color();
|
term_end_color();
|
||||||
if (twoparts) {
|
if (twoparts) {
|
||||||
*bar2 = savedch;
|
*bar2 = savedch;
|
||||||
@@ -4249,14 +4250,13 @@ render_status(VOID_ARGS)
|
|||||||
}
|
}
|
||||||
/* multiple attributes can be in effect concurrently */
|
/* multiple attributes can be in effect concurrently */
|
||||||
Begin_Attr(attridx);
|
Begin_Attr(attridx);
|
||||||
if (do_color && coloridx != NO_COLOR
|
if (coloridx != NO_COLOR && coloridx != CLR_MAX)
|
||||||
&& coloridx != CLR_MAX)
|
|
||||||
term_start_color(coloridx);
|
term_start_color(coloridx);
|
||||||
}
|
}
|
||||||
tty_putstatusfield(&tty_status[NOW][fldidx],
|
tty_putstatusfield(&tty_status[NOW][fldidx],
|
||||||
text, x, y);
|
text, x, y);
|
||||||
if (iflags.hilite_delta) {
|
if (iflags.hilite_delta) {
|
||||||
if (do_color && coloridx != NO_COLOR)
|
if (coloridx != NO_COLOR && coloridx != CLR_MAX)
|
||||||
term_end_color();
|
term_end_color();
|
||||||
End_Attr(attridx);
|
End_Attr(attridx);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user