├── gpmanager.h ├── README.md ├── .gitignore ├── shortcut.h ├── main.cpp ├── settings.h ├── LICENSE ├── touchscreen.h ├── configwindow.h ├── settings.cpp ├── InputRedirectionClient-Qt.pro ├── global.h ├── shortcut.cpp ├── gpconfigurator.h ├── touchscreen.cpp ├── global.cpp ├── tsshortcut.h ├── mainwidget.h ├── gpmanager.cpp └── configwindow.cpp /gpmanager.h: -------------------------------------------------------------------------------- 1 | #ifndef GPMANAGER_H 2 | #define GPMANAGER_H 3 | 4 | #include 5 | #include 6 | 7 | #include "global.h" 8 | 9 | struct GamepadMonitor : public QObject { 10 | GamepadMonitor(QObject *parent); 11 | }; 12 | 13 | #endif // GPMANAGER_H 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InputRedirectionClient-Qt 2 | Input redirection client for the 3DS using QtGamepad 3 | 4 | Supported platforms: 5 | 6 | * Windows (via xinput, if you don't have a Xbox controller you should use x360ce) 7 | * Linux (via evdev) 8 | * OSX 9 | * maybe others? 10 | 11 | If you have multiple controllers connected at the same time, this software will combine their inputs. 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | *.user 35 | -------------------------------------------------------------------------------- /shortcut.h: -------------------------------------------------------------------------------- 1 | #ifndef SHORTCUT_H 2 | #define SHORTCUT_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | struct ShortCut 9 | 10 | { 11 | QString name; 12 | QGamepadManager::GamepadButton button; 13 | QPoint pos; 14 | QColor color; 15 | 16 | };Q_DECLARE_METATYPE(ShortCut) 17 | 18 | extern QDataStream &operator<<(QDataStream &out, const ShortCut &obj); 19 | extern QDataStream &operator>>(QDataStream &in, ShortCut &obj); 20 | 21 | 22 | #endif // SHORTCUT_H 23 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #ifdef _MSC_VER 2 | #define _USE_MATH_DEFINES 3 | #endif 4 | 5 | #include "mainwidget.h" 6 | #include "gpmanager.h" 7 | #include 8 | #include 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | QApplication a(argc, argv); 13 | Widget w; 14 | GamepadMonitor m(&w); 15 | 16 | w.show(); 17 | QThread* thread = new QThread(); 18 | QTimer timer; 19 | timer.setInterval(20); 20 | 21 | timer.moveToThread(thread); 22 | worker.moveToThread(thread); 23 | 24 | QObject::connect(thread, SIGNAL (started()), &timer, SLOT (start())); 25 | QObject::connect(&worker, SIGNAL (finished()), thread, SLOT (quit())); 26 | QObject::connect(thread, SIGNAL (finished()), thread, SLOT (deleteLater())); 27 | QObject::connect(&timer, SIGNAL(timeout()), &worker, SLOT(sendFrame())); 28 | thread->start(); 29 | a.exec(); 30 | worker.closeThread(); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /settings.h: -------------------------------------------------------------------------------- 1 | #ifndef SETTINGS_H 2 | #define SETTINGS_H 3 | 4 | class Settings 5 | { 6 | private: 7 | bool shouldSwapStick; 8 | bool monsterHunterCamera; 9 | bool rightStickSmash; 10 | bool smashingV; 11 | bool smashingH; 12 | bool rightStickFaceButtons; 13 | bool cStickDisabled; 14 | 15 | public: 16 | Settings() 17 | { 18 | shouldSwapStick = false; 19 | } 20 | 21 | bool isShouldSwapStick(); 22 | bool isMonsterHunterCamera(); 23 | bool isRightStickSmash(); 24 | bool isSmashingV(); 25 | bool isSmashingH(); 26 | bool isRightStickFaceButtons(); 27 | bool isCStickDisabled(); 28 | 29 | 30 | void setShouldSwapStick(bool); 31 | void setMonsterHunterCamera(bool); 32 | void setRightStickSmash(bool); 33 | void setSmashingV(bool); 34 | void setSmashingH(bool); 35 | void setRightStickFaceButtons(bool); 36 | void setCStickDisabled(bool); 37 | }; 38 | 39 | #endif // SETTINGS_H 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /touchscreen.h: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "gpmanager.h" 3 | #include "tsshortcut.h" 4 | #include 5 | 6 | #ifndef TOUCHSCREEN_H 7 | #define TOUCHSCREEN_H 8 | 9 | #include "tsshortcut.h" 10 | 11 | struct TouchScreen : public QWidget { 12 | Q_OBJECT 13 | public slots: 14 | void ShowContextMenu(const QPoint& pos); 15 | 16 | private: 17 | QLabel *bgLabel; 18 | TsShortcut tsShortcutGui; 19 | 20 | public: 21 | TouchScreen(QWidget *parent = nullptr); 22 | 23 | bool ellipNeedDraw; 24 | 25 | void resizeEvent(QResizeEvent* e); 26 | void mousePressEvent(QMouseEvent *ev); 27 | void mouseMoveEvent(QMouseEvent *ev); 28 | void mouseReleaseEvent(QMouseEvent *ev); 29 | void closeEvent(QCloseEvent *ev); 30 | 31 | QPoint getTouchScreenPosition(); 32 | QSize getTouchScreenSize(); 33 | bool isTouchScreenPressed(); 34 | void setTouchScreenPressed(bool b); 35 | void updatePixmap(void); 36 | void clearImage(void); 37 | void paintEvent(QPaintEvent* e); 38 | 39 | ~TouchScreen(void) 40 | { 41 | qDebug() << "DECON"; 42 | tsShortcutGui.close(); 43 | } 44 | }; 45 | 46 | #endif // TOUCHSCREEN_H 47 | -------------------------------------------------------------------------------- /configwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGWINDOW_H 2 | #define CONFIGWINDOW_H 3 | 4 | #include "global.h" 5 | #include "touchscreen.h" 6 | #include 7 | 8 | class ConfigWindow : public QDialog 9 | { 10 | private: 11 | QGridLayout *layout; 12 | QComboBox *comboBoxA, *comboBoxB, *comboBoxX, 13 | *comboBoxY, *comboBoxL, *comboBoxR, 14 | *comboBoxUp, *comboBoxDown, *comboBoxLeft, 15 | *comboBoxRight, *comboBoxStart, *comboBoxSelect, 16 | *comboBoxZL, *comboBoxZR, *comboBoxHome, 17 | *comboBoxPower, *comboBoxPowerLong; 18 | 19 | QPushButton *saveButton; 20 | 21 | QCheckBox *invertYCheckbox, *invertYCppCheckbox, *swapSticksCheckbox, 22 | *mhCameraCheckbox, *rsSmashCheckbox, 23 | *disableCStickCheckbox, *rsFaceButtonsCheckbox; 24 | 25 | QComboBox* populateItems(QGamepadManager::GamepadButton button); 26 | 27 | QLineEdit *txtStickVal, *txtCppVal; 28 | QValidator *validator; 29 | 30 | QVariant currentData(QComboBox *comboBox); 31 | 32 | public: 33 | ConfigWindow(QWidget *parent = nullptr, TouchScreen *ts = nullptr); 34 | }; 35 | 36 | #endif // CONFIGWINDOW_H 37 | -------------------------------------------------------------------------------- /settings.cpp: -------------------------------------------------------------------------------- 1 | #include "settings.h" 2 | 3 | bool Settings::isShouldSwapStick() 4 | { 5 | return shouldSwapStick; 6 | } 7 | 8 | bool Settings::isMonsterHunterCamera() 9 | { 10 | return monsterHunterCamera; 11 | } 12 | 13 | bool Settings::isRightStickSmash() 14 | { 15 | return rightStickSmash; 16 | } 17 | 18 | bool Settings::isSmashingV() 19 | { 20 | return smashingV; 21 | } 22 | 23 | bool Settings::isSmashingH() 24 | { 25 | return smashingH; 26 | } 27 | 28 | bool Settings::isRightStickFaceButtons() 29 | { 30 | return rightStickFaceButtons; 31 | } 32 | 33 | bool Settings::isCStickDisabled() 34 | { 35 | return cStickDisabled; 36 | } 37 | 38 | /***SETTERS***/ 39 | void Settings::setShouldSwapStick(bool b) 40 | { 41 | shouldSwapStick = b; 42 | } 43 | 44 | void Settings::setMonsterHunterCamera(bool b) 45 | { 46 | monsterHunterCamera = b; 47 | } 48 | 49 | void Settings::setRightStickSmash(bool b) 50 | { 51 | rightStickSmash = b; 52 | } 53 | 54 | void Settings::setSmashingV(bool b) 55 | { 56 | smashingV = b; 57 | } 58 | 59 | void Settings::setSmashingH(bool b) 60 | { 61 | smashingH = b; 62 | } 63 | 64 | void Settings::setRightStickFaceButtons(bool b) 65 | { 66 | rightStickFaceButtons = b; 67 | } 68 | 69 | void Settings::setCStickDisabled(bool b) 70 | { 71 | cStickDisabled = b; 72 | } 73 | -------------------------------------------------------------------------------- /InputRedirectionClient-Qt.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-05-15T08:44:03 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui network gamepad 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = InputRedirectionClient-Qt 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which as been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | 20 | # You can also make your code fail to compile if you use deprecated APIs. 21 | # In order to do so, uncomment the following line. 22 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 23 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 24 | 25 | 26 | SOURCES += main.cpp \ 27 | global.cpp \ 28 | gpmanager.cpp \ 29 | touchscreen.cpp \ 30 | configwindow.cpp \ 31 | settings.cpp \ 32 | shortcut.cpp 33 | 34 | #HEADERS += widget.h 35 | 36 | HEADERS += \ 37 | global.h \ 38 | gpmanager.h \ 39 | mainwidget.h \ 40 | touchscreen.h \ 41 | configwindow.h \ 42 | gpconfigurator.h \ 43 | settings.h \ 44 | tsshortcut.h \ 45 | shortcut.h 46 | -------------------------------------------------------------------------------- /global.h: -------------------------------------------------------------------------------- 1 | #ifndef GLOBAL_H 2 | #define GLOBAL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "gpconfigurator.h" 25 | #include "settings.h" 26 | #include "shortcut.h" 27 | 28 | #define TOUCH_SCREEN_WIDTH 320 29 | #define TOUCH_SCREEN_HEIGHT 240 30 | 31 | extern int CPAD_BOUND; 32 | extern int CPP_BOUND; 33 | 34 | extern Settings btnSettings; 35 | 36 | typedef uint32_t u32; 37 | typedef uint16_t u16; 38 | typedef uint8_t u8; 39 | 40 | int appScreenTo3dsX(int); 41 | int appScreenTo3dsY(int); 42 | 43 | struct TouchButton 44 | { 45 | int x, y; 46 | }; 47 | 48 | 49 | extern std::vector listShortcuts; 50 | QGamepadManager::GamepadButton variantToButton(QVariant variant); 51 | ShortCut variantToShortCut(QVariant variant); 52 | 53 | extern int id, fid; 54 | 55 | extern QSettings settings; 56 | 57 | extern QGamepadManager::GamepadButtons buttons; 58 | extern u32 interfaceButtons; 59 | 60 | extern int yAxisMultiplier, yAxisMultiplierCpp; 61 | 62 | extern QString ipAddress; 63 | extern bool timerEnabled; 64 | 65 | extern GamepadConfigurator *gpConfigurator; 66 | 67 | extern bool touchScreenPressed; 68 | extern QSize touchScreenSize; 69 | extern QPoint touchScreenPosition; 70 | extern double tsRatio; 71 | 72 | extern QGamepadManager::GamepadButton homeButton; 73 | extern QGamepadManager::GamepadButton powerButton; 74 | extern QGamepadManager::GamepadButton powerLongButton; 75 | 76 | extern QGamepadManager::GamepadButton touchButton1; 77 | extern QGamepadManager::GamepadButton touchButton2; 78 | extern QGamepadManager::GamepadButton touchButton3; 79 | extern QGamepadManager::GamepadButton touchButton4; 80 | 81 | extern TouchButton tbOne, tbTwo, tbThree, tbFour; 82 | 83 | extern QGamepadManager::GamepadButton hidButtonsAB[2]; 84 | extern QGamepadManager::GamepadButton hidButtonsMiddle[8]; 85 | extern QGamepadManager::GamepadButton hidButtonsXY[2]; 86 | extern QGamepadManager::GamepadButton irButtons[2]; 87 | 88 | 89 | struct MyAxis 90 | { 91 | double x, y; 92 | }; 93 | 94 | class Worker : public QObject { 95 | Q_OBJECT 96 | public: 97 | 98 | MyAxis getLeftAxis(); 99 | MyAxis getRightAxis(); 100 | MyAxis getPreviousLAxis(); 101 | 102 | void setLeftAxis(double x, double y); 103 | void setRightAxis(double x, double y); 104 | void setPreviousLAxis(double x, double y); 105 | void closeThread() { emit finished(); } 106 | 107 | explicit Worker(QObject *parent = 0) : QObject(parent) 108 | { 109 | previousLeftAxis.x = leftAxis.x; 110 | previousLeftAxis.y = leftAxis.y; 111 | } 112 | ~Worker() 113 | { 114 | 115 | } 116 | 117 | public slots: 118 | void sendFrame(); 119 | 120 | signals: 121 | void finished(); 122 | void error(QString err); 123 | 124 | private: 125 | MyAxis leftAxis; 126 | MyAxis rightAxis; 127 | MyAxis previousLeftAxis; 128 | 129 | }; 130 | 131 | extern Worker worker; 132 | 133 | #endif // GLOBAL_H 134 | -------------------------------------------------------------------------------- /shortcut.cpp: -------------------------------------------------------------------------------- 1 | #include "shortcut.h" 2 | #include 3 | #include 4 | 5 | qint8 getButtonId(QGamepadManager::GamepadButton btn) 6 | { 7 | qint8 button = 0; 8 | if(btn == QGamepadManager::ButtonInvalid) 9 | { 10 | button = 0; 11 | } 12 | if(btn == QGamepadManager::ButtonA) 13 | { 14 | button = 1; 15 | } 16 | 17 | if(btn == QGamepadManager::ButtonB) 18 | { 19 | button = 2; 20 | } 21 | if(btn == QGamepadManager::ButtonX) 22 | { 23 | button = 3; 24 | } 25 | if(btn == QGamepadManager::ButtonY) 26 | { 27 | button = 4; 28 | } 29 | if(btn == QGamepadManager::ButtonL1) 30 | { 31 | button = 5; 32 | } 33 | if(btn == QGamepadManager::ButtonL2) 34 | { 35 | button = 6; 36 | } 37 | 38 | if(btn == QGamepadManager::ButtonL3) 39 | { 40 | button = 7; 41 | } 42 | if(btn == QGamepadManager::ButtonR1) 43 | { 44 | button = 8; 45 | } 46 | if(btn == QGamepadManager::ButtonR2) 47 | { 48 | button = 9; 49 | } 50 | if(btn == QGamepadManager::ButtonR3) 51 | { 52 | button = 10; 53 | } 54 | if(btn == QGamepadManager::ButtonUp) 55 | { 56 | button = 11; 57 | } 58 | if(btn == QGamepadManager::ButtonDown) 59 | { 60 | button = 12; 61 | } 62 | if(btn == QGamepadManager::ButtonLeft) 63 | { 64 | button = 13; 65 | } 66 | if(btn == QGamepadManager::ButtonRight) 67 | { 68 | button = 14; 69 | } 70 | if(btn == QGamepadManager::ButtonSelect) 71 | { 72 | button = 15; 73 | } 74 | if(btn == QGamepadManager::ButtonStart) 75 | { 76 | button = 16; 77 | } 78 | if(btn == QGamepadManager::ButtonGuide) 79 | { 80 | button = 17; 81 | } 82 | 83 | return button; 84 | } 85 | 86 | QGamepadManager::GamepadButton getIdButton(int btn) 87 | { 88 | QGamepadManager::GamepadButton button; 89 | if(btn == 0) 90 | { 91 | button = QGamepadManager::ButtonInvalid; 92 | } 93 | if(btn == 1) 94 | { 95 | button = QGamepadManager::ButtonA; 96 | } 97 | 98 | if(btn == 2) 99 | { 100 | button = QGamepadManager::ButtonB; 101 | } 102 | if(btn == 3) 103 | { 104 | button = QGamepadManager::ButtonX; 105 | } 106 | if(btn == 4) 107 | { 108 | button = QGamepadManager::ButtonY; 109 | } 110 | 111 | if(btn == 5) 112 | { 113 | button = QGamepadManager::ButtonL1; 114 | } 115 | if(btn == 6) 116 | { 117 | button = QGamepadManager::ButtonL2; 118 | } 119 | 120 | if(btn == 7) 121 | { 122 | button = QGamepadManager::ButtonL3; 123 | } 124 | if(btn == 8) 125 | { 126 | button = QGamepadManager::ButtonR1; 127 | } 128 | if(btn == 9) 129 | { 130 | button = QGamepadManager::ButtonR2; 131 | } 132 | if(btn == 10) 133 | { 134 | button = QGamepadManager::ButtonR3; 135 | } 136 | if(btn == 11) 137 | { 138 | button = QGamepadManager::ButtonUp; 139 | } 140 | if(btn == 12) 141 | { 142 | button = QGamepadManager::ButtonDown; 143 | } 144 | if(btn == 13) 145 | { 146 | button = QGamepadManager::ButtonLeft; 147 | } 148 | if(btn == 14) 149 | { 150 | button = QGamepadManager::ButtonRight; 151 | } 152 | if(btn == 15) 153 | { 154 | button = QGamepadManager::ButtonSelect; 155 | } 156 | if(btn == 16) 157 | { 158 | button = QGamepadManager::ButtonStart; 159 | } 160 | if(btn == 17) 161 | { 162 | button = QGamepadManager::ButtonGuide; 163 | } 164 | 165 | return button; 166 | } 167 | 168 | QDataStream &operator<<(QDataStream &out, const ShortCut &obj) 169 | { 170 | out << obj.name << obj.pos << obj.color << getIdButton(obj.button); 171 | return out; 172 | } 173 | 174 | QDataStream &operator>>(QDataStream &in, ShortCut &obj) 175 | { 176 | qint8 id = getButtonId(obj.button); 177 | in >> obj.name >> obj.pos >> obj.color >> id; 178 | return in; 179 | } 180 | -------------------------------------------------------------------------------- /gpconfigurator.h: -------------------------------------------------------------------------------- 1 | #ifndef GPCONFIGURATOR_H 2 | #define GPCONFIGURATOR_H 3 | 4 | #include "global.h" 5 | 6 | struct GamepadConfigurator : public QWidget { 7 | 8 | private: 9 | QLabel* lblCurButton; 10 | QFormLayout *formLayout; 11 | QVBoxLayout* layout; 12 | int devId; 13 | int count; 14 | 15 | public: 16 | QPushButton* skipButton, *resetConfigButton; 17 | 18 | GamepadConfigurator(QWidget *parent = 0) : QWidget(parent) 19 | { 20 | this->setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint); 21 | this->setWindowTitle(tr("Gamepad Configurator")); 22 | 23 | 24 | layout = new QVBoxLayout(this); 25 | formLayout = new QFormLayout(this); 26 | lblCurButton = new QLabel(this); 27 | skipButton = new QPushButton(tr("&Skip"), this); 28 | resetConfigButton = new QPushButton(tr("&Reset Configuration"), this); 29 | 30 | count = 0; 31 | 32 | resetConfigButton->setEnabled(false); 33 | skipButton->setEnabled(false); 34 | 35 | formLayout->addRow(lblCurButton); 36 | lblCurButton->setText(QString("Press any button on the controller to continue...")); 37 | layout->addLayout(formLayout); 38 | layout->addWidget(skipButton); 39 | layout->addWidget(resetConfigButton); 40 | 41 | setMinimumSize(300, 75); 42 | 43 | } 44 | 45 | void setCurDeviceId(int id) 46 | { 47 | devId = id; 48 | } 49 | 50 | int getCurDeviceId() 51 | { 52 | return devId; 53 | } 54 | 55 | int getCount() 56 | { 57 | return count; 58 | } 59 | 60 | void next() 61 | { 62 | 63 | getInput(devId, showDirections(QGamepadManager::ButtonInvalid)); 64 | repaint(); 65 | } 66 | 67 | QGamepadManager::GamepadButton showDirections(QGamepadManager::GamepadButton btn) 68 | { 69 | QGamepadManager::GamepadButton btnToMap = QGamepadManager::ButtonInvalid; 70 | btnToMap = btn; 71 | 72 | 73 | switch(count) 74 | { 75 | case 0: 76 | lblCurButton->setText("Press Any Button To Continue..."); 77 | btnToMap = QGamepadManager::ButtonA; 78 | 79 | return btnToMap; 80 | break; 81 | 82 | case 1: 83 | resetConfigButton->setEnabled(true); 84 | skipButton->setEnabled(true); 85 | 86 | lblCurButton->setText("BUTTON A"); 87 | btnToMap = QGamepadManager::ButtonB; 88 | break; 89 | 90 | case 2: 91 | lblCurButton->setText("BUTTON B"); 92 | btnToMap = QGamepadManager::ButtonX; 93 | break; 94 | 95 | case 3: 96 | lblCurButton->setText("BUTTON X"); 97 | btnToMap = QGamepadManager::ButtonY; 98 | break; 99 | 100 | case 4: 101 | lblCurButton->setText("BUTTON Y"); 102 | btnToMap = QGamepadManager::ButtonR1; 103 | break; 104 | 105 | case 5: 106 | lblCurButton->setText("R1"); 107 | btnToMap = QGamepadManager::ButtonR2; 108 | break; 109 | 110 | case 6: 111 | lblCurButton->setText("R2"); 112 | btnToMap = QGamepadManager::ButtonR3; 113 | break; 114 | 115 | case 7: 116 | lblCurButton->setText("R3"); 117 | btnToMap = QGamepadManager::ButtonL1; 118 | break; 119 | 120 | case 8: 121 | lblCurButton->setText("L1"); 122 | btnToMap = QGamepadManager::ButtonL2; 123 | break; 124 | 125 | case 9: 126 | lblCurButton->setText("L2"); 127 | btnToMap = QGamepadManager::ButtonL3; 128 | break; 129 | 130 | case 10: 131 | lblCurButton->setText("L3"); 132 | btnToMap = QGamepadManager::ButtonUp; 133 | break; 134 | 135 | case 11: 136 | lblCurButton->setText("D Up"); 137 | btnToMap = QGamepadManager::ButtonDown; 138 | break; 139 | 140 | case 12: 141 | lblCurButton->setText("D Down"); 142 | btnToMap = QGamepadManager::ButtonLeft; 143 | break; 144 | 145 | case 13: 146 | lblCurButton->setText("D Left"); 147 | btnToMap = QGamepadManager::ButtonRight; 148 | break; 149 | 150 | case 14: 151 | lblCurButton->setText("D Right"); 152 | btnToMap = QGamepadManager::ButtonSelect; 153 | break; 154 | 155 | case 15: 156 | lblCurButton->setText("SELECT"); 157 | btnToMap = QGamepadManager::ButtonStart; 158 | break; 159 | 160 | case 16: 161 | lblCurButton->setText("Start"); 162 | btnToMap = QGamepadManager::ButtonGuide; 163 | break; 164 | 165 | 166 | case 17: 167 | lblCurButton->setText("Guide Button"); 168 | btnToMap = QGamepadManager::ButtonGuide; 169 | break; 170 | 171 | case 18: 172 | lblCurButton->setText("Done!!"); 173 | break; 174 | 175 | default: 176 | resetConfigButton->setEnabled(false); 177 | skipButton->setEnabled(false); 178 | 179 | this->close(); 180 | count = 0; 181 | break; 182 | } 183 | 184 | this->repaint(); 185 | 186 | return btnToMap; 187 | } 188 | 189 | void getInput(int deviceId, QGamepadManager::GamepadButton btn) 190 | { 191 | QGamepadManager::GamepadButton btnToMap = QGamepadManager::ButtonInvalid; 192 | btnToMap = showDirections(btn); 193 | 194 | devId = deviceId; 195 | 196 | while(!QGamepadManager::instance()->configureButton(devId, btnToMap)); 197 | 198 | count++; 199 | 200 | btnToMap = showDirections(btn); 201 | } 202 | 203 | void showGui() 204 | { 205 | if(!this->isVisible()) 206 | { 207 | this->setVisible(true); 208 | showDirections(QGamepadManager::ButtonInvalid); 209 | } 210 | } 211 | 212 | virtual ~GamepadConfigurator(void) 213 | { 214 | 215 | } 216 | }; 217 | 218 | #endif // GPCONFIGURATOR_H 219 | -------------------------------------------------------------------------------- /touchscreen.cpp: -------------------------------------------------------------------------------- 1 | #include "touchscreen.h" 2 | #include "global.h" 3 | #include 4 | 5 | void TouchScreen::setTouchScreenPressed(bool b) 6 | { 7 | touchScreenPressed = b; 8 | } 9 | 10 | bool TouchScreen::isTouchScreenPressed() 11 | { 12 | return touchScreenPressed; 13 | } 14 | 15 | QSize TouchScreen::getTouchScreenSize() 16 | { 17 | return touchScreenSize; 18 | } 19 | 20 | QPoint TouchScreen::getTouchScreenPosition() 21 | { 22 | return touchScreenPosition; 23 | } 24 | 25 | TouchScreen::TouchScreen(QWidget *parent) : QWidget(parent) 26 | { 27 | this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint); 28 | this->setWindowTitle(tr("InputRedirectionClient-Qt - Touch screen")); 29 | this->setContextMenuPolicy(Qt::CustomContextMenu); 30 | 31 | connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), 32 | this, SLOT(ShowContextMenu(const QPoint&))); 33 | 34 | bgLabel = new QLabel(this); 35 | 36 | updatePixmap(); 37 | setMinimumWidth(TOUCH_SCREEN_WIDTH); 38 | setMinimumHeight(TOUCH_SCREEN_HEIGHT); 39 | 40 | bgLabel->setScaledContents(true); 41 | bgLabel->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored ); 42 | 43 | ellipNeedDraw = true; 44 | } 45 | 46 | void TouchScreen::ShowContextMenu(const QPoint& pos) 47 | { 48 | QMenu* myMenu = new QMenu(); 49 | QString strOpenOverlay = "Open Overlay Image..."; 50 | QString clearOverlayBtn = "Clear Overlay"; 51 | QString strPtToBtn = "Set point to button..."; 52 | QPoint globalPos = this->mapToGlobal(pos); 53 | 54 | myMenu->addAction(strOpenOverlay); 55 | myMenu->addAction(clearOverlayBtn); 56 | myMenu->addSeparator(); 57 | myMenu->addAction(strPtToBtn); 58 | 59 | myMenu->popup(globalPos); 60 | QAction* selectedItem = myMenu->exec(globalPos); 61 | 62 | QPoint newPos; 63 | newPos.setX(pos.x()); 64 | newPos.setY(pos.y()); 65 | //If custom size, scale the point to orig 3ds touchscreen size 66 | if(this->width() != TOUCH_SCREEN_WIDTH || 67 | this->height() != TOUCH_SCREEN_HEIGHT) 68 | { 69 | newPos.setX((TOUCH_SCREEN_WIDTH*pos.x())/this->width()); 70 | newPos.setY((TOUCH_SCREEN_HEIGHT*pos.y())/this->height()); 71 | } 72 | 73 | //Update the shortcut gui position title text 74 | tsShortcutGui.setCurrentPos(newPos); 75 | 76 | if(!selectedItem) 77 | { 78 | myMenu->close(); 79 | return; 80 | } 81 | 82 | if(selectedItem->text() == strOpenOverlay) 83 | { 84 | QString strPic = QFileDialog::getOpenFileName(this, 85 | tr("Open Touchscreen Image (320x240)"), "MyDocuments", 86 | tr("Image Files (*.jpg *.jpeg *.png *.bmp *.gif *.pbm *.pgm *.ppm *.xbm *.xpm)")); 87 | 88 | if(!strPic.isNull()) 89 | { 90 | settings.setValue("tsBackgroundImage", strPic); 91 | updatePixmap(); 92 | } 93 | } 94 | 95 | if(selectedItem->text() == strPtToBtn ) 96 | { 97 | if(tsShortcutGui.isVisible()) 98 | { 99 | tsShortcutGui.updateTitleText(); 100 | } 101 | 102 | tsShortcutGui.setVisible(true); 103 | 104 | } 105 | 106 | if(selectedItem->text() == clearOverlayBtn) 107 | { 108 | clearImage(); 109 | } 110 | 111 | myMenu->deleteLater(); 112 | } 113 | 114 | void TouchScreen::resizeEvent(QResizeEvent* e) 115 | { 116 | QSize newWinSize = e->size(); 117 | QSize curWinSize = e->oldSize(); 118 | QSize propWinSize = e->size(); 119 | 120 | if(curWinSize.height() != newWinSize.height()) 121 | { 122 | propWinSize.setWidth((TOUCH_SCREEN_WIDTH*newWinSize.height())/TOUCH_SCREEN_HEIGHT); 123 | propWinSize.setHeight(newWinSize.height()); 124 | } 125 | 126 | if(curWinSize.width() != newWinSize.width()) 127 | { 128 | propWinSize.setWidth(newWinSize.width()); 129 | propWinSize.setHeight((TOUCH_SCREEN_HEIGHT*newWinSize.width())/TOUCH_SCREEN_WIDTH); 130 | } 131 | 132 | touchScreenSize = propWinSize; 133 | this->resize(propWinSize); 134 | bgLabel->setFixedHeight(this->height()); 135 | bgLabel->setFixedWidth(this->width()); 136 | 137 | tsRatio = (double)this->width() / (double)TOUCH_SCREEN_WIDTH; 138 | } 139 | 140 | void TouchScreen::mousePressEvent(QMouseEvent *ev) 141 | { 142 | if(ev->button() == Qt::LeftButton) 143 | { 144 | touchScreenPressed = true; 145 | touchScreenPosition = ev->pos(); 146 | } 147 | } 148 | 149 | void TouchScreen::mouseMoveEvent(QMouseEvent *ev) 150 | { 151 | if(touchScreenPressed && (ev->buttons() & Qt::LeftButton)) 152 | { 153 | touchScreenPosition = ev->pos(); 154 | } 155 | } 156 | 157 | void TouchScreen::mouseReleaseEvent(QMouseEvent *ev) 158 | { 159 | if(ev->button() == Qt::LeftButton) 160 | { 161 | touchScreenPressed = false; 162 | } 163 | } 164 | 165 | void TouchScreen::closeEvent(QCloseEvent *ev) 166 | { 167 | touchScreenPressed = false; 168 | ev->accept(); 169 | } 170 | 171 | void TouchScreen::updatePixmap(void) 172 | { 173 | QString strPic = settings.value("tsBackgroundImage", "").toString(); 174 | QPixmap newPic(strPic); 175 | 176 | if (newPic.isNull()) 177 | { 178 | newPic = QPixmap(TOUCH_SCREEN_WIDTH, TOUCH_SCREEN_HEIGHT); 179 | newPic.fill(Qt::transparent); 180 | } 181 | } 182 | 183 | 184 | void TouchScreen::paintEvent(QPaintEvent* e) 185 | { 186 | QString strPic = settings.value("tsBackgroundImage", "").toString(); 187 | QPixmap newPic(strPic); 188 | 189 | if (newPic.isNull()) 190 | { 191 | newPic = QPixmap(TOUCH_SCREEN_WIDTH, TOUCH_SCREEN_HEIGHT); 192 | newPic.fill(Qt::transparent); 193 | } 194 | 195 | 196 | QPainter painter; 197 | painter.begin(&newPic); 198 | painter.setBrush(QBrush(Qt::black)); 199 | painter.setRenderHint(QPainter::Antialiasing, true); 200 | 201 | for (unsigned i=0; iheight()*curShort.pos.x())/TOUCH_SCREEN_HEIGHT)/this->width(), 207 | TOUCH_SCREEN_HEIGHT*((this->width()*curShort.pos.y())/TOUCH_SCREEN_WIDTH)/this->height(), 208 | (3*this->width())/TOUCH_SCREEN_WIDTH, 209 | (3*this->height())/TOUCH_SCREEN_HEIGHT); 210 | 211 | } 212 | 213 | bgLabel->setPixmap(newPic); 214 | bgLabel->show(); 215 | e->accept(); 216 | } 217 | 218 | void TouchScreen::clearImage(void) 219 | { 220 | settings.setValue("tsBackgroundImage", ""); 221 | updatePixmap(); 222 | } 223 | 224 | -------------------------------------------------------------------------------- /global.cpp: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include 3 | #include "gpmanager.h" 4 | 5 | QSettings settings("TuxSH", "InputRedirectionClient-Qt"); 6 | 7 | Worker worker; 8 | Settings btnSettings; 9 | double tsRatio; 10 | 11 | std::vector listShortcuts; 12 | 13 | QGamepadManager::GamepadButtons buttons = 0; 14 | u32 interfaceButtons = 0; 15 | int yAxisMultiplier = 1, yAxisMultiplierCpp = 1; 16 | bool shouldSwapStick = false; 17 | int CPAD_BOUND = (settings.contains("StickBound") ? settings.value("StickBound").toInt() : 1488); 18 | int CPP_BOUND = (settings.contains("CppBound") ? settings.value("CppBound").toInt() : 127); 19 | 20 | GamepadConfigurator *gpConfigurator; 21 | 22 | QString ipAddress; 23 | 24 | bool touchScreenPressed; 25 | QSize touchScreenSize = QSize(TOUCH_SCREEN_WIDTH, TOUCH_SCREEN_HEIGHT); 26 | QPoint touchScreenPosition; 27 | 28 | QGamepadManager::GamepadButton homeButton = variantToButton(settings.value("ButtonHome", QGamepadManager::ButtonInvalid)); 29 | QGamepadManager::GamepadButton powerButton = variantToButton(settings.value("ButtonPower", QGamepadManager::ButtonInvalid)); 30 | QGamepadManager::GamepadButton powerLongButton = variantToButton(settings.value("ButtonPowerLong", QGamepadManager::ButtonInvalid)); 31 | 32 | QGamepadManager::GamepadButton touchButton1 = variantToButton(settings.value("ButtonT1", QGamepadManager::ButtonInvalid)); 33 | QGamepadManager::GamepadButton touchButton2 = variantToButton(settings.value("ButtonT2", QGamepadManager::ButtonInvalid)); 34 | QGamepadManager::GamepadButton touchButton3 = variantToButton(settings.value("ButtonT3", QGamepadManager::ButtonInvalid)); 35 | QGamepadManager::GamepadButton touchButton4 = variantToButton(settings.value("ButtonT4", QGamepadManager::ButtonInvalid)); 36 | 37 | TouchButton tbOne={.x=settings.value("touchButton1X").toInt(), 38 | .y=settings.value("touchButton1Y").toInt()}; 39 | 40 | TouchButton tbTwo={.x=settings.value("touchButton2X").toInt(), 41 | .y=settings.value("touchButton2Y").toInt()}; 42 | 43 | TouchButton tbThree={.x=settings.value("touchButton3X").toInt(), 44 | .y=settings.value("touchButton3Y").toInt()}; 45 | 46 | TouchButton tbFour={.x=settings.value("touchButton4X").toInt(), 47 | .y=settings.value("touchButton4Y").toInt()}; 48 | 49 | QGamepadManager::GamepadButton hidButtonsAB[2]={ 50 | variantToButton(settings.value("ButtonA", QGamepadManager::ButtonA)), 51 | variantToButton(settings.value("ButtonB", QGamepadManager::ButtonB))}; 52 | 53 | QGamepadManager::GamepadButton hidButtonsMiddle[8] ={ 54 | variantToButton(settings.value("ButtonSelect", QGamepadManager::ButtonSelect)), 55 | variantToButton(settings.value("ButtonStart", QGamepadManager::ButtonStart)), 56 | variantToButton(settings.value("ButtonRight", QGamepadManager::ButtonRight)), 57 | variantToButton(settings.value("ButtonLeft", QGamepadManager::ButtonLeft)), 58 | variantToButton(settings.value("ButtonUp", QGamepadManager::ButtonUp)), 59 | variantToButton(settings.value("ButtonDown", QGamepadManager::ButtonDown)), 60 | variantToButton(settings.value("ButtonR", QGamepadManager::ButtonR1)), 61 | variantToButton(settings.value("ButtonL", QGamepadManager::ButtonL1))}; 62 | 63 | QGamepadManager::GamepadButton hidButtonsXY[2] = { 64 | variantToButton(settings.value("ButtonX", QGamepadManager::ButtonX)), 65 | variantToButton(settings.value("ButtonY", QGamepadManager::ButtonY))}; 66 | 67 | QGamepadManager::GamepadButton irButtons[2] = { 68 | variantToButton(settings.value("ButtonZR", QGamepadManager::ButtonR2)), 69 | variantToButton(settings.value("ButtonZL", QGamepadManager::ButtonL2))}; 70 | 71 | 72 | void Worker::setLeftAxis(double x, double y) 73 | { 74 | leftAxis.x = x; 75 | leftAxis.y = y; 76 | } 77 | 78 | void Worker::setRightAxis(double x, double y) 79 | { 80 | rightAxis.x = x; 81 | rightAxis.y = y; 82 | } 83 | 84 | void Worker::setPreviousLAxis(double x, double y) 85 | { 86 | previousLeftAxis.x = x; 87 | previousLeftAxis.y = y; 88 | } 89 | 90 | MyAxis Worker::getLeftAxis() 91 | { 92 | return leftAxis; 93 | } 94 | 95 | MyAxis Worker::getRightAxis() 96 | { 97 | return rightAxis; 98 | } 99 | 100 | MyAxis Worker::getPreviousLAxis() 101 | { 102 | return previousLeftAxis; 103 | } 104 | 105 | void Worker::sendFrame(void) 106 | { 107 | u32 hidPad = 0xfff; 108 | for(u32 i = 0; i < 2; i++) 109 | { 110 | if(buttons & (1 << hidButtonsAB[i])) 111 | hidPad &= ~(1 << i); 112 | } 113 | 114 | for(u32 i = 2; i < 10; i++) 115 | { 116 | if(buttons & (1 << hidButtonsMiddle[i-2])) 117 | hidPad &= ~(1 << i); 118 | } 119 | 120 | for(u32 i = 10; i < 12; i++) 121 | { 122 | if(buttons & (1 << hidButtonsXY[i-10])) 123 | hidPad &= ~(1 << i); 124 | } 125 | 126 | u32 irButtonsState = 0; 127 | for(u32 i = 0; i < 2; i++) 128 | { 129 | if(buttons & (1 << irButtons[i])) 130 | irButtonsState |= 1 << (i + 1); 131 | } 132 | 133 | u32 touchScreenState = 0x2000000; 134 | u32 circlePadState = 0x7ff7ff; 135 | u32 cppState = 0x80800081; 136 | 137 | if(touchScreenPressed) 138 | { 139 | 140 | u32 x = (u32)(0xfff * std::min(std::max(0, touchScreenPosition.x()), 141 | TOUCH_SCREEN_WIDTH*touchScreenPosition.x())) / touchScreenSize.width(); 142 | u32 y = (u32)(0xfff * std::min(std::max(0, touchScreenPosition.y()), 143 | TOUCH_SCREEN_HEIGHT*touchScreenPosition.y())) / touchScreenSize.height(); 144 | 145 | touchScreenState = (1 << 24) | (y << 12) | x; 146 | } 147 | 148 | if(leftAxis.x != 0.0 || leftAxis.y != 0.0) 149 | { 150 | u32 x = (u32)(leftAxis.x * CPAD_BOUND + 0x800); 151 | u32 y = (u32)(leftAxis.y * CPAD_BOUND + 0x800); 152 | x = x >= 0xfff ? (leftAxis.x < 0.0 ? 0x000 : 0xfff) : x; 153 | y = y >= 0xfff ? (leftAxis.y < 0.0 ? 0x000 : 0xfff) : y; 154 | 155 | circlePadState = (y << 12) | x; 156 | } 157 | 158 | if(rightAxis.x != 0.0 || rightAxis.y != 0.0 || irButtonsState != 0) 159 | { 160 | // We have to rotate the c-stick position 45°. Thanks, Nintendo. 161 | u32 x = (u32)(M_SQRT1_2 * (rightAxis.x + rightAxis.y) * CPP_BOUND + 0x80); 162 | u32 y = (u32)(M_SQRT1_2 * (rightAxis.y - rightAxis.x) * CPP_BOUND + 0x80); 163 | x = x >= 0xff ? (rightAxis.x < 0.0 ? 0x00 : 0xff) : x; 164 | y = y >= 0xff ? (rightAxis.y < 0.0 ? 0x00 : 0xff) : y; 165 | 166 | cppState = (y << 24) | (x << 16) | (irButtonsState << 8) | 0x81; 167 | } 168 | 169 | QByteArray ba(20, 0); 170 | qToLittleEndian(hidPad, (uchar *)ba.data()); 171 | qToLittleEndian(touchScreenState, (uchar *)ba.data() + 4); 172 | qToLittleEndian(circlePadState, (uchar *)ba.data() + 8); 173 | qToLittleEndian(cppState, (uchar *)ba.data() + 12); 174 | qToLittleEndian(interfaceButtons, (uchar *)ba.data() + 16); 175 | QUdpSocket().writeDatagram(ba, QHostAddress(ipAddress), 4950); 176 | } 177 | 178 | QGamepadManager::GamepadButton variantToButton(QVariant variant) 179 | { 180 | QGamepadManager::GamepadButton button; 181 | 182 | button = static_cast(variant.toInt()); 183 | 184 | return button; 185 | } 186 | 187 | int appScreenTo3dsX(int posX) 188 | { 189 | qDebug() << "PosX: " << posX; 190 | return TOUCH_SCREEN_WIDTH*((touchScreenSize.height()*posX)/TOUCH_SCREEN_HEIGHT)/touchScreenSize.width(); 191 | } 192 | 193 | int appScreenTo3dsY(int posY) 194 | { 195 | qDebug() << "PosX: " << posY; 196 | return TOUCH_SCREEN_HEIGHT*((touchScreenSize.width()*posY)/TOUCH_SCREEN_WIDTH)/touchScreenSize.height(); 197 | } 198 | -------------------------------------------------------------------------------- /tsshortcut.h: -------------------------------------------------------------------------------- 1 | #ifndef TSSHORTCUT_H 2 | #define TSSHORTCUT_H 3 | #include "global.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class TsShortcut : public QWidget 12 | { 13 | private: 14 | QString wTitle; 15 | QVBoxLayout *layout; 16 | QFormLayout *formLayout; 17 | QListWidget *lstWidget; 18 | QLabel *lblDirections; 19 | QPushButton *btnColorDialog, *btnCreateShort, 20 | *btnDelShort, *btnHelp, *btnPressNow; 21 | QLineEdit* txtShortName; 22 | QPoint curPos; 23 | QComboBox* cboxBtns; 24 | QColor curColor; 25 | 26 | 27 | public: 28 | TsShortcut(QWidget *parent = nullptr) : QWidget(parent) 29 | { 30 | layout = new QVBoxLayout(this); 31 | formLayout= new QFormLayout(this); 32 | 33 | lblDirections = new QLabel(this); 34 | lstWidget = new QListWidget(this); 35 | btnColorDialog = new QPushButton(this); 36 | btnCreateShort = new QPushButton(this); 37 | btnPressNow = new QPushButton(this); 38 | btnDelShort = new QPushButton(this); 39 | btnHelp = new QPushButton(this); 40 | txtShortName = new QLineEdit(this); 41 | cboxBtns = populateItems(); 42 | 43 | lblDirections->setText("Select a shortcut, then press a button to map it."); 44 | btnColorDialog->setText("Choose &Color"); 45 | btnPressNow->setText("Press Selected &Shortcut"); 46 | btnCreateShort->setText("&Create"); 47 | btnDelShort->setText("&Delete"); 48 | btnHelp->setText("&Help"); 49 | 50 | layout->addWidget(lblDirections); 51 | layout->addWidget(lstWidget); 52 | layout->addWidget(txtShortName); 53 | layout->addWidget(cboxBtns); 54 | 55 | layout->addWidget(btnColorDialog); 56 | layout->addWidget(btnCreateShort); 57 | layout->addSpacing(10); 58 | layout->addWidget(btnPressNow); 59 | layout->addWidget(btnDelShort); 60 | layout->addWidget(btnHelp); 61 | 62 | this->setMinimumSize(300, 200); 63 | this->setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint); 64 | this->setVisible(false); 65 | 66 | connect(btnColorDialog, &QPushButton::released, this, 67 | [this](void) 68 | { 69 | QColor color = QColorDialog::getColor(Qt::yellow, this ); 70 | if( color.isValid() ) 71 | { 72 | curColor = color; 73 | QString qss = QString("background-color: %1").arg(color.name()); 74 | btnColorDialog->setStyleSheet(qss); 75 | 76 | } 77 | }); 78 | 79 | connect(btnCreateShort, &QPushButton::released, this, 80 | [this](void) 81 | { 82 | ShortCut newShortCut; 83 | QString newShortName = txtShortName->text(); 84 | 85 | if(newShortName != "") 86 | { 87 | newShortCut.name = newShortName; 88 | 89 | newShortCut.button =variantToButton(cboxBtns->currentData()); 90 | newShortCut.pos = curPos; 91 | newShortCut.color = curColor; 92 | 93 | if(!curColor.isValid()) 94 | { 95 | newShortCut.color = Qt::blue; 96 | } 97 | 98 | lstWidget->addItem(newShortName); 99 | listShortcuts.push_back(newShortCut); 100 | txtShortName->clear(); 101 | btnColorDialog->setStyleSheet(""); 102 | curColor = nullptr; 103 | } 104 | else 105 | { 106 | QMessageBox *msgBox = new QMessageBox(0); 107 | msgBox->setInformativeText(tr("Cannot create new shortcut without a name.")); 108 | msgBox->show(); 109 | } 110 | }); 111 | 112 | connect(btnDelShort, &QPushButton::released, this, 113 | [this](void) 114 | { 115 | if(lstWidget->selectedItems().size() != 0) 116 | { 117 | listShortcuts.erase(listShortcuts.begin()+(lstWidget->currentRow())); 118 | qDeleteAll(lstWidget->selectedItems()); 119 | } 120 | }); 121 | 122 | connect(btnPressNow, &QPushButton::pressed, this, 123 | [this](void) 124 | { 125 | if(lstWidget->selectedItems().size() != 0) 126 | { 127 | touchScreenPressed = true; 128 | touchScreenPosition = listShortcuts[lstWidget->currentRow()].pos*tsRatio; 129 | } 130 | 131 | }); 132 | 133 | connect(btnPressNow, &QPushButton::released, this, 134 | [this](void) 135 | { 136 | touchScreenPressed = false; 137 | }); 138 | 139 | 140 | connect(btnHelp, &QPushButton::released, this, 141 | [this](void) 142 | { 143 | QMessageBox *msgBox = new QMessageBox(0); 144 | 145 | msgBox->setText("Map Touchpad to Button"); 146 | msgBox->setInformativeText(tr("1. Right-click touchpad in the position you want then open this menu.\n\ 147 | 2. Type a name for your shortcut in the textbox.\n\ 148 | 3. Choose a button on the gamepad to map this point to.\n\ 149 | 4. Choose a color for your shortcut, (this will the circle's color\ 150 | on the touchpad window\ 151 | 5. Press create, then close this window")); 152 | msgBox->show(); 153 | 154 | }); 155 | 156 | 157 | } 158 | 159 | void setCurrentPos(QPoint pos) 160 | { 161 | curPos = pos; 162 | } 163 | 164 | void updateTitleText() 165 | { 166 | wTitle = QString("Current X: %1 Y: %2").arg(QString::number(curPos.x())).arg(QString::number(curPos.y())); 167 | this->setWindowTitle(wTitle); 168 | } 169 | 170 | void showEvent(QShowEvent * event) 171 | { 172 | lstWidget->clear(); 173 | for (unsigned int i=0; iaddItem(curName); 177 | } 178 | 179 | updateTitleText(); 180 | event->accept(); 181 | } 182 | 183 | 184 | QComboBox* populateItems() 185 | { 186 | QComboBox *comboBox = new QComboBox(); 187 | comboBox->addItem("None", QGamepadManager::ButtonInvalid); 188 | comboBox->addItem("A", QGamepadManager::ButtonA); 189 | comboBox->addItem("B", QGamepadManager::ButtonB); 190 | comboBox->addItem("X", QGamepadManager::ButtonX); 191 | comboBox->addItem("Y", QGamepadManager::ButtonY); 192 | comboBox->addItem("Up", QGamepadManager::ButtonUp); 193 | comboBox->addItem("Down", QGamepadManager::ButtonDown); 194 | comboBox->addItem("Right", QGamepadManager::ButtonRight); 195 | comboBox->addItem("Left", QGamepadManager::ButtonLeft); 196 | comboBox->addItem("LB", QGamepadManager::ButtonL1); 197 | comboBox->addItem("RB", QGamepadManager::ButtonR1); 198 | comboBox->addItem("LT", QGamepadManager::ButtonL2); 199 | comboBox->addItem("RT", QGamepadManager::ButtonR2); 200 | comboBox->addItem("Start", QGamepadManager::ButtonStart); 201 | comboBox->addItem("Back", QGamepadManager::ButtonSelect); 202 | comboBox->addItem("L3", QGamepadManager::ButtonL3); 203 | comboBox->addItem("R3", QGamepadManager::ButtonR3); 204 | comboBox->addItem("Guide", QGamepadManager::ButtonGuide); 205 | 206 | return comboBox; 207 | } 208 | 209 | }; 210 | 211 | #endif // TSSHORTCUT_H 212 | -------------------------------------------------------------------------------- /mainwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWIDGET_H 2 | #define MAINWIDGET_H 3 | 4 | #include "global.h" 5 | 6 | #include 7 | #include 8 | 9 | #include "touchscreen.h" 10 | #include "configwindow.h" 11 | #include "gpconfigurator.h" 12 | 13 | 14 | class Widget : public QWidget 15 | { 16 | 17 | private slots: 18 | void ShowContextMenu(const QPoint &pos); 19 | private: 20 | QVBoxLayout *layout; 21 | QFormLayout *formLayout; 22 | QPushButton *homeButton, *powerButton, *longPowerButton, *settingsConfigButton, 23 | *clearImageButton, *configGamepadButton; 24 | QLineEdit *addrLineEdit; 25 | QSlider *touchOpacitySlider; 26 | ConfigWindow *settingsConfig; 27 | 28 | public: 29 | TouchScreen *touchScreen; 30 | 31 | Widget(QWidget *parent = nullptr) : QWidget(parent) 32 | { 33 | layout = new QVBoxLayout(this); 34 | 35 | addrLineEdit = new QLineEdit(this); 36 | addrLineEdit->setClearButtonEnabled(true); 37 | 38 | formLayout = new QFormLayout(); 39 | formLayout->addRow(tr("IP &address"), addrLineEdit); 40 | 41 | touchOpacitySlider = new QSlider(Qt::Horizontal); 42 | touchOpacitySlider->setRange(0, 10); 43 | touchOpacitySlider->setValue(10); 44 | touchOpacitySlider->setTickInterval(1); 45 | formLayout->addRow(tr("TS &Opacity"), touchOpacitySlider); 46 | 47 | homeButton = new QPushButton(tr("&Home"), this); 48 | powerButton = new QPushButton(tr("&Power"), this); 49 | longPowerButton = new QPushButton(tr("Power (&long)"), this); 50 | settingsConfigButton = new QPushButton(tr("&Settings"), this); 51 | clearImageButton = new QPushButton(tr("&Clear Image"), this); 52 | configGamepadButton = new QPushButton(tr("&Configure Custom Gamepad")); 53 | 54 | setContextMenuPolicy(Qt::CustomContextMenu); 55 | 56 | // Disable/hide the configurator button if running windows since it's not supported 57 | if (QSysInfo::productType() == "windows" || 58 | QSysInfo::productType() == "osx") 59 | { 60 | configGamepadButton->setEnabled(false); 61 | configGamepadButton->setVisible(false); 62 | } 63 | 64 | layout->addLayout(formLayout); 65 | layout->addWidget(homeButton); 66 | layout->addWidget(powerButton); 67 | layout->addWidget(longPowerButton); 68 | layout->addWidget(configGamepadButton); 69 | layout->addWidget(settingsConfigButton); 70 | layout->addWidget(clearImageButton); 71 | 72 | gpConfigurator = new GamepadConfigurator(); 73 | 74 | connect(addrLineEdit, &QLineEdit::textChanged, this, 75 | [](const QString &text) 76 | { 77 | ipAddress = text; 78 | settings.setValue("ipAddress", text); 79 | }); 80 | 81 | connect(configGamepadButton, &QPushButton::released, this, 82 | [](void) 83 | { 84 | gpConfigurator->showGui(); 85 | }); 86 | 87 | connect(homeButton, &QPushButton::pressed, this, 88 | [](void) 89 | { 90 | interfaceButtons |= 1; 91 | }); 92 | 93 | connect(homeButton, &QPushButton::released, this, 94 | [](void) 95 | { 96 | interfaceButtons &= ~1; 97 | }); 98 | 99 | connect(powerButton, &QPushButton::pressed, this, 100 | [](void) 101 | { 102 | interfaceButtons |= 2; 103 | }); 104 | 105 | connect(QGamepadManager::instance(), &QGamepadManager::gamepadButtonReleaseEvent, this, 106 | [](int deviceId, QGamepadManager::GamepadButton button) 107 | { 108 | (void)deviceId; 109 | 110 | gpConfigurator->setCurDeviceId(deviceId); 111 | 112 | if(gpConfigurator->isVisible()) 113 | { 114 | gpConfigurator->getInput(deviceId, button); 115 | return; 116 | } 117 | 118 | buttons &= QGamepadManager::GamepadButtons(~(1 << button)); 119 | }); 120 | 121 | connect(gpConfigurator->skipButton, &QPushButton::released, this, 122 | [](void) 123 | { 124 | gpConfigurator->next(); 125 | }); 126 | 127 | 128 | connect(gpConfigurator->resetConfigButton, &QPushButton::released, this, 129 | [](void) 130 | { 131 | QMessageBox *msgBox = new QMessageBox(0); 132 | QGamepadManager::instance()->resetConfiguration(gpConfigurator->getCurDeviceId()); 133 | 134 | msgBox->setText("Reset"); 135 | msgBox->setInformativeText("Please restart the program for changes to take affect."); 136 | msgBox->show(); 137 | 138 | }); 139 | 140 | connect(powerButton, &QPushButton::released, this, 141 | [](void) 142 | { 143 | interfaceButtons &= ~2; 144 | }); 145 | 146 | connect(longPowerButton, &QPushButton::pressed, this, 147 | [](void) 148 | { 149 | interfaceButtons |= 4; 150 | }); 151 | 152 | connect(longPowerButton, &QPushButton::released, this, 153 | [](void) 154 | { 155 | interfaceButtons &= ~4; 156 | }); 157 | 158 | connect(settingsConfigButton, &QPushButton::released, this, 159 | [this](void) 160 | { 161 | if (!settingsConfig->isVisible()) 162 | { 163 | settingsConfig->move(this->x() - settingsConfig->width() - 5,this->y()); 164 | settingsConfig->show(); 165 | } else settingsConfig->hide(); 166 | }); 167 | 168 | connect(clearImageButton, &QPushButton::released, this, 169 | [this](void) 170 | { 171 | touchScreen->clearImage(); 172 | }); 173 | 174 | connect(touchOpacitySlider, &QSlider::valueChanged, this, 175 | [this](int value) 176 | { 177 | touchScreen->setWindowOpacity(value / 10.0); 178 | touchScreen->update(); 179 | }); 180 | 181 | touchScreen = new TouchScreen(nullptr); 182 | settingsConfig = new ConfigWindow(nullptr, touchScreen); 183 | this->setWindowTitle(tr("InputRedirectionClient-Qt")); 184 | 185 | addrLineEdit->setText(settings.value("ipAddress", "").toString()); 186 | } 187 | 188 | void show(void) 189 | { 190 | QWidget::show(); 191 | touchScreen->move(this->x() + this->width() + 5,this->y()); 192 | touchScreen->show(); 193 | settingsConfig->hide(); 194 | } 195 | 196 | //When closing, save shortcuts 197 | void closeEvent(QCloseEvent *ev) 198 | { 199 | //Save shortcuts 200 | unsigned int i = 0; 201 | for (i=0; iclose(); 213 | settingsConfig->close(); 214 | 215 | touchScreen->setTouchScreenPressed(false); 216 | delete touchScreen; 217 | ev->accept(); 218 | } 219 | 220 | //Move touchscreen window with main window if moved 221 | void moveEvent(QMoveEvent *event) 222 | { 223 | touchScreen->move(touchScreen->pos() + (event->pos() - event->oldPos())); 224 | } 225 | 226 | //When main window is opened, load shortcut settings 227 | void showEvent(QShowEvent* event) 228 | { 229 | qRegisterMetaType("ShortCut"); 230 | qRegisterMetaTypeStreamOperators("ShortCut"); 231 | 232 | QString valName = "tsShortcut0"; 233 | for(int i = 0; settings.contains(valName); i++) 234 | { 235 | valName = tr("tsShortcut%1").arg(i); 236 | QVariant variant = settings.value(valName); 237 | 238 | ShortCut curShort = variant.value(); 239 | if(variant.isValid() && curShort.name != "") 240 | { 241 | if(curShort.name != "") 242 | { 243 | listShortcuts.push_back(curShort); 244 | } 245 | 246 | } 247 | else 248 | { 249 | settings.remove(tr("tsShortcut%1").arg(i)); 250 | } 251 | 252 | } 253 | } 254 | 255 | virtual ~Widget(void) 256 | { 257 | worker.setLeftAxis(0.0, 0.0); 258 | worker.setRightAxis(0.0, 0.0); 259 | 260 | buttons = 0; 261 | interfaceButtons = 0; 262 | 263 | delete settingsConfig; 264 | } 265 | }; 266 | 267 | #endif // MAINWIDGET_H 268 | -------------------------------------------------------------------------------- /gpmanager.cpp: -------------------------------------------------------------------------------- 1 | #include "gpmanager.h" 2 | 3 | GamepadMonitor::GamepadMonitor(QObject *parent) : QObject(parent) 4 | { 5 | connect(QGamepadManager::instance(), &QGamepadManager::gamepadButtonPressEvent, this, 6 | [this](int deviceId, QGamepadManager::GamepadButton button, double value) 7 | { 8 | (void)deviceId; 9 | (void)value; 10 | buttons |= QGamepadManager::GamepadButtons(1 << button); 11 | 12 | if (button == homeButton) 13 | { 14 | interfaceButtons |= 1; 15 | } 16 | if (button == powerButton) 17 | { 18 | interfaceButtons |= 2; 19 | } 20 | if (button == powerLongButton) 21 | { 22 | interfaceButtons |= 4; 23 | } 24 | for (auto it = listShortcuts.begin(); it != listShortcuts.end(); ++it) { 25 | int index = std::distance(listShortcuts.begin(), it); 26 | ShortCut curShort = listShortcuts.at(index); 27 | 28 | if(curShort.button == button) 29 | { 30 | touchScreenPressed = true; 31 | touchScreenPosition = curShort.pos*tsRatio; 32 | } 33 | } 34 | 35 | }); 36 | 37 | connect(QGamepadManager::instance(), &QGamepadManager::gamepadButtonReleaseEvent, this, 38 | [this](int deviceId, QGamepadManager::GamepadButton button) 39 | { 40 | (void)deviceId; 41 | buttons &= QGamepadManager::GamepadButtons(~(1 << button)); 42 | 43 | if (button == homeButton) 44 | { 45 | interfaceButtons &= ~1; 46 | } 47 | if (button == powerButton) 48 | { 49 | interfaceButtons &= ~2; 50 | } 51 | if (button == powerLongButton) 52 | { 53 | interfaceButtons &= ~4; 54 | } 55 | 56 | 57 | for (auto it = listShortcuts.begin(); it != listShortcuts.end(); ++it) { 58 | int index = std::distance(listShortcuts.begin(), it); 59 | ShortCut curShort = listShortcuts.at(index); 60 | 61 | if(curShort.button == button) 62 | { 63 | touchScreenPressed = false; 64 | return; 65 | } 66 | } 67 | 68 | }); 69 | 70 | connect(QGamepadManager::instance(), &QGamepadManager::gamepadAxisEvent, this, 71 | [this](int deviceId, QGamepadManager::GamepadAxis axis, double value) 72 | { 73 | (void)deviceId; 74 | (void)value; 75 | QGamepadManager::GamepadAxis axLeftX = QGamepadManager::AxisLeftX, 76 | axLeftY= QGamepadManager::AxisLeftY, 77 | axRightX= QGamepadManager::AxisRightX, 78 | axRightY= QGamepadManager::AxisRightY; 79 | 80 | if(btnSettings.isShouldSwapStick()) 81 | { 82 | axLeftX = QGamepadManager::AxisRightX; 83 | axLeftY = QGamepadManager::AxisRightY; 84 | 85 | axRightX = QGamepadManager::AxisLeftX; 86 | axRightY = QGamepadManager::AxisLeftY; 87 | } 88 | 89 | if(axis==axLeftX) 90 | { 91 | worker.setLeftAxis(value, worker.getLeftAxis().y); 92 | worker.setPreviousLAxis(worker.getLeftAxis().x, worker.getPreviousLAxis().y); 93 | } 94 | else 95 | if(axis==axLeftY) 96 | { 97 | worker.setLeftAxis(worker.getLeftAxis().x, yAxisMultiplier * -value); // for some reason qt inverts this 98 | worker.setPreviousLAxis(worker.getPreviousLAxis().x, worker.getLeftAxis().y); 99 | } 100 | else 101 | if(axis==axRightX) 102 | { 103 | if (!btnSettings.isCStickDisabled()) worker.setRightAxis(value, worker.getRightAxis().y); 104 | 105 | if (btnSettings.isMonsterHunterCamera()) 106 | { 107 | if (value > -1.2 && value < -0.5) // RS tilted left 108 | { 109 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[3]); // press Left 110 | } else if (value > 0.5 && value < 1.2) // RS tilted right 111 | { 112 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[2]); // press Right 113 | } else { // RS neutral, release buttons 114 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[3])); // Release Left 115 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[2])); // release Right 116 | } 117 | } 118 | if (btnSettings.isRightStickFaceButtons()) 119 | { 120 | if (value > -1.2 && value < -0.5) // RS tilted left 121 | { 122 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsXY[1]); // press Y 123 | } else if (value > 0.5 && value < 1.2) // RS tilted right 124 | { 125 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A 126 | } else { // RS neutral, release buttons 127 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsXY[1])); // Release Y 128 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[0])); // release A 129 | } 130 | } 131 | if (btnSettings.isRightStickSmash()) 132 | { 133 | if (value > -1.2 && value < -0.5) // RS tilted left 134 | { 135 | btnSettings.setSmashingH(true); 136 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A 137 | worker.setLeftAxis(-1.2, worker.getLeftAxis().y); 138 | } else if (value > 0.5 && value < 1.2) // RS tilted right 139 | { 140 | btnSettings.setSmashingH(true); 141 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A 142 | worker.setLeftAxis(1.2, worker.getLeftAxis().y); 143 | } else { // RS neutral, release buttons 144 | if (btnSettings.isSmashingH()) 145 | { 146 | if (!btnSettings.isSmashingV()) 147 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[0])); // Release A 148 | worker.setLeftAxis(worker.getPreviousLAxis().x, worker.getRightAxis().y); 149 | btnSettings.setSmashingH(false); 150 | } 151 | } 152 | } 153 | } 154 | else 155 | if(axis==axRightY) 156 | { 157 | worker.setRightAxis(worker.getRightAxis().x, yAxisMultiplierCpp * -value); 158 | 159 | if (btnSettings.isMonsterHunterCamera()) 160 | { 161 | if (worker.getRightAxis().y > -1.2 && worker.getRightAxis().y < -0.5) // RS tilted down 162 | { 163 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[5]); // press Down 164 | } else if (worker.getRightAxis().y > 0.5 && worker.getRightAxis().y < 1.2) // RS tilted up 165 | { 166 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[4]); // press Up 167 | } else { // RS neutral, release buttons 168 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[5])); // release Down 169 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[4])); // Release Up 170 | } 171 | } 172 | if (btnSettings.isRightStickFaceButtons()) 173 | { 174 | if (worker.getRightAxis().y > -1.2 && worker.getRightAxis().y < -0.5) // RS tilted down 175 | { 176 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[1]); // press B 177 | } else if (worker.getRightAxis().y > 0.5 && worker.getRightAxis().y < 1.2) // RS tilted up 178 | { 179 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsXY[0]); // press X 180 | } else { // RS neutral, release buttons 181 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[1])); // release B 182 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsXY[0])); // Release X 183 | } 184 | } 185 | if (btnSettings.isRightStickSmash()) 186 | { 187 | if (worker.getRightAxis().y > -1.2 && worker.getRightAxis().y < -0.5) // RS tilted down 188 | { 189 | btnSettings.setSmashingV(true); 190 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A 191 | worker.setLeftAxis(worker.getLeftAxis().x, -1.2); 192 | } else if (worker.getRightAxis().y > 0.5 && worker.getRightAxis().y < 1.2) // RS tilted up 193 | { 194 | btnSettings.setSmashingV(true); 195 | buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A 196 | worker.setLeftAxis(worker.getLeftAxis().x, 1.2); 197 | } else { // RS neutral, release button A 198 | if (btnSettings.isSmashingV()) 199 | { 200 | if (!btnSettings.isSmashingH()) 201 | buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[0])); // Release A 202 | worker.setLeftAxis(worker.getLeftAxis().x, worker.getPreviousLAxis().y); 203 | btnSettings.setSmashingV(false); 204 | } 205 | } 206 | } 207 | if (btnSettings.isCStickDisabled()) 208 | { 209 | worker.setRightAxis(0.0, 0.0); 210 | } 211 | } 212 | }); 213 | } 214 | 215 | 216 | -------------------------------------------------------------------------------- /configwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "configwindow.h" 2 | #include "gpmanager.h" 3 | 4 | ConfigWindow::ConfigWindow(QWidget *parent, TouchScreen *ts) : QDialog(parent) 5 | { 6 | this->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); 7 | this->setWindowTitle(tr("InputRedirectionClient-Qt - Button Config")); 8 | 9 | comboBoxA = populateItems(variantToButton(settings.value("ButtonA", QGamepadManager::ButtonA))); 10 | comboBoxB = populateItems(variantToButton(settings.value("ButtonB", QGamepadManager::ButtonB))); 11 | comboBoxX = populateItems(variantToButton(settings.value("ButtonX", QGamepadManager::ButtonX))); 12 | comboBoxY = populateItems(variantToButton(settings.value("ButtonY", QGamepadManager::ButtonY))); 13 | comboBoxUp = populateItems(variantToButton(settings.value("ButtonUp", QGamepadManager::ButtonUp))); 14 | comboBoxDown = populateItems(variantToButton(settings.value("ButtonDown", QGamepadManager::ButtonDown))); 15 | comboBoxLeft = populateItems(variantToButton(settings.value("ButtonLeft", QGamepadManager::ButtonLeft))); 16 | comboBoxRight = populateItems(variantToButton(settings.value("ButtonRight", QGamepadManager::ButtonRight))); 17 | comboBoxL = populateItems(variantToButton(settings.value("ButtonL", QGamepadManager::ButtonL1))); 18 | comboBoxR = populateItems(variantToButton(settings.value("ButtonR", QGamepadManager::ButtonR1))); 19 | comboBoxSelect = populateItems(variantToButton(settings.value("ButtonSelect", QGamepadManager::ButtonSelect))); 20 | comboBoxStart = populateItems(variantToButton(settings.value("ButtonStart", QGamepadManager::ButtonStart))); 21 | comboBoxZL = populateItems(variantToButton(settings.value("ButtonZL", QGamepadManager::ButtonL2))); 22 | comboBoxZR = populateItems(variantToButton(settings.value("ButtonZR", QGamepadManager::ButtonR2))); 23 | comboBoxHome = populateItems(variantToButton(settings.value("ButtonHome", QGamepadManager::ButtonInvalid))); 24 | comboBoxPower = populateItems(variantToButton(settings.value("ButtonPower", QGamepadManager::ButtonInvalid))); 25 | comboBoxPowerLong = populateItems(variantToButton(settings.value("ButtonPowerLong", QGamepadManager::ButtonInvalid))); 26 | txtCppVal = new QLineEdit(); 27 | txtStickVal = new QLineEdit(); 28 | validator = new QIntValidator(); 29 | 30 | txtCppVal->setValidator(validator); 31 | txtStickVal->setValidator(validator); 32 | 33 | txtCppVal->setText(tr("%1").arg(CPP_BOUND)); 34 | txtStickVal->setText(tr("%1").arg(CPAD_BOUND)); 35 | 36 | txtCppVal->setClearButtonEnabled(true); 37 | txtStickVal->setClearButtonEnabled(true); 38 | 39 | invertYCheckbox = new QCheckBox(this); 40 | invertYCppCheckbox = new QCheckBox(this); 41 | swapSticksCheckbox = new QCheckBox(this); 42 | mhCameraCheckbox = new QCheckBox(this); 43 | rsSmashCheckbox = new QCheckBox(this); 44 | rsFaceButtonsCheckbox = new QCheckBox(); 45 | disableCStickCheckbox = new QCheckBox(); 46 | 47 | saveButton = new QPushButton(tr("&SAVE"), this); 48 | 49 | layout = new QGridLayout(this); 50 | 51 | layout->addWidget(new QLabel("Y Button"), 0, 0); 52 | layout->addWidget(comboBoxY, 0, 1); 53 | layout->addWidget(new QLabel("X Button"), 0, 2); 54 | layout->addWidget(comboBoxX, 0, 3); 55 | layout->addWidget(new QLabel("B Button"), 1, 0); 56 | layout->addWidget(comboBoxB, 1, 1); 57 | layout->addWidget(new QLabel("A Button"), 1, 2); 58 | layout->addWidget(comboBoxA, 1, 3); 59 | 60 | layout->addWidget(new QLabel("DPad-Down"), 2, 0); 61 | layout->addWidget(comboBoxDown, 2, 1); 62 | layout->addWidget(new QLabel("DPad-Up"), 2, 2); 63 | layout->addWidget(comboBoxUp, 2, 3); 64 | layout->addWidget(new QLabel("DPad-Left"), 3, 0); 65 | layout->addWidget(comboBoxLeft, 3, 1); 66 | layout->addWidget(new QLabel("DPad-Right"), 3, 2); 67 | layout->addWidget(comboBoxRight, 3, 3); 68 | 69 | layout->addWidget(new QLabel("L Button"), 4, 0); 70 | layout->addWidget(comboBoxL, 4, 1); 71 | layout->addWidget(new QLabel("R Button"), 4, 2); 72 | layout->addWidget(comboBoxR, 4, 3); 73 | layout->addWidget(new QLabel("ZL Button"), 5, 0); 74 | layout->addWidget(comboBoxZL, 5, 1); 75 | layout->addWidget(new QLabel("ZR Button"), 5, 2); 76 | layout->addWidget(comboBoxZR, 5, 3); 77 | 78 | layout->addWidget(new QLabel("Select"), 6, 0); 79 | layout->addWidget(comboBoxSelect, 6, 1); 80 | layout->addWidget(new QLabel("Start"), 6, 2); 81 | layout->addWidget(comboBoxStart, 6, 3); 82 | 83 | layout->addWidget(new QLabel("Power Button"), 7, 0); 84 | layout->addWidget(comboBoxPower, 7, 1); 85 | layout->addWidget(new QLabel("Power-Long"), 7, 2); 86 | layout->addWidget(comboBoxPowerLong, 7, 3); 87 | layout->addWidget(new QLabel("Home Button"), 8, 0, 1, 2); 88 | layout->addWidget(comboBoxHome, 8, 1, 1, 2); 89 | layout->addWidget(new QLabel("Stick Range:"), 9, 0); 90 | layout->addWidget(txtStickVal, 9, 1, 2, 2); 91 | layout->addWidget(new QLabel("CPP Range:"), 11, 0); 92 | layout->addWidget(txtCppVal, 11, 1, 2, 2); 93 | 94 | layout->addWidget(new QLabel("Invert Y axis"), 17, 0); 95 | layout->addWidget(invertYCheckbox, 17, 1); 96 | layout->addWidget(new QLabel("Invert CPP Y"), 17, 2); 97 | layout->addWidget(invertYCppCheckbox, 17, 3); 98 | layout->addWidget(new QLabel("Swap CPads"), 18, 2); 99 | layout->addWidget(swapSticksCheckbox, 18, 3); 100 | layout->addWidget(new QLabel("Disable C"), 18, 0); 101 | layout->addWidget(disableCStickCheckbox, 18, 1); 102 | 103 | layout->addWidget(new QLabel("RS as DPad"), 19, 0); 104 | layout->addWidget(mhCameraCheckbox, 19, 1); 105 | layout->addWidget(new QLabel("RS as Smash"), 20, 0); 106 | layout->addWidget(rsSmashCheckbox, 20, 1); 107 | layout->addWidget(new QLabel("RS as ABXY"), 19, 2); 108 | layout->addWidget(rsFaceButtonsCheckbox, 19, 3); 109 | 110 | layout->addWidget(saveButton, 21, 1, 1, 2); 111 | 112 | connect(invertYCheckbox, &QCheckBox::stateChanged, this, 113 | [](int state) 114 | { 115 | switch(state) 116 | { 117 | case Qt::Unchecked: 118 | yAxisMultiplier = 1; 119 | settings.setValue("invertY", false); 120 | break; 121 | case Qt::Checked: 122 | yAxisMultiplier = -1; 123 | settings.setValue("invertY", true); 124 | break; 125 | default: break; 126 | } 127 | }); 128 | 129 | connect(invertYCppCheckbox, &QCheckBox::stateChanged, this, 130 | [](int state) 131 | { 132 | switch(state) 133 | { 134 | case Qt::Unchecked: 135 | yAxisMultiplierCpp = 1; 136 | settings.setValue("invertCPPY", false); 137 | break; 138 | case Qt::Checked: 139 | yAxisMultiplierCpp = -1; 140 | settings.setValue("invertCPPY", true); 141 | break; 142 | default: break; 143 | } 144 | }); 145 | 146 | 147 | connect(swapSticksCheckbox, &QCheckBox::stateChanged, this, 148 | [](int state) 149 | { 150 | switch(state) 151 | { 152 | case Qt::Unchecked: 153 | btnSettings.setShouldSwapStick(false); 154 | settings.setValue("swapSticks", false); 155 | break; 156 | case Qt::Checked: 157 | btnSettings.setShouldSwapStick(true); 158 | settings.setValue("swapSticks", true); 159 | break; 160 | default: break; 161 | } 162 | 163 | }); 164 | 165 | connect(rsSmashCheckbox, &QCheckBox::stateChanged, this, 166 | [](int state) 167 | { 168 | switch(state) 169 | { 170 | case Qt::Unchecked: 171 | btnSettings.setRightStickSmash(false); 172 | settings.setValue("rightStickSmash", false); 173 | break; 174 | case Qt::Checked: 175 | btnSettings.setRightStickSmash(true); 176 | settings.setValue("rightStickSmash", true); 177 | break; 178 | default: break; 179 | } 180 | 181 | }); 182 | 183 | connect(mhCameraCheckbox, &QCheckBox::stateChanged, this, 184 | [](int state) 185 | { 186 | switch(state) 187 | { 188 | case Qt::Unchecked: 189 | btnSettings.setMonsterHunterCamera(false); 190 | settings.setValue("monsterHunterCamera", false); 191 | break; 192 | case Qt::Checked: 193 | btnSettings.setMonsterHunterCamera(true); 194 | settings.setValue("monsterHunterCamera", true); 195 | break; 196 | default: break; 197 | } 198 | }); 199 | connect(disableCStickCheckbox, &QCheckBox::stateChanged, this, 200 | [](int state) 201 | { 202 | switch(state) 203 | { 204 | case Qt::Unchecked: 205 | btnSettings.setCStickDisabled(false); 206 | settings.setValue("cStickDisable", false); 207 | break; 208 | case Qt::Checked: 209 | btnSettings.setCStickDisabled(true); 210 | settings.setValue("cStickDisable", true); 211 | break; 212 | default: break; 213 | } 214 | }); 215 | connect(rsFaceButtonsCheckbox, &QCheckBox::stateChanged, this, 216 | [](int state) 217 | { 218 | switch(state) 219 | { 220 | case Qt::Unchecked: 221 | btnSettings.setRightStickFaceButtons(false); 222 | settings.setValue("rightStickABXY", false); 223 | break; 224 | case Qt::Checked: 225 | btnSettings.setRightStickFaceButtons(true); 226 | settings.setValue("rightStickABXY", true); 227 | break; 228 | default: break; 229 | } 230 | }); 231 | 232 | connect(saveButton, &QPushButton::pressed, this, 233 | [this, ts](void) 234 | { 235 | QGamepadManager::GamepadButton a = variantToButton(currentData(comboBoxA)); 236 | hidButtonsAB[0] = a; 237 | settings.setValue("ButtonA", a); 238 | QGamepadManager::GamepadButton b = variantToButton(currentData(comboBoxB)); 239 | hidButtonsAB[1] = b; 240 | settings.setValue("ButtonB", b); 241 | 242 | QGamepadManager::GamepadButton select = variantToButton(currentData(comboBoxSelect)); 243 | hidButtonsMiddle[0] = select; 244 | settings.setValue("ButtonSelect", select); 245 | QGamepadManager::GamepadButton start = variantToButton(currentData(comboBoxStart)); 246 | hidButtonsMiddle[1] = start; 247 | settings.setValue("ButtonStart", start); 248 | QGamepadManager::GamepadButton right = variantToButton(currentData(comboBoxRight)); 249 | hidButtonsMiddle[2] = right; 250 | settings.setValue("ButtonRight", right); 251 | QGamepadManager::GamepadButton left = variantToButton(currentData(comboBoxLeft)); 252 | hidButtonsMiddle[3] = left; 253 | settings.setValue("ButtonLeft", left); 254 | QGamepadManager::GamepadButton up = variantToButton(currentData(comboBoxUp)); 255 | hidButtonsMiddle[4] = up; 256 | settings.setValue("ButtonUp", up); 257 | QGamepadManager::GamepadButton down = variantToButton(currentData(comboBoxDown)); 258 | hidButtonsMiddle[5] = down; 259 | settings.setValue("ButtonDown", down); 260 | QGamepadManager::GamepadButton r = variantToButton(currentData(comboBoxR)); 261 | hidButtonsMiddle[6] = r; 262 | settings.setValue("ButtonR", r); 263 | QGamepadManager::GamepadButton l = variantToButton(currentData(comboBoxL)); 264 | hidButtonsMiddle[7] = l; 265 | settings.setValue("ButtonL", l); 266 | 267 | QGamepadManager::GamepadButton x = variantToButton(currentData(comboBoxX)); 268 | hidButtonsXY[0] = x; 269 | settings.setValue("ButtonX", x); 270 | QGamepadManager::GamepadButton y = variantToButton(currentData(comboBoxY)); 271 | hidButtonsXY[1] = y; 272 | settings.setValue("ButtonY", y); 273 | 274 | QGamepadManager::GamepadButton zr = variantToButton(currentData(comboBoxZR)); 275 | irButtons[0] = zr; 276 | settings.setValue("ButtonZR", zr); 277 | QGamepadManager::GamepadButton zl = variantToButton(currentData(comboBoxZL)); 278 | irButtons[1] = zl; 279 | settings.setValue("ButtonZL", zl); 280 | 281 | QGamepadManager::GamepadButton power = variantToButton(currentData(comboBoxPower)); 282 | powerButton = power; 283 | settings.setValue("ButtonPower", power); 284 | QGamepadManager::GamepadButton powerLong = variantToButton(currentData(comboBoxPowerLong)); 285 | powerLongButton = powerLong; 286 | settings.setValue("ButtonPowerLong", powerLong); 287 | QGamepadManager::GamepadButton home = variantToButton(currentData(comboBoxHome)); 288 | homeButton = home; 289 | settings.setValue("ButtonHome", home); 290 | 291 | CPP_BOUND = txtCppVal->text().toInt(); 292 | CPAD_BOUND = txtStickVal->text().toInt(); 293 | settings.setValue("StickBound", CPAD_BOUND); 294 | settings.setValue("CppBound", CPP_BOUND); 295 | 296 | ts->updatePixmap(); 297 | 298 | }); 299 | 300 | invertYCheckbox->setChecked(settings.value("invertY", false).toBool()); 301 | invertYCppCheckbox->setChecked(settings.value("invertCPPY", false).toBool()); 302 | swapSticksCheckbox->setChecked(settings.value("swapSticks", false).toBool()); 303 | mhCameraCheckbox->setChecked(settings.value("monsterHunterCamera", false).toBool()); 304 | rsSmashCheckbox->setChecked(settings.value("rightStickSmash", false).toBool()); 305 | disableCStickCheckbox->setChecked(settings.value("cStickDisable", false).toBool()); 306 | rsFaceButtonsCheckbox->setChecked(settings.value("rightStickABXY", false).toBool()); 307 | } 308 | 309 | QComboBox* ConfigWindow::populateItems(QGamepadManager::GamepadButton button) 310 | { 311 | QComboBox *comboBox = new QComboBox(); 312 | comboBox->addItem("A", QGamepadManager::ButtonA); 313 | comboBox->addItem("B", QGamepadManager::ButtonB); 314 | comboBox->addItem("X", QGamepadManager::ButtonX); 315 | comboBox->addItem("Y", QGamepadManager::ButtonY); 316 | comboBox->addItem("Up", QGamepadManager::ButtonUp); 317 | comboBox->addItem("Down", QGamepadManager::ButtonDown); 318 | comboBox->addItem("Right", QGamepadManager::ButtonRight); 319 | comboBox->addItem("Left", QGamepadManager::ButtonLeft); 320 | comboBox->addItem("LB", QGamepadManager::ButtonL1); 321 | comboBox->addItem("RB", QGamepadManager::ButtonR1); 322 | comboBox->addItem("LT", QGamepadManager::ButtonL2); 323 | comboBox->addItem("RT", QGamepadManager::ButtonR2); 324 | comboBox->addItem("Start", QGamepadManager::ButtonStart); 325 | comboBox->addItem("Back", QGamepadManager::ButtonSelect); 326 | comboBox->addItem("L3", QGamepadManager::ButtonL3); 327 | comboBox->addItem("R3", QGamepadManager::ButtonR3); 328 | comboBox->addItem("Guide", QGamepadManager::ButtonGuide); 329 | comboBox->addItem("None", QGamepadManager::ButtonInvalid); 330 | 331 | int index = comboBox->findData(button); 332 | comboBox->setCurrentIndex(index); 333 | 334 | return comboBox; 335 | } 336 | 337 | QVariant ConfigWindow::currentData(QComboBox *comboBox) 338 | { 339 | QVariant variant; 340 | 341 | variant = comboBox->itemData(comboBox->currentIndex()); 342 | 343 | return variant; 344 | } 345 | --------------------------------------------------------------------------------