follow-up to curses windowcolors

Make sure the windowcolors option can be specified more than
once without a config file warning.

Make the struct holding the details a little more extendable.
This commit is contained in:
nhmall
2024-03-17 14:18:14 -04:00
parent 0700f60983
commit b6b9bb0f27
6 changed files with 84 additions and 47 deletions

View File

@@ -195,6 +195,16 @@ struct debug_flags {
#endif
};
enum windowcolors_windows {
wcolor_menu, wcolor_message, wcolor_status, wcolor_text,
WC_COUNT
};
struct windowcolors_struct {
char *fg;
char *bg;
};
struct accessibility_data {
boolean accessiblemsg; /* use msg_loc for plined messages */
coord msg_loc; /* accessiblemsg: location */
@@ -379,6 +389,7 @@ struct instance_flags {
int wc_align_status; /* status win at top|bot|right|left */
int wc_align_message; /* message win at top|bot|right|left */
int wc_vary_msgcount; /* show more old messages at a time */
#if 0
char *wc_foregrnd_menu; /* points to foregrnd color name for menu win */
char *wc_backgrnd_menu; /* points to backgrnd color name for menu win */
char *wc_foregrnd_message; /* points to foregrnd color name for msg win */
@@ -387,6 +398,9 @@ struct instance_flags {
char *wc_backgrnd_status; /* points to backgrnd color name for status */
char *wc_foregrnd_text; /* points to foregrnd color name for text win */
char *wc_backgrnd_text; /* points to backgrnd color name for text win */
#else
struct windowcolors_struct wcolors[WC_COUNT];
#endif
char *wc_font_map; /* points to font name for the map win */
char *wc_font_message; /* points to font name for message win */
char *wc_font_status; /* points to font name for status win */

View File

@@ -96,10 +96,12 @@ static int optfn_##a(int, int, boolean, char *, char *);
#endif
#endif
/* B:nm, ln, opt_*, setwhere?, on?, negat?, val?, dup?, hndlr? Alias, bool_p, term */
/* C:nm, ln, opt_*, setwhere?, negateok?, valok?, dupok?, hndlr? Alias, desc */
/* P:pfx, ln, opt_*, setwhere?, negateok?, valok?, dupok?, hndlr? Alias, desc*/
/* B:nm, sec, ln, opt_*, setwhere?, on?, negat?, val?, dup?, hndlr? Alias,
bool_p, term */
/* C:nm, sec, ln, opt_*, setwhere?, negateok?, valok?, dupok?, hndlr? Alias,
desc */
/* P:pfx, sec, ln, opt_*, setwhere?, negateok?, valok?, dupok?, hndlr? Alias,
desc*/
/*
* Most of the options are in alphabetical order; a few are forced
* to the top of list so that doset() will list them first and
@@ -850,7 +852,7 @@ static int optfn_##a(int, int, boolean, char *, char *);
No, Yes, No, No, NoAlias, "window processor to use")
#endif
NHOPTC(windowcolors, Advanced, 80, opt_in, set_gameview,
No, Yes, No, No, NoAlias,
No, Yes, Yes, No, NoAlias,
"the foreground/background colors of windows")
/* NHOPTC(windowtype) -- moved to top */
NHOPTB(wizmgender, Advanced, 0, opt_in, set_wizonly,

View File

@@ -4698,17 +4698,31 @@ optfn_windowcolors(int optidx, int req, boolean negated UNUSED,
}
if (req == get_val || req == get_cnf_val) {
Sprintf(
opts, "%s/%s %s/%s %s/%s %s/%s",
iflags.wc_foregrnd_menu ? iflags.wc_foregrnd_menu : defbrief,
iflags.wc_backgrnd_menu ? iflags.wc_backgrnd_menu : defbrief,
iflags.wc_foregrnd_message ? iflags.wc_foregrnd_message
: defbrief,
iflags.wc_backgrnd_message ? iflags.wc_backgrnd_message
: defbrief,
iflags.wc_foregrnd_status ? iflags.wc_foregrnd_status : defbrief,
iflags.wc_backgrnd_status ? iflags.wc_backgrnd_status : defbrief,
iflags.wc_foregrnd_text ? iflags.wc_foregrnd_text : defbrief,
iflags.wc_backgrnd_text ? iflags.wc_backgrnd_text : defbrief);
opts, "%s/%s %s/%s %s/%s %s/%s",
iflags.wcolors[wcolor_menu].fg
? iflags.wcolors[wcolor_menu].fg
: defbrief,
iflags.wcolors[wcolor_menu].bg
? iflags.wcolors[wcolor_menu].bg
: defbrief,
iflags.wcolors[wcolor_message].fg
? iflags.wcolors[wcolor_message].fg
: defbrief,
iflags.wcolors[wcolor_message].bg
? iflags.wcolors[wcolor_message].bg
: defbrief,
iflags.wcolors[wcolor_status].fg
? iflags.wcolors[wcolor_status].fg
: defbrief,
iflags.wcolors[wcolor_status].bg
? iflags.wcolors[wcolor_status].bg
: defbrief,
iflags.wcolors[wcolor_text].fg
? iflags.wcolors[wcolor_text].fg
: defbrief,
iflags.wcolors[wcolor_text].bg
? iflags.wcolors[wcolor_text].bg
: defbrief);
return optn_ok;
}
return optn_ok;
@@ -9635,14 +9649,14 @@ wc_set_window_colors(char *op)
"menu", "message", "status", "text"
};
static const char *const shortnames[] = { "mnu", "msg", "sts", "txt" };
static char **fgp[] = { &iflags.wc_foregrnd_menu,
&iflags.wc_foregrnd_message,
&iflags.wc_foregrnd_status,
&iflags.wc_foregrnd_text };
static char **bgp[] = { &iflags.wc_backgrnd_menu,
&iflags.wc_backgrnd_message,
&iflags.wc_backgrnd_status,
&iflags.wc_backgrnd_text };
static char **fgp[] = { &iflags.wcolors[wcolor_menu].fg,
&iflags.wcolors[wcolor_message].fg,
&iflags.wcolors[wcolor_status].fg,
&iflags.wcolors[wcolor_text].fg };
static char **bgp[] = { &iflags.wcolors[wcolor_menu].bg,
&iflags.wcolors[wcolor_message].bg,
&iflags.wcolors[wcolor_status].bg,
&iflags.wcolors[wcolor_text].bg };
Strcpy(buf, op);
newop = mungspaces(buf);

View File

@@ -427,9 +427,11 @@ curses_create_nhwindow(int type)
winid wid = curses_get_wid(type);
if (curses_is_menu(wid))
curses_parse_wid_colors(MENU_WIN, iflags.wc_foregrnd_menu, iflags.wc_backgrnd_menu);
curses_parse_wid_colors(MENU_WIN, iflags.wcolors[wcolor_menu].fg,
iflags.wcolors[wcolor_menu].bg);
else if (curses_is_text(wid))
curses_parse_wid_colors(TEXT_WIN, iflags.wc_foregrnd_text, iflags.wc_backgrnd_text);
curses_parse_wid_colors(TEXT_WIN, iflags.wcolors[wcolor_text].fg,
iflags.wcolors[wcolor_text].bg);
if (curses_is_menu(wid) || curses_is_text(wid)) {
curses_start_menu(wid, MENU_BEHAVE_STANDARD);
curses_add_wid(wid);

View File

@@ -179,15 +179,18 @@ curses_set_wid_colors(int wid, WINDOW *win)
if (wid == TEXT_WIN || curses_is_text(wid)) {
wid = TEXT_WIN;
if (!nhwins[wid].clr_inited)
curses_parse_wid_colors(wid, iflags.wc_foregrnd_text, iflags.wc_backgrnd_text);
curses_parse_wid_colors(wid, iflags.wcolors[wcolor_text].fg,
iflags.wcolors[wcolor_text].bg);
} else if (wid == MENU_WIN || curses_is_menu(wid)) {
wid = MENU_WIN;
if (!nhwins[wid].clr_inited)
curses_parse_wid_colors(wid, iflags.wc_foregrnd_menu, iflags.wc_backgrnd_menu);
curses_parse_wid_colors(wid, iflags.wcolors[wcolor_menu].fg,
iflags.wcolors[wcolor_menu].bg);
}
/* FIXME: colors and nhwins[] entry for perm invent window */
if (nhwins[wid].clr_inited > 0) {
wbkgd(win ? win : nhwins[wid].curwin, COLOR_PAIR(nhwins[wid].colorpair));
wbkgd(win ? win : nhwins[wid].curwin,
COLOR_PAIR(nhwins[wid].colorpair));
}
}
@@ -361,12 +364,14 @@ curses_add_nhwin(winid wid, int height, int width, int y, int x,
switch (wid) {
case MESSAGE_WIN:
messagewin = win;
curses_parse_wid_colors(wid, iflags.wc_foregrnd_message, iflags.wc_backgrnd_message);
curses_parse_wid_colors(wid, iflags.wcolors[wcolor_message].fg,
iflags.wcolors[wcolor_message].bg);
curses_set_wid_colors(wid, NULL);
break;
case STATUS_WIN:
statuswin = win;
curses_parse_wid_colors(wid, iflags.wc_foregrnd_status, iflags.wc_backgrnd_status);
curses_parse_wid_colors(wid, iflags.wcolors[wcolor_status].fg,
iflags.wcolors[wcolor_status].bg);
curses_set_wid_colors(wid, NULL);
break;
case MAP_WIN:

View File

@@ -240,22 +240,22 @@ mswin_init_nhwindows(int *argc, char **argv)
| WC_FONTSIZ_TEXT | WC_VARY_MSGCOUNT,
set_in_game);
mswin_color_from_string(iflags.wc_foregrnd_menu, &menu_fg_brush,
&menu_fg_color);
mswin_color_from_string(iflags.wc_foregrnd_message, &message_fg_brush,
&message_fg_color);
mswin_color_from_string(iflags.wc_foregrnd_status, &status_fg_brush,
&status_fg_color);
mswin_color_from_string(iflags.wc_foregrnd_text, &text_fg_brush,
&text_fg_color);
mswin_color_from_string(iflags.wc_backgrnd_menu, &menu_bg_brush,
&menu_bg_color);
mswin_color_from_string(iflags.wc_backgrnd_message, &message_bg_brush,
&message_bg_color);
mswin_color_from_string(iflags.wc_backgrnd_status, &status_bg_brush,
&status_bg_color);
mswin_color_from_string(iflags.wc_backgrnd_text, &text_bg_brush,
&text_bg_color);
mswin_color_from_string(iflags.wcolors[wcolor_menu].fg,
&menu_fg_brush, &menu_fg_color);
mswin_color_from_string(iflags.wcolors[wcolor_message].fg,
&message_fg_brush, &message_fg_color);
mswin_color_from_string(iflags.wcolors[wcolor_status].fg,
&status_fg_brush, &status_fg_color);
mswin_color_from_string(iflags.wcolors[wcolor_text].fg,
&text_fg_brush, &text_fg_color);
mswin_color_from_string(iflags.wcolors[wcolor_menu].bg,
&menu_bg_brush, &menu_bg_color);
mswin_color_from_string(iflags.wcolors[wcolor_message].bg,
&message_bg_brush, &message_bg_color);
mswin_color_from_string(iflags.wcolors[wcolor_status].bg,
&status_bg_brush, &status_bg_color);
mswin_color_from_string(iflags.wcolors[wcolor_text].bg,
&text_bg_brush, &text_bg_color);
if (iflags.wc_splash_screen)
mswin_display_splash_window(FALSE);