X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fcontrollerwidget.cpp;h=53a747a01d62e2f919ffe3a55fdf2a454525fce5;hb=725caa0f8bb826a73edef366906ccb41a3197819;hp=fd9ebf24bee74952235e38e458c5a15c0054a407;hpb=2136446c0d38d00a651d3eb665ee564b18f94b28;p=virtualjaguar diff --git a/src/gui/controllerwidget.cpp b/src/gui/controllerwidget.cpp index fd9ebf2..53a747a 100644 --- a/src/gui/controllerwidget.cpp +++ b/src/gui/controllerwidget.cpp @@ -5,7 +5,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ @@ -15,8 +15,10 @@ #include "controllerwidget.h" #include "joystick.h" +#include "gamepad.h" #include "keygrabber.h" + // These tables are used to convert Qt keycodes into human readable form. Note that // a lot of these are just filler. char ControllerWidget::keyName1[96][16] = { @@ -40,16 +42,21 @@ char ControllerWidget::keyName2[64][16] = { "F14", "F15", "F16" }; +char ControllerWidget::hatName[4][16] = { "Up", "Rt", "Dn", "Lf" }; + +char ControllerWidget::axisName[2][8] = { "+", "-" }; + // This is hard-coded crap. It's crap-tastic! // These are the positions to draw the button names at, ordered by the BUTTON_* sequence // found in joystick.h. -int ControllerWidget::buttonPos[21][2] = { { 86, 59 }, { 86, 94 }, { 68, 76 }, { 108, 76 }, - { 125, 223 }, { 125, 200 }, { 125, 177 }, { 125, 153 }, - { 160, 223 }, { 160, 200 }, { 160, 177 }, { 160, 153 }, - { 196, 223 }, { 196, 200 }, { 196, 177 }, { 196, 153 }, - { 242, 60 }, { 224, 80 }, { 207, 104 }, { 164, 101 }, { 141, 108+13 } +int ControllerWidget::buttonPos[21][2] = { { 74, 32 }, { 71, 67 }, { 53, 49 }, { 93, 49 }, + { 110, 200 }, { 110, 175 }, { 110, 151 }, { 110, 126 }, + { 148, 200 }, { 148, 175 }, { 148, 151 }, { 148, 126 }, + { 186, 200 }, { 186, 175 }, { 186, 151 }, { 186, 126 }, + { 234, 31 }, { 216, 51 }, { 199, 71 }, { 164-11, 101-30 }, { 141-11, 108+13-30 } }; + ControllerWidget::ControllerWidget(QWidget * parent/*= 0*/): QWidget(parent), controllerPic(":/res/controller.png"), widgetSize(controllerPic.size()), keyToHighlight(-1), mouseDown(false) @@ -58,22 +65,28 @@ ControllerWidget::ControllerWidget(QWidget * parent/*= 0*/): QWidget(parent), widgetSize += QSize(4, 4); // We want to know when the mouse is moving over our widget... setMouseTracking(true); +//nope +//setFixedSize(widgetSize); } + ControllerWidget::~ControllerWidget() { } + QSize ControllerWidget::sizeHint(void) const { return widgetSize; } + QSizePolicy ControllerWidget::sizePolicy(void) const { return QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); } + void ControllerWidget::paintEvent(QPaintEvent * /*event*/) { QPainter painter(this); @@ -94,13 +107,13 @@ void ControllerWidget::paintEvent(QPaintEvent * /*event*/) blackPen.setWidth(4); QPen colorPen(QColor(48, 255, 255, 255)); colorPen.setWidth(2); - QLine line(QPoint(141, 100), QPoint(141, 108+5)); + QLine line(QPoint(141-11, 100-30), QPoint(141-11, 108+5-30)); painter.setPen(blackPen); painter.drawLine(line); blackPen.setWidth(1); painter.setPen(blackPen); - painter.drawEllipse(QPoint(141, 100), 4, 4); + painter.drawEllipse(QPoint(141-11, 100-30), 4, 4); painter.setPen(colorPen); painter.drawLine(line); @@ -127,17 +140,36 @@ void ControllerWidget::paintEvent(QPaintEvent * /*event*/) DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], QString(keyName2[keys[i] & 0x3F])); } +#if 1 + else if (keys[i] & JOY_BUTTON) + { + DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], + QString("JB%1").arg(keys[i] & JOY_BUTTON_MASK)); + } + else if (keys[i] & JOY_HAT) + { + DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], + QString("j%1").arg(hatName[keys[i] & JOY_BUTTON_MASK])); + } + else if (keys[i] & JOY_AXIS) + { + DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], + QString("JA%1%2").arg((keys[i] & JOY_AXISNUM_MASK) >> 1).arg(axisName[keys[i] & JOY_AXISDIR_MASK])); + } +#endif else DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], QString("???")); } } + void ControllerWidget::mousePressEvent(QMouseEvent * /*event*/) { mouseDown = true; update(); } + void ControllerWidget::mouseReleaseEvent(QMouseEvent * /*event*/) { mouseDown = false; @@ -150,12 +182,16 @@ void ControllerWidget::mouseReleaseEvent(QMouseEvent * /*event*/) int key = keyGrab.key; if (key != Qt::Key_Escape) + { keys[keyToHighlightSave] = key; + emit(KeyDefined(keyToHighlightSave, key)); + } keyToHighlight = keyToHighlightSave; update(); } + void ControllerWidget::mouseMoveEvent(QMouseEvent * event) { if (mouseDown) @@ -184,12 +220,14 @@ void ControllerWidget::mouseMoveEvent(QMouseEvent * event) update(); } + void ControllerWidget::leaveEvent(QEvent * /*event*/) { keyToHighlight = -1; update(); } + void ControllerWidget::DrawBorderedText(QPainter & painter, int x, int y, QString text) { // Text is drawn centered at (x, y) as well, using a bounding rect for the purpose. @@ -210,3 +248,4 @@ void ControllerWidget::DrawBorderedText(QPainter & painter, int x, int y, QStrin rect.moveCenter(QPoint(x, y)); painter.drawText(rect, Qt::AlignCenter, text); } +