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
13 // JLH 07/20/2011 Fixed a bunch of stuff
16 #include "controllertab.h"
19 #include "keygrabber.h"
22 // These tables are used to convert Qt keycodes into human readable form. Note that
23 // a lot of these are just filler.
24 char ControllerTab::keyName1[96][16] = {
26 "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/",
27 "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?",
28 "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
29 "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
30 "[", "]", "\\", "^", "_", "`",
31 "$61", "$62", "$63", "$64", "$65", "$66", "$67", "$68", "$69", "$6A", "$6B", "$6C", "$6D",
32 "$6E", "$6F", "$70", "$71", "$72", "$73", "$74", "$75", "$76", "$77", "$78", "$79", "$7A",
36 char ControllerTab::keyName2[64][16] = {
37 "Esc", "Tab", "BTab", "BS", "Ret", "Ent", "Ins", "Del", "Pau", "Prt", "SRq", "Clr",
38 "$C", "$D", "$E", "$F", "Hm", "End", "Lf", "Up", "Rt", "Dn", "PgU", "PgD", "$18",
39 "$19", "$1A", "$1B", "$1C", "$1D", "$1E", "$1F", "Shf", "Ctl", "Mta", "Alt",
40 "Cap", "Num", "ScL", "$27", "$28", "$29", "$2A", "$2B", "$2C", "$2D", "$2E", "$2F",
41 "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13",
45 ControllerTab::ControllerTab(QWidget * parent/*= 0*/): QWidget(parent)
47 controllerPic = new QLabel;
48 QImage controller(":/res/controller.png");
49 controllerPic->setPixmap(QPixmap::fromImage(controller));
51 redefineAll = new QPushButton(tr("Redefine All Keys"));
53 QVBoxLayout * layout = new QVBoxLayout;
54 layout->addWidget(controllerPic);
55 layout->addWidget(redefineAll);
58 connect(redefineAll, SIGNAL(clicked()), this, SLOT(DefineAllKeys()));
61 ControllerTab::~ControllerTab()
65 void ControllerTab::DefineAllKeys(void)
67 char jagButtonName[21][10] = { "Up", "Down", "Left", "Right",
68 "*", "7", "4", "1", "0", "8", "5", "2", "#", "9", "6", "3",
69 "A", "B", "C", "Option", "Pause" };
70 int orderToDefine[21] = { 0, 1, 2, 3, 18, 17, 16, 20, 19, 7, 11, 15, 6, 10, 14, 5, 9, 13, 8, 4, 12 };
71 KeyGrabber keyGrab(this);
73 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
75 keyGrab.SetText(jagButtonName[orderToDefine[i]]);
77 int key = keyGrab.key;
79 if (key == Qt::Key_Escape)
82 // Otherwise, populate the appropriate spot in the settings & update screen...
83 p1Keys[orderToDefine[i]] = key;
88 void ControllerTab::UpdateLabel(void)
90 QImage controller(":/res/controller.png");
91 QPainter painter(&controller);
93 // Bump up the size of the default font...
94 QFont font = painter.font();
95 font.setPixelSize(15);
97 painter.setFont(font);
98 painter.setPen(QColor(48, 255, 255, 255)); // This is R,G,B,A
100 // This is hard-coded crap. It's crap-tastic!
101 int buttonPos[21][2] = { { 87, 64 }, { 87, 94 }, { 73, 78 }, { 105, 77 },
102 { 125, 223 }, { 125, 199 }, { 125, 178 }, { 125, 153 },
103 { 160, 223 }, { 160, 199 }, { 160, 178 }, { 160, 153 },
104 { 196, 223 }, { 196, 199 }, { 196, 178 }, { 196, 153 },
105 { 242, 60 }, { 225, 80 }, { 209, 104 }, { 165, 108 }, { 141, 108 }
108 for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
110 if (p1Keys[i] < 0x80)
111 DrawBorderedText(painter, buttonPos[i][0] - 5, buttonPos[i][1] + 5,
112 QString(keyName1[p1Keys[i] - 0x20]));
113 else if ((p1Keys[i] & 0xFFFFFF00) == 0x01000000)
115 DrawBorderedText(painter, buttonPos[i][0] - 5, buttonPos[i][1] + 5,
116 QString(keyName2[p1Keys[i] & 0x3F]));
119 DrawBorderedText(painter, buttonPos[i][0] - 5, buttonPos[i][1] + 5, QString("???"));
123 controllerPic->setPixmap(QPixmap::fromImage(controller));
126 void ControllerTab::DrawBorderedText(QPainter & painter, int x, int y, QString text)
128 painter.setPen(QColor(0, 0, 0, 255)); // This is R,G,B,A
130 for(int i=-1; i<=1; i++)
132 for(int j=-1; j<=1; j++)
134 painter.drawText(QPoint(x + i, y + j), text);
138 painter.setPen(QColor(48, 255, 255, 255)); // This is R,G,B,A
139 painter.drawText(QPoint(x, y), text);