]> Shamusworld >> Repos - virtualjaguar/commitdiff
Hotfix for bug #28.
authorShamus Hammons <jlhamm@acm.org>
Fri, 10 Oct 2014 03:42:52 +0000 (22:42 -0500)
committerShamus Hammons <jlhamm@acm.org>
Fri, 10 Oct 2014 03:42:52 +0000 (22:42 -0500)
src/gui/controllertab.cpp
src/gui/controllerwidget.cpp
src/gui/profile.cpp

index 89a678f380ddff453bce1b412735ba527813c5a2..bd73c2b0f8bc8e3afdc0c9c2df6b572f02e86407 100644 (file)
@@ -226,17 +226,28 @@ void ControllerTab::AddMapName(void)
        profile[profileNum].mapName[31] = 0;
        profile[profileNum].preferredSlot = CONTROLLER1;
 
-       for(int i=BUTTON_FIRST; i<BUTTON_LAST; i++)
+       for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
                profile[profileNum].map[i] = '*';
 
        mapNameList->addItem(text, profileNum);
+#if 0
        mapNameList->setCurrentIndex(mapNameList->count() - 1);
+#else
+       int selection = mapNameList->count() - 1;
+       mapNameList->setCurrentIndex(selection);
+       ChangeMapName(selection);
+       // We just added a new mapping, so enable the delete button!
+       deleteMapName->setDisabled(false);
+#endif
 }
 
 
 void ControllerTab::DeleteMapName(void)
 {
-       QMessageBox::StandardButton retVal = QMessageBox::question(this, tr("Remove Mapping"), tr("Are you sure you want to remove this mapping?"), QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
+       QString msg = QString("Map name: %1\n\nAre you sure you want to remove this mapping?").arg(profile[profileNum].mapName);
+
+//     QMessageBox::StandardButton retVal = QMessageBox::question(this, tr("Remove Mapping"), tr("Are you sure you want to remove this mapping?"), QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
+       QMessageBox::StandardButton retVal = QMessageBox::question(this, tr("Remove Mapping"), msg, QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
 
        if (retVal == QMessageBox::No)
                return;
@@ -245,5 +256,11 @@ void ControllerTab::DeleteMapName(void)
        int profileToRemove = profileNum;
        mapNameList->removeItem(index);
        DeleteProfile(profileToRemove);
+       // We need to reload the profile that we move to after deleting the current
+       // one...
+       ChangeMapName(mapNameList->currentIndex());
+       // If we get down to one profile left for the device, we need to make sure
+       // that the user can't delete it!
+       deleteMapName->setDisabled(mapNameList->count() == 1 ? true : false);
 }
 
index f268c00ce65267f181886866045348d0e08f8558..f7ea8d03ce1746b0b8546290256e0e9f88c5ff9b 100644 (file)
@@ -117,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)
@@ -132,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
        }
 }
 
index 434d01d8ac0918d7d183cb96ab816a3fae99de94..cbb12f47efc7da55c697c34649cb9c573a68e1a1 100644 (file)
@@ -49,6 +49,7 @@ int gamepadIDSlot2;
 int numberOfProfiles;
 int numberOfDevices;
 char deviceNames[MAX_DEVICES][128];
+static int numberOfProfilesSave;
 
 // This is so that new devices have something reasonable to show for default
 uint32_t defaultMap[21] = {
@@ -68,6 +69,7 @@ int FindProfileForDevice(int deviceNum, int preferred, int * found);
 //
 void SaveProfiles(void)
 {
+       numberOfProfilesSave = numberOfProfiles;
        memcpy(&profileBackup, &profile, sizeof(Profile) * MAX_PROFILES);
 }
 
@@ -75,6 +77,7 @@ void SaveProfiles(void)
 void RestoreProfiles(void)
 {
        memcpy(&profile, &profileBackup, sizeof(Profile) * MAX_PROFILES);
+       numberOfProfiles = numberOfProfilesSave;
 }