summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface/Touch/Touchscreen.cpp
blob: a4c20b0ae04b7615f57918c8ce88ca9464cb24a7 (plain)
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
// Copyright 2013 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "InputCommon/ControllerInterface/Touch/Touchscreen.h"

#include <sstream>
#include <thread>
#ifdef ANDROID
#include <jni/AndroidCommon/IDCache.h>
#endif

#include "InputCommon/ControllerInterface/ControllerInterface.h"

namespace ciface::Touch
{
// Touchscreens and stuff
std::string Touchscreen::GetName() const
{
  return "Touchscreen";
}

std::string Touchscreen::GetSource() const
{
  return "Android";
}

Touchscreen::Touchscreen(int pad_id, bool accelerometer_enabled, bool gyroscope_enabled)
    : m_pad_id(pad_id)
{
  // GC
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_A));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_B));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_START));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_X));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_Y));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_Z));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_UP));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_DOWN));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_LEFT));
  AddInput(new Button(m_pad_id, ButtonManager::BUTTON_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::STICK_MAIN_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::STICK_MAIN_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::STICK_MAIN_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::STICK_MAIN_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::STICK_C_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::STICK_C_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::STICK_C_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::STICK_C_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::TRIGGER_L));
  AddInput(new Axis(m_pad_id, ButtonManager::TRIGGER_R));

  // Wiimote
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_BUTTON_A));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_BUTTON_B));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_BUTTON_MINUS));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_BUTTON_PLUS));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_BUTTON_HOME));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_BUTTON_1));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_BUTTON_2));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_UP));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_DOWN));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_LEFT));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_RIGHT));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_IR_HIDE));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_TILT_MODIFIER));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_SHAKE_X));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_SHAKE_Y));
  AddInput(new Button(m_pad_id, ButtonManager::WIIMOTE_SHAKE_Z));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_IR_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_IR_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_IR_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_IR_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_IR_FORWARD));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_IR_BACKWARD));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_SWING_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_SWING_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_SWING_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_SWING_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_SWING_FORWARD));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_SWING_BACKWARD));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_TILT_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_TILT_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_TILT_FORWARD));
  AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_TILT_BACKWARD));

  // Wii ext: Nunchuk
  AddInput(new Button(m_pad_id, ButtonManager::NUNCHUK_BUTTON_C));
  AddInput(new Button(m_pad_id, ButtonManager::NUNCHUK_BUTTON_Z));
  AddInput(new Button(m_pad_id, ButtonManager::NUNCHUK_TILT_MODIFIER));
  AddInput(new Button(m_pad_id, ButtonManager::NUNCHUK_SHAKE_X));
  AddInput(new Button(m_pad_id, ButtonManager::NUNCHUK_SHAKE_Y));
  AddInput(new Button(m_pad_id, ButtonManager::NUNCHUK_SHAKE_Z));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_STICK_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_STICK_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_STICK_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_STICK_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_SWING_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_SWING_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_SWING_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_SWING_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_SWING_FORWARD));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_SWING_BACKWARD));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_TILT_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_TILT_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_TILT_FORWARD));
  AddInput(new Axis(m_pad_id, ButtonManager::NUNCHUK_TILT_BACKWARD));

  // Wii ext: Classic
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_A));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_B));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_X));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_Y));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_MINUS));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_PLUS));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_HOME));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_ZL));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_BUTTON_ZR));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_DPAD_UP));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_DPAD_DOWN));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_DPAD_LEFT));
  AddInput(new Button(m_pad_id, ButtonManager::CLASSIC_DPAD_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_STICK_LEFT_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_STICK_LEFT_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_STICK_LEFT_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_STICK_LEFT_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_STICK_RIGHT_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_STICK_RIGHT_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_STICK_RIGHT_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_STICK_RIGHT_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_TRIGGER_L));
  AddInput(new Axis(m_pad_id, ButtonManager::CLASSIC_TRIGGER_R));

  // Wii-ext: Guitar
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_BUTTON_MINUS));
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_BUTTON_PLUS));
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_FRET_GREEN));
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_FRET_RED));
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_FRET_YELLOW));
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_FRET_BLUE));
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_FRET_ORANGE));
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_STRUM_UP));
  AddInput(new Button(m_pad_id, ButtonManager::GUITAR_STRUM_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::GUITAR_STICK_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::GUITAR_STICK_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::GUITAR_STICK_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::GUITAR_STICK_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::GUITAR_WHAMMY_BAR));

  // Wii-ext: Drums
  AddInput(new Button(m_pad_id, ButtonManager::DRUMS_BUTTON_MINUS));
  AddInput(new Button(m_pad_id, ButtonManager::DRUMS_BUTTON_PLUS));
  AddInput(new Button(m_pad_id, ButtonManager::DRUMS_PAD_RED));
  AddInput(new Button(m_pad_id, ButtonManager::DRUMS_PAD_YELLOW));
  AddInput(new Button(m_pad_id, ButtonManager::DRUMS_PAD_BLUE));
  AddInput(new Button(m_pad_id, ButtonManager::DRUMS_PAD_GREEN));
  AddInput(new Button(m_pad_id, ButtonManager::DRUMS_PAD_ORANGE));
  AddInput(new Button(m_pad_id, ButtonManager::DRUMS_PAD_BASS));
  AddInput(new Axis(m_pad_id, ButtonManager::DRUMS_STICK_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::DRUMS_STICK_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::DRUMS_STICK_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::DRUMS_STICK_DOWN));

  // Wii-ext: Turntable
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_GREEN_LEFT));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_RED_LEFT));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_BLUE_LEFT));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_GREEN_RIGHT));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_RED_RIGHT));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_BLUE_RIGHT));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_MINUS));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_PLUS));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_HOME));
  AddInput(new Button(m_pad_id, ButtonManager::TURNTABLE_BUTTON_EUPHORIA));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_TABLE_LEFT_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_TABLE_LEFT_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_TABLE_RIGHT_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_TABLE_RIGHT_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_STICK_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_STICK_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_STICK_UP));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_STICK_DOWN));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_CROSSFADE_LEFT));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_CROSSFADE_RIGHT));
  AddInput(new Axis(m_pad_id, ButtonManager::TURNTABLE_EFFECT_DIAL));

  // Wiimote IMU
  // Only add inputs if we actually can receive data from the relevant sensor.
  // Whether inputs exist affects what WiimoteEmu gets when calling ControlReference::BoundCount.
  if (accelerometer_enabled)
  {
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_ACCEL_LEFT));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_ACCEL_RIGHT));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_ACCEL_FORWARD));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_ACCEL_BACKWARD));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_ACCEL_UP));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_ACCEL_DOWN));
  }
  if (gyroscope_enabled)
  {
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_GYRO_PITCH_UP));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_GYRO_PITCH_DOWN));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_GYRO_ROLL_LEFT));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_GYRO_ROLL_RIGHT));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_GYRO_YAW_LEFT));
    AddInput(new Axis(m_pad_id, ButtonManager::WIIMOTE_GYRO_YAW_RIGHT));
  }

  // Rumble
  AddOutput(new Motor(m_pad_id, ButtonManager::RUMBLE));
}
// Buttons and stuff

std::string Touchscreen::Button::GetName() const
{
  std::ostringstream ss;
  ss << "Button " << static_cast<int>(m_index);
  return ss.str();
}

ControlState Touchscreen::Button::GetState() const
{
  return ButtonManager::GetButtonPressed(m_pad_id, m_index);
}

std::string Touchscreen::Axis::GetName() const
{
  std::ostringstream ss;
  ss << "Axis " << static_cast<int>(m_index);
  return ss.str();
}

ControlState Touchscreen::Axis::GetState() const
{
  return ButtonManager::GetAxisValue(m_pad_id, m_index) * m_neg;
}

Touchscreen::Motor::~Motor()
{
}

std::string Touchscreen::Motor::GetName() const
{
  std::ostringstream ss;
  ss << "Rumble " << static_cast<int>(m_index);
  return ss.str();
}

void Touchscreen::Motor::SetState(ControlState state)
{
  if (state > 0)
  {
    std::thread(Rumble, m_pad_id, state).detach();
  }
}

void Touchscreen::Motor::Rumble(int pad_id, double state)
{
#ifdef ANDROID
  JNIEnv* env = IDCache::GetEnvForThread();
  env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetDoRumble(), pad_id,
                            state);
#endif
}
}  // namespace ciface::Touch