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

Method drawBorderedCell

win/Qt/qt_glyph.cpp:144–201  ·  view source on GitHub ↗

draw a tile into the paper doll and then draw a BUC border around it

Source from the content-addressed store, hash-verified

142
143// draw a tile into the paper doll and then draw a BUC border around it
144void
145NetHackQtGlyphs::drawBorderedCell(
146 QPainter& painter,
147 int glyph, int tileidx,
148 int cellx, int celly,
149 int border, bool reversed)
150{
151 int wd = width(),
152 ht = height(),
153 yoffset = 1, // tiny extra margin at top
154 lox = cellx * (wd + 2),
155 loy = celly * (ht + 2) + yoffset;
156
157 drawGlyph(painter, glyph, tileidx, lox + 1, loy + 1, reversed);
158
159 if (border != NO_BORDER) {
160 // gray would be a better mid-point between red and cyan but it
161 // doesn't show up well enough against the wall tile background
162 painter.setPen((border == BORDER_CURSED) ? Qt::red
163 : (border == BORDER_UNCURSED) ? Qt::yellow
164 : (border == BORDER_BLESSED) ? Qt::cyan
165 : Qt::white); // BORDER_DEFAULT
166 // assuming 32x32, draw 34x34 rectangle from 0..33x0..33, outside glyph
167#if 0 /* Qt 5.11 drawRect(x,y,width,height) seems to have an off by 1 bug;
168 * drawRect(0,0,34,34) is drawing at 0..34x0..34 which is 35x35;
169 * should subtract 1 when adding width and/or height to base coord;
170 * the relevant code in QtCore/QRect.h is correct so this observable
171 * misbehavior is a mystery... */
172 painter.drawRect(lox, loy, wd + 2, ht + 2);
173#else
174 painter.drawLine(lox, loy, lox + wd + 1, loy); // 0,0->33,0
175 painter.drawLine(lox, loy + ht + 1, lox + wd + 1, loy + ht + 1);
176 painter.drawLine(lox, loy, lox, loy + ht + 1); // 0,0->0,33
177 painter.drawLine(lox + wd + 1, loy, lox + wd + 1, loy + ht + 1);
178#endif
179 if (border != BORDER_DEFAULT) {
180 // assuming 32x32, draw rectangle from 1..32x1..32, inside glyph
181#if 0 /* (see above) */
182 painter.drawRect(lox + 1, loy + 1, wd, ht);
183#else
184 painter.drawLine(lox + 1, loy + 1, lox + wd, loy + 1); // 1,1->32,1
185 painter.drawLine(lox + 1, loy + ht, lox + wd, loy + ht);
186 painter.drawLine(lox + 1, loy + 1, lox + 1, loy + ht); // 1,1->1,32
187 painter.drawLine(lox + wd, loy + 1, lox + wd, loy + ht);
188#endif
189 for (int i = lox + 2; i < lox + wd - 1; i += 2) {
190 // assuming 32x32, draw points along <2..31,2> and <2..31,31>
191 painter.drawPoint(i, loy + 2);
192 painter.drawPoint(i + 1, loy + ht - 1);
193 }
194 for (int j = loy + 2; j < loy + ht - 1; j += 2) {
195 // assuming 32x32, draw points along <2,2..31> and <31,2..31>
196 painter.drawPoint(lox + 2, j);
197 painter.drawPoint(lox + wd - 1, j + 1);
198 }
199 }
200 }
201}

Callers 1

drawWornMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected