From b6b9bb0f27c88c577fc6f8270d5141c3c2141b04 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sun, 17 Mar 2024 14:18:14 -0400 Subject: [PATCH] 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. --- include/flag.h | 14 ++++++++++++ include/optlist.h | 12 +++++----- src/options.c | 52 +++++++++++++++++++++++++++---------------- win/curses/cursmain.c | 6 +++-- win/curses/curswins.c | 15 ++++++++----- win/win32/mswproc.c | 32 +++++++++++++------------- 6 files changed, 84 insertions(+), 47 deletions(-) diff --git a/include/flag.h b/include/flag.h index 9c660f83b..680e19954 100644 --- a/include/flag.h +++ b/include/flag.h @@ -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 */ diff --git a/include/optlist.h b/include/optlist.h index a2919ed84..b757f1b71 100644 --- a/include/optlist.h +++ b/include/optlist.h @@ -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, diff --git a/src/options.c b/src/options.c index 2d63f2294..65b368a15 100644 --- a/src/options.c +++ b/src/options.c @@ -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); diff --git a/win/curses/cursmain.c b/win/curses/cursmain.c index f2bd12af2..eea0afc2f 100644 --- a/win/curses/cursmain.c +++ b/win/curses/cursmain.c @@ -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); diff --git a/win/curses/curswins.c b/win/curses/curswins.c index 39cf10804..f8f72247c 100644 --- a/win/curses/curswins.c +++ b/win/curses/curswins.c @@ -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: diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index e40c8a307..8f5f86c61 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -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);