X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fcontrollerwidget.cpp;h=79e91b602859c25b345b4fe1405db8535e624f8d;hb=5c28b6dbf7aa20441c8a51f484f4f64b1966f7e3;hp=25fb8b1b8206bef1baa4f6b2059379b567644803;hpb=f63cd569374c4fbcd872bb8a67c94788da29c3a8;p=virtualjaguar diff --git a/src/gui/controllerwidget.cpp b/src/gui/controllerwidget.cpp index 25fb8b1..79e91b6 100644 --- a/src/gui/controllerwidget.cpp +++ b/src/gui/controllerwidget.cpp @@ -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,6 +42,8 @@ char ControllerWidget::keyName2[64][16] = { "F14", "F15", "F16" }; +char ControllerWidget::hatName[4][16] = { "Up", "Rt", "Dn", "Lf" }; + // 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. @@ -50,6 +54,7 @@ int ControllerWidget::buttonPos[21][2] = { { 74, 32 }, { 71, 67 }, { 53, 49 }, { { 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) @@ -60,20 +65,24 @@ ControllerWidget::ControllerWidget(QWidget * parent/*= 0*/): QWidget(parent), setMouseTracking(true); } + 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); @@ -127,17 +136,31 @@ 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])); + } +#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; @@ -156,6 +179,7 @@ void ControllerWidget::mouseReleaseEvent(QMouseEvent * /*event*/) update(); } + void ControllerWidget::mouseMoveEvent(QMouseEvent * event) { if (mouseDown) @@ -184,12 +208,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 +236,4 @@ void ControllerWidget::DrawBorderedText(QPainter & painter, int x, int y, QStrin rect.moveCenter(QPoint(x, y)); painter.drawText(rect, Qt::AlignCenter, text); } +