forked from TuxSH/InputRedirectionClient-Qt
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgpmanager.cpp
294 lines (253 loc) · 10.4 KB
/
gpmanager.cpp
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include "gpmanager.h"
GamepadMonitor::GamepadMonitor(QObject *parent) : QObject(parent)
{
axLeftX = QGamepadManager::AxisLeftX;
axLeftY = QGamepadManager::AxisLeftY;
axRightX = QGamepadManager::AxisRightX;
axRightY = QGamepadManager::AxisRightY;
connect(QGamepadManager::instance(), &QGamepadManager::gamepadButtonPressEvent, this,
[this](int deviceId, QGamepadManager::GamepadButton button, double value)
{
(void)value;
if (deviceId != selectedControllerId) return;
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)
{
if (deviceId != selectedControllerId) return;
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)
{
if (deviceId != selectedControllerId) return;
if(btnSettings.isShouldSwapStick())
{
axLeftX = QGamepadManager::AxisRightX;
axLeftY = QGamepadManager::AxisRightY;
axRightX = QGamepadManager::AxisLeftX;
axRightY = QGamepadManager::AxisLeftY;
}
leftX(axis, value);
leftY(axis, value);
rightX(axis, value);
rightY(axis, value);
});
}
void GamepadMonitor::leftX(QGamepadManager::GamepadAxis axis, double value)
{
if(axis != axLeftX) return;
worker->setLeftAxis(value, worker->getLeftAxis().y);
if (!btnSettings.isSamusAimingH() && !btnSettings.isSamusAimingV())
worker->setPreviousLAxis(worker->getLeftAxis().x, worker->getPreviousLAxis().y);
}
void GamepadMonitor::leftY(QGamepadManager::GamepadAxis axis, double value)
{
if(axis != axLeftY) return;
worker->setLeftAxis(worker->getLeftAxis().x, yAxisMultiplier * -value); // for some reason qt inverts this
if (!btnSettings.isSamusAimingH() && !btnSettings.isSamusAimingV())
worker->setPreviousLAxis(worker->getPreviousLAxis().x, worker->getLeftAxis().y);
}
void GamepadMonitor::rightX(QGamepadManager::GamepadAxis axis, double value)
{
if(axis != axRightX) return;
if (!btnSettings.isCStickDisabled())
worker->setRightAxis(value, worker->getRightAxis().y);
rsSmashX(value);
samusReturnsAimingX(value);
rsDpadX(value);
rsFaceButtonsX(value);
}
void GamepadMonitor::rightY(QGamepadManager::GamepadAxis axis, double value)
{
if(axis != axRightY) return;
worker->setRightAxis(worker->getRightAxis().x, yAxisMultiplierCpp * -value);
rsSmashY();
samusReturnsAimingY();
rsDPadY();
rsFaceButtonsY();
if (btnSettings.isCStickDisabled())
{
worker->setRightAxis(0.0, 0.0);
}
}
void GamepadMonitor::rsSmashX(double value)
{
if (!btnSettings.isRightStickSmash()) return;
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()) return;
if (!btnSettings.isSmashingV())
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[0])); // Release A
worker->setLeftAxis(worker->getPreviousLAxis().x, worker->getRightAxis().y);
btnSettings.setSmashingH(false);
}
}
void GamepadMonitor::rsSmashY()
{
if (!btnSettings.isRightStickSmash()) return;
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()) return;
if (!btnSettings.isSmashingH())
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsAB[0])); // Release A
worker->setLeftAxis(worker->getLeftAxis().x, worker->getPreviousLAxis().y);
btnSettings.setSmashingV(false);
}
}
void GamepadMonitor::samusReturnsAimingX(double value)
{
if (!btnSettings.isSamusReturnsAiming()) return;
if ((value > -1.2 && value < -0.05) || (value > 0.05 && value < 1.2)) // RS tilted left
{
btnSettings.setSamusAimingH(true);
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[7]); // press L
worker->setLeftAxis(value, worker->getLeftAxis().y);
} else
{
if (!btnSettings.isSamusAimingH()) return;
if (!btnSettings.isSamusAimingV())
{
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[7])); // Release L
worker->setLeftAxis(worker->getPreviousLAxis().x-0.01, worker->getPreviousLAxis().y-0.01);
}
btnSettings.setSamusAimingH(false);
}
}
void GamepadMonitor::samusReturnsAimingY(void)
{
if (!btnSettings.isSamusReturnsAiming()) return;
if ((worker->getRightAxis().y > -1.2 && worker->getRightAxis().y < -0.05) ||
(worker->getRightAxis().y > 0.05 && worker->getRightAxis().y < 1.2)) // RS tilted down
{
btnSettings.setSamusAimingV(true);
buttons |= QGamepadManager::GamepadButtons(1 << hidButtonsMiddle[7]); // press L
worker->setLeftAxis(worker->getLeftAxis().x, worker->getRightAxis().y);
} else
{
if (!btnSettings.isSamusAimingV()) return;
if (!btnSettings.isSamusAimingH())
{
buttons &= QGamepadManager::GamepadButtons(~(1 << hidButtonsMiddle[7])); // Release L
worker->setLeftAxis(worker->getLeftAxis().x-0.01, worker->getPreviousLAxis().y-0.01);
}
btnSettings.setSamusAimingV(false);
}
}
void GamepadMonitor::rsDpadX(double value)
{
if (!btnSettings.isMonsterHunterCamera()) return;
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
}
}
void GamepadMonitor::rsDPadY(void)
{
if (!btnSettings.isMonsterHunterCamera()) return;
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
}
}
void GamepadMonitor::rsFaceButtonsX(double value)
{
if (!btnSettings.isRightStickFaceButtons()) return;
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
}
}
void GamepadMonitor::rsFaceButtonsY()
{
if (!btnSettings.isRightStickFaceButtons()) return;
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
}
}