OSDN Git Service

upgrade to 3.6.1
[jnethack/source.git] / win / Qt4 / qt4inv.cpp
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.
4
5 // qt4inv.cpp -- inventory usage window
6 // This is at the top center of the main window
7
8 extern "C" {
9 #include "hack.h"
10 }
11 #undef Invisible
12 #undef Warning
13 #undef index
14 #undef msleep
15 #undef rindex
16 #undef wizard
17 #undef yn
18 #undef min
19 #undef max
20
21 #include <QtGui/QtGui>
22 #if QT_VERSION >= 0x050000
23 #include <QtWidgets/QtWidgets>
24 #endif
25 #include "qt4inv.h"
26 #include "qt4glyph.h"
27 #include "qt4set.h"
28
29 namespace nethack_qt4 {
30
31 NetHackQtInvUsageWindow::NetHackQtInvUsageWindow(QWidget* parent) :
32     QWidget(parent)
33 {
34     setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
35 }
36
37 void NetHackQtInvUsageWindow::drawWorn(QPainter& painter, obj* nhobj, int x, int y, bool canbe)
38 {
39     short int glyph;
40     if (nhobj)
41         glyph=obj_to_glyph(nhobj);
42     else if (canbe)
43         glyph=cmap_to_glyph(S_room);
44     else
45         glyph=cmap_to_glyph(S_stone);
46
47     qt_settings->glyphs().drawCell(painter,glyph,x,y);
48 }
49
50 void NetHackQtInvUsageWindow::paintEvent(QPaintEvent*)
51 {
52     //  012
53     //
54     //0 WhB   
55     //1 s"w   
56     //2 gCg   
57     //3 =A=   
58     //4  T    
59     //5  S    
60
61     QPainter painter;
62     painter.begin(this);
63
64     // Blanks
65     drawWorn(painter,0,0,4,false);
66     drawWorn(painter,0,0,5,false);
67     drawWorn(painter,0,2,4,false);
68     drawWorn(painter,0,2,5,false);
69
70     drawWorn(painter,uarm,1,3); // Armour
71     drawWorn(painter,uarmc,1,2); // Cloak
72     drawWorn(painter,uarmh,1,0); // Helmet
73     drawWorn(painter,uarms,0,1); // Shield
74     drawWorn(painter,uarmg,0,2); // Gloves - repeated
75     drawWorn(painter,uarmg,2,2); // Gloves - repeated
76     drawWorn(painter,uarmf,1,5); // Shoes (feet)
77     drawWorn(painter,uarmu,1,4); // Undershirt
78     drawWorn(painter,uleft,0,3); // RingL
79     drawWorn(painter,uright,2,3); // RingR
80
81     drawWorn(painter,uwep,2,1); // Weapon
82     drawWorn(painter,uswapwep,0,0); // Secondary weapon
83     drawWorn(painter,uamul,1,1); // Amulet
84     drawWorn(painter,ublindf,2,0); // Blindfold
85
86     painter.end();
87 }
88
89 QSize NetHackQtInvUsageWindow::sizeHint(void) const
90 {
91     if (qt_settings) {
92         return QSize(qt_settings->glyphs().width()*3,
93                      qt_settings->glyphs().height()*6);
94     } else {
95         return QWidget::sizeHint();
96     }
97 }
98
99 } // namespace nethack_qt4