Draw the hitpoint bar in the hitpoint colors

This commit is contained in:
Ray Chason
2026-08-10 09:28:04 +03:00
committed by Pasi Kallinen
parent b9bf823100
commit c50f9d8176
+36 -25
View File
@@ -117,7 +117,8 @@ static void tty_status_blink(XtPointer client_data, XtIntervalId *timer);
static void tty_status_redraw(Widget); static void tty_status_redraw(Widget);
static int tty_render_field(Widget, int, int, enum statusfields); static int tty_render_field(Widget, int, int, enum statusfields);
static void tty_status_colors(Widget, int, int, Pixel *, Pixel *); static void tty_status_colors(Widget, int, int, Pixel *, Pixel *);
static int tty_render_text(Widget, int, int, const char *, int, int, enum statusfields); static int tty_render_text(Widget, const XRectangle *, int, int, const char *,
int, int, enum statusfields);
static unsigned long X11_condition_bits, old_condition_bits; static unsigned long X11_condition_bits, old_condition_bits;
static int X11_status_colors[MAXBLSTATS], static int X11_status_colors[MAXBLSTATS],
@@ -641,23 +642,26 @@ tty_status_redraw(Widget w)
} }
} }
/*
* Draw the hit point bar using:
* * the colors for hit points
* * the opposite of the HL_INVERSE bit for the title
* * the font for the title
*/
if (name_width != 0 && iflags.wc2_hitpointbar) { if (name_width != 0 && iflags.wc2_hitpointbar) {
XGCValues values; XRectangle clip = {
Pixel fgpixel, bgpixel; .x = name_x,
struct tty_status_field const *fldp = &X11_status_labels[BL_TITLE]; .y = name_y,
tty_status_colors(w, fldp->color, fldp->attrs, &fgpixel, &bgpixel); .width = name_width * X11_status_labels[BL_HP].percent / 100,
values.foreground = fgpixel ^ bgpixel; .height = height
values.background = fgpixel ^ bgpixel; };
values.function = GXxor; struct tty_status_field const *title = &X11_status_labels[BL_TITLE];
values.fill_style = FillSolid; struct tty_status_field const *hitp = &X11_status_labels[BL_HP];
GC ggc = XtGetGC(w, int attrs = ((title->attrs & ~HL_DIM) ^ HL_INVERSE)
GCFunction | GCForeground | GCBackground | GCFillStyle, | (hitp->attrs & HL_DIM);
&values); tty_render_text(w, &clip, name_x, name_y,
XFillRectangle(XtDisplay(w), XtWindow(w), ggc, title->text, hitp->color, attrs,
name_x, name_y, BL_TITLE);
name_width * X11_status_labels[BL_HP].percent / 100,
height);
XtReleaseGC(w, ggc);
} }
} }
@@ -708,8 +712,8 @@ tty_render_field(Widget w, int x, int y, enum statusfields fld)
for (unsigned j = 0; j < SIZE(X11_cond_labels); ++j) { for (unsigned j = 0; j < SIZE(X11_cond_labels); ++j) {
struct tty_cond_field const *fldp = &X11_cond_labels[j]; struct tty_cond_field const *fldp = &X11_cond_labels[j];
if (fldp->text != NULL) { if (fldp->text != NULL) {
width += tty_render_text(w, x + width, y, " ", NO_COLOR, 0, BL_FLUSH); width += tty_render_text(w, NULL, x + width, y, " ", NO_COLOR, 0, BL_FLUSH);
width += tty_render_text(w, x + width, y, fldp->text, fldp->color, fldp->attrs, BL_FLUSH); width += tty_render_text(w, NULL, x + width, y, fldp->text, fldp->color, fldp->attrs, BL_FLUSH);
} }
} }
break; break;
@@ -719,15 +723,15 @@ tty_render_field(Widget w, int x, int y, enum statusfields fld)
struct tty_status_field const *fldp = &X11_status_labels[fld]; struct tty_status_field const *fldp = &X11_status_labels[fld];
if (fldp->text != NULL && fldp->text[0] != '\0') { if (fldp->text != NULL && fldp->text[0] != '\0') {
if (x != 0 && (formats[fld].pre == NULL || strchr("(/", formats[fld].pre[0]) == NULL)) { if (x != 0 && (formats[fld].pre == NULL || strchr("(/", formats[fld].pre[0]) == NULL)) {
width += tty_render_text(w, x + width, y, " ", NO_COLOR, 0, BL_FLUSH); width += tty_render_text(w, NULL, x + width, y, " ", NO_COLOR, 0, BL_FLUSH);
} }
if (formats[fld].pre != NULL) { if (formats[fld].pre != NULL) {
width += tty_render_text(w, x + width, y, formats[fld].pre, NO_COLOR, 0, BL_FLUSH); width += tty_render_text(w, NULL, x + width, y, formats[fld].pre, NO_COLOR, 0, BL_FLUSH);
} }
width += tty_render_text(w, x + width, y, fldp->text, fldp->color, width += tty_render_text(w, NULL, x + width, y, fldp->text, fldp->color,
fldp->attrs, fld); fldp->attrs, fld);
if (formats[fld].post != NULL) { if (formats[fld].post != NULL) {
width += tty_render_text(w, x + width, y, formats[fld].post, NO_COLOR, 0, BL_FLUSH); width += tty_render_text(w, NULL, x + width, y, formats[fld].post, NO_COLOR, 0, BL_FLUSH);
} }
} }
} }
@@ -739,8 +743,8 @@ tty_render_field(Widget w, int x, int y, enum statusfields fld)
/* Render text as part of the TTY status */ /* Render text as part of the TTY status */
static int static int
tty_render_text(Widget w, int x, int y, const char *text, int color, int attr, tty_render_text(Widget w, const XRectangle *clip, int x, int y,
enum statusfields fld) const char *text, int color, int attr, enum statusfields fld)
{ {
#ifndef STATUS_HILITES #ifndef STATUS_HILITES
nhUse(color); nhUse(color);
@@ -788,6 +792,13 @@ tty_render_text(Widget w, int x, int y, const char *text, int color, int attr,
GCFunction | GCForeground | GCBackground | GCFont, GCFunction | GCForeground | GCBackground | GCFont,
&values); &values);
/* If drawing a hitpoint bar, we'll need a clipping rectangle */
if (clip != NULL) {
/* @#$% non-const-correct Xlib functions */
XRectangle clip2 = *clip;
XSetClipRectangles(XtDisplay(w), ggc, 0, 0, &clip2, 1, Unsorted);
}
/* Gold will begin with a glyph string. Convert this to the proper /* Gold will begin with a glyph string. Convert this to the proper
character, which might possibly be Unicode */ character, which might possibly be Unicode */
if (fld == BL_GOLD && memcmp(text, "\\G", 2) == 0) { if (fld == BL_GOLD && memcmp(text, "\\G", 2) == 0) {