X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Fcontrollerwidget.cpp;h=38ce4150b4a7cca3b8918259c2ec6b4c166e1bc5;hb=c9d57b57d70ab2ae842144828175820fb207a3b0;hp=0386334a92846cfc21e781c808b21f858101227e;hpb=9d399cea8466c7e4a6a1336dafdc830c4680d977;p=virtualjaguar diff --git a/src/gui/controllerwidget.cpp b/src/gui/controllerwidget.cpp index 0386334..38ce415 100644 --- a/src/gui/controllerwidget.cpp +++ b/src/gui/controllerwidget.cpp @@ -19,8 +19,8 @@ #include "keygrabber.h" -// These tables are used to convert Qt keycodes into human readable form. Note that -// a lot of these are just filler. +// 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] = { "Space", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", @@ -47,8 +47,8 @@ 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. +// These are the positions to draw the button names at, ordered by the BUTTON_* +// sequence found in joystick.h. 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 }, @@ -65,6 +65,8 @@ 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); } @@ -115,6 +117,10 @@ void ControllerWidget::paintEvent(QPaintEvent * /*event*/) painter.setPen(colorPen); painter.drawLine(line); +//#define DEBUG_CWPAINT +#ifdef DEBUG_CWPAINT +printf("------------------------------\n"); +#endif for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++) { if (keyToHighlight == i) @@ -130,33 +136,63 @@ void ControllerWidget::paintEvent(QPaintEvent * /*event*/) painter.setFont(font); } +#ifdef DEBUG_CWPAINT +printf("key %02i: ", i); +#endif + if (keys[i] < 0x80) +#ifdef DEBUG_CWPAINT +{ +printf("Drawing a key < 0x80 [keys[i]=%X, keyname=%s]...\n", keys[i], keyName1[keys[i] - 0x20]); +#endif DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], QString(keyName1[keys[i] - 0x20])); +#ifdef DEBUG_CWPAINT +} +#endif else if ((keys[i] & 0xFFFFFF00) == 0x01000000) { +#ifdef DEBUG_CWPAINT +printf("Drawing a key with bit 48 set...\n"); +#endif DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], QString(keyName2[keys[i] & 0x3F])); } #if 1 else if (keys[i] & JOY_BUTTON) { +#ifdef DEBUG_CWPAINT +printf("Drawing a joystick button...\n"); +#endif DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], QString("JB%1").arg(keys[i] & JOY_BUTTON_MASK)); } else if (keys[i] & JOY_HAT) { +#ifdef DEBUG_CWPAINT +printf("Drawing a joystick hat...\n"); +#endif DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], QString("j%1").arg(hatName[keys[i] & JOY_BUTTON_MASK])); } else if (keys[i] & JOY_AXIS) { +#ifdef DEBUG_CWPAINT +printf("Drawing a joystick axis...\n"); +#endif 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 +#ifdef DEBUG_CWPAINT +{ +printf("Drawing ???...\n"); +#endif DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], QString("???")); +#ifdef DEBUG_CWPAINT +} +#endif } } @@ -171,7 +207,8 @@ void ControllerWidget::mousePressEvent(QMouseEvent * /*event*/) void ControllerWidget::mouseReleaseEvent(QMouseEvent * /*event*/) { mouseDown = false; - // Spawning the keygrabber causes leaveEvent() to be called, so we need to save this + // Spawning the keygrabber causes leaveEvent() to be called, so we need to + // save this int keyToHighlightSave = keyToHighlight; KeyGrabber keyGrab(this); @@ -180,7 +217,10 @@ void ControllerWidget::mouseReleaseEvent(QMouseEvent * /*event*/) int key = keyGrab.key; if (key != Qt::Key_Escape) + { keys[keyToHighlightSave] = key; + emit(KeyDefined(keyToHighlightSave, key)); + } keyToHighlight = keyToHighlightSave; update(); @@ -199,7 +239,8 @@ void ControllerWidget::mouseMoveEvent(QMouseEvent * event) for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++) { - // We loop through the button text positions, to see which one is closest. + // We loop through the button text positions, to see which one is + // closest. double distX = (double)(event->x() - buttonPos[i][0]); double distY = (double)(event->y() - buttonPos[i][1]); double currentDistance = sqrt((distX * distX) + (distY * distY)); @@ -225,7 +266,8 @@ void ControllerWidget::leaveEvent(QEvent * /*event*/) 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. + // Text is drawn centered at (x, y) as well, using a bounding rect for the + // purpose. QRect rect(0, 0, 60, 30); QPen oldPen = painter.pen(); painter.setPen(QColor(0, 0, 0, 255)); // This is R,G,B,A