// needed to enable tool tips
setMouseTracking(true);
+ // paperdoll is 6x3 but the indices are column oriented: 0..2x0..5
for (int x = 0; x <= 2; ++x)
for (int y = 0; y <= 5; ++y)
tips[x][y] = NULL;
{
short int glyph;
int border;
- bool rev = false;
+ char tipstr[1 + BUFSZ + 1]; // extra room for leading and trailing space
+ bool rev = (flags == dollReverse),
+ canbe = (flags != dollUnused);
if (nhobj) {
border = BORDER_DEFAULT;
: BORDER_BLESSED;
// set up a tool tip describing the item that will be displayed here
- char *itmnam = xprname(nhobj, (char *) 0, nhobj->invlet, TRUE, 0L, 0L);
- if (tips[x][y] && strlen(itmnam) > strlen(tips[x][y]))
+ Sprintf(tipstr, " %s ", // extra spaces for enhanced readability
+ // xprname: invlet, space, dash, space, object description
+ xprname(nhobj, (char *) NULL, nhobj->invlet, FALSE, 0L, 0L));
+ // tips are managed with nethack's alloc(); we don't track allocation
+ // amount; allocated buffers get reused when big enough (usual case
+ // since paperdoll updates occur more often than equipment changes)
+ if (tips[x][y] && strlen(tipstr) > strlen(tips[x][y]))
free((void *) tips[x][y]), tips[x][y] = NULL;
if (tips[x][y])
- Strcpy(tips[x][y], itmnam);
+ Strcpy(tips[x][y], tipstr); // guaranteed to fit
else
- tips[x][y] = dupstr(itmnam);
-
- rev = (flags == dollReverse);
+ tips[x][y] = dupstr(tipstr);
#endif
glyph = obj_to_glyph(nhobj, rn2_on_display_rng);
} else {
border = NO_BORDER;
#ifdef ENHANCED_PAPERDOLL
- // caller passes an alternative tool tip for empty cells
- if (tips[x][y] && (!alttip || strlen(alttip) > strlen(tips[x][y])))
+ // caller usually passes an alternate tool tip for empty cells
+ size_t altlen = alttip ? 1U + strlen(alttip) + 1U : 0U;
+ if (tips[x][y] && (!alttip || altlen > strlen(tips[x][y])))
free((void *) tips[x][y]), tips[x][y] = NULL;
- if (tips[x][y]) // above guarantees that test fails if alttip is Null
- Strcpy(tips[x][y], alttip);
- else if (alttip)
- tips[x][y] = dupstr(alttip);
+ if (alttip) {
+ Sprintf(tipstr, " %s ", alttip);
+ if (tips[x][y])
+ Strcpy(tips[x][y], tipstr); // guaranteed to fit
+ else
+ tips[x][y] = dupstr(tipstr);
+ }
#else
nhUse(alttip);
#endif
// an empty slot is shown as floor tile unless it's always empty
- glyph = (flags != dollUnused) ? cmap_to_glyph(S_room)
- : GLYPH_UNEXPLORED;
+ glyph = canbe ? cmap_to_glyph(S_room) : GLYPH_UNEXPLORED;
}
qt_settings->glyphs().drawBorderedCell(painter, glyph, x, y, border, rev);
}