2 // controllertab.cpp: "Controller" tab on the config dialog
4 // Part of the Virtual Jaguar Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- ------------------------------------------------------------
12 // JLH 06/23/2011 Created this file
14 #include "controllertab.h"
17 #include "keygrabber.h"
20 // These tables are used to convert Qt keycodes into human readable form. Note that
21 // a lot of these are just filler.
22 char ControllerTab::keyName1[96][16] = {
24 "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
25 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
26 "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
27 "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
28 "[", "]", "\\", "^", "_", "`",
29 "$61", "$62", "$63", "$64", "$65", "$66", "$67", "$68", "$69", "$6A", "$6B", "$6C", "$6D",
30 "$6E", "$6F", "$70", "$71", "$72", "$73", "$74", "$75", "$76", "$77", "$78", "$79", "$7A",
34 char ControllerTab::keyName2[64][16] = {
35 "Esc", "Tab", "BTab", "BS", "Ret", "Ent", "Ins", "Del", "Pau", "Prt", "SRq", "Clr",
36 "$C", "$D", "$E", "$F", "Hm", "End", "Lf", "Up", "Rt", "Dn", "PgU", "PgD", "$18",
37 "$19", "$1A", "$1B", "$1C", "$1D", "$1E", "$1F", "Shf", "Ctl", "Mta", "Alt",
38 "Cap", "Num", "ScL", "$27", "$28", "$29", "$2A", "$2B", "$2C", "$2D", "$2E", "$2F",
39 "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13",
43 ControllerTab::ControllerTab(QWidget * parent/*= 0*/): QWidget(parent)
45 QLabel * img = new QLabel;
46 // img->setPixmap(QPixmap(":/res/controller.png"));
49 QImage cartImg(":/res/cart-blank.png");
50 QPainter painter(&cartImg);
51 painter.drawPixmap(23, 87, QPixmap(":/res/label-blank.png"));
53 cartSmall = cartImg.scaled(488/4, 395/4, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
55 QImage controller(":/res/controller.png");
56 QPainter painter(&controller);
58 // painter->drawText(QRect(option.rect.x()+10, option.rect.y()+36, 196/2, 70/2),
59 // Qt::TextWordWrap | Qt::AlignHCenter, nameToDraw);
61 // Bump up the size of the default font...
62 QFont font = painter.font();
63 font.setPixelSize(14);
65 painter.setFont(font);
66 painter.setPen(QColor(48, 255, 255, 255)); // This is R,G,B,A
68 // This is hard-coded crap. It's crap-tastic!
93 enum { BUTTON_FIRST = 0, BUTTON_U = 0,
115 BUTTON_PAUSE = 20, BUTTON_LAST = 20 };
117 int buttonPos[21][2] = { { 87, 64 }, { 87, 94 }, { 73, 78 }, { 105, 77 },
118 { 125, 223 }, { 125, 199 }, { 125, 177 }, { 125, 153 },
119 { 160, 223 }, { 160, 199 }, { 160, 177 }, { 160, 153 },
120 { 196, 223 }, { 196, 199 }, { 196, 177 }, { 196, 153 },
121 { 242, 60 }, { 225, 80 }, { 209, 104 }, { 165, 107 }, { 141, 109 }
124 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
125 // painter.drawText(QPoint(buttonPos[i][0] - 5, buttonPos[i][1] + 5), QString(buttonName[i]));
127 // Need to convert this back to p1Keys, but will require some restructuring...
128 // if (p1Keys[i] < 0x80)
129 if (vjs.p1KeyBindings[i] < 0x80)
130 // painter.drawText(QPoint(buttonPos[i][0] - 5, buttonPos[i][1] + 5), QString(keyName1[p1Keys[i] - 0x20]));
131 // painter.drawText(QPoint(buttonPos[i][0] - 5, buttonPos[i][1] + 5), QString(keyName1[vjs.p1KeyBindings[i] - 0x20]));
132 DrawBorderedText(painter, buttonPos[i][0] - 5, buttonPos[i][1] + 5, QString(keyName1[vjs.p1KeyBindings[i] - 0x20]));
133 else if ((vjs.p1KeyBindings[i] & 0xFFFFFF00) == 0x01000000)
135 // painter.drawText(QPoint(buttonPos[i][0] - 5, buttonPos[i][1] + 5), QString(keyName2[vjs.p1KeyBindings[i] & 0x3F]));
136 DrawBorderedText(painter, buttonPos[i][0] - 5, buttonPos[i][1] + 5, QString(keyName2[vjs.p1KeyBindings[i] & 0x3F]));
139 // painter.drawText(QPoint(buttonPos[i][0] - 5, buttonPos[i][1] + 5), QString("???"));
140 DrawBorderedText(painter, buttonPos[i][0] - 5, buttonPos[i][1] + 5, QString("???"));
144 img->setPixmap(QPixmap::fromImage(controller));
146 redefineAll = new QPushButton(tr("Redefine All Keys"));
148 QVBoxLayout * layout = new QVBoxLayout;
149 layout->addWidget(img);
150 layout->addWidget(redefineAll);
153 connect(redefineAll, SIGNAL(clicked()), this, SLOT(DefineAllKeys()));
156 ControllerTab::~ControllerTab()
160 void ControllerTab::DefineAllKeys(void)
162 char jagButtonName[21][10] = { "Up", "Down", "Left", "Right",
163 "*", "7", "4", "1", "0", "8", "5", "2", "#", "9", "6", "3",
164 "A", "B", "C", "Option", "Pause" };
165 int orderToDefine[21] = { 0, 1, 2, 3, 18, 17, 16, 20, 19, 7, 11, 15, 6, 10, 14, 5, 9, 13, 8, 4, 12 };
166 KeyGrabber keyGrab(this);
168 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
170 keyGrab.SetText(jagButtonName[orderToDefine[i]]);
172 int key = keyGrab.key;
174 if (key == Qt::Key_Escape)
177 // Otherwise, populate the appropriate spot in the settings...
178 p1Keys[orderToDefine[i]] = key;
182 void ControllerTab::DrawBorderedText(QPainter & painter, int x, int y, QString text)
184 painter.setPen(QColor(0, 0, 0, 255)); // This is R,G,B,A
186 for(int i=-1; i<=1; i++)
188 for(int j=-1; j<=1; j++)
190 painter.drawText(QPoint(x + i, y + j), text);
194 painter.setPen(QColor(48, 255, 255, 255)); // This is R,G,B,A
195 painter.drawText(QPoint(x, y), text);