diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index c4fe8cd5a..b1ab56459 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -2631,4 +2631,6 @@ replace some old 'time_t' hackery in system.h and hacklib.c with something remove the per dungeon level door limit remove various '#if LINT' hacks used to suppress warnings from pre-ANSI 'lint' VMS: removed NO_VSNPRINTF conditional code - +remove the window port get_menu_coloring() calls from all the existing window + ports, and implement the functionality on the core-side of the + interface prior to calling the window port's foo_add_menu() function diff --git a/include/extern.h b/include/extern.h index 5710f150c..745bded6c 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2095,7 +2095,6 @@ extern const char *clr2colorname(int); extern int match_str2clr(char *); extern int match_str2attr(const char *, boolean); extern boolean add_menu_coloring(char *); -extern boolean get_menu_coloring(const char *, int *, int *); extern void free_menu_coloring(void); extern boolean msgtype_parse_add(char *); extern int msgtype_type(const char *, boolean); @@ -3440,6 +3439,8 @@ extern void genl_putmixed(winid, int, const char *); extern void genl_display_file(const char *, boolean); extern boolean menuitem_invert_test(int, unsigned, boolean); extern const char *mixed_to_glyphinfo(const char *str, glyph_info *gip); +extern void add_menu(winid, const glyph_info *, const ANY_P *, + char, char, int, int, const char *, unsigned int); /* ### windows.c ### */ diff --git a/include/winprocs.h b/include/winprocs.h index 5e0064819..ed02d24a3 100644 --- a/include/winprocs.h +++ b/include/winprocs.h @@ -125,7 +125,11 @@ extern #define putmixed (*windowprocs.win_putmixed) #define display_file (*windowprocs.win_display_file) #define start_menu (*windowprocs.win_start_menu) -#define add_menu (*windowprocs.win_add_menu) +/* 3.7: There is a real add_menu() in the core now, which does + * some common activities, such as menu_colors. + * add_menu() is in windows.c + */ +/* #define add_menu (*windowprocs.win_add_menu) */ #define end_menu (*windowprocs.win_end_menu) #define select_menu (*windowprocs.win_select_menu) #define message_menu (*windowprocs.win_message_menu) diff --git a/src/options.c b/src/options.c index f5ac201fd..e170c9cf6 100644 --- a/src/options.c +++ b/src/options.c @@ -8014,21 +8014,6 @@ add_menu_coloring(char *tmpstr) /* never Null but could be empty */ return add_menu_coloring_parsed(tmps, c, a); } -boolean -get_menu_coloring(const char *str, int *color, int *attr) -{ - struct menucoloring *tmpmc; - - if (iflags.use_menu_color) - for (tmpmc = gm.menu_colorings; tmpmc; tmpmc = tmpmc->next) - if (regex_match(str, tmpmc->match)) { - *color = tmpmc->color; - *attr = tmpmc->attr; - return TRUE; - } - return FALSE; -} - /* release all menu color patterns */ void free_menu_coloring(void) diff --git a/src/windows.c b/src/windows.c index 11892a1fd..894e2213f 100644 --- a/src/windows.c +++ b/src/windows.c @@ -61,6 +61,7 @@ extern void *trace_procs_chain(int, int, void *, void *, void *); static void def_raw_print(const char *s); static void def_wait_synch(void); +static boolean get_menu_coloring(const char *, int *, int *); #ifdef DUMPLOG static winid dump_create_nhwindow(int); @@ -1592,4 +1593,46 @@ mixed_to_glyphinfo(const char *str, glyph_info *gip) return str; } + +/* + * Common code point leading into the interface-specifc + * add_menu() to allow single-spot adjustments to the parameters, + * such as those done by menu_colors. + */ +void +add_menu( + winid window, /* window to use, must be of type NHW_MENU */ + const glyph_info *glyphinfo, /* glyph info with glyph to + * display with item */ + const anything *identifier, /* what to return if selected */ + char ch, /* selector letter (0 = pick our own) */ + char gch, /* group accelerator (0 = no group) */ + int attr, /* attribute for menu text (str) */ + int color, /* color for menu text (str) */ + const char *str, /* menu text */ + unsigned int itemflags) /* itemflags such as MENU_ITEMFLAGS_SELECTED */ +{ + if (iflags.use_menu_color) + (void) get_menu_coloring(str, &color, &attr); + + (*windowprocs.win_add_menu)(window, glyphinfo, identifier, + ch, gch, attr, color, str, itemflags); +} + +static boolean +get_menu_coloring(const char *str, int *color, int *attr) +{ + struct menucoloring *tmpmc; + + if (iflags.use_menu_color) + for (tmpmc = gm.menu_colorings; tmpmc; tmpmc = tmpmc->next) + if (regex_match(str, tmpmc->match)) { + *color = tmpmc->color; + *attr = tmpmc->attr; + return TRUE; + } + return FALSE; +} + + /*windows.c*/ diff --git a/win/Qt/qt_menu.cpp b/win/Qt/qt_menu.cpp index 834d91d00..de6e7552f 100644 --- a/win/Qt/qt_menu.cpp +++ b/win/Qt/qt_menu.cpp @@ -293,12 +293,6 @@ void NetHackQtMenuWindow::AddMenu(int glyph, const ANY_P *identifier, + str.mid(bracket+2); } } - int mcolor, mattr; - if (::iflags.use_menu_color - && get_menu_coloring(str.toLatin1().constData(), &mcolor, &mattr)) { - itemlist[itemcount].attr = mattr; - itemlist[itemcount].color = mcolor; - } ++itemcount; if (glyph != NO_GLYPH) diff --git a/win/X11/winmenu.c b/win/X11/winmenu.c index c6eff3af8..aa19b2567 100644 --- a/win/X11/winmenu.c +++ b/win/X11/winmenu.c @@ -1314,11 +1314,9 @@ menu_create_entries(struct xwindow *wp, struct menu *curr_menu) XtSetArg(args[num_args], nhStr(XtNborderWidth), 0); num_args++; XtSetArg(args[num_args], nhStr(XtNvertDistance), 0); num_args++; - if (!iflags.use_menu_color || wp->menu_information->disable_mcolors - || !get_menu_coloring(curr->str, &color, &attr)) { - attr = curr->attr; + attr = curr->attr; + if (!wp->menu_information->disable_mcolors) color = curr->color; - } if (color != NO_COLOR) { if (attr != ATR_INVERSE) diff --git a/win/curses/cursdial.c b/win/curses/cursdial.c index bf62dcc1b..8f7c068bf 100644 --- a/win/curses/cursdial.c +++ b/win/curses/cursdial.c @@ -1176,7 +1176,6 @@ menu_display_page( char *tmpstr; boolean first_accel = TRUE; int color = NO_COLOR, attr = A_NORMAL; - boolean menu_color = FALSE; /* letters assigned to entries on current page */ if (selectors) @@ -1281,19 +1280,15 @@ menu_display_page( start_col += 2; } #endif - color = NONE; - menu_color = iflags.use_menu_color - && get_menu_coloring(menu_item_ptr->str, &color, &attr); - if (menu_color) { - attr = curses_convert_attr(attr); - if (color != NONE || attr != A_NORMAL) - curses_menu_color_attr(win, color, attr, ON); - } else { - attr = menu_item_ptr->attr; + if (color != NO_COLOR) color = menu_item_ptr->color; - if (color != NONE || attr != A_NORMAL) - curses_toggle_color_attr(win, color, attr, ON); - } + + if (color == NO_COLOR) + color = NONE; + attr = menu_item_ptr->attr; + attr = curses_convert_attr(attr); + if (color != NONE || attr != A_NORMAL) + curses_menu_color_attr(win, color, attr, ON); num_lines = curses_num_lines(menu_item_ptr->str, entry_cols); for (count = 0; count < num_lines; count++) { @@ -1306,12 +1301,8 @@ menu_display_page( } } if (color != NONE || attr != A_NORMAL) { - if (menu_color) - curses_menu_color_attr(win, color, attr, OFF); - else - curses_toggle_color_attr(win, color, attr, OFF); + curses_menu_color_attr(win, color, attr, OFF); } - menu_item_ptr = menu_item_ptr->next_item; } diff --git a/win/curses/cursinvt.c b/win/curses/cursinvt.c index 416b4d77d..83f831e16 100644 --- a/win/curses/cursinvt.c +++ b/win/curses/cursinvt.c @@ -375,8 +375,10 @@ curs_show_invt(WINDOW *win) for (lineno = pi.rowoffset; lineno < pi.inuseindx; ++lineno) { str = pi.array[lineno].invtxt; accelerator = pi.array[lineno].letter; - attr = pi.array[lineno].c_attr; + attr = curses_convert_attr(pi.array[lineno].c_attr); color = pi.array[lineno].color; + if (color == NO_COLOR) + color = NONE; if (accelerator) ++item_count; @@ -413,17 +415,9 @@ curs_show_invt(WINDOW *win) stroffset = pi_article_skip(str); /* to skip "a "/"an "/"the " */ /* if/when scrolled right, invtxt for item lines gets shifted */ stroffset += pi.coloffset; - - /* only perform menu coloring on item entries, not subtitles */ - if (iflags.use_menu_color) { - get_menu_coloring(str, &color, (int *) &attr); - attr = curses_convert_attr(attr); - } } if (stroffset < strlen(str)) { - if (color == NO_COLOR) - color = NONE; curses_menu_color_attr(win, color, attr, ON); wprintw(win, "%.*s", available_width, str + stroffset); curses_menu_color_attr(win, color, attr, OFF); diff --git a/win/tty/wintty.c b/win/tty/wintty.c index 187469842..0ebbed4dd 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1419,11 +1419,8 @@ process_menu_window(winid window, struct WinDesc *cw) (void) putchar(' '); ++ttyDisplay->curx; - if (!iflags.use_menu_color - || !get_menu_coloring(curr->str, &color, &attr)) { - attr = curr->attr; - color = curr->color; - } + attr = curr->attr; + color = curr->color; /* which character to start attribute highlighting; whole line for headers and such, after the selector diff --git a/win/win32/mhmenu.c b/win/win32/mhmenu.c index 123b19bf8..c66d5d437 100644 --- a/win/win32/mhmenu.c +++ b/win/win32/mhmenu.c @@ -991,9 +991,6 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) char *p, *p1; int column; int spacing = 0; - - int color = NO_COLOR, attr; - boolean menucolr = FALSE; double monitorScale = win10_monitor_scale(hWnd); int tileXScaled = (int) (TILE_X * monitorScale); int tileYScaled = (int) (TILE_Y * monitorScale); @@ -1021,6 +1018,9 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) ? menu_fg_color : (COLORREF) GetSysColor(DEFAULT_COLOR_FG_MENU)); + if (item->color != NO_COLOR) + (void) SetTextColor(lpdis->hDC, nhcolor_to_RGB(item->color)); + GetTextMetrics(lpdis->hDC, &tm); spacing = tm.tmAveCharWidth; @@ -1058,15 +1058,6 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) if (item->accelerator != 0) { buf[0] = item->accelerator; buf[1] = '\x0'; - - if (iflags.use_menu_color - && (menucolr = get_menu_coloring(item->str, &color, &attr))) { - cached_font * menu_font = mswin_get_font(NHW_MENU, attr, lpdis->hDC, FALSE); - SelectObject(lpdis->hDC, menu_font->hFont); - if (color != NO_COLOR) - SetTextColor(lpdis->hDC, nhcolor_to_RGB(color)); - } - SetRect(&drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom); DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, @@ -1074,12 +1065,6 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) } x += tm.tmAveCharWidth + tm.tmOverhang + spacing; } else { - /* heading */ - if (iflags.use_menu_color) { - color = item->color; - if (color != NO_COLOR) - (void) SetTextColor(lpdis->hDC, nhcolor_to_RGB(color)); - } x += tileXScaled + tm.tmAveCharWidth + tm.tmOverhang + 2 * spacing; }