in win/Qt/qt_win.cpp [1636:1773]
void NetHackQtMapWindow::paintEvent(QPaintEvent* event)
{
QRect area=event->rect();
QRect garea;
garea.setCoords(
QMAX(0,area.left()/qt_settings->glyphs().width()),
QMAX(0,area.top()/qt_settings->glyphs().height()),
QMIN(COLNO-1,area.right()/qt_settings->glyphs().width()),
QMIN(ROWNO-1,area.bottom()/qt_settings->glyphs().height())
);
QPainter painter;
painter.begin(this);
if (Is_rogue_level(&u.uz) || iflags.wc_ascii_map)
{
// You enter a VERY primitive world!
painter.setClipRect( event->rect() ); // (normally we don't clip)
painter.fillRect( event->rect(), black );
if ( !rogue_font ) {
// Find font...
int pts = 5;
QString fontfamily = iflags.wc_font_map
? iflags.wc_font_map : "Courier";
bool bold = FALSE;
if ( fontfamily.right(5).lower() == "-bold" ) {
fontfamily.truncate(fontfamily.length()-5);
bold = TRUE;
}
while ( pts < 32 ) {
QFont f(fontfamily, pts, bold ? QFont::Bold : QFont::Normal);
painter.setFont(QFont(fontfamily, pts));
QFontMetrics fm = painter.fontMetrics();
if ( fm.width("M") > qt_settings->glyphs().width() )
break;
if ( fm.height() > qt_settings->glyphs().height() )
break;
pts++;
}
rogue_font = new QFont(fontfamily,pts-1);
}
painter.setFont(*rogue_font);
for (int j=garea.top(); j<=garea.bottom(); j++) {
for (int i=garea.left(); i<=garea.right(); i++) {
unsigned short g=Glyph(i,j);
uchar ch;
int color, och;
unsigned special;
painter.setPen( green );
/* map glyph to character and color */
(void)mapglyph(g, &och, &color, &special, i, j, 0);
ch = (uchar)och;
#ifdef TEXTCOLOR
painter.setPen( nhcolor_to_pen(color) );
#endif
painter.drawText(
i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height(),
qt_settings->glyphs().width(),
qt_settings->glyphs().height(),
AlignCenter,
(const char*)&ch, 1
);
if (glyph_is_pet(g)
#ifdef TEXTCOLOR
&& ::iflags.hilite_pet
#endif
) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()),
pet_annotation);
}
}
}
painter.setFont(font());
} else {
for (int j=garea.top(); j<=garea.bottom(); j++) {
for (int i=garea.left(); i<=garea.right(); i++) {
unsigned short g=Glyph(i,j);
qt_settings->glyphs().drawCell(painter, g, i, j);
if (glyph_is_pet(g)
#ifdef TEXTCOLOR
&& ::iflags.hilite_pet
#endif
) {
painter.drawPixmap(QPoint(i*qt_settings->glyphs().width(),
j*qt_settings->glyphs().height()),
pet_annotation);
}
}
}
}
if (garea.contains(cursor)) {
if (Is_rogue_level(&u.uz)) {
#ifdef TEXTCOLOR
painter.setPen( white );
#else
painter.setPen( green ); // REALLY primitive
#endif
} else
{
int hp100;
if (u.mtimedone) {
hp100=u.mhmax ? u.mh*100/u.mhmax : 100;
} else {
hp100=u.uhpmax ? u.uhp*100/u.uhpmax : 100;
}
if (hp100 > 75) painter.setPen(white);
else if (hp100 > 50) painter.setPen(yellow);
else if (hp100 > 25) painter.setPen(QColor(0xff,0xbf,0x00)); // orange
else if (hp100 > 10) painter.setPen(red);
else painter.setPen(magenta);
}
painter.drawRect(
cursor.x()*qt_settings->glyphs().width(),cursor.y()*qt_settings->glyphs().height(),
qt_settings->glyphs().width(),qt_settings->glyphs().height());
}
if (area.intersects(messages_rect)) {
painter.setPen(black);
painter.drawText(viewport.contentsX()+1,viewport.contentsY()+1,
viewport.width(),0, WordBreak|AlignTop|AlignLeft|DontClip, messages);
painter.setPen(white);
painter.drawText(viewport.contentsX(),viewport.contentsY(),
viewport.width(),0, WordBreak|AlignTop|AlignLeft|DontClip, messages);
}
painter.end();
}