Hilite Status: Improved

Allow defining multiple stops per field. Add hitpointbar.
This commit is contained in:
Pasi Kallinen
2017-09-26 10:04:25 +03:00
parent cac4344754
commit 69f7a78dba
37 changed files with 3227 additions and 1532 deletions
+1 -5
View File
@@ -5286,15 +5286,11 @@ struct window_procs Qt_procs = {
genl_preference_update,
genl_getmsghistory,
genl_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
genl_status_init,
genl_status_finish,
genl_status_enablefield,
genl_status_update,
# ifdef STATUS_HILITES
genl_status_threshold,
# endif
#endif
genl_can_suspend_yes,
};
extern "C" void play_usersound(const char* filename, int volume)
-5
View File
@@ -125,13 +125,8 @@ struct window_procs X11_procs = {
genl_outrip,
#endif
X11_preference_update, genl_getmsghistory, genl_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
genl_status_init, genl_status_finish, genl_status_enablefield,
genl_status_update,
#ifdef STATUS_HILITES
genl_status_threshold,
#endif
#endif
genl_can_suspend_no, /* XXX may not always be correct */
};
+4 -24
View File
@@ -462,7 +462,6 @@ boolean is_restoring;
(*cibase->nprocs->win_putmsghistory)(cibase->ndata, msg, is_restoring);
}
#ifdef STATUS_VIA_WINDOWPORT
void
chainin_status_init()
{
@@ -487,29 +486,15 @@ boolean enable;
}
void
chainin_status_update(idx, ptr, chg, percent)
int idx, chg, percent;
chainin_status_update(idx, ptr, chg, percent, color, colormasks)
int idx, chg, percent, color;
genericptr_t ptr;
unsigned long *colormasks;
{
(*cibase->nprocs->win_status_update)(cibase->ndata, idx, ptr, chg,
percent);
percent, color, colormasks);
}
#ifdef STATUS_HILITES
void
chainin_status_threshold(fldidx, thresholdtype, threshold, behavior, under,
over)
int fldidx, thresholdtype;
int behavior, under, over;
anything threshold;
{
(*cibase->nprocs->win_status_threshold)(cibase->ndata, fldidx,
thresholdtype, threshold,
behavior, under, over);
}
#endif
#endif
boolean
chainin_can_suspend()
{
@@ -561,12 +546,7 @@ struct window_procs chainin_procs = {
chainin_outrip, chainin_preference_update, chainin_getmsghistory,
chainin_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
chainin_status_init, chainin_status_finish, chainin_status_enablefield,
chainin_status_update,
#ifdef STATUS_HILITES
chainin_status_threshold,
#endif
#endif
chainin_can_suspend,
};
+3 -25
View File
@@ -586,7 +586,6 @@ boolean is_restoring;
(*tdp->nprocs->win_putmsghistory)(msg, is_restoring);
}
#ifdef STATUS_VIA_WINDOWPORT
void
chainout_status_init(vp)
void *vp;
@@ -619,33 +618,17 @@ boolean enable;
}
void
chainout_status_update(vp, idx, ptr, chg, percent)
chainout_status_update(vp, idx, ptr, chg, percent, color, colormasks)
void *vp;
int idx, chg, percent;
genericptr_t ptr;
unsigned long *colormasks;
{
struct chainout_data *tdp = vp;
(*tdp->nprocs->win_status_update)(idx, ptr, chg, percent);
(*tdp->nprocs->win_status_update)(idx, ptr, chg, percent, color, colormasks);
}
#ifdef STATUS_HILITES
void
chainout_status_threshold(vp, fldidx, thresholdtype, threshold, behavior,
under, over)
void *vp;
int fldidx, thresholdtype;
int behavior, under, over;
anything threshold;
{
struct chainout_data *tdp = vp;
(*tdp->nprocs->win_status_threshold)(fldidx, thresholdtype, threshold,
behavior, under, over);
}
#endif
#endif
boolean
chainout_can_suspend(vp)
void *vp;
@@ -700,12 +683,7 @@ struct chain_procs chainout_procs = {
chainout_outrip, chainout_preference_update, chainout_getmsghistory,
chainout_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
chainout_status_init, chainout_status_finish, chainout_status_enablefield,
chainout_status_update,
#ifdef STATUS_HILITES
chainout_status_threshold,
#endif
#endif
chainout_can_suspend,
};
+3 -31
View File
@@ -1027,7 +1027,6 @@ boolean is_restoring;
POST;
}
#ifdef STATUS_VIA_WINDOWPORT
void
trace_status_init(vp)
void *vp;
@@ -1084,10 +1083,11 @@ boolean enable;
}
void
trace_status_update(vp, idx, ptr, chg, percent)
trace_status_update(vp, idx, ptr, chg, color, colormasks)
void *vp;
int idx, chg, percent;
genericptr_t ptr;
unsigned long *colormasks;
{
struct trace_data *tdp = vp;
@@ -1095,33 +1095,10 @@ genericptr_t ptr;
ptr, chg, percent);
PRE;
(*tdp->nprocs->win_status_update)(tdp->ndata, idx, ptr, chg, percent);
(*tdp->nprocs->win_status_update)(tdp->ndata, idx, ptr, chg, color colormasks);
POST;
}
#ifdef STATUS_HILITES
void
trace_status_threshold(vp, fldidx, thresholdtype, threshold, behavior, under,
over)
void *vp;
int fldidx, thresholdtype;
int behavior, under, over;
anything threshold;
{
struct trace_data *tdp = vp;
/* XXX how do we print an anything? We don't. */
fprintf(wc_tracelogf, "%sstatus_threshold(%d, %d, -, %d, %d, %d)\n",
INDENT, fldidx, thresholdtype, behavior, under, over);
PRE;
(*tdp->nprocs->win_status_threshold)(tdp->ndata, fldidx, thresholdtype,
threshold, behavior, under, over);
POST;
}
#endif
#endif
boolean
trace_can_suspend(vp)
void *vp;
@@ -1179,12 +1156,7 @@ struct chain_procs trace_procs = {
trace_outrip, trace_preference_update, trace_getmsghistory,
trace_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
trace_status_init, trace_status_finish, trace_status_enablefield,
trace_status_update,
#ifdef STATUS_HILITES
trace_status_threshold,
#endif
#endif
trace_can_suspend,
};
-5
View File
@@ -70,13 +70,8 @@ struct window_procs Gem_procs = {
/* other defs that really should go away (they're tty specific) */
Gem_start_screen, Gem_end_screen, Gem_outrip, Gem_preference_update,
genl_getmsghistory, genl_putmsghistory
#ifdef STATUS_VIA_WINDOWPORT
genl_status_init,
genl_status_finish, genl_status_enablefield, genl_status_update,
#ifdef STATUS_HILITES
genl_status_threshold,
#endif
#endif
genl_can_suspend_no,
};
-5
View File
@@ -48,13 +48,8 @@ struct window_procs Gnome_procs = {
/* other defs that really should go away (they're tty specific) */
gnome_start_screen, gnome_end_screen, gnome_outrip,
genl_preference_update, genl_getmsghistory, genl_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
genl_status_init, genl_status_finish, genl_status_enablefield,
genl_status_update,
#ifdef STATUS_HILITES
genl_status_threshold,
#endif
#endif
genl_can_suspend_yes,
};
+296 -264
View File
@@ -62,6 +62,9 @@ struct window_procs tty_procs = {
WC_COLOR | WC_HILITE_PET | WC_INVERSE | WC_EIGHT_BIT_IN,
#if defined(SELECTSAVED)
WC2_SELECTSAVED |
#endif
#if defined(STATUS_HILITES)
WC2_HITPOINTBAR | WC2_FLUSH_STATUS |
#endif
WC2_DARKGRAY,
tty_init_nhwindows, tty_player_selection, tty_askname, tty_get_nh_event,
@@ -96,13 +99,12 @@ struct window_procs tty_procs = {
genl_preference_update,
#endif
tty_getmsghistory, tty_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
tty_status_init,
genl_status_finish, genl_status_enablefield,
tty_status_update,
#ifdef STATUS_HILITES
tty_status_threshold,
#endif
tty_status_update,
#else
genl_status_update,
#endif
genl_can_suspend_yes,
};
@@ -1293,9 +1295,7 @@ const char *str;
}
}
WIN_MAP = WIN_MESSAGE = WIN_INVEN = WIN_ERR; /* these are all gone now */
#ifndef STATUS_VIA_WINDOWPORT
WIN_STATUS = WIN_ERR;
#endif
#ifdef FREE_ALL_MEMORY
if (BASE_WINDOW != WIN_ERR && wins[BASE_WINDOW]) {
free_window_info(wins[BASE_WINDOW], TRUE);
@@ -2527,7 +2527,16 @@ const char *str;
}
break;
}
#ifdef STATUS_HILITES
/* Don't optimize the putsym away, in case it happens
to be the same character but different color/attr.
We don't optimize on iflags.use_status_hilites either,
in case old chars were written with highlighting and
that option has just now been toggled off. [We could
do better by tracking color/attr more closely.] */
#else
if (*ob != *nb)
#endif
tty_putsym(WIN_STATUS, i, cw->cury, *nb);
if (*ob)
ob++;
@@ -2535,13 +2544,9 @@ const char *str;
(void) strncpy(&cw->data[cw->cury][j], str, cw->cols - j - 1);
cw->data[cw->cury][cw->cols - 1] = '\0'; /* null terminate */
#ifdef STATUS_VIA_WINDOWPORT
if (!iflags.use_status_hilites) {
#endif
cw->cury = (cw->cury + 1) % 2;
cw->curx = 0;
#ifdef STATUS_VIA_WINDOWPORT
}
#ifndef STATUS_HILITES
cw->cury = (cw->cury + 1) % 2;
cw->curx = 0;
#endif
break;
case NHW_MAP:
@@ -3402,40 +3407,26 @@ char *posbar;
}
#endif
#ifdef STATUS_VIA_WINDOWPORT
/*
* The following data structures come from the genl_ routines in
* src/windows.c and as such are considered to be on the window-port
* "side" of things, rather than the NetHack-core "side" of things.
*/
extern const char *status_fieldnm[MAXBLSTATS];
extern const char *status_fieldfmt[MAXBLSTATS];
extern char *status_vals[MAXBLSTATS];
extern boolean status_activefields[MAXBLSTATS];
extern winid WIN_STATUS;
#ifdef STATUS_HILITES
typedef struct hilite_data_struct {
int thresholdtype;
anything threshold;
int behavior;
int under;
int over;
} hilite_data_t;
static hilite_data_t tty_status_hilites[MAXBLSTATS];
static long tty_condition_bits;
static int tty_status_colors[MAXBLSTATS];
int hpbar_percent, hpbar_color;
#endif /* STATUS_HILITES */
struct color_option {
int color;
int attr_bits;
};
static int FDECL(condcolor, (long, unsigned long *));
static int FDECL(condattr, (long, unsigned long *));
static void FDECL(start_color_option, (struct color_option));
static void FDECL(end_color_option, (struct color_option));
static void FDECL(apply_color_option, (struct color_option, const char *));
static void FDECL(add_colored_text, (const char *, char *));
#endif
void
tty_status_init()
@@ -3445,15 +3436,11 @@ tty_status_init()
/* let genl_status_init do most of the initialization */
genl_status_init();
for (i = 0; i < MAXBLSTATS; ++i) {
#ifdef STATUS_HILITES
for (i = 0; i < MAXBLSTATS; ++i) {
tty_status_colors[i] = NO_COLOR; /* no color */
tty_status_hilites[i].thresholdtype = 0;
tty_status_hilites[i].behavior = BL_TH_NONE;
tty_status_hilites[i].under = BL_HILITE_NONE;
tty_status_hilites[i].over = BL_HILITE_NONE;
#endif /* STATUS_HILITES */
}
#endif /* STATUS_HILITES */
}
/*
@@ -3490,22 +3477,102 @@ tty_status_init()
* symbol for GOLD "\GXXXXNNNN:nnn". If the window port needs to use
* the textual gold amount without the leading "$:" the port will
* have to skip past ':' in the passed "ptr" for the BL_GOLD case.
* -- color is an unsigned int.
* color_index = color & 0x00FF; CLR_* value
* attribute = color & 0xFF00 >> 8; BL_* values
* This holds the color and attribute that the field should
* be displayed in.
* This is relevant for everything except BL_CONDITION fldindex.
* If fldindex is BL_CONDITION, this parameter should be ignored,
* as condition hilighting is done via the next colormasks
* parameter instead.
*
* -- colormasks - pointer to cond_hilites[] array of colormasks.
* Only relevant for BL_CONDITION fldindex. The window port
* should ignore this parameter for other fldindex values.
* Each condition bit must only ever appear in one of the
* CLR_ array members, but can appear in multiple HL_ATTCLR_
* offsets (because more than one attribute can co-exist).
* See doc/window.doc for more details.
*/
/* new approach through status_update() only */
#define Begin_Attr(m) \
if (m) { \
if ((m) & HL_BOLD) \
term_start_attr(ATR_BOLD); \
if ((m) & HL_INVERSE) \
term_start_attr(ATR_INVERSE); \
if ((m) & HL_ULINE) \
term_start_attr(ATR_ULINE); \
if ((m) & HL_BLINK) \
term_start_attr(ATR_BLINK); \
if ((m) & HL_DIM) \
term_start_attr(ATR_DIM); \
}
#define End_Attr(m) \
if (m) { \
if ((m) & HL_DIM) \
term_end_attr(ATR_DIM); \
if ((m) & HL_BLINK) \
term_end_attr(ATR_BLINK); \
if ((m) & HL_ULINE) \
term_end_attr(ATR_ULINE); \
if ((m) & HL_INVERSE) \
term_end_attr(ATR_INVERSE); \
if ((m) & HL_BOLD) \
term_end_attr(ATR_BOLD); \
}
#ifdef STATUS_HILITES
#ifdef TEXTCOLOR
#define MaybeDisplayCond(bm,txt) \
if (tty_condition_bits & (bm)) { \
putstr(WIN_STATUS, 0, " "); \
if (iflags.hilite_delta) { \
attrmask = condattr(bm, colormasks); \
Begin_Attr(attrmask); \
if ((coloridx = condcolor(bm, colormasks)) != NO_COLOR) \
term_start_color(coloridx); \
} \
putstr(WIN_STATUS, 0, txt); \
if (iflags.hilite_delta) { \
if (coloridx != NO_COLOR) \
term_end_color(); \
End_Attr(attrmask); \
} \
}
#else
#define MaybeDisplayCond(bm,txt) \
if (tty_condition_bits & (bm)) { \
putstr(WIN_STATUS, 0, " "); \
if (iflags.hilite_delta) { \
attrmask = condattr(bm, colormasks); \
Begin_Attr(attrmask); \
} \
putstr(WIN_STATUS, 0, txt); \
if (iflags.hilite_delta) { \
End_Attr(attrmask); \
} \
}
#endif
void
tty_status_update(fldidx, ptr, chg, percent)
int fldidx, chg, percent;
tty_status_update(fldidx, ptr, chg, percent, color, colormasks)
int fldidx, chg UNUSED, percent UNUSED, color;
genericptr_t ptr;
unsigned long *colormasks;
{
long cond, *condptr = (long *) ptr;
register int i;
long *condptr = (long *) ptr;
int i, attrmask = 0;
#ifdef TEXTCOLOR
int coloridx = NO_COLOR;
#endif
char *text = (char *) ptr;
/* Mapping BL attributes to tty attributes
* BL_HILITE_NONE -1 + 3 = 2 (statusattr[2])
* BL_HILITE_INVERSE -2 + 3 = 1 (statusattr[1])
* BL_HILITE_BOLD -3 + 3 = 0 (statusattr[0])
*/
long value = -1L;
static boolean beenhere = FALSE;
static boolean oncearound = FALSE; /* prevent premature partial status display */
enum statusfields fieldorder[2][15] = {
{ BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH, BL_ALIGN,
BL_SCORE, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH, BL_FLUSH,
@@ -3514,175 +3581,118 @@ genericptr_t ptr;
BL_AC, BL_XP, BL_EXP, BL_HD, BL_TIME, BL_HUNGER,
BL_CAP, BL_CONDITION, BL_FLUSH }
};
#ifdef STATUS_HILITES
static int statusattr[] = { ATR_BOLD, ATR_INVERSE, ATR_NONE };
int attridx = 0;
#else
nhUse(chg);
nhUse(percent);
#endif
if (fldidx != BL_FLUSH) {
if (!status_activefields[fldidx])
return;
switch (fldidx) {
case BL_CONDITION:
cond = *condptr;
*status_vals[fldidx] = '\0';
if (cond & BL_MASK_STONE)
Strcat(status_vals[fldidx], " Stone");
if (cond & BL_MASK_SLIME)
Strcat(status_vals[fldidx], " Slime");
if (cond & BL_MASK_STRNGL)
Strcat(status_vals[fldidx], " Strngl");
if (cond & BL_MASK_FOODPOIS)
Strcat(status_vals[fldidx], " FoodPois");
if (cond & BL_MASK_TERMILL)
Strcat(status_vals[fldidx], " TermIll");
if (cond & BL_MASK_BLIND)
Strcat(status_vals[fldidx], " Blind");
if (cond & BL_MASK_DEAF)
Strcat(status_vals[fldidx], " Deaf");
if (cond & BL_MASK_STUN)
Strcat(status_vals[fldidx], " Stun");
if (cond & BL_MASK_CONF)
Strcat(status_vals[fldidx], " Conf");
if (cond & BL_MASK_HALLU)
Strcat(status_vals[fldidx], " Hallu");
if (cond & BL_MASK_LEV)
Strcat(status_vals[fldidx], " Lev");
if (cond & BL_MASK_FLY)
Strcat(status_vals[fldidx], " Fly");
if (cond & BL_MASK_RIDE)
Strcat(status_vals[fldidx], " Ride");
value = cond;
tty_condition_bits = *condptr;
oncearound = TRUE;
break;
default:
value = atol(text);
Sprintf(status_vals[fldidx],
(fldidx == BL_TITLE && iflags.wc2_hitpointbar) ? "%-30s" :
status_fieldfmt[fldidx] ? status_fieldfmt[fldidx] : "%s",
text);
break;
}
#ifdef STATUS_HILITES
switch (tty_status_hilites[fldidx].behavior) {
case BL_TH_NONE:
#ifdef TEXTCOLOR
tty_status_colors[fldidx] = color;
#else
tty_status_colors[fldidx] = NO_COLOR;
break;
case BL_TH_UPDOWN:
if (chg > 0)
tty_status_colors[fldidx] = tty_status_hilites[fldidx].over;
else if (chg < 0)
tty_status_colors[fldidx] = tty_status_hilites[fldidx].under;
else
tty_status_colors[fldidx] = NO_COLOR;
break;
case BL_TH_VAL_PERCENTAGE: {
int pct_th = 0;
if (tty_status_hilites[fldidx].thresholdtype != ANY_INT) {
impossible(
"tty_status_update: unsupported percentage threshold type %d",
tty_status_hilites[fldidx].thresholdtype);
} else {
pct_th = tty_status_hilites[fldidx].threshold.a_int;
tty_status_colors[fldidx] = (percent >= pct_th)
? tty_status_hilites[fldidx].over
: tty_status_hilites[fldidx].under;
#endif
if (iflags.wc2_hitpointbar && fldidx == BL_HP) {
hpbar_percent = percent;
#ifdef TEXTCOLOR
hpbar_color = color;
#else
hpbar_color = NO_COLOR;
#endif
}
break;
}
case BL_TH_VAL_ABSOLUTE: {
int c = NO_COLOR;
int o = tty_status_hilites[fldidx].over;
int u = tty_status_hilites[fldidx].under;
anything *t = &tty_status_hilites[fldidx].threshold;
switch (tty_status_hilites[fldidx].thresholdtype) {
case ANY_LONG:
c = (value >= t->a_long) ? o : u;
break;
case ANY_INT:
c = (value >= t->a_int) ? o : u;
break;
case ANY_UINT:
c = ((unsigned long) value >= t->a_uint) ? o : u;
break;
case ANY_ULONG:
c = ((unsigned long) value >= t->a_ulong) ? o : u;
break;
case ANY_MASK32:
c = (value & t->a_ulong) ? o : u;
break;
default:
impossible(
"tty_status_update: unsupported absolute threshold type %d\n",
tty_status_hilites[fldidx].thresholdtype);
break;
}
tty_status_colors[fldidx] = c;
break;
} /* case */
} /* switch */
#endif /* STATUS_HILITES */
}
/* For now, this version copied from the genl_ version currently
* updates everything on the display, everytime
*/
if (!beenhere || !iflags.use_status_hilites) {
char newbot1[MAXCO], newbot2[MAXCO];
newbot1[0] = '\0';
for (i = 0; fieldorder[0][i] >= 0; ++i) {
int idx1 = fieldorder[0][i];
if (status_activefields[idx1])
Strcat(newbot1, status_vals[idx1]);
}
newbot2[0] = '\0';
for (i = 0; fieldorder[1][i] >= 0; ++i) {
int idx2 = fieldorder[1][i];
if (status_activefields[idx2])
Strcat(newbot2, status_vals[idx2]);
}
curs(WIN_STATUS, 1, 0);
putstr(WIN_STATUS, 0, newbot1);
curs(WIN_STATUS, 1, 1);
putmixed(WIN_STATUS, 0, newbot2); /* putmixed() due to GOLD glyph */
beenhere = TRUE;
return;
}
if (!oncearound) return;
curs(WIN_STATUS, 1, 0);
for (i = 0; fieldorder[0][i] != BL_FLUSH; ++i) {
int fldidx1 = fieldorder[0][i];
if (status_activefields[fldidx1]) {
#ifdef STATUS_HILITES
if (tty_status_colors[fldidx1] < 0
&& tty_status_colors[fldidx1] >= -3) {
/* attribute, not a color */
attridx = tty_status_colors[fldidx1] + 3;
term_start_attr(statusattr[attridx]);
putstr(WIN_STATUS, 0, status_vals[fldidx1]);
term_end_attr(statusattr[attridx]);
} else
if (fldidx1 != BL_TITLE || !iflags.wc2_hitpointbar) {
#ifdef TEXTCOLOR
if (tty_status_colors[fldidx1] != CLR_MAX) {
if (tty_status_colors[fldidx1] != NO_COLOR)
term_start_color(tty_status_colors[fldidx1]);
putstr(WIN_STATUS, 0, status_vals[fldidx1]);
if (tty_status_colors[fldidx1] != NO_COLOR)
term_end_color();
} else
coloridx = tty_status_colors[fldidx1] & 0x00FF;
#endif
#endif /* STATUS_HILITES */
putstr(WIN_STATUS, 0, status_vals[fldidx1]);
attridx = (tty_status_colors[fldidx1] & 0xFF00) >> 8;
text = status_vals[fldidx1];
if (iflags.hilite_delta) {
if (*text == ' ') {
putstr(WIN_STATUS, 0, " ");
text++;
}
/* multiple attributes can be in effect concurrently */
Begin_Attr(attridx);
#ifdef TEXTCOLOR
if (coloridx != NO_COLOR && coloridx != CLR_MAX)
term_start_color(coloridx);
#endif
}
putstr(WIN_STATUS, 0, text);
if (iflags.hilite_delta) {
#ifdef TEXTCOLOR
if (coloridx != NO_COLOR)
term_end_color();
#endif
End_Attr(attridx);
}
} else {
/* hitpointbar using hp percent calculation */
int bar_pos, bar_len;
char *bar2 = (char *)0;
char bar[MAXCO], savedch;
boolean twoparts = FALSE;
text = status_vals[fldidx1];
bar_len = strlen(text);
if (bar_len < MAXCO-1) {
Strcpy(bar, text);
bar_pos = (bar_len * hpbar_percent) / 100;
if (bar_pos < 1 && hpbar_percent > 0)
bar_pos = 1;
if (bar_pos >= bar_len && hpbar_percent < 100)
bar_pos = bar_len - 1;
if (bar_pos > 0 && bar_pos < bar_len) {
twoparts = TRUE;
bar2 = &bar[bar_pos];
savedch = *bar2;
*bar2 = '\0';
}
}
if (iflags.hilite_delta && iflags.wc2_hitpointbar) {
putstr(WIN_STATUS, 0, "[");
#ifdef TEXTCOLOR
coloridx = hpbar_color & 0x00FF;
/* attridx = (hpbar_color & 0xFF00) >> 8; */
if (coloridx != NO_COLOR)
term_start_color(coloridx);
#endif
term_start_attr(ATR_INVERSE);
putstr(WIN_STATUS, 0, bar);
term_end_attr(ATR_INVERSE);
#ifdef TEXTCOLOR
if (coloridx != NO_COLOR)
term_end_color();
#endif
if (twoparts) {
*bar2 = savedch;
putstr(WIN_STATUS, 0, bar2);
}
putstr(WIN_STATUS, 0, "]");
} else
putstr(WIN_STATUS, 0, text);
}
}
}
curs(WIN_STATUS, 1, 1);
@@ -3690,93 +3700,115 @@ genericptr_t ptr;
int fldidx2 = fieldorder[1][i];
if (status_activefields[fldidx2]) {
#ifdef STATUS_HILITES
if (tty_status_colors[fldidx2] < 0
&& tty_status_colors[fldidx2] >= -3) {
/* attribute, not a color */
attridx = tty_status_colors[fldidx2] + 3;
term_start_attr(statusattr[attridx]);
putstr(WIN_STATUS, 0, status_vals[fldidx2]);
term_end_attr(statusattr[attridx]);
} else
if (fldidx2 != BL_CONDITION) {
#ifdef TEXTCOLOR
if (tty_status_colors[fldidx2] != CLR_MAX) {
if (tty_status_colors[fldidx2] != NO_COLOR)
term_start_color(tty_status_colors[fldidx2]);
coloridx = tty_status_colors[fldidx2] & 0x00FF;
#endif
attridx = (tty_status_colors[fldidx2] & 0xFF00) >> 8;
text = status_vals[fldidx2];
if (iflags.hilite_delta) {
if (*text == ' ') {
putstr(WIN_STATUS, 0, " ");
text++;
}
/* multiple attributes can be in effect concurrently */
Begin_Attr(attridx);
#ifdef TEXTCOLOR
if (coloridx != NO_COLOR && coloridx != CLR_MAX)
term_start_color(coloridx);
#endif
}
if (fldidx2 == BL_GOLD) {
/* putmixed() due to GOLD glyph */
putmixed(WIN_STATUS, 0, status_vals[fldidx2]);
putmixed(WIN_STATUS, 0, text);
} else {
putstr(WIN_STATUS, 0, status_vals[fldidx2]);
putstr(WIN_STATUS, 0, text);
}
if (tty_status_colors[fldidx2] != NO_COLOR)
term_end_color();
} else
if (iflags.hilite_delta) {
#ifdef TEXTCOLOR
if (coloridx != NO_COLOR)
term_end_color();
#endif
#endif /* STATUS_HILITES */
putstr(WIN_STATUS, 0, status_vals[fldidx2]);
End_Attr(attridx);
}
} else {
MaybeDisplayCond(BL_MASK_STONE, "Stone");
MaybeDisplayCond(BL_MASK_SLIME, "Slime");
MaybeDisplayCond(BL_MASK_STRNGL, "Strngl");
MaybeDisplayCond(BL_MASK_FOODPOIS, "FoodPois");
MaybeDisplayCond(BL_MASK_TERMILL, "TermIll");
MaybeDisplayCond(BL_MASK_BLIND, "Blind");
MaybeDisplayCond(BL_MASK_DEAF, "Deaf");
MaybeDisplayCond(BL_MASK_STUN, "Stun");
MaybeDisplayCond(BL_MASK_CONF, "Conf");
MaybeDisplayCond(BL_MASK_HALLU, "Hallu");
MaybeDisplayCond(BL_MASK_LEV, "Lev");
MaybeDisplayCond(BL_MASK_FLY, "Fly");
MaybeDisplayCond(BL_MASK_RIDE, "Ride");
}
}
}
return;
}
#ifdef STATUS_HILITES
#ifdef TEXTCOLOR
/*
* status_threshold(int fldidx, int threshholdtype, anything threshold,
* int behavior, int under, int over)
*
* -- called when a hiliting preference is added, changed, or
* removed.
* -- the fldindex identifies which field is having its hiliting
* preference set. It is an integer index value from botl.h
* -- fldindex could be any one of the following from botl.h:
* BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
* BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX,
* BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX,
* BL_LEVELDESC, BL_EXP, BL_CONDITION
* -- datatype is P_INT, P_UINT, P_LONG, or P_MASK.
* -- threshold is an "anything" union which can contain the
* datatype value.
* -- behavior is used to define how threshold is used and can
* be BL_TH_NONE, BL_TH_VAL_PERCENTAGE, BL_TH_VAL_ABSOLUTE,
* or BL_TH_UPDOWN. BL_TH_NONE means don't do anything above
* or below the threshold. BL_TH_VAL_PERCENTAGE treats the
* threshold value as a precentage of the maximum possible
* value. BL_TH_VAL_ABSOLUTE means that the threshold is an
* actual value. BL_TH_UPDOWN means that threshold is not
* used, and the two below/above hilite values indicate how
* to display something going down (under) or rising (over).
* -- under is the hilite attribute used if value is below the
* threshold. The attribute can be BL_HILITE_NONE,
* BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one
* of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN,
* CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY,
* CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE,
* CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15).
* -- over is the hilite attribute used if value is at or above
* the threshold. The attribute can be BL_HILITE_NONE,
* BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one
* of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN,
* CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY,
* CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE,
* CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15).
* Return what color this condition should
* be displayed in based on user settings.
*/
void
tty_status_threshold(fldidx, thresholdtype, threshold, behavior, under, over)
int fldidx, thresholdtype;
int behavior, under, over;
anything threshold;
int condcolor(bm, bmarray)
long bm;
unsigned long *bmarray;
{
tty_status_hilites[fldidx].thresholdtype = thresholdtype;
tty_status_hilites[fldidx].threshold = threshold;
tty_status_hilites[fldidx].behavior = behavior;
tty_status_hilites[fldidx].under = under;
tty_status_hilites[fldidx].over = over;
return;
}
#ifdef STATUS_HILITES
int i;
if (bm && bmarray)
for (i = 0; i < CLR_MAX; ++i) {
if (bmarray[i] && (bm & bmarray[i]))
return i;
}
#endif
return NO_COLOR;
}
#endif /* TEXTCOLOR */
int condattr(bm, bmarray)
long bm;
unsigned long *bmarray;
{
int attr = 0;
int i;
if (bm && bmarray) {
for (i = HL_ATTCLR_DIM; i < BL_ATTCLR_MAX; ++i) {
if (bmarray[i] && (bm & bmarray[i])) {
switch(i) {
case HL_ATTCLR_DIM:
attr |= HL_DIM;
break;
case HL_ATTCLR_BLINK:
attr |= HL_BLINK;
break;
case HL_ATTCLR_ULINE:
attr |= HL_ULINE;
break;
case HL_ATTCLR_INVERSE:
attr |= HL_INVERSE;
break;
case HL_ATTCLR_BOLD:
attr |= HL_BOLD;
break;
}
}
}
}
return attr;
}
#endif /* STATUS_HILITES */
#endif /*STATUS_VIA_WINDOWPORT*/
#endif /* TTY_GRAPHICS */
+1
View File
@@ -72,6 +72,7 @@ typedef struct mswin_nhmsg_update_status {
int n_fields;
const char **vals;
boolean *activefields;
int *percents;
int *colors;
} MSNHMsgUpdateStatus, *PMSNHMsgUpdateStatus;
+76 -35
View File
@@ -18,10 +18,10 @@ typedef struct mswin_nethack_status_window {
int n_fields;
const char **vals;
boolean *activefields;
int *percents;
int *colors;
} NHStatusWindow, *PNHStatusWindow;
#ifdef STATUS_VIA_WINDOWPORT
static int fieldorder1[] = { BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN,
BL_WI, BL_CH, BL_ALIGN, BL_SCORE, -1 };
static int fieldorder2[] = { BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX,
@@ -29,7 +29,6 @@ static int fieldorder2[] = { BL_LEVELDESC, BL_GOLD, BL_HP, BL_HPMAX,
BL_EXP, BL_HD, BL_TIME, BL_HUNGER,
BL_CAP, BL_CONDITION, -1 };
static int *fieldorders[] = { fieldorder1, fieldorder2, NULL };
#endif /* STATUS_VIA_WINDOWPORT */
static TCHAR szStatusWindowClass[] = TEXT("MSNHStatusWndClass");
LRESULT CALLBACK StatusWndProc(HWND, UINT, WPARAM, LPARAM);
@@ -133,9 +132,10 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case MSNH_MSG_GETTEXT: {
PMSNHMsgGetText msg_data = (PMSNHMsgGetText) lParam;
#ifdef STATUS_VIA_WINDOWPORT
#ifdef STATUS_HILITES
int **fop;
int *f;
msg_data->buffer[0] = '\0';
if (data->n_fields > 0) {
for (fop = fieldorders; *fop; fop++) {
@@ -143,20 +143,20 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (data->activefields[*f])
strncat(msg_data->buffer, data->vals[*f],
msg_data->max_size
- strlen(msg_data->buffer));
- strlen(msg_data->buffer));
}
strncat(msg_data->buffer, "\r\n",
msg_data->max_size - strlen(msg_data->buffer));
}
}
#else /* STATUS_VIA_WINDOWPORT */
#else
strncpy(msg_data->buffer, data->window_text[0],
msg_data->max_size);
strncat(msg_data->buffer, "\r\n",
msg_data->max_size - strlen(msg_data->buffer));
strncat(msg_data->buffer, data->window_text[1],
msg_data->max_size - strlen(msg_data->buffer));
#endif /* STATUS_VIA_WINDOWPORT */
#endif
} break;
case MSNH_MSG_UPDATE_STATUS: {
@@ -164,6 +164,7 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
data->n_fields = msg_data->n_fields;
data->vals = msg_data->vals;
data->activefields = msg_data->activefields;
data->percents = msg_data->percents;
data->colors = msg_data->colors;
InvalidateRect(hWnd, NULL, TRUE);
} break;
@@ -206,10 +207,12 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}
#ifdef STATUS_VIA_WINDOWPORT
#ifdef STATUS_HILITES
static LRESULT
onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
int hpbar_percent = 100;
int hpbar_color = NO_COLOR;
int *f;
int **fop;
SIZE sz;
@@ -238,45 +241,83 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
: (COLORREF) GetSysColor(DEFAULT_COLOR_FG_STATUS);
OldFg = SetTextColor(hdc, Fg);
if (iflags.wc2_hitpointbar && BL_HP < data->n_fields
&& data->activefields[BL_HP]) {
hpbar_percent = data->percents[BL_HP];
hpbar_color = data->colors[BL_HP] & 0x00ff;
}
for (fop = fieldorders; *fop; fop++) {
LONG left = rt.left;
LONG cy = 0;
int vlen;
for (f = *fop; *f != -1; f++) {
int clr, atr;
int fntatr = ATR_NONE;
HGDIOBJ fnt;
COLORREF nFg, nBg;
if (((*f) >= data->n_fields) || (!data->activefields[*f]))
continue;
clr = data->colors[*f] & 0x00ff;
atr = (data->colors[*f] & 0xff00) >> 8;
vlen = strlen(data->vals[*f]);
NH_A2W(data->vals[*f], wbuf, SIZE(wbuf));
if (!iflags.use_status_hilites) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else if (data->colors[*f] == CLR_MAX
|| data->colors[*f] == BL_HILITE_NONE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else if (data->colors[*f] > 0) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, nhcolor_to_RGB(data->colors[*f]));
} else if (data->colors[*f] == BL_HILITE_INVERSE) {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Fg);
SetTextColor(hdc, Bg);
} else if (data->colors[*f] == BL_HILITE_BOLD) {
SelectObject(hdc, boldFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
} else {
SelectObject(hdc, normalFont);
SetBkColor(hdc, Bg);
SetTextColor(hdc, Fg);
}
if (atr & HL_BOLD)
fntatr = ATR_BOLD;
else if (atr & HL_INVERSE)
fntatr = ATR_INVERSE;
else if (atr & HL_ULINE)
fntatr = ATR_ULINE;
else if (atr & HL_BLINK)
fntatr = ATR_BLINK;
else if (atr & HL_DIM)
fntatr = ATR_DIM;
fnt = mswin_get_font(NHW_STATUS, fntatr, hdc, FALSE);
nFg = (clr >= 0 && clr < CLR_MAX) ? nhcolor_to_RGB(clr) : Fg;
nBg = Bg;
GetTextExtentPoint32(hdc, wbuf, vlen, &sz);
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
if (*f == BL_TITLE && iflags.wc2_hitpointbar) {
HBRUSH back_brush = CreateSolidBrush(nhcolor_to_RGB(hpbar_color));
RECT barrect;
/* first draw title normally */
SelectObject(hdc, fnt);
SetBkMode(hdc, OPAQUE);
SetBkColor(hdc, Bg);
SetTextColor(hdc, nhcolor_to_RGB(hpbar_color));
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
/* calc bar length */
barrect.left = rt.left;
barrect.top = rt.top;
barrect.bottom = sz.cy;
if (hpbar_percent > 0)
barrect.right = (int)((hpbar_percent * sz.cx) / 100);
else
barrect.right = sz.cx;
/* then draw hpbar on top of title */
FillRect(hdc, &barrect, back_brush);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, nBg);
DrawText(hdc, wbuf, vlen, &barrect, DT_LEFT);
DeleteObject(back_brush);
} else {
if (atr & HL_INVERSE) {
COLORREF tmp = nFg;
nFg = nBg;
nBg = tmp;
}
SelectObject(hdc, fnt);
SetBkMode(hdc, OPAQUE);
SetBkColor(hdc, nBg);
SetTextColor(hdc, nFg);
DrawText(hdc, wbuf, vlen, &rt, DT_LEFT);
}
rt.left += sz.cx;
cy = max(cy, sz.cy);
@@ -336,7 +377,7 @@ onWMPaint(HWND hWnd, WPARAM wParam, LPARAM lParam)
return 0;
}
#endif /*STATUS_VIA_WINDOWPORT*/
#endif /* !STATUS_HILITES */
void
mswin_status_window_size(HWND hWnd, LPSIZE sz)
+16 -126
View File
@@ -85,6 +85,9 @@ struct window_procs mswin_procs = {
| WC_FONTSIZ_TEXT | WC_TILE_WIDTH | WC_TILE_HEIGHT | WC_TILE_FILE
| WC_VARY_MSGCOUNT | WC_WINDOWCOLORS | WC_PLAYER_SELECTION
| WC_SPLASH_SCREEN | WC_POPUP_DIALOG | WC_MOUSE_SUPPORT,
#ifdef STATUS_HILITES
WC2_HITPOINTBAR | WC2_FLUSH_STATUS |
#endif
0L, mswin_init_nhwindows, mswin_player_selection, mswin_askname,
mswin_get_nh_event, mswin_exit_nhwindows, mswin_suspend_nhwindows,
mswin_resume_nhwindows, mswin_create_nhwindow, mswin_clear_nhwindow,
@@ -108,13 +111,8 @@ struct window_procs mswin_procs = {
/* other defs that really should go away (they're tty specific) */
mswin_start_screen, mswin_end_screen, mswin_outrip,
mswin_preference_update, mswin_getmsghistory, mswin_putmsghistory,
#ifdef STATUS_VIA_WINDOWPORT
mswin_status_init, mswin_status_finish, mswin_status_enablefield,
mswin_status_update,
#ifdef STATUS_HILITES
mswin_status_threshold,
#endif
#endif
genl_can_suspend_yes,
};
@@ -2713,18 +2711,18 @@ NHMessageBox(HWND hWnd, LPCTSTR text, UINT type)
return MessageBox(hWnd, text, title, type);
}
#ifdef STATUS_VIA_WINDOWPORT
static const char *_status_fieldnm[MAXBLSTATS];
static const char *_status_fieldfmt[MAXBLSTATS];
static char *_status_vals[MAXBLSTATS];
static int _status_colors[MAXBLSTATS];
static int _status_percents[MAXBLSTATS];
static boolean _status_activefields[MAXBLSTATS];
extern winid WIN_STATUS;
#ifdef STATUS_HILITES
typedef struct hilite_data_struct {
int thresholdtype;
anything threshold;
anything value;
int behavior;
int under;
int over;
@@ -2747,6 +2745,7 @@ mswin_status_init(void)
_status_activefields[i] = FALSE;
_status_fieldfmt[i] = (const char *) 0;
_status_colors[i] = CLR_MAX; /* no color */
_status_percents[i] = 0;
#ifdef STATUS_HILITES
_status_hilites[i].thresholdtype = 0;
_status_hilites[i].behavior = BL_TH_NONE;
@@ -2804,64 +2803,9 @@ mswin_status_enablefield(int fieldidx, const char *nm, const char *fmt,
_status_activefields[fieldidx] = enable;
}
#ifdef STATUS_HILITES
/*
status_threshold(int fldidx, int threshholdtype, anything threshold,
int behavior, int under, int over)
-- called when a hiliting preference is added, changed, or
removed.
-- the fldindex identifies which field is having its hiliting
preference set. It is an integer index value from botl.h
-- fldindex could be any one of the following from botl.h:
BL_TITLE, BL_STR, BL_DX, BL_CO, BL_IN, BL_WI, BL_CH,
BL_ALIGN, BL_SCORE, BL_CAP, BL_GOLD, BL_ENE, BL_ENEMAX,
BL_XP, BL_AC, BL_HD, BL_TIME, BL_HUNGER, BL_HP, BL_HPMAX,
BL_LEVELDESC, BL_EXP, BL_CONDITION
-- datatype is P_INT, P_UINT, P_LONG, or P_MASK.
-- threshold is an "anything" union which can contain the
datatype value.
-- behavior is used to define how threshold is used and can
be BL_TH_NONE, BL_TH_VAL_PERCENTAGE, BL_TH_VAL_ABSOLUTE,
or BL_TH_UPDOWN. BL_TH_NONE means don't do anything above
or below the threshold. BL_TH_VAL_PERCENTAGE treats the
threshold value as a precentage of the maximum possible
value. BL_TH_VAL_ABSOLUTE means that the threshold is an
actual value. BL_TH_UPDOWN means that threshold is not
used, and the two below/above hilite values indicate how
to display something going down (under) or rising (over).
-- under is the hilite attribute used if value is below the
threshold. The attribute can be BL_HILITE_NONE,
BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one
of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN,
CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY,
CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE,
CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15).
-- over is the hilite attribute used if value is at or above
the threshold. The attribute can be BL_HILITE_NONE,
BL_HILITE_INVERSE, BL_HILITE_BOLD (-1, -2, or -3), or one
of the color indexes of CLR_BLACK, CLR_RED, CLR_GREEN,
CLR_BROWN, CLR_BLUE, CLR_MAGENTA, CLR_CYAN, CLR_GRAY,
CLR_ORANGE, CLR_BRIGHT_GREEN, CLR_YELLOW, CLR_BRIGHT_BLUE,
CLR_BRIGHT_MAGENTA, CLR_BRIGHT_CYAN, or CLR_WHITE (0 - 15).
*/
void
mswin_status_threshold(int fldidx, int thresholdtype, anything threshold,
int behavior, int under, int over)
{
logDebug("mswin_status_threshold(%d, %d, %d, %d, %d)\n", fldidx,
thresholdtype, behavior, under, over);
assert(fldidx >= 0 && fldidx < MAXBLSTATS);
_status_hilites[fldidx].thresholdtype = thresholdtype;
_status_hilites[fldidx].threshold = threshold;
_status_hilites[fldidx].behavior = behavior;
_status_hilites[fldidx].under = under;
_status_hilites[fldidx].over = over;
}
#endif /* STATUS_HILITES */
/*
status_update(int fldindex, genericptr_t ptr, int chg, int percentage)
status_update(int fldindex, genericptr_t ptr, int chg, int percent, int color, unsigned long *colormasks)
-- update the value of a status field.
-- the fldindex identifies which field is changing and
is an integer index value from botl.h
@@ -2894,9 +2838,13 @@ status_update(int fldindex, genericptr_t ptr, int chg, int percentage)
symbol for GOLD "\GXXXXNNNN:nnn". If window port needs
textual gold amount without the leading "$:" the port will
have to skip past ':' in passed "ptr" for the BL_GOLD case.
-- color is the color that the NetHack core is telling you to
use to display the text.
-- colormasks is a pointer to a set of CLR_MAX unsigned longs
telling you which fields should be displayed in each color.
*/
void
mswin_status_update(int idx, genericptr_t ptr, int chg, int percent)
mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color, unsigned long *colormasks)
{
long cond, *condptr = (long *) ptr;
char *text = (char *) ptr;
@@ -2905,11 +2853,12 @@ mswin_status_update(int idx, genericptr_t ptr, int chg, int percent)
unsigned ospecial;
long value = -1;
logDebug("mswin_status_update(%d, %p, %d, %d)\n", idx, ptr, chg, percent);
logDebug("mswin_status_update(%d, %p, %d, %d, %x, %p)\n", idx, ptr, chg, percent, color, colormasks);
if (idx != BL_FLUSH) {
if (!_status_activefields[idx])
return;
_status_percents[idx] = percent;
switch (idx) {
case BL_CONDITION: {
cond = *condptr;
@@ -2971,75 +2920,16 @@ mswin_status_update(int idx, genericptr_t ptr, int chg, int percent)
}
}
#ifdef STATUS_HILITES
switch (_status_hilites[idx].behavior) {
case BL_TH_NONE: {
_status_colors[idx] = CLR_MAX;
} break;
case BL_TH_UPDOWN: {
if (chg > 0)
_status_colors[idx] = _status_hilites[idx].over;
else if (chg < 0)
_status_colors[idx] = _status_hilites[idx].under;
else
_status_colors[idx] = CLR_MAX;
} break;
case BL_TH_VAL_PERCENTAGE: {
int pct_th = 0;
if (_status_hilites[idx].thresholdtype != ANY_INT) {
impossible("mswin_status_update: unsupported percentage "
"threshold type %d",
_status_hilites[idx].thresholdtype);
break;
}
pct_th = _status_hilites[idx].threshold.a_int;
_status_colors[idx] = (percent >= pct_th)
? _status_hilites[idx].over
: _status_hilites[idx].under;
} break;
case BL_TH_VAL_ABSOLUTE: {
int c = CLR_MAX;
int o = _status_hilites[idx].over;
int u = _status_hilites[idx].under;
anything *t = &_status_hilites[idx].threshold;
switch (_status_hilites[idx].thresholdtype) {
case ANY_LONG:
c = (value >= t->a_long) ? o : u;
break;
case ANY_INT:
c = (value >= t->a_int) ? o : u;
break;
case ANY_UINT:
c = ((unsigned long) value >= t->a_uint) ? o : u;
break;
case ANY_ULONG:
c = ((unsigned long) value >= t->a_ulong) ? o : u;
break;
case ANY_MASK32:
c = (value & t->a_ulong) ? o : u;
break;
default:
impossible("mswin_status_update: unsupported absolute threshold "
"type %d\n",
_status_hilites[idx].thresholdtype);
break;
}
_status_colors[idx] = c;
} break;
}
#endif /* STATUS_HILITES */
_status_colors[idx] = color;
/* send command to status window */
ZeroMemory(&update_cmd_data, sizeof(update_cmd_data));
update_cmd_data.n_fields = MAXBLSTATS;
update_cmd_data.vals = _status_vals;
update_cmd_data.activefields = _status_activefields;
update_cmd_data.percents = _status_percents;
update_cmd_data.colors = _status_colors;
SendMessage(mswin_hwnd_from_winid(WIN_STATUS), WM_MSNH_COMMAND,
(WPARAM) MSNH_MSG_UPDATE_STATUS, (LPARAM) &update_cmd_data);
}
#endif /*STATUS_VIA_WINDOWPORT*/
+1 -8
View File
@@ -182,18 +182,11 @@ void mswin_preference_update(const char *pref);
char *mswin_getmsghistory(BOOLEAN_P init);
void mswin_putmsghistory(const char *msg, BOOLEAN_P);
#ifdef STATUS_VIA_WINDOWPORT
void mswin_status_init(void);
void mswin_status_finish(void);
void mswin_status_enablefield(int fieldidx, const char *nm, const char *fmt,
boolean enable);
void mswin_status_update(int idx, genericptr_t ptr, int chg, int percent);
#ifdef STATUS_HILITES
void mswin_status_threshold(int fldidx, int thresholdtype, anything threshold,
int behavior, int under, int over);
#endif /* STATUS_HILITES */
#endif /*STATUS_VIA_WINDOWPORT*/
void mswin_status_update(int idx, genericptr_t ptr, int chg, int percent, int color, unsigned long *colormasks);
/* helper function */
HWND mswin_hwnd_from_winid(winid wid);