MCPcopy Create free account
hub / github.com/NetHack/NetHack / drawWorn

Method drawWorn

win/Qt/qt_inv.cpp:79–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void NetHackQtInvUsageWindow::drawWorn(
80 QPainter &painter,
81 obj *nhobj,
82 int x, int y, // cell index, not pixels
83 const char *alttip,
84 int flags)
85{
86 short int glyph;
87 glyph_info gi;
88 int border;
89 char tipstr[1 + BUFSZ + 1]; // extra room for leading and trailing space
90 bool rev = (flags == dollReverse),
91 canbe = (flags != dollUnused);
92
93 if (nhobj) {
94 border = BORDER_DEFAULT;
95 // don't expect this to happen but check just in case;
96 // learn_unseen_invent() is normally called when regaining sight
97 // and sets dknown and maybe bknown, then updates perm_invent (do
98 // it regardless of ENHANCED_PAPERDOLL for same effect either way)
99 if (!Blind && (!nhobj->dknown
100 || (Role_if(PM_CLERIC) && !nhobj->bknown)))
101 ::learn_unseen_invent();
102#ifdef ENHANCED_PAPERDOLL
103 // color margin around cell containing item whose BUC state is known
104 if (nhobj->bknown)
105 border = nhobj->cursed ? BORDER_CURSED
106 : !nhobj->blessed ? BORDER_UNCURSED
107 : BORDER_BLESSED;
108
109 // border color is used to indicate BUC state; make tip text match
110 boolean save_implicit_uncursed = ::flags.implicit_uncursed;
111 ::flags.implicit_uncursed = FALSE;
112 // set up a tool tip describing the item that will be displayed here
113 Sprintf(tipstr, " %s ", // extra spaces for enhanced readability
114 // xprname: invlet, space, dash, space, object description
115 xprname(nhobj, (char *) NULL, nhobj->invlet, FALSE, 0L, 0L));
116 ::flags.implicit_uncursed = save_implicit_uncursed;
117
118 // tips are managed with nethack's alloc(); we don't track allocation
119 // amount; allocated buffers get reused when big enough (usual case
120 // since paperdoll updates occur more often than equipment changes)
121 if (tips[x][y] && strlen(tipstr) > strlen(tips[x][y]))
122 free((void *) tips[x][y]), tips[x][y] = NULL;
123
124 if (tips[x][y])
125 Strcpy(tips[x][y], tipstr); // guaranteed to fit
126 else
127 tips[x][y] = dupstr(tipstr);
128#endif
129 glyph = obj_to_glyph(nhobj, rn2_on_display_rng);
130 } else {
131 border = NO_BORDER;
132#ifdef ENHANCED_PAPERDOLL
133 // caller usually passes an alternate tool tip for empty cells
134 size_t altlen = alttip ? 1U + strlen(alttip) + 1U : 0U;
135 if (tips[x][y] && (!alttip || altlen > strlen(tips[x][y])))
136 free((void *) tips[x][y]), tips[x][y] = NULL;

Callers

nothing calls this directly

Calls 6

learn_unseen_inventFunction · 0.85
xprnameFunction · 0.85
dupstrFunction · 0.85
fn_cmap_to_glyphFunction · 0.85
map_glyphinfoFunction · 0.85
drawBorderedCellMethod · 0.80

Tested by

no test coverage detected