more window port interface adjustments

further adjustments to the window port interface to pass a pointer
to a glyph_info struct which describes not just the glyph number
itself, but also the ttychar, the color, the glyphflags, and the
symset index.

This affects two existing window port calls that get passed glyphs
and does the parameter consistently for both of them using the
glyph_info struct pointer:
	print_glyph()
	add_menu().

The recently added glyphmod parameter is now unnecessary and has been
removed.
This commit is contained in:
nhmall
2021-01-05 10:09:37 -05:00
parent 2a9a18fa2f
commit c9673b3d9e
63 changed files with 841 additions and 705 deletions
+28 -33
View File
@@ -35,9 +35,8 @@ extern short glyph2tile[];
typedef struct mswin_nethack_map_window {
HWND hWnd; /* window */
int map[COLNO][ROWNO]; /* glyph map */
int bkmap[COLNO][ROWNO]; /* backround glyph map */
unsigned glyphmod[COLNO][ROWNO][NUM_GLYPHMOD];
glyph_info map[COLNO][ROWNO];
glyph_info bkmap[COLNO][ROWNO];
boolean mapDirty[COLNO][ROWNO]; /* dirty flag for map */
int mapMode; /* current map mode */
boolean bAsciiMode; /* switch ASCII/tiled mode */
@@ -86,7 +85,8 @@ static void nhcoord2display(PNHMapWindow data, int x, int y, LPRECT lpOut);
static void paint(PNHMapWindow data, int i, int j);
static void dirtyAll(PNHMapWindow data);
static void dirty(PNHMapWindow data, int i, int j);
static void setGlyph(PNHMapWindow data, int i, int j, int fg, int bg, unsigned *glyphmod);
static void setGlyph(PNHMapWindow data, int i, int j,
const glyph_info *fg, const glyph_info *bg);
static void clearAll(PNHMapWindow data);
#if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2)
@@ -639,7 +639,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
case MSNH_MSG_PRINT_GLYPH: {
PMSNHMsgPrintGlyph msg_data = (PMSNHMsgPrintGlyph) lParam;
setGlyph(data, msg_data->x, msg_data->y,
msg_data->glyph, msg_data->bkglyph, msg_data->glyphmod);
&msg_data->glyphinfo, &msg_data->bkglyphinfo);
} break;
case MSNH_MSG_CLIPAROUND: {
@@ -719,9 +719,9 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
for (col = 0; col < COLNO; col++) {
if (index >= msg_data->max_size)
break;
if (data->map[col][row] == NO_GLYPH)
if (data->map[col][row].glyph == NO_GLYPH)
mgch = ' ';
msg_data->buffer[index] = data->glyphmod[col][row][GM_TTYCHAR];
msg_data->buffer[index] = data->map[col][row].ttychar;
index++;
}
if (index >= msg_data->max_size - 1)
@@ -788,8 +788,8 @@ paintTile(PNHMapWindow data, int i, int j, RECT * rect)
// int mgch;
#endif
layer = 0;
glyph = data->map[i][j];
bkglyph = data->bkmap[i][j];
glyph = data->map[i][j].glyph;
bkglyph = data->bkmap[i][j].glyph;
if (glyph == NO_GLYPH && bkglyph == NO_GLYPH) {
HBRUSH blackBrush = CreateSolidBrush(RGB(0, 0, 0));
@@ -812,7 +812,7 @@ paintTile(PNHMapWindow data, int i, int j, RECT * rect)
if ((glyph != NO_GLYPH) && (glyph != bkglyph)) {
/* rely on NetHack core helper routine */
ntile = glyph2tile[glyph];
if (data->glyphmod[i][j][GM_FLAGS] & MG_FEMALE)
if (data->map[i][j].glyphflags & MG_FEMALE)
ntile++;
t_x = TILEBMP_X(ntile);
t_y = TILEBMP_Y(ntile);
@@ -834,7 +834,7 @@ paintTile(PNHMapWindow data, int i, int j, RECT * rect)
}
#ifdef USE_PILEMARK
if ((glyph != NO_GLYPH) && (data->glyphmod[i][j][GM_FLAGS] & MG_PET)
if ((glyph != NO_GLYPH) && (data->map[i][j].glyphflags & MG_PET)
#else
if ((glyph != NO_GLYPH) && glyph_is_pet(glyph)
#endif
@@ -857,7 +857,7 @@ paintTile(PNHMapWindow data, int i, int j, RECT * rect)
DeleteDC(hdcPetMark);
}
#ifdef USE_PILEMARK
if ((glyph != NO_GLYPH) && (data->glyphmod[i][j][GM_FLAGS] & MG_OBJPILE)
if ((glyph != NO_GLYPH) && (data->map[i][j].glyphflags & MG_OBJPILE)
&& iflags.hilite_pile) {
/* apply pilemark transparently over other image */
HDC hdcPileMark;
@@ -886,7 +886,7 @@ paintTile(PNHMapWindow data, int i, int j, RECT * rect)
static void
paintGlyph(PNHMapWindow data, int i, int j, RECT * rect)
{
if (data->map[i][j] >= 0) {
if (data->map[i][j].glyph >= 0) {
char ch;
WCHAR wch;
@@ -906,10 +906,10 @@ paintGlyph(PNHMapWindow data, int i, int j, RECT * rect)
nhglyph2charcolor(data->map[i][j], &ch, &color);
OldFg = SetTextColor(hDC, nhcolor_to_RGB(color));
#else
ch = (char) data->glyphmod[i][j][GM_TTYCHAR];
color = (int) data->glyphmod[i][j][GM_COLOR];
if (((data->glyphmod[i][j][GM_FLAGS] & MG_PET) && iflags.hilite_pet)
|| ((data->glyphmod[i][j][GM_FLAGS] & (MG_DETECT | MG_BW_LAVA))
ch = (char) data->map[i][j].ttychar;
color = (int) data->map[i][j].color;
if (((data->map[i][j].glyphflags & MG_PET) && iflags.hilite_pet)
|| ((data->map[i][j].glyphflags & (MG_DETECT | MG_BW_LAVA))
&& iflags.use_inverse)) {
back_brush =
CreateSolidBrush(nhcolor_to_RGB(CLR_GRAY));
@@ -968,19 +968,17 @@ paintGlyph(PNHMapWindow data, int i, int j, RECT * rect)
}
}
static void setGlyph(PNHMapWindow data, int i, int j, int fg, int bg, unsigned *glyphmod)
static void setGlyph(PNHMapWindow data, int i, int j,
const glyph_info *fg, const glyph_info *bg)
{
int gm;
if ((data->map[i][j] != fg) || (data->bkmap[i][j] != bg)
|| data->glyphmod[i][j][GM_TTYCHAR] != glyphmod[GM_TTYCHAR]
|| data->glyphmod[i][j][GM_COLOR] != glyphmod[GM_COLOR]
|| data->glyphmod[i][j][GM_FLAGS] != glyphmod[GM_FLAGS]) {
data->map[i][j] = fg;
data->bkmap[i][j] = bg;
if ((data->map[i][j].glyph != fg->glyph)
|| (data->bkmap[i][j].glyph != bg->glyph)
|| data->map[i][j].ttychar != fg->ttychar
|| data->map[i][j].color != fg->color
|| data->map[i][j].glyphflags != fg->glyphflags) {
data->map[i][j] = *fg;
data->bkmap[i][j] = *bg;
data->mapDirty[i][j] = TRUE;
for (gm = 0; gm < NUM_GLYPHMOD; ++gm)
data->glyphmod[i][j][gm] = glyphmod[gm];
RECT rect;
nhcoord2display(data, i, j, &rect);
InvalidateRect(data->hWnd, &rect, FALSE);
@@ -991,11 +989,8 @@ static void clearAll(PNHMapWindow data)
{
for (int x = 0; x < COLNO; x++)
for (int y = 0; y < ROWNO; y++) {
data->map[x][y] = NO_GLYPH;
data->bkmap[x][y] = NO_GLYPH;
data->glyphmod[x][y][GM_TTYCHAR] = ' ';
data->glyphmod[x][y][GM_COLOR] = NO_COLOR;
data->glyphmod[x][y][GM_FLAGS] = 0U;
data->map[x][y] = nul_glyphinfo;
data->bkmap[x][y] = nul_glyphinfo;
data->mapDirty[x][y] = TRUE;
}
InvalidateRect(data->hWnd, NULL, FALSE);
+5 -5
View File
@@ -27,7 +27,7 @@
#define CHECK_HEIGHT 16
typedef struct mswin_menu_item {
int glyph;
glyph_info glyphinfo;
ANY_P identifier;
CHAR_P accelerator;
CHAR_P group_accel;
@@ -78,7 +78,7 @@ static WNDPROC editControlWndProc = NULL;
#define NHMENU_IS_SELECTABLE(item) ((item).identifier.a_obj != NULL)
#define NHMENU_IS_SELECTED(item) ((item).count != 0)
#define NHMENU_HAS_GLYPH(item) ((item).glyph != NO_GLYPH)
#define NHMENU_HAS_GLYPH(item) ((item).glyphinfo.glyph != NO_GLYPH)
INT_PTR CALLBACK MenuWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK NHMenuListWndProc(HWND, UINT, WPARAM, LPARAM);
@@ -618,7 +618,7 @@ onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
new_item = data->menu.size;
ZeroMemory(&data->menu.items[new_item],
sizeof(data->menu.items[new_item]));
data->menu.items[new_item].glyph = msg_data->glyph;
data->menu.items[new_item].glyphinfo = msg_data->glyphinfo;
data->menu.items[new_item].identifier = *msg_data->identifier;
data->menu.items[new_item].accelerator = msg_data->accelerator;
data->menu.items[new_item].group_accel = msg_data->group_accel;
@@ -1082,7 +1082,7 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
double monitorScale = win10_monitor_scale(hWnd);
saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles);
ntile = glyph2tile[item->glyph];
ntile = glyph2tile[item->glyphinfo.glyph];
t_x =
(ntile % GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_X;
t_y =
@@ -1166,7 +1166,7 @@ onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
client_rt.right = min(client_rt.right, lpdis->rcItem.right);
if (NHMENU_IS_SELECTABLE(*item)
&& data->menu.items[lpdis->itemID].count != 0
&& item->glyph != NO_GLYPH) {
&& item->glyphinfo.glyph != NO_GLYPH) {
if (data->menu.items[lpdis->itemID].count == -1) {
_stprintf(wbuf, TEXT("Count: All"));
} else {
+3 -4
View File
@@ -36,9 +36,8 @@ typedef struct mswin_nhmsg_putstr {
typedef struct mswin_nhmsg_print_glyph {
XCHAR_P x;
XCHAR_P y;
int glyph;
int bkglyph;
int glyphmod[NUM_GLYPHMOD];
glyph_info glyphinfo;
glyph_info bkglyphinfo;
} MSNHMsgPrintGlyph, *PMSNHMsgPrintGlyph;
typedef struct mswin_nhmsg_cliparound {
@@ -47,7 +46,7 @@ typedef struct mswin_nhmsg_cliparound {
} MSNHMsgClipAround, *PMSNHMsgClipAround;
typedef struct mswin_nhmsg_add_menu {
int glyph;
glyph_info glyphinfo;
const ANY_P *identifier;
CHAR_P accelerator;
CHAR_P group_accel;
+50 -47
View File
@@ -428,8 +428,8 @@ prompt_for_player_selection(void)
} else
Strcpy(rolenamebuf, roles[i].name.m);
}
add_menu(win, NO_GLYPH, &any, thisch, 0, ATR_NONE,
an(rolenamebuf), MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, thisch, 0,
ATR_NONE, an(rolenamebuf), MENU_ITEMFLAGS_NONE);
lastch = thisch;
}
}
@@ -437,11 +437,11 @@ prompt_for_player_selection(void)
flags.initalign, PICK_RANDOM) + 1;
if (any.a_int == 0) /* must be non-zero */
any.a_int = randrole(FALSE) + 1;
add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random",
MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, '*', 0,
ATR_NONE, "Random", MENU_ITEMFLAGS_NONE);
any.a_int = i + 1; /* must be non-zero */
add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit",
MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, 'q', 0,
ATR_NONE, "Quit", MENU_ITEMFLAGS_NONE);
Sprintf(pbuf, "Pick a role for your %s", plbuf);
end_menu(win, pbuf);
n = select_menu(win, PICK_ONE, &selected);
@@ -503,18 +503,19 @@ prompt_for_player_selection(void)
if (ok_race(flags.initrole, i, flags.initgend,
flags.initalign)) {
any.a_int = i + 1; /* must be non-zero */
add_menu(win, NO_GLYPH, &any, races[i].noun[0], 0,
ATR_NONE, races[i].noun, MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any,
races[i].noun[0], 0, ATR_NONE,
races[i].noun, MENU_ITEMFLAGS_NONE);
}
any.a_int = pick_race(flags.initrole, flags.initgend,
flags.initalign, PICK_RANDOM) + 1;
if (any.a_int == 0) /* must be non-zero */
any.a_int = randrace(flags.initrole) + 1;
add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random",
MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, '*', 0,
ATR_NONE, "Random", MENU_ITEMFLAGS_NONE);
any.a_int = i + 1; /* must be non-zero */
add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit",
MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, 'q', 0,
ATR_NONE, "Quit", MENU_ITEMFLAGS_NONE);
Sprintf(pbuf, "Pick the race of your %s", plbuf);
end_menu(win, pbuf);
n = select_menu(win, PICK_ONE, &selected);
@@ -577,18 +578,19 @@ prompt_for_player_selection(void)
if (ok_gend(flags.initrole, flags.initrace, i,
flags.initalign)) {
any.a_int = i + 1;
add_menu(win, NO_GLYPH, &any, genders[i].adj[0], 0,
ATR_NONE, genders[i].adj, MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any,
genders[i].adj[0], 0, ATR_NONE,
genders[i].adj, MENU_ITEMFLAGS_NONE);
}
any.a_int = pick_gend(flags.initrole, flags.initrace,
flags.initalign, PICK_RANDOM) + 1;
if (any.a_int == 0) /* must be non-zero */
any.a_int = randgend(flags.initrole, flags.initrace) + 1;
add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random",
MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, '*', 0,
ATR_NONE, "Random", MENU_ITEMFLAGS_NONE);
any.a_int = i + 1; /* must be non-zero */
add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit",
MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, 'q', 0,
ATR_NONE, "Quit", MENU_ITEMFLAGS_NONE);
Sprintf(pbuf, "Pick the gender of your %s", plbuf);
end_menu(win, pbuf);
n = select_menu(win, PICK_ONE, &selected);
@@ -650,18 +652,19 @@ prompt_for_player_selection(void)
if (ok_align(flags.initrole, flags.initrace,
flags.initgend, i)) {
any.a_int = i + 1;
add_menu(win, NO_GLYPH, &any, aligns[i].adj[0], 0,
ATR_NONE, aligns[i].adj, MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any,
aligns[i].adj[0], 0, ATR_NONE,
aligns[i].adj, MENU_ITEMFLAGS_NONE);
}
any.a_int = pick_align(flags.initrole, flags.initrace,
flags.initgend, PICK_RANDOM) + 1;
if (any.a_int == 0) /* must be non-zero */
any.a_int = randalign(flags.initrole, flags.initrace) + 1;
add_menu(win, NO_GLYPH, &any, '*', 0, ATR_NONE, "Random",
MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, '*', 0,
ATR_NONE, "Random", MENU_ITEMFLAGS_NONE);
any.a_int = i + 1; /* must be non-zero */
add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE, "Quit",
MENU_ITEMFLAGS_NONE);
add_menu(win, &nul_glyphinfo, &any, 'q', 0,
ATR_NONE, "Quit", MENU_ITEMFLAGS_NONE);
Sprintf(pbuf, "Pick the alignment of your %s", plbuf);
end_menu(win, pbuf);
n = select_menu(win, PICK_ONE, &selected);
@@ -1093,12 +1096,12 @@ mswin_start_menu(winid wid, unsigned long mbehavior)
}
/*
add_menu(windid window, int glyph, const anything identifier,
add_menu(windid window, const glyph_info *glyphinfo,
const anything identifier,
char accelerator, char groupacc,
int attr, char *str, unsigned int itemflags)
-- Add a text line str to the given menu window. If
identifier
is 0, then the line cannot be selected (e.g. a title).
identifier is 0, then the line cannot be selected (e.g. a title).
Otherwise, identifier is the value returned if the line is
selected. Accelerator is a keyboard key that can be used
to select the line. If the accelerator of a selectable
@@ -1106,8 +1109,8 @@ identifier
accelerator. It is up to the window-port to make the
accelerator visible to the user (e.g. put "a - " in front
of str). The value attr is the same as in putstr().
Glyph is an optional glyph to accompany the line. If
window port cannot or does not want to display it, this
Glyphinfo->glyph is an optional glyph to accompany the line.
If window port cannot or does not want to display it, this
is OK. If there is no glyph applicable, then this
value will be NO_GLYPH.
-- All accelerators should be in the range [A-Za-z].
@@ -1125,19 +1128,22 @@ identifier
menu is displayed, set preselected to TRUE.
*/
void
mswin_add_menu(winid wid, int glyph, const ANY_P *identifier,
mswin_add_menu(winid wid, const glyph_info *glyphinfo,
const ANY_P *identifier,
CHAR_P accelerator, CHAR_P group_accel, int attr,
const char *str, unsigned int itemflags)
{
boolean presel = ((itemflags & MENU_ITEMFLAGS_SELECTED) != 0);
logDebug("mswin_add_menu(%d, %d, %p, %c, %c, %d, %s, %u)\n", wid, glyph,
logDebug("mswin_add_menu(%d, %d, %u, %p, %c, %c, %d, %s, %u)\n", wid,
glyphinfo->glyph, glyphinfo->glyphflags,
identifier, (char) accelerator, (char) group_accel, attr, str,
itemflags);
if ((wid >= 0) && (wid < MAXWINDOWS)
&& (GetNHApp()->windowlist[wid].win != NULL)) {
MSNHMsgAddMenu data;
ZeroMemory(&data, sizeof(data));
data.glyph = glyph;
if (glyphinfo)
data.glyphinfo = *glyphinfo;
data.identifier = identifier;
data.accelerator = accelerator;
data.group_accel = group_accel;
@@ -1281,24 +1287,22 @@ mswin_cliparound(int x, int y)
}
/*
print_glyph(window, x, y, glyph, bkglyph, glyphmod)
-- Print the glyph at (x,y) on the given window. Glyphs are
integers at the interface, mapped to whatever the window-
print_glyph(window, x, y, glyphinfo, bkglyphinfo)
-- Print a glyph (glyphinfo->glyph) at (x,y) on the given
window. Glyphs are integers mapped to whatever the window-
port wants (symbol, font, color, attributes, ...there's
a 1-1 map between glyphs and distinct things on the map).
-- bkglyph is a background glyph for potential use by some
graphical or tiled environments to allow the depiction
-- bkglyphinfo contains a background glyph for potential use
by some graphical or tiled environments to allow the depiction
to fall against a background consistent with the grid
around x,y.
-- glyphmod provides extended information about the glyph
that window ports can use to enhance the display in
various ways.
*/
void
mswin_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph, int bkglyph, unsigned *glyphmod)
mswin_print_glyph(winid wid, XCHAR_P x, XCHAR_P y,
const glyph_info *glyphinfo, const glyph_info *bkglyphinfo)
{
logDebug("mswin_print_glyph(%d, %d, %d, %d, %d, %lu)\n", wid, x, y, glyph, bkglyph, glyphmod);
logDebug("mswin_print_glyph(%d, %d, %d, %d, %d, %lu)\n", wid, x, y, glyphinfo->glyph, bkglyphinfo->glyph);
if ((wid >= 0) && (wid < MAXWINDOWS)
&& (GetNHApp()->windowlist[wid].win != NULL)) {
@@ -1307,11 +1311,10 @@ mswin_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph, int bkglyph, unsig
ZeroMemory(&data, sizeof(data));
data.x = x;
data.y = y;
data.glyph = glyph;
data.bkglyph = bkglyph;
data.glyphmod[GM_TTYCHAR] = glyphmod[GM_TTYCHAR];
data.glyphmod[GM_COLOR] = glyphmod[GM_COLOR];
data.glyphmod[GM_FLAGS] = glyphmod[GM_FLAGS];
if (glyphinfo)
data.glyphinfo = *glyphinfo;
if (bkglyphinfo)
data.bkglyphinfo = *bkglyphinfo;
SendMessage(GetNHApp()->windowlist[wid].win, WM_MSNH_COMMAND,
(WPARAM) MSNH_MSG_PRINT_GLYPH, (LPARAM) &data);
}
+4 -2
View File
@@ -153,7 +153,8 @@ void mswin_putstr(winid wid, int attr, const char *text);
void mswin_putstr_ex(winid wid, int attr, const char *text, int);
void mswin_display_file(const char *filename, BOOLEAN_P must_exist);
void mswin_start_menu(winid wid, unsigned long mbehavior);
void mswin_add_menu(winid wid, int glyph, const ANY_P *identifier,
void mswin_add_menu(winid wid, const glyph_info *glyphinfo,
const ANY_P *identifier,
CHAR_P accelerator, CHAR_P group_accel, int attr,
const char *str, unsigned int itemflags);
void mswin_end_menu(winid wid, const char *prompt);
@@ -162,7 +163,8 @@ void mswin_update_inventory(void);
void mswin_mark_synch(void);
void mswin_wait_synch(void);
void mswin_cliparound(int x, int y);
void mswin_print_glyph(winid wid, XCHAR_P x, XCHAR_P y, int glyph, int bkglyph, unsigned *glyphmod);
void mswin_print_glyph(winid wid, XCHAR_P x, XCHAR_P y,
const glyph_info *glyph, const glyph_info *bkglyph);
void mswin_raw_print(const char *str);
void mswin_raw_print_bold(const char *str);
void mswin_raw_print_flush();