MCPcopy Create free account
hub / github.com/NetHack/NetHack / HiliteField

Function HiliteField

win/X11/winstat.c:294–366  ·  view source on GitHub ↗

highlight a tty-style status field (or condition) */

Source from the content-addressed store, hash-verified

292
293/* highlight a tty-style status field (or condition) */
294static void
295HiliteField(Widget label,
296 int fld, int cond, int colrattr,
297 XFontStruct **font_p)
298{
299#ifdef STATUS_HILITES
300 static Pixel grayPxl, blackPxl, whitePxl;
301 Arg args[6];
302 Cardinal num_args;
303 XFontStruct *font = X11_status_font;
304 Pixel px, fg = X11_status_fg, bg = X11_status_bg;
305 struct xwindow *xw = xw_status_win;
306 int colr, attr;
307
308 if ((colrattr & 0x00ff) >= CLR_MAX)
309 colrattr = (colrattr & ~0x00ff) | NO_COLOR;
310 colr = colrattr & 0x00ff; /* guaranteed to be >= 0 and < CLR_MAX */
311 attr = (colrattr >> 8) & 0x00ff;
312
313 if (!grayPxl) {/* one-time init */
314 grayPxl = get_nhcolor(xw, CLR_GRAY).pixel;
315 blackPxl = get_nhcolor(xw, CLR_BLACK).pixel;
316 whitePxl = get_nhcolor(xw, CLR_WHITE).pixel;
317 }
318 /* [shouldn't be necessary; setting up gray will set up all colors] */
319 if (colr != NO_COLOR && !xw->nh_colors[colr].pixel)
320 (void) get_nhcolor(xw, colr);
321
322 /* handle highlighting if caller has specified that; set foreground,
323 background, and font even if not specified this time in case they
324 used modified values last time (which would stick if not reset) */
325 (void) memset((genericptr_t) args, 0, sizeof args);
326 num_args = 0;
327 if (colr != NO_COLOR)
328 fg = xw->nh_colors[colr].pixel;
329 if ((attr & HL_INVERSE) != 0) {
330 px = fg;
331 fg = bg;
332 bg = px;
333 }
334 /* foreground and background might both default to black, so we
335 need to force one to be different if/when they're the same
336 (actually, tt_status_fixup() takes care of that nowadays);
337 using gray to implement 'dim' only works for black and white
338 (or color+'inverse' when former background was black or white) */
339 if (fg == bg
340 || ((attr & HL_DIM) != 0 && (fg == whitePxl || fg == blackPxl)))
341 fg = (fg != grayPxl) ? grayPxl
342 : (fg != blackPxl) ? blackPxl
343 : whitePxl;
344 XtSetArg(args[num_args], nhStr(XtNforeground), fg); num_args++;
345 XtSetArg(args[num_args], nhStr(XtNbackground), bg); num_args++;
346 if (attr & HL_BOLD) {
347 load_boldfont(xw_status_win, label);
348 if (xw_status_win->boldfs)
349 font = xw_status_win->boldfs;
350 }
351 XtSetArg(args[num_args], nhStr(XtNfont), font); num_args++;

Callers 3

PrepStatusFieldFunction · 0.85
DisplayCondFunction · 0.85
tt_reset_colorFunction · 0.85

Calls 2

get_nhcolorFunction · 0.85
load_boldfontFunction · 0.85

Tested by

no test coverage detected