1 // Copyright (c) Warwick Allison, 1999.
2 // Qt4 conversion copyright (c) Ray Chason, 2012-2014.
3 // NetHack may be freely redistributed. See license for details.
5 // Qt Binding for NetHack 3.4
7 // Copyright (C) 1996-2001 by Warwick W. Allison (warwick@troll.no)
10 // Michael Hohmuth <hohmuth@inf.tu-dresden.de>
12 // Svante Gerhard <svante@algonet.se>
13 // - .nethackrc tile and font size settings
14 // Dirk Schoenberger <schoenberger@signsoft.com>
17 // and many others for bug reports.
19 // Unfortunately, this doesn't use Qt as well as I would like,
20 // primarily because NetHack is fundamentally a getkey-type program
21 // rather than being event driven (hence the ugly key and click buffer)
22 // and also because this is my first major application of Qt.
24 // The problem of NetHack's getkey requirement is solved by intercepting
25 // key events by overiding QApplicion::notify(...), and putting them in
26 // a buffer. Mouse clicks on the map window are treated with a similar
27 // buffer. When the NetHack engine calls for a key, one is taken from
28 // the buffer, or if that is empty, QApplication::exec() is called.
29 // Whenever keys or clicks go into the buffer, QApplication::exit()
32 // Another problem is that some NetHack players are decade-long players who
33 // demand complete keyboard control (while Qt and X11 conspire to make this
34 // difficult by having widget-based focus rather than application based -
35 // a good thing in general). This problem is solved by again using the key
38 // Out of all this hackery comes a silver lining however, as macros for
39 // the super-expert and menus for the ultra-newbie are also made possible
40 // by the key event buffer.
43 // This includes all the definitions we need from the NetHack main
44 // engine. We pretend MSC is a STDC compiler, because C++ is close
45 // enough, and we undefine NetHack macros which conflict with Qt
48 #define QT_DEPRECATED_WARNINGS
60 #include <QtGui/QtGui>
61 #if QT_VERSION >= 0x050000
62 #include <QtWidgets/QtWidgets>
88 #if QT_VERSION >= 0x050000
89 # include <QtMultimedia/QSound>
91 # include <QtGui/QSound>
97 extern void play_sound_for_message(const std::string& str);
100 namespace nethack_qt4 {
103 centerOnMain( QWidget* w )
105 QWidget* m = NetHackQtBind::mainWidget();
106 if (!m) m = qApp->desktop();
107 QPoint p = m->mapToGlobal(QPoint(0,0));
108 w->move( p.x() + m->width()/2 - w->width()/2,
109 p.y() + m->height()/2 - w->height()/2 );
112 NetHackQtWindow::NetHackQtWindow()
115 NetHackQtWindow::~NetHackQtWindow()
119 // XXX Use "expected ..." for now, abort or default later.
121 void NetHackQtWindow::Clear() { puts("unexpected Clear"); }
122 void NetHackQtWindow::Display(bool block) { puts("unexpected Display"); }
123 bool NetHackQtWindow::Destroy() { return true; }
124 void NetHackQtWindow::CursorTo(int x,int y) { puts("unexpected CursorTo"); }
125 void NetHackQtWindow::PutStr(int attr, const QString& text) { puts("unexpected PutStr"); }
126 void NetHackQtWindow::StartMenu() { puts("unexpected StartMenu"); }
127 void NetHackQtWindow::AddMenu(int glyph, const ANY_P* identifier, char ch, char gch, int attr,
128 const QString& str, bool presel) { puts("unexpected AddMenu"); }
129 void NetHackQtWindow::EndMenu(const QString& prompt) { puts("unexpected EndMenu"); }
130 int NetHackQtWindow::SelectMenu(int how, MENU_ITEM_P **menu_list) { puts("unexpected SelectMenu"); return 0; }
131 void NetHackQtWindow::ClipAround(int x,int y) { puts("unexpected ClipAround"); }
132 void NetHackQtWindow::PrintGlyph(int x,int y,int glyph) { puts("unexpected PrintGlyph"); }
133 //void NetHackQtWindow::PrintGlyphCompose(int x,int y,int,int) { puts("unexpected PrintGlyphCompose"); }
134 void NetHackQtWindow::UseRIP(int how, time_t when) { puts("unexpected UseRIP"); }
136 } // namespace nethack_qt4