use ctrl_nhwindow() for menu prompt style

This implements the mechanics to use the ctrl_nhwindow() interface
capability to pass down a setting change from the core to the active
window port, without resorting to accessing a core global variable
from within the window port, and without altering the interface..

The passed setting is honored in the tty and curses window ports.

X11 and mswin receive and store the values, but no implementation
to change the menu prompt style is there yet.

Qt does not store the values or have an implementation.

The setting change is done in allmain.c immediately after
creating the WIN_INVEN window.
This commit is contained in:
nhmall
2023-11-16 00:10:06 -05:00
parent 657d0f6105
commit 86067dcffd
13 changed files with 112 additions and 25 deletions
+1
View File
@@ -3437,6 +3437,7 @@ extern void genl_putmixed(winid, int, const char *);
extern void genl_display_file(const char *, boolean); extern void genl_display_file(const char *, boolean);
extern boolean menuitem_invert_test(int, unsigned, boolean); extern boolean menuitem_invert_test(int, unsigned, boolean);
extern const char *mixed_to_glyphinfo(const char *str, glyph_info *gip); extern const char *mixed_to_glyphinfo(const char *str, glyph_info *gip);
extern void adjust_menu_promptstyle(winid, color_attr *);
extern void add_menu(winid, const glyph_info *, const ANY_P *, extern void add_menu(winid, const glyph_info *, const ANY_P *,
char, char, int, int, const char *, unsigned int); char, char, int, int, const char *, unsigned int);
extern void add_menu_heading(winid, const char *); extern void add_menu_heading(winid, const char *);
-4
View File
@@ -186,10 +186,6 @@ struct debug_flags {
#endif #endif
}; };
typedef struct color_and_attr {
int color, attr;
} color_attr;
/* /*
* Stuff that really isn't option or platform related and does not * Stuff that really isn't option or platform related and does not
* get saved and restored. They are set and cleared during the game * get saved and restored. They are set and cleared during the game
+4
View File
@@ -445,6 +445,10 @@ extern struct nomakedefs_s nomakedefs;
#define MAXMONNO 120 /* extinct monst after this number created */ #define MAXMONNO 120 /* extinct monst after this number created */
#define MHPMAX 500 /* maximum monster hp */ #define MHPMAX 500 /* maximum monster hp */
typedef struct color_and_attr {
int color, attr;
} color_attr;
/* /*
* Version 3.7.x has aspirations of portable file formats. We * Version 3.7.x has aspirations of portable file formats. We
* make a distinction between MAIL functionality and MAIL_STRUCTURES * make a distinction between MAIL functionality and MAIL_STRUCTURES
+5 -2
View File
@@ -204,8 +204,9 @@ enum to_core_flags {
}; };
enum from_core_requests { enum from_core_requests {
set_mode = 1, set_mode = 1,
request_settings = 2, request_settings = 2,
set_menu_promptstyle = 3
}; };
struct to_core { struct to_core {
@@ -220,6 +221,7 @@ struct to_core {
struct from_core { struct from_core {
enum from_core_requests core_request; enum from_core_requests core_request;
enum inv_modes invmode; enum inv_modes invmode;
color_attr menu_promptstyle;
}; };
struct win_request_info_t { struct win_request_info_t {
@@ -228,6 +230,7 @@ struct win_request_info_t {
}; };
typedef struct win_request_info_t win_request_info; typedef struct win_request_info_t win_request_info;
extern win_request_info zerowri; /* windows.c */
/* #define CORE_INVENT */ /* #define CORE_INVENT */
+3
View File
@@ -662,6 +662,7 @@ void
init_sound_disp_gamewindows(void) init_sound_disp_gamewindows(void)
{ {
int menu_behavior = MENU_BEHAVE_STANDARD; int menu_behavior = MENU_BEHAVE_STANDARD;
color_attr menu_promptstyle = { NO_COLOR, ATR_INVERSE };
activate_chosen_soundlib(); activate_chosen_soundlib();
@@ -680,6 +681,8 @@ init_sound_disp_gamewindows(void)
} }
WIN_MAP = create_nhwindow(NHW_MAP); WIN_MAP = create_nhwindow(NHW_MAP);
WIN_INVEN = create_nhwindow(NHW_MENU); WIN_INVEN = create_nhwindow(NHW_MENU);
if (WIN_INVEN != WIN_ERR)
adjust_menu_promptstyle(WIN_INVEN, &menu_promptstyle);
#ifdef TTY_PERM_INVENT #ifdef TTY_PERM_INVENT
if (WINDOWPORT(tty) && WIN_INVEN != WIN_ERR) { if (WINDOWPORT(tty) && WIN_INVEN != WIN_ERR) {
menu_behavior = MENU_BEHAVE_PERMINV; menu_behavior = MENU_BEHAVE_PERMINV;
-1
View File
@@ -45,7 +45,6 @@ static void itemactions_pushkeys(struct obj *, int);
static void mime_action(const char *); static void mime_action(const char *);
/* enum and structs are defined in wintype.h */ /* enum and structs are defined in wintype.h */
static win_request_info zerowri = { { 0L, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0 } };
static win_request_info wri_info; static win_request_info wri_info;
static int perminv_flags = InvOptNone; static int perminv_flags = InvOptNone;
static boolean in_perm_invent_toggled; static boolean in_perm_invent_toggled;
+14
View File
@@ -1593,6 +1593,20 @@ mixed_to_glyphinfo(const char *str, glyph_info *gip)
return str; return str;
} }
/* enum and structs are defined in wintype.h */
win_request_info zerowri = { { 0L, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, { NO_COLOR, ATR_NONE }}};
void
adjust_menu_promptstyle(winid window, color_attr *style)
{
win_request_info wri = zerowri;
wri.fromcore.menu_promptstyle.color = style->color;
wri.fromcore.menu_promptstyle.attr = style->attr;
/* relay the style change to the window port */
(void) ctrl_nhwindow(window, set_menu_promptstyle, &wri);
}
/* /*
* Common code point leading into the interface-specifc * Common code point leading into the interface-specifc
+16 -4
View File
@@ -504,12 +504,24 @@ void NetHackQtBind::qt_update_inventory(int arg UNUSED)
} }
win_request_info *NetHackQtBind::qt_ctrl_nhwindow( win_request_info *NetHackQtBind::qt_ctrl_nhwindow(
winid wid UNUSED, winid wid,
int request UNUSED, int request,
win_request_info *wri UNUSED) win_request_info *wri)
{ {
NetHackQtWindow* window UNUSED =id_to_window[(int)wid]; NetHackQtWindow* window UNUSED =id_to_window[(int)wid];
return (win_request_info *) 0;
if (!wri)
return (win_request_info *) 0;
switch(request) {
case set_menu_promptstyle:
/* = wri->fromcore.menu_promptstyle; */
break;
default:
impossible("invalid request to ctrl_nhwindow: %d", request);
break;
}
return wri;
} }
void NetHackQtBind::qt_mark_synch() void NetHackQtBind::qt_mark_synch()
+13 -1
View File
@@ -98,6 +98,7 @@ void (*input_func)(Widget, XEvent *, String *, Cardinal *);
int click_x, click_y, click_button; /* Click position on a map window int click_x, click_y, click_button; /* Click position on a map window
* (filled by set_button_values()). */ * (filled by set_button_values()). */
int updated_inventory; /* used to indicate perm_invent updating */ int updated_inventory; /* used to indicate perm_invent updating */
color_attr X11_menu_promptstyle = { NO_COLOR, ATR_NONE };
static void X11_error_handler(String) NORETURN; static void X11_error_handler(String) NORETURN;
static int X11_io_error_handler(Display *); static int X11_io_error_handler(Display *);
@@ -1308,7 +1309,18 @@ X11_ctrl_nhwindow(
int request UNUSED, int request UNUSED,
win_request_info *wri UNUSED) win_request_info *wri UNUSED)
{ {
return (win_request_info *) 0; if (!wri)
return (win_request_info *) 0;
switch(request) {
case set_menu_promptstyle:
X11_menu_promptstyle = wri->fromcore.menu_promptstyle;
break;
default:
impossible("invalid request to ctrl_nhwindow: %d", request);
break;
}
return wri;
} }
/* The current implementation has all of the saved lines on the screen. */ /* The current implementation has all of the saved lines on the screen. */
+6 -2
View File
@@ -1164,6 +1164,8 @@ get_menuitem_y(
/* Displays menu selections in the given window */ /* Displays menu selections in the given window */
extern color_attr curses_menu_promptstyle; /*cursmain.c */
static void static void
menu_display_page( menu_display_page(
nhmenu *menu, WINDOW *win, nhmenu *menu, WINDOW *win,
@@ -1207,9 +1209,11 @@ menu_display_page(
for (count = 0; count < num_lines; count++) { for (count = 0; count < num_lines; count++) {
tmpstr = curses_break_str(menu->prompt, menu->width, count + 1); tmpstr = curses_break_str(menu->prompt, menu->width, count + 1);
curses_toggle_color_attr(win, NO_COLOR, A_NORMAL, ON); curses_toggle_color_attr(win, curses_menu_promptstyle.color,
curses_menu_promptstyle.attr, ON);
mvwprintw(win, count + 1, 1, "%s", tmpstr); mvwprintw(win, count + 1, 1, "%s", tmpstr);
curses_toggle_color_attr(win, NO_COLOR, A_NORMAL, OFF); curses_toggle_color_attr(win, curses_menu_promptstyle.color,
curses_menu_promptstyle.attr, OFF);
free(tmpstr); free(tmpstr);
} }
} }
+26 -3
View File
@@ -149,6 +149,7 @@ int orig_cursor; /* Preserve initial cursor state */
WINDOW *base_term; /* underlying terminal window */ WINDOW *base_term; /* underlying terminal window */
boolean counting; /* Count window is active */ boolean counting; /* Count window is active */
WINDOW *mapwin, *statuswin, *messagewin; /* Main windows */ WINDOW *mapwin, *statuswin, *messagewin; /* Main windows */
color_attr curses_menu_promptstyle = { NO_COLOR, ATR_NONE };
/* Track if we're performing an update to the permanent window. /* Track if we're performing an update to the permanent window.
Needed since we aren't using the normal menu functions to handle Needed since we aren't using the normal menu functions to handle
@@ -799,10 +800,32 @@ curses_update_inventory(int arg)
win_request_info * win_request_info *
curses_ctrl_nhwindow( curses_ctrl_nhwindow(
winid window UNUSED, winid window UNUSED,
int request UNUSED, int request,
win_request_info *wri UNUSED) win_request_info *wri)
{ {
return (win_request_info *) 0; int attr;
if (!wri)
return (win_request_info *) 0;
switch (request) {
#if 0
case set_mode:
case request_settings:
break;
#endif
case set_menu_promptstyle:
curses_menu_promptstyle.color = wri->fromcore.menu_promptstyle.color;
if (curses_menu_promptstyle.color == NO_COLOR)
curses_menu_promptstyle.color = NONE;
attr = wri->fromcore.menu_promptstyle.attr;
curses_menu_promptstyle.attr = curses_convert_attr(attr);;
break;
default:
impossible("invalid request to ctrl_nhwindow: %d", request);
break;
}
return wri;
} }
/* /*
+11 -7
View File
@@ -2593,6 +2593,8 @@ reverse(tty_menu_item *curr)
return head; return head;
} }
static color_attr tty_menu_promptstyle = { NO_COLOR, ATR_NONE };
/* /*
* End a menu in this window, window must a type NHW_MENU. This routine * End a menu in this window, window must a type NHW_MENU. This routine
* processes the string list. We calculate the # of pages, then assign * processes the string list. We calculate the # of pages, then assign
@@ -2642,7 +2644,8 @@ tty_end_menu(
tty_add_menu(window, &nul_glyphinfo, &any, 0, 0, tty_add_menu(window, &nul_glyphinfo, &any, 0, 0,
ATR_NONE, clr, "", MENU_ITEMFLAGS_NONE); ATR_NONE, clr, "", MENU_ITEMFLAGS_NONE);
tty_add_menu(window, &nul_glyphinfo, &any, 0, 0, tty_add_menu(window, &nul_glyphinfo, &any, 0, 0,
ATR_NONE, clr, prompt, MENU_ITEMFLAGS_NONE); tty_menu_promptstyle.attr, tty_menu_promptstyle.color,
prompt, MENU_ITEMFLAGS_NONE);
} }
/* 52: 'a'..'z' and 'A'..'Z'; avoids selector duplication within a page */ /* 52: 'a'..'z' and 'A'..'Z'; avoids selector duplication within a page */
@@ -2807,22 +2810,20 @@ RESTORE_WARNING_FORMAT_NONLITERAL
win_request_info * win_request_info *
tty_ctrl_nhwindow(winid window UNUSED, int request, win_request_info *wri) tty_ctrl_nhwindow(winid window UNUSED, int request, win_request_info *wri)
{ {
#if !defined(TTY_PERM_INVENT) #if defined(TTY_PERM_INVENT)
wri = (win_request_info *) 0;
nhUse(window);
nhUse(request);
#else
boolean tty_ok /*, show_gold */, inuse_only; boolean tty_ok /*, show_gold */, inuse_only;
int maxslot; int maxslot;
/* these types are set match the wintty.h field declarations */ /* these types are set match the wintty.h field declarations */
long minrow; /* long to match maxrow declaration in wintty.h */ long minrow; /* long to match maxrow declaration in wintty.h */
short offx, offy; short offx, offy;
long rows, cols, maxrow, maxcol; long rows, cols, maxrow, maxcol;
#endif
if (!wri) if (!wri)
return (win_request_info *) 0; return (win_request_info *) 0;
switch (request) { switch (request) {
#if defined(TTY_PERM_INVENT)
case set_mode: case set_mode:
case request_settings: case request_settings:
ttyinvmode = wri->fromcore.invmode; ttyinvmode = wri->fromcore.invmode;
@@ -2850,11 +2851,14 @@ tty_ctrl_nhwindow(winid window UNUSED, int request, win_request_info *wri)
wri->tocore.maxslot = maxslot; wri->tocore.maxslot = maxslot;
} }
break; break;
#endif /* TTY_PERM_INVENT */
case set_menu_promptstyle:
tty_menu_promptstyle = wri->fromcore.menu_promptstyle;
break;
default: default:
impossible("invalid request to tty_ctrl_nhwindow: %d", request); impossible("invalid request to tty_ctrl_nhwindow: %d", request);
break; break;
} }
#endif
return wri; return wri;
} }
+13 -1
View File
@@ -76,6 +76,7 @@ COLORREF message_bg_color = RGB(0, 0, 0);
COLORREF message_fg_color = RGB(0xFF, 0xFF, 0xFF); COLORREF message_fg_color = RGB(0xFF, 0xFF, 0xFF);
strbuf_t raw_print_strbuf = { 0 }; strbuf_t raw_print_strbuf = { 0 };
mswin_menu_promptstyle = { NO_COLOR, ATR_NONE };
/* Interface definition, for windows.c */ /* Interface definition, for windows.c */
struct window_procs mswin_procs = { struct window_procs mswin_procs = {
@@ -1255,7 +1256,18 @@ mswin_ctrl_nhwindow(
int request, int request,
win_request_info *wri) win_request_info *wri)
{ {
return (win_request_info *) 0; if (!wri)
return (win_request_info *) 0;
switch(request) {
case set_menu_promptstyle:
mswin_menu_promptstyle = wri->fromcore.menu_promptstyle;
break;
default:
impossible("invalid request to ctrl_nhwindow: %d", request);
break;
}
return wri;
} }
/* /*