forked from gbrown5/InputRedirectionClient-Qt
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgpmanager.cpp
More file actions
215 lines (197 loc) · 8.99 KB
/
gpmanager.cpp
File metadata and controls
215 lines (197 loc) · 8.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "gpmanager.h"
GamepadMonitor::GamepadMonitor(QObject *parent) : QObject(parent)
{
connect(QGamepadManager::instance(), &QGamepadManager::gamepadButtonPressEvent, this,
[this](int deviceId, QGamepadManager::GamepadButton button, double value)
{
(void)deviceId;
(void)value;
buttons |= QGamepadManager::GamepadButtons(1 << button);
if (button == homeButton)
{
interfaceButtons |= 1;
}
if (button == powerButton)
{
interfaceButtons |= 2;
}
if (button == powerLongButton)
{
interfaceButtons |= 4;
}
for (auto it = listShortcuts.begin(); it != listShortcuts.end(); ++it) {
int index = std::distance(listShortcuts.begin(), it);
ShortCut curShort = listShortcuts.at(index);
if(curShort.button == button)
{
touchScreenPressed = true;
touchScreenPosition = curShort.pos*tsRatio;
}
}
});
connect(QGamepadManager::instance(), &QGamepadManager::gamepadButtonReleaseEvent, this,
[this](int deviceId, QGamepadManager::GamepadButton button)
{
(void)deviceId;
buttons &= QGamepadManager::GamepadButtons(~(1 << button));
if (button == homeButton)
{
interfaceButtons &= ~1;
}
if (button == powerButton)
{
interfaceButtons &= ~2;
}
if (button == powerLongButton)
{
interfaceButtons &= ~4;
}
for (auto it = listShortcuts.begin(); it != listShortcuts.end(); ++it) {
int index = std::distance(listShortcuts.begin(), it);
ShortCut curShort = listShortcuts.at(index);
if(curShort.button == button)
{
touchScreenPressed = false;
return;
}
}
});
connect(QGamepadManager::instance(), &QGamepadManager::gamepadAxisEvent, this,
[this](int deviceId, QGamepadManager::GamepadAxis axis, double value)
{
(void)deviceId;
(void)value;
QGamepadManager::GamepadAxis axLeftX = QGamepadManager::AxisLeftX,
axLeftY= QGamepadManager::AxisLeftY,
axRightX= QGamepadManager::AxisRightX,
axRightY= QGamepadManager::AxisRightY;
if(btnSettings.isShouldSwapStick())
{
axLeftX = QGamepadManager::AxisRightX;
axLeftY = QGamepadManager::AxisRightY;
axRightX = QGamepadManager::AxisLeftX;
axRightY = QGamepadManager::AxisLeftY;
}
if(axis==axLeftX)
{
worker.setLeftAxis(value, worker.getLeftAxis().y);
worker.setPreviousLAxis(worker.getLeftAxis().x, worker.getPreviousLAxis().y);
}
else
if(axis==axLeftY)
{
worker.setLeftAxis(worker.getLeftAxis().x, yAxisMultiplier * -value); // for some reason qt inverts this
worker.setPreviousLAxis(worker.getPreviousLAxis().x, worker.getLeftAxis().y);
}
else
if(axis==axRightX)
{
if (!btnSettings.isCStickDisabled()) worker.setRightAxis(value, worker.getRightAxis().y);
if (btnSettings.isMonsterHunterCamera())
{
if (value > -1.2 && value < -0.5) // RS tilted left
{
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[3]); // press Left
} else if (value > 0.5 && value < 1.2) // RS tilted right
{
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[2]); // press Right
} else { // RS neutral, release buttons
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[3])); // Release Left
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[2])); // release Right
}
}
if (btnSettings.isRightStickFaceButtons())
{
if (value > -1.2 && value < -0.5) // RS tilted left
{
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsXY[1]); // press Y
} else if (value > 0.5 && value < 1.2) // RS tilted right
{
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A
} else { // RS neutral, release buttons
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsXY[1])); // Release Y
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[0])); // release A
}
}
if (btnSettings.isRightStickSmash())
{
if (value > -1.2 && value < -0.5) // RS tilted left
{
btnSettings.setSmashingH(true);
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A
worker.setLeftAxis(-1.2, worker.getLeftAxis().y);
} else if (value > 0.5 && value < 1.2) // RS tilted right
{
btnSettings.setSmashingH(true);
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A
worker.setLeftAxis(1.2, worker.getLeftAxis().y);
} else { // RS neutral, release buttons
if (btnSettings.isSmashingH())
{
if (!btnSettings.isSmashingV())
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[0])); // Release A
worker.setLeftAxis(worker.getPreviousLAxis().x, worker.getRightAxis().y);
btnSettings.setSmashingH(false);
}
}
}
}
else
if(axis==axRightY)
{
worker.setRightAxis(worker.getRightAxis().x, yAxisMultiplierCpp * -value);
if (btnSettings.isMonsterHunterCamera())
{
if (worker.getRightAxis().y > -1.2 && worker.getRightAxis().y < -0.5) // RS tilted down
{
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[5]); // press Down
} else if (worker.getRightAxis().y > 0.5 && worker.getRightAxis().y < 1.2) // RS tilted up
{
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[4]); // press Up
} else { // RS neutral, release buttons
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[5])); // release Down
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[4])); // Release Up
}
}
if (btnSettings.isRightStickFaceButtons())
{
if (worker.getRightAxis().y > -1.2 && worker.getRightAxis().y < -0.5) // RS tilted down
{
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[1]); // press B
} else if (worker.getRightAxis().y > 0.5 && worker.getRightAxis().y < 1.2) // RS tilted up
{
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsXY[0]); // press X
} else { // RS neutral, release buttons
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[1])); // release B
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsXY[0])); // Release X
}
}
if (btnSettings.isRightStickSmash())
{
if (worker.getRightAxis().y > -1.2 && worker.getRightAxis().y < -0.5) // RS tilted down
{
btnSettings.setSmashingV(true);
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A
worker.setLeftAxis(worker.getLeftAxis().x, -1.2);
} else if (worker.getRightAxis().y > 0.5 && worker.getRightAxis().y < 1.2) // RS tilted up
{
btnSettings.setSmashingV(true);
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsAB[0]); // press A
worker.setLeftAxis(worker.getLeftAxis().x, 1.2);
} else { // RS neutral, release button A
if (btnSettings.isSmashingV())
{
if (!btnSettings.isSmashingH())
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[0])); // Release A
worker.setLeftAxis(worker.getLeftAxis().x, worker.getPreviousLAxis().y);
btnSettings.setSmashingV(false);
}
}
}
if (btnSettings.isCStickDisabled())
{
worker.setRightAxis(0.0, 0.0);
}
}
});
}