I forced a test compile to -std=c++20 mostly to see what we would
be up against. There was only a small number of things and they
are corrected in this commit.
c++20 has some issues with comparisons and bit twiddling between
different enums.
The vendor-supplied Qt5 header files triggered some of those issues as
well, so the qt_pre.h and qt_post.h NetHack header files were adjusted
to make those new warnings go away. I have not tested Qt6 under the
new compiler and c++ version yet.
Because there are multiple pragmas in qt_pre.h now, the conditional
ifdef structure in there was modified a little to make maintenance
simpler and have a single pragma push at the top. The pragma pop
comes after the Qt vendor-supplied header files, and is done
in qt_post.h.
The display.h macro cmap_to_glyph() was used in
a Qt c++ file and triggered a series of warnings because of that.
Rather than write c++20-friendly versions of those macros, the
simple fix is to provide a function on the C side of things
to front the cmap_to_glyph() macro, so fn_cmap_to_glyph()
was added.
Also thrown into this commit, PatR picked up on the fact that for
yesterday's new warning in qt_menu.cpp, the compiler had correctly
picked up on the fact that the format range of the variable 'cash'
had been correctly upper-capped at 999999999L in the warning message
because of an assignment prior. He suggested that perhaps by also adding
if (cash < 0)
cash = 0;
the warning might be eliminated altogether.
After a test, that was proven to be correct, so yesterday's
more-kludgy change is reverted and replaced with that variable
variable restriction ahead of the snprintf().
96 lines
2.0 KiB
C++
96 lines
2.0 KiB
C++
// Copyright (c) Warwick Allison, 1999.
|
|
// Qt4 conversion copyright (c) Ray Chason, 2012-2014.
|
|
// NetHack may be freely redistributed. See license for details.
|
|
|
|
// qt_rip.cpp -- tombstone window
|
|
|
|
extern "C" {
|
|
#include "hack.h"
|
|
}
|
|
|
|
#include "qt_pre.h"
|
|
#include <QtGui/QtGui>
|
|
#if QT_VERSION >= 0x050000
|
|
#include <QtWidgets/QtWidgets>
|
|
#endif
|
|
#include "qt_post.h"
|
|
#include "qt_rip.h"
|
|
#include "qt_bind.h"
|
|
#include "qt_str.h"
|
|
|
|
namespace nethack_qt_ {
|
|
|
|
QPixmap* NetHackQtRIP::pixmap=0;
|
|
|
|
// Debian uses a separate PIXMAPDIR
|
|
#ifndef PIXMAPDIR
|
|
# ifdef HACKDIR
|
|
# define PIXMAPDIR HACKDIR
|
|
# else
|
|
# define PIXMAPDIR "."
|
|
# endif
|
|
#endif
|
|
|
|
static void
|
|
tryload(QPixmap& pm, const char* fn)
|
|
{
|
|
if (!pm.load(fn)) {
|
|
QString msg;
|
|
msg = QString::asprintf("Cannot load \"%s\"", fn);
|
|
QMessageBox::warning(NetHackQtBind::mainWidget(), "IO Error", msg);
|
|
}
|
|
}
|
|
|
|
NetHackQtRIP::NetHackQtRIP(QWidget* parent) :
|
|
QWidget(parent)
|
|
{
|
|
if (!pixmap) {
|
|
pixmap=new QPixmap;
|
|
tryload(*pixmap, PIXMAPDIR "/rip.xpm");
|
|
}
|
|
riplines=0;
|
|
resize(pixmap->width(),pixmap->height());
|
|
setFont(QFont("times",12)); // XXX may need to be configurable
|
|
}
|
|
|
|
void NetHackQtRIP::setLines(char** l, int n)
|
|
{
|
|
line=l;
|
|
riplines=n;
|
|
}
|
|
|
|
QSize NetHackQtRIP::sizeHint() const
|
|
{
|
|
return pixmap->size();
|
|
}
|
|
|
|
void NetHackQtRIP::paintEvent(QPaintEvent* event UNUSED)
|
|
{
|
|
if ( riplines ) {
|
|
int pix_x=(width()-pixmap->width())/2;
|
|
int pix_y=(height()-pixmap->height())/2;
|
|
|
|
// XXX positions based on RIP image
|
|
int rip_text_x=pix_x+156;
|
|
int rip_text_y=pix_y+67;
|
|
int rip_text_h=94/riplines;
|
|
|
|
QPainter painter;
|
|
painter.begin(this);
|
|
painter.drawPixmap(pix_x,pix_y,*pixmap);
|
|
for (int i=0; i<riplines; i++) {
|
|
painter.drawText(rip_text_x-i/2,rip_text_y+i*rip_text_h, 1,1,
|
|
#if __cplusplus >= 202002L
|
|
static_cast<int>(Qt::TextDontClip)
|
|
| static_cast<int>(Qt::AlignHCenter),
|
|
#else
|
|
Qt::TextDontClip|Qt::AlignHCenter,
|
|
#endif
|
|
line[i]);
|
|
}
|
|
painter.end();
|
|
}
|
|
}
|
|
|
|
} // namespace nethack_qt_
|