PAD: clang-format

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2020-12-11 04:26:46 +01:00 committed by lightningterror
parent 2e0be1f75a
commit 82f7a23be4
27 changed files with 19520 additions and 19192 deletions

View File

@ -57,7 +57,8 @@ int GamePad::uid_to_index(int pad)
{
size_t uid = g_conf.get_joy_uid(pad);
for (int i = 0; i < (int)s_vgamePad.size(); ++i) {
for (int i = 0; i < (int)s_vgamePad.size(); ++i)
{
if (s_vgamePad[i]->GetUniqueIdentifier() == uid)
return i;
}

View File

@ -17,13 +17,15 @@
void KeyStatus::Init()
{
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
m_button[pad] = 0xFFFF;
m_internal_button_kbd[pad] = 0xFFFF;
m_internal_button_joy[pad] = 0xFFFF;
m_state_acces[pad] = false;
for (int index = 0; index < MAX_KEYS; index++) {
for (int index = 0; index < MAX_KEYS; index++)
{
m_button_pressure[pad][index] = 0xFF;
m_internal_button_pressure[pad][index] = 0xFF;
}
@ -45,13 +47,16 @@ void KeyStatus::Init()
void KeyStatus::press(u32 pad, u32 index, s32 value)
{
if (!IsAnalogKey(index)) {
if (!IsAnalogKey(index))
{
m_internal_button_pressure[pad][index] = value;
if (m_state_acces[pad])
clear_bit(m_internal_button_kbd[pad], index);
else
clear_bit(m_internal_button_joy[pad], index);
} else {
}
else
{
// clamp value
if (value > MAX_ANALOG_VALUE)
value = MAX_ANALOG_VALUE;
@ -73,12 +78,15 @@ void KeyStatus::press(u32 pad, u32 index, s32 value)
void KeyStatus::release(u32 pad, u32 index)
{
if (!IsAnalogKey(index)) {
if (!IsAnalogKey(index))
{
if (m_state_acces[pad])
set_bit(m_internal_button_kbd[pad], index);
else
set_bit(m_internal_button_joy[pad], index);
} else {
}
else
{
analog_set(pad, index, m_analog_released_val);
}
}
@ -96,7 +104,8 @@ void KeyStatus::analog_set(u32 pad, u32 index, u8 value)
else
m_internal_analog_ref = &m_internal_analog_joy[pad];
switch (index) {
switch (index)
{
case PAD_R_LEFT:
case PAD_R_RIGHT:
m_internal_analog_ref->rx = value;
@ -124,7 +133,8 @@ void KeyStatus::analog_set(u32 pad, u32 index, u8 value)
bool KeyStatus::analog_is_reversed(u32 pad, u32 index)
{
switch (index) {
switch (index)
{
case PAD_L_RIGHT:
case PAD_L_LEFT:
return (g_conf.pad_options[pad].reverse_lx);
@ -148,7 +158,8 @@ bool KeyStatus::analog_is_reversed(u32 pad, u32 index)
u8 KeyStatus::get(u32 pad, u32 index)
{
switch (index) {
switch (index)
{
case PAD_R_LEFT:
case PAD_R_RIGHT:
return m_analog[pad].rx;

View File

@ -81,7 +81,8 @@ void initLogging()
void CloseLogging()
{
#ifdef PAD_LOG
if (padLog) {
if (padLog)
{
fclose(padLog);
padLog = NULL;
}
@ -152,7 +153,8 @@ s32 PADsetSlot(u8 port, u8 slot)
{
port--;
slot--;
if (port > 1 || slot > 3) {
if (port > 1 || slot > 3)
{
return 0;
}
// Even if no pad there, record the slot, as it is the active slot regardless.
@ -166,10 +168,12 @@ s32 PADfreeze(int mode, freezeData *data)
if (!data)
return -1;
if (mode == FREEZE_SIZE) {
if (mode == FREEZE_SIZE)
{
data->size = sizeof(PadPluginFreezeData);
} else if (mode == FREEZE_LOAD) {
}
else if (mode == FREEZE_LOAD)
{
PadPluginFreezeData* pdata = (PadPluginFreezeData*)(data->data);
Pad::stop_vibrate_all();
@ -179,17 +183,21 @@ s32 PADfreeze(int mode, freezeData *data)
return 0;
query = pdata->query;
if (pdata->query.slot < 4) {
if (pdata->query.slot < 4)
{
query = pdata->query;
}
// Tales of the Abyss - pad fix
// - restore data for both ports
for (int port = 0; port < 2; port++) {
for (int slot = 0; slot < 4; slot++) {
for (int port = 0; port < 2; port++)
{
for (int slot = 0; slot < 4; slot++)
{
u8 mode = pdata->padData[port][slot].mode;
if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) {
if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE)
{
break;
}
@ -199,8 +207,9 @@ s32 PADfreeze(int mode, freezeData *data)
if (pdata->slot[port] < 4)
slots[port] = pdata->slot[port];
}
} else if (mode == FREEZE_SAVE) {
}
else if (mode == FREEZE_SAVE)
{
if (data->size != sizeof(PadPluginFreezeData))
return 0;
@ -214,15 +223,18 @@ s32 PADfreeze(int mode, freezeData *data)
pdata->version = PAD_SAVE_STATE_VERSION;
pdata->query = query;
for (int port = 0; port < 2; port++) {
for (int slot = 0; slot < 4; slot++) {
for (int port = 0; port < 2; port++)
{
for (int slot = 0; slot < 4; slot++)
{
pdata->padData[port][slot] = pads[port][slot];
}
pdata->slot[port] = slots[port];
}
} else {
}
else
{
return -1;
}
@ -245,8 +257,10 @@ keyEvent * PADkeyEvent()
#ifdef SDL_BUILD
// Take the opportunity to handle hot plugging here
SDL_Event events;
while (SDL_PollEvent(&events)) {
switch (events.type) {
while (SDL_PollEvent(&events))
{
switch (events.type)
{
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
GamePad::EnumerateGamePads(s_vgamePad);
@ -256,7 +270,8 @@ keyEvent * PADkeyEvent()
}
}
#endif
if (g_ev_fifo.size() == 0) {
if (g_ev_fifo.size() == 0)
{
// PAD_LOG("No events in queue, returning empty event\n");
s_event = event;
event.evt = 0;

View File

@ -43,7 +43,8 @@
#define PADdefs
enum PadOptions {
enum PadOptions
{
PADOPTION_FORCEFEEDBACK = 0x1,
PADOPTION_REVERSELX = 0x2,
PADOPTION_REVERSELY = 0x4,
@ -53,7 +54,8 @@ enum PadOptions {
PADOPTION_MOUSE_R = 0x40,
};
enum PadCommands {
enum PadCommands
{
CMD_SET_VREF_PARAM = 0x40,
CMD_QUERY_DS2_ANALOG_MODE = 0x41,
CMD_READ_DATA_AND_VIBRATE = 0x42,
@ -67,7 +69,8 @@ enum PadCommands {
CMD_SET_DS2_NATIVE_MODE = 0x4F // SET_DS2_NATIVE_MODE
};
enum gamePadValues {
enum gamePadValues
{
PAD_L2 = 0, // L2 button
PAD_R2, // R2 button
PAD_L1, // L1 button

View File

@ -26,7 +26,8 @@ void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjo
{
uint32_t flag = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER;
if ((SDL_WasInit(0) & flag) != flag) {
if ((SDL_WasInit(0) & flag) != flag)
{
// Tell SDL to catch event even if the windows isn't focussed
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
@ -63,7 +64,8 @@ void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjo
vjoysticks.clear();
for (int i = 0; i < SDL_NumJoysticks(); ++i) {
for (int i = 0; i < SDL_NumJoysticks(); ++i)
{
vjoysticks.push_back(std::unique_ptr<GamePad>(new JoystickInfo(i)));
// Something goes wrong in the init, let's drop it
if (!vjoysticks.back()->IsProperlyInitialized())
@ -83,7 +85,8 @@ void JoystickInfo::Rumble(unsigned type, unsigned pad)
return;
int id = m_effects_id[type];
if (SDL_HapticRunEffect(m_haptic, id, 1) != 0) {
if (SDL_HapticRunEffect(m_haptic, id, 1) != 0)
{
fprintf(stderr, "ERROR: Effect is not working! %s, id is %d\n", SDL_GetError(), id);
}
}
@ -91,8 +94,10 @@ void JoystickInfo::Rumble(unsigned type, unsigned pad)
JoystickInfo::~JoystickInfo()
{
// Haptic must be closed before the joystick
if (m_haptic != nullptr) {
for (const auto &eid : m_effects_id) {
if (m_haptic != nullptr)
{
for (const auto& eid : m_effects_id)
{
if (eid >= 0)
SDL_HapticDestroyEffect(m_haptic, eid);
}
@ -100,7 +105,8 @@ JoystickInfo::~JoystickInfo()
SDL_HapticClose(m_haptic);
}
if (m_controller != nullptr) {
if (m_controller != nullptr)
{
#if SDL_MINOR_VERSION >= 4
// Version before 2.0.4 are bugged, JoystickClose crashes randomly
// Note: GameControllerClose calls JoystickClose)
@ -143,14 +149,18 @@ JoystickInfo::JoystickInfo(int id)
m_pad_to_sdl[PAD_R_DOWN] = SDL_CONTROLLER_AXIS_RIGHTY;
m_pad_to_sdl[PAD_R_LEFT] = SDL_CONTROLLER_AXIS_RIGHTX;
if (SDL_IsGameController(id)) {
if (SDL_IsGameController(id))
{
m_controller = SDL_GameControllerOpen(id);
joy = SDL_GameControllerGetJoystick(m_controller);
} else {
}
else
{
joy = SDL_JoystickOpen(id);
}
if (joy == nullptr) {
if (joy == nullptr)
{
fprintf(stderr, "PAD: failed to open joystick %d\n", id);
return;
}
@ -160,7 +170,8 @@ JoystickInfo::JoystickInfo(int id)
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, 64);
const char* devname = SDL_JoystickNameForIndex(id);
if (m_controller == nullptr) {
if (m_controller == nullptr)
{
fprintf(stderr, "PAD: Joystick (%s,GUID:%s) isn't yet supported by the SDL2 game controller API\n"
"Fortunately you can use AntiMicro (https://github.com/AntiMicro/antimicro) or Steam to configure your joystick\n"
"The mapping can be stored in OnePAD2.ini as 'SDL2 = <...mapping description...>'\n"
@ -179,7 +190,8 @@ JoystickInfo::JoystickInfo(int id)
// Default haptic effect
SDL_HapticEffect effects[NB_EFFECT];
for (int i = 0; i < NB_EFFECT; i++) {
for (int i = 0; i < NB_EFFECT; i++)
{
SDL_HapticEffect effect;
memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
SDL_HapticDirection direction;
@ -196,13 +208,16 @@ JoystickInfo::JoystickInfo(int id)
/* Sine and triangle are quite probably the best, don't change that lightly and if you do
* keep effects ordered by type
*/
if (i == 0) {
if (i == 0)
{
/* Effect for small motor */
/* Sine seems to be the only effect making little motor from DS3/4 react
* Intensity has pretty much no effect either(which is coherent with what is explain in hid_sony driver
*/
effect.type = SDL_HAPTIC_SINE;
} else {
}
else
{
/** Effect for big motor **/
effect.type = SDL_HAPTIC_TRIANGLE;
}
@ -210,12 +225,15 @@ JoystickInfo::JoystickInfo(int id)
effects[i] = effect;
}
if (SDL_JoystickIsHaptic(joy)) {
if (SDL_JoystickIsHaptic(joy))
{
m_haptic = SDL_HapticOpenFromJoystick(joy);
for (auto &eid : m_effects_id) {
for (auto& eid : m_effects_id)
{
eid = SDL_HapticNewEffect(m_haptic, &effects[0]);
if (eid < 0) {
if (eid < 0)
{
fprintf(stderr, "ERROR: Effect is not uploaded! %s\n", SDL_GetError());
m_haptic = nullptr;
break;
@ -248,7 +266,8 @@ bool JoystickInfo::TestForce(float strength = 0.60)
SDL_HapticRumbleInit(m_haptic);
// Make the haptic pad rumble 60% strength for half a second, shoudld be enough for user to see if it works or not
if (SDL_HapticRumblePlay(m_haptic, strength, 400) != 0) {
if (SDL_HapticRumblePlay(m_haptic, strength, 400) != 0)
{
fprintf(stderr, "ERROR: Rumble is not working! %s\n", SDL_GetError());
return false;
}
@ -261,14 +280,16 @@ int JoystickInfo::GetInput(gamePadValues input)
float k = g_conf.get_sensibility() / 100.0; // convert sensibility to float
// Handle analog inputs which range from -32k to +32k. Range conversion is handled later in the controller
if (IsAnalogKey(input)) {
if (IsAnalogKey(input))
{
int value = SDL_GameControllerGetAxis(m_controller, (SDL_GameControllerAxis)m_pad_to_sdl[input]);
value *= k;
return (abs(value) > m_deadzone) ? value : 0;
}
// Handle triggers which range from 0 to +32k. They must be converted to 0-255 range
if (input == PAD_L2 || input == PAD_R2) {
if (input == PAD_L2 || input == PAD_R2)
{
int value = SDL_GameControllerGetAxis(m_controller, (SDL_GameControllerAxis)m_pad_to_sdl[input]);
return (value > m_deadzone) ? value / 128 : 0;
}

View File

@ -59,7 +59,8 @@ public:
packed_options = 0;
ff_intensity = 0x7FFF; // set it at max value by default
sensibility = 100;
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
keysym_map[pad].clear();
}
unique_id.fill(0);
@ -94,7 +95,8 @@ public:
**/
void set_ff_intensity(u32 new_intensity)
{
if (new_intensity <= 0x7FFF) {
if (new_intensity <= 0x7FFF)
{
ff_intensity = new_intensity;
}
}

View File

@ -45,7 +45,8 @@ void PADSaveConfig()
const std::string iniFile(s_padstrIniPath + "PAD.ini");
f = fopen(iniFile.c_str(), "w");
if (f == NULL) {
if (f == NULL)
{
printf("PAD: failed to save ini %s\n", iniFile.c_str());
return;
}
@ -77,7 +78,8 @@ void PADLoadConfig()
const std::string iniFile(s_padstrIniPath + "PAD.ini");
f = fopen(iniFile.c_str(), "r");
if (f == NULL) {
if (f == NULL)
{
printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
PADSaveConfig(); //save and return
return;
@ -109,7 +111,8 @@ void PADLoadConfig()
u32 pad;
u32 keysym;
u32 index;
while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) == 3) {
while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) == 3)
{
set_keyboard_key(pad & 1, keysym, index);
if (pad == 0)
have_user_setting = true;

View File

@ -38,10 +38,13 @@ char *KeysymToChar(int keysym)
#endif
/// g_key_status.press but with proper handling for analog buttons
static void PressButton(u32 pad, u32 button) {
static void PressButton(u32 pad, u32 button)
{
// Analog controls.
if (IsAnalogKey(button)) {
switch (button) {
if (IsAnalogKey(button))
{
switch (button)
{
case PAD_R_LEFT:
case PAD_R_UP:
case PAD_L_LEFT:
@ -55,7 +58,9 @@ static void PressButton(u32 pad, u32 button) {
g_key_status.press(pad, button, MAX_ANALOG_VALUE);
break;
}
} else {
}
else
{
g_key_status.press(pad, button);
}
}
@ -69,36 +74,49 @@ static void PressButton(u32 pad, u32 button) {
// Keyboard keys use discriminator 0
// Mouse buttons use discriminator 1
void UpdateKeyboardInput() {
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
void UpdateKeyboardInput()
{
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
const auto& map = g_conf.keysym_map[pad];
// If we loop over all keys press/release based on current state,
// joystick axes (which have two bound keys) will always go to the later-polled key
// Instead, release all keys first and then set the ones that are pressed
for (const auto& key : map) g_key_status.release(pad, key.second);
for (const auto& key : map) {
for (const auto& key : map)
g_key_status.release(pad, key.second);
for (const auto& key : map)
{
bool state;
if (key.first >> 16 == 0) {
if (key.first >> 16 == 0)
{
state = CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key.first);
} else {
}
else
{
state = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, (CGMouseButton)(key.first & 0xFFFF));
}
if (state) PressButton(pad, key.second);
if (state)
PressButton(pad, key.second);
}
}
}
bool PollForNewKeyboardKeys(u32 &pkey) {
bool PollForNewKeyboardKeys(u32& pkey)
{
// All keycodes in <HIToolbox/Events.h> are 0x7e or lower. If you notice
// keys that aren't being recognized, bump this number up!
for (int key = 0; key < 0x80; key++) {
if (CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key)) {
for (int key = 0; key < 0x80; key++)
{
if (CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key))
{
pkey = key == kVK_Escape ? 0 : key;
return true;
}
}
for (auto btn : {kCGMouseButtonLeft, kCGMouseButtonCenter, kCGMouseButtonRight}) {
if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, btn)) {
for (auto btn : {kCGMouseButtonLeft, kCGMouseButtonCenter, kCGMouseButtonRight})
{
if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, btn))
{
pkey = btn | (1 << 16);
return true;
}
@ -117,15 +135,18 @@ void AnalyzeKeyEvent(keyEvent &evt)
int pad = 0;
int index = -1;
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++)
{
int tmp_index = get_keyboard_key(cpad, key);
if (tmp_index != -1) {
if (tmp_index != -1)
{
pad = cpad;
index = tmp_index;
}
}
switch (evt.evt) {
switch (evt.evt)
{
case KeyPress:
// Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input
// I found it very handy vs the automatic fullscreen detection
@ -134,12 +155,16 @@ void AnalyzeKeyEvent(keyEvent &evt)
// 3/ Can grab input in window without the need of a pixelated full-screen
if (key == XK_Shift_R || key == XK_Shift_L)
s_Shift = true;
if (key == XK_F12 && s_Shift) {
if (!s_grab_input) {
if (key == XK_F12 && s_Shift)
{
if (!s_grab_input)
{
s_grab_input = true;
XGrabPointer(GSdsp, GSwin, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, GSwin, None, CurrentTime);
XGrabKeyboard(GSdsp, GSwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
} else {
}
else
{
s_grab_input = false;
XUngrabPointer(GSdsp, CurrentTime);
XUngrabKeyboard(GSdsp, CurrentTime);
@ -188,14 +213,18 @@ void AnalyzeKeyEvent(keyEvent &evt)
// 1/ small move == no move. Cons : can not do small movement
// 2/ use a watchdog timer thread
// 3/ ??? idea welcome ;)
if (g_conf.pad_options[pad].mouse_l | g_conf.pad_options[pad].mouse_r) {
if (g_conf.pad_options[pad].mouse_l | g_conf.pad_options[pad].mouse_r)
{
unsigned int pad_x;
unsigned int pad_y;
// Note when both PADOPTION_MOUSE_R and PADOPTION_MOUSE_L are set, take only the right one
if (g_conf.pad_options[pad].mouse_r) {
if (g_conf.pad_options[pad].mouse_r)
{
pad_x = PAD_R_RIGHT;
pad_y = PAD_R_UP;
} else {
}
else
{
pad_x = PAD_L_RIGHT;
pad_y = PAD_L_UP;
}
@ -248,13 +277,15 @@ void UpdateKeyboardInput()
g_ev_fifo.consume_all(AnalyzeKeyEvent);
// keyboard input
while (XPending(GSdsp) > 0) {
while (XPending(GSdsp) > 0)
{
XNextEvent(GSdsp, &E);
// Change the format of the structure to be compatible with GSOpen2
// mode (event come from pcsx2 not X)
evt.evt = E.type;
switch (E.type) {
switch (E.type)
{
case MotionNotify:
evt.key = (E.xbutton.x & 0xFFFF) | (E.xbutton.y << 16);
break;
@ -274,11 +305,15 @@ bool PollForNewKeyboardKeys(u32 &pkey)
{
GdkEvent* ev = gdk_event_get();
if (ev != NULL) {
if (ev->type == GDK_KEY_PRESS) {
if (ev != NULL)
{
if (ev->type == GDK_KEY_PRESS)
{
pkey = ev->key.keyval != GDK_KEY_Escape ? ev->key.keyval : 0;
return true;
} else if (ev->type == GDK_BUTTON_PRESS) {
}
else if (ev->type == GDK_BUTTON_PRESS)
{
pkey = ev->button.button;
return true;
}
@ -296,13 +331,16 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
g_key_status.keyboard_state_acces(pad);
}
switch (msg) {
switch (msg)
{
case WM_KEYDOWN:
if (lParam & 0x40000000)
return TRUE;
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
for (int i = 0; i < MAX_KEYS; i++) {
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
{
for (int i = 0; i < MAX_KEYS; i++)
{
assert(0);
#if 0
if (wParam == get_key(pad, i)) {
@ -318,8 +356,10 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
break;
case WM_KEYUP:
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
for (int i = 0; i < MAX_KEYS; i++) {
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
{
for (int i = 0; i < MAX_KEYS; i++)
{
assert(0);
#if 0
if (wParam == get_key(pad, i)) {

View File

@ -68,7 +68,8 @@ void PollForJoystickInput(int cpad)
gamePad->UpdateGamePadState();
for (int i = 0; i < MAX_KEYS; i++) {
for (int i = 0; i < MAX_KEYS; i++)
{
s32 value = gamePad->GetInput((gamePadValues)i);
if (value != 0)
g_key_status.press(cpad, i, value);
@ -85,7 +86,8 @@ void PADupdate(int pad)
// Emulate an user activity
static int count = 0;
count++;
if ((count & 0xFFF) == 0) {
if ((count & 0xFFF) == 0)
{
// 1 call every 4096 Vsync is enough
XResetScreenSaver(GSdsp);
}
@ -96,13 +98,15 @@ void PADupdate(int pad)
// Poll keyboard/mouse event. There is currently no way to separate pad0 from pad1 event.
// So we will populate both pad in the same time
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++)
{
g_key_status.keyboard_state_acces(cpad);
}
UpdateKeyboardInput();
// Get joystick state + Commit
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++)
{
g_key_status.joystick_state_acces(cpad);
PollForJoystickInput(cpad);

View File

@ -7,8 +7,12 @@
#endif
#ifdef _MSC_VER
static const SECTION union { const guint8 data[134558]; const double alignment; void * const ptr;} PAD_res_resource_data = { {
0107, 0126, 0141, 0162, 0151, 0141, 0156, 0164, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
static const SECTION union
{
const guint8 data[134558];
const double alignment;
void* const ptr;
} PAD_res_resource_data = {{0107, 0126, 0141, 0162, 0151, 0141, 0156, 0164, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
0030, 0000, 0000, 0000, 0220, 0000, 0000, 0000, 0000, 0000, 0000, 0050, 0004, 0000, 0000, 0000,
0000, 0000, 0000, 0000, 0002, 0000, 0000, 0000, 0004, 0000, 0000, 0000, 0004, 0000, 0000, 0000,
0230, 0173, 0176, 0013, 0001, 0000, 0000, 0000, 0220, 0000, 0000, 0000, 0004, 0000, 0114, 0000,
@ -8417,10 +8421,14 @@ static const SECTION union { const guint8 data[134558]; const double alignment;
0147, 0150, 0164, 0170, 0072, 0141, 0062, 0054, 0162, 0151, 0147, 0150, 0164, 0171, 0072, 0141,
0065, 0054, 0163, 0164, 0141, 0162, 0164, 0072, 0142, 0071, 0054, 0170, 0072, 0142, 0060, 0054,
0171, 0072, 0142, 0063, 0054, 0160, 0154, 0141, 0164, 0146, 0157, 0162, 0155, 0072, 0114, 0151,
0156, 0165, 0170, 0054, 0012, 0000, 0000, 0050, 0165, 0165, 0141, 0171, 0051
} };
0156, 0165, 0170, 0054, 0012, 0000, 0000, 0050, 0165, 0165, 0141, 0171, 0051}};
#else /* _MSC_VER */
static const SECTION union { const guint8 data[134558]; const double alignment; void * const ptr;} PAD_res_resource_data = {
static const SECTION union
{
const guint8 data[134558];
const double alignment;
void* const ptr;
} PAD_res_resource_data = {
"\107\126\141\162\151\141\156\164\000\000\000\000\000\000\000\000"
"\030\000\000\000\220\000\000\000\000\000\000\050\004\000\000\000"
"\000\000\000\000\002\000\000\000\004\000\000\000\004\000\000\000"
@ -16900,18 +16908,26 @@ GResource *PAD_res_get_resource (void)
#define G_MSVC_CTOR(_func, _sym_prefix) \
static void _func(void); \
extern int (*_array##_func)(void); \
int _func ## _wrapper(void) { _func(); g_slist_find (NULL, _array ## _func); return 0; } \
int _func##_wrapper(void) \
{ \
_func(); \
g_slist_find(NULL, _array##_func); \
return 0; \
} \
__pragma(comment(linker, "/include:" _sym_prefix #_func "_wrapper")) \
__pragma(section(".CRT$XCU",read)) \
__declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _wrapper;
__pragma(section(".CRT$XCU", read)) __declspec(allocate(".CRT$XCU")) int (*_array##_func)(void) = _func##_wrapper;
#define G_MSVC_DTOR(_func, _sym_prefix) \
static void _func(void); \
extern int (*_array##_func)(void); \
int _func ## _constructor(void) { atexit (_func); g_slist_find (NULL, _array ## _func); return 0; } \
int _func##_constructor(void) \
{ \
atexit(_func); \
g_slist_find(NULL, _array##_func); \
return 0; \
} \
__pragma(comment(linker, "/include:" _sym_prefix #_func "_constructor")) \
__pragma(section(".CRT$XCU",read)) \
__declspec(allocate(".CRT$XCU")) int (* _array ## _func)(void) = _func ## _constructor;
__pragma(section(".CRT$XCU", read)) __declspec(allocate(".CRT$XCU")) int (*_array##_func)(void) = _func##_constructor;
#elif defined(_MSC_VER)
@ -16925,14 +16941,22 @@ GResource *PAD_res_get_resource (void)
section(".CRT$XCU", read)
#define G_DEFINE_CONSTRUCTOR(_func) \
static void _func(void); \
static int _func ## _wrapper(void) { _func(); return 0; } \
static int _func##_wrapper(void) \
{ \
_func(); \
return 0; \
} \
__declspec(allocate(".CRT$XCU")) static int (*p)(void) = _func##_wrapper;
#define G_DEFINE_DESTRUCTOR_PRAGMA_ARGS(_func) \
section(".CRT$XCU", read)
#define G_DEFINE_DESTRUCTOR(_func) \
static void _func(void); \
static int _func ## _constructor(void) { atexit (_func); return 0; } \
static int _func##_constructor(void) \
{ \
atexit(_func); \
return 0; \
} \
__declspec(allocate(".CRT$XCU")) static int (*_array##_func)(void) = _func##_constructor;
#elif defined(__SUNPRO_C)

View File

@ -53,7 +53,8 @@ void QueryInfo::reset()
u8 QueryInfo::start_poll(int _port)
{
if (port > 1) {
if (port > 1)
{
reset();
return 0;
}
@ -114,9 +115,11 @@ void Pad::reset()
void Pad::rumble(unsigned port)
{
for (unsigned motor = 0; motor < 2; motor++) {
for (unsigned motor = 0; motor < 2; motor++)
{
// TODO: Probably be better to send all of these at once.
if (nextVibrate[motor] | currentVibrate[motor]) {
if (nextVibrate[motor] | currentVibrate[motor])
{
currentVibrate[motor] = nextVibrate[motor];
GamePad::DoRumble(motor, port);
@ -174,29 +177,35 @@ u8 pad_start_poll(u8 pad)
u8 pad_poll(u8 value)
{
if (query.lastByte + 1 >= query.numBytes) {
if (query.lastByte + 1 >= query.numBytes)
{
return 0;
}
if (query.lastByte && query.queryDone) {
if (query.lastByte && query.queryDone)
{
return query.response[++query.lastByte];
}
Pad* pad = &pads[query.port][query.slot];
if (query.lastByte == 0) {
if (query.lastByte == 0)
{
query.lastByte++;
query.currentCommand = value;
switch (value) {
switch (value)
{
case CMD_CONFIG_MODE:
if (pad->config) {
if (pad->config)
{
// In config mode. Might not actually be leaving it.
query.set_result(ConfigExit);
return 0xF3;
}
[[fallthrough]]; // fallthrough on purpose (but I don't know why)
case CMD_READ_DATA_AND_VIBRATE: {
case CMD_READ_DATA_AND_VIBRATE:
{
query.response[2] = 0x5A;
#if 0
int i;
@ -241,7 +250,8 @@ u8 pad_poll(u8 value)
query.response[3] = (buttons >> 8) & 0xFF;
query.response[4] = (buttons >> 0) & 0xFF;
if (pad->mode != MODE_DIGITAL) { // ANALOG || DS2 native
if (pad->mode != MODE_DIGITAL)
{ // ANALOG || DS2 native
query.numBytes = 9;
query.response[5] = g_key_status.get(query.port, PAD_R_RIGHT);
@ -249,7 +259,8 @@ u8 pad_poll(u8 value)
query.response[7] = g_key_status.get(query.port, PAD_L_RIGHT);
query.response[8] = g_key_status.get(query.port, PAD_L_UP);
if (pad->mode != MODE_ANALOG) { // DS2 native
if (pad->mode != MODE_ANALOG)
{ // DS2 native
query.numBytes = 21;
query.response[9] = !test_bit(buttons, 13) ? g_key_status.get(query.port, PAD_RIGHT) : 0;
@ -314,10 +325,13 @@ u8 pad_poll(u8 value)
case CMD_QUERY_DS2_ANALOG_MODE:
// Right? Wrong? No clue.
if (pad->mode == MODE_DIGITAL) {
if (pad->mode == MODE_DIGITAL)
{
queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0;
queryMaskMode[6] = 0x00;
} else {
}
else
{
queryMaskMode[1] = pad->umask[0];
queryMaskMode[2] = pad->umask[1];
queryMaskMode[3] = 0x03;
@ -334,9 +348,12 @@ u8 pad_poll(u8 value)
break;
case CMD_QUERY_MODEL_AND_MODE:
if (IsDualshock2()) {
if (IsDualshock2())
{
query.set_final_result(queryModelDS2);
} else {
}
else
{
query.set_final_result(queryModelDS1);
}
// Not digital mode.
@ -363,9 +380,12 @@ u8 pad_poll(u8 value)
break;
case CMD_SET_DS2_NATIVE_MODE:
if (IsDualshock2()) {
if (IsDualshock2())
{
query.set_result(setNativeMode);
} else {
}
else
{
query.set_final_result(setNativeMode);
}
break;
@ -377,11 +397,13 @@ u8 pad_poll(u8 value)
}
return 0xF3;
} else {
}
else
{
query.lastByte++;
switch (query.currentCommand) {
switch (query.currentCommand)
{
case CMD_READ_DATA_AND_VIBRATE:
if (query.lastByte == pad->vibrateI[0])
pad->set_vibrate(1, 255 * (value & 1));
@ -391,16 +413,20 @@ u8 pad_poll(u8 value)
break;
case CMD_CONFIG_MODE:
if (query.lastByte == 3) {
if (query.lastByte == 3)
{
query.queryDone = 1;
pad->config = value;
}
break;
case CMD_SET_MODE_AND_LOCK:
if (query.lastByte == 3 && value < 2) {
if (query.lastByte == 3 && value < 2)
{
pad->set_mode(value ? MODE_ANALOG : MODE_DIGITAL);
} else if (query.lastByte == 4) {
}
else if (query.lastByte == 4)
{
if (value == 3)
pad->modeLock = 3;
else
@ -411,7 +437,8 @@ u8 pad_poll(u8 value)
break;
case CMD_QUERY_ACT:
if (query.lastByte == 3) {
if (query.lastByte == 3)
{
if (value < 2)
query.set_result(queryAct[value]);
// bunch of 0's
@ -421,7 +448,8 @@ u8 pad_poll(u8 value)
break;
case CMD_QUERY_MODE:
if (query.lastByte == 3 && value < 2) {
if (query.lastByte == 3 && value < 2)
{
query.response[6] = 4 + value * 3;
query.queryDone = 1;
}
@ -430,10 +458,14 @@ u8 pad_poll(u8 value)
break;
case CMD_VIBRATION_TOGGLE:
if (query.lastByte >= 3) {
if (value == 0) {
if (query.lastByte >= 3)
{
if (value == 0)
{
pad->vibrateI[0] = (u8)query.lastByte;
} else if (value == 1) {
}
else if (value == 1)
{
pad->vibrateI[1] = (u8)query.lastByte;
}
pad->vibrate[query.lastByte - 2] = value;
@ -441,9 +473,12 @@ u8 pad_poll(u8 value)
break;
case CMD_SET_DS2_NATIVE_MODE:
if (query.lastByte == 3 || query.lastByte == 4) {
if (query.lastByte == 3 || query.lastByte == 4)
{
pad->umask[query.lastByte - 3] = value;
} else if (query.lastByte == 5) {
}
else if (query.lastByte == 5)
{
if (!(value & 1))
pad->set_mode(MODE_DIGITAL);
else if (!(value & 2))

View File

@ -24,7 +24,8 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent)
wxBoxSizer* gamepad_box = new wxBoxSizer(wxVERTICAL);
wxArrayString choices;
for (const auto &j : s_vgamePad) {
for (const auto& j : s_vgamePad)
{
choices.Add(j->GetName());
}
@ -74,7 +75,8 @@ void GamepadConfiguration::InitGamepadConfiguration()
* if the pad id is 1, you need at least 2 gamepads connected,
* Prevent to use a none initialized value on s_vgamePad (core dump)
*/
if (s_vgamePad.size() >= m_pad_id + 1) {
if (s_vgamePad.size() >= m_pad_id + 1)
{
/*
* Determine if the device can use rumble
* Use TestForce with a very low strength (can't be felt)
@ -87,7 +89,9 @@ void GamepadConfiguration::InitGamepadConfiguration()
// m_cb_rumble->Disable(); // disable the rumble checkbox
// m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
// }
} else {
}
else
{
wxMessageBox(L"No gamepad detected.");
m_sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider
m_cb_rumble->Disable(); // disable the rumble checkbox

View File

@ -40,7 +40,6 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
joy_conf_box->Add(m_cb_mouse_Ljoy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
m_cb_reverse_Rx = m_cb_reverse_Ry = m_cb_mouse_Rjoy = nullptr;
}
else
{
@ -77,7 +76,8 @@ void JoystickConfiguration::InitJoystickConfiguration()
* if the pad id is 1, you need at least 2 gamepads connected,
* Prevent to use a none initialized value on s_vgamePad (core dump)
*/
if (s_vgamePad.size() < m_pad_id + 1) {
if (s_vgamePad.size() < m_pad_id + 1)
{
if (s_vgamePad.empty())
wxMessageBox(L"No gamepad detected.");
else

View File

@ -21,8 +21,10 @@
static std::string KeyName(int pad, int key, int keysym)
{
// Mouse
if (keysym >> 16) {
switch (keysym & 0xFFFF) {
if (keysym >> 16)
{
switch (keysym & 0xFFFF)
{
case kCGMouseButtonLeft:
return "Mouse Left";
case kCGMouseButtonRight:
@ -34,135 +36,258 @@ static std::string KeyName(int pad, int key, int keysym)
}
}
switch (keysym) {
case kVK_ANSI_A: return "A";
case kVK_ANSI_B: return "B";
case kVK_ANSI_C: return "C";
case kVK_ANSI_D: return "D";
case kVK_ANSI_E: return "E";
case kVK_ANSI_F: return "F";
case kVK_ANSI_G: return "G";
case kVK_ANSI_H: return "H";
case kVK_ANSI_I: return "I";
case kVK_ANSI_J: return "J";
case kVK_ANSI_K: return "K";
case kVK_ANSI_L: return "L";
case kVK_ANSI_M: return "M";
case kVK_ANSI_N: return "N";
case kVK_ANSI_O: return "O";
case kVK_ANSI_P: return "P";
case kVK_ANSI_Q: return "Q";
case kVK_ANSI_R: return "R";
case kVK_ANSI_S: return "S";
case kVK_ANSI_T: return "T";
case kVK_ANSI_U: return "U";
case kVK_ANSI_V: return "V";
case kVK_ANSI_W: return "W";
case kVK_ANSI_X: return "X";
case kVK_ANSI_Y: return "Y";
case kVK_ANSI_Z: return "Z";
case kVK_ANSI_0: return "0";
case kVK_ANSI_1: return "1";
case kVK_ANSI_2: return "2";
case kVK_ANSI_3: return "3";
case kVK_ANSI_4: return "4";
case kVK_ANSI_5: return "5";
case kVK_ANSI_6: return "6";
case kVK_ANSI_7: return "7";
case kVK_ANSI_8: return "8";
case kVK_ANSI_9: return "9";
case kVK_ANSI_Grave: return "`";
case kVK_ANSI_Minus: return "-";
case kVK_ANSI_Equal: return "=";
case kVK_ANSI_LeftBracket: return "[";
case kVK_ANSI_RightBracket: return "]";
case kVK_ANSI_Backslash: return "\\";
case kVK_ANSI_Semicolon: return ";";
case kVK_ANSI_Quote: return "'";
case kVK_ANSI_Comma: return ",";
case kVK_ANSI_Period: return ".";
case kVK_ANSI_Slash: return "/";
case kVK_Escape: return "";
case kVK_Tab: return "";
case kVK_Delete: return "";
case kVK_ForwardDelete: return "";
case kVK_Return: return "";
case kVK_Space: return "";
case kVK_ANSI_KeypadDecimal: return "Keypad .";
case kVK_ANSI_KeypadMultiply: return "Keypad *";
case kVK_ANSI_KeypadPlus: return "Keypad +";
case kVK_ANSI_KeypadClear: return "";
case kVK_ANSI_KeypadDivide: return "Keypad /";
case kVK_ANSI_KeypadEnter: return "";
case kVK_ANSI_KeypadMinus: return "Keypad -";
case kVK_ANSI_KeypadEquals: return "Keypad =";
case kVK_ANSI_Keypad0: return "Keypad 0";
case kVK_ANSI_Keypad1: return "Keypad 1";
case kVK_ANSI_Keypad2: return "Keypad 2";
case kVK_ANSI_Keypad3: return "Keypad 3";
case kVK_ANSI_Keypad4: return "Keypad 4";
case kVK_ANSI_Keypad5: return "Keypad 5";
case kVK_ANSI_Keypad6: return "Keypad 6";
case kVK_ANSI_Keypad7: return "Keypad 7";
case kVK_ANSI_Keypad8: return "Keypad 8";
case kVK_ANSI_Keypad9: return "Keypad 9";
case kVK_Command: return "Left ⌘";
case kVK_Shift: return "Left ⇧";
case kVK_CapsLock: return "";
case kVK_Option: return "Left ⌥";
case kVK_Control: return "Left ⌃";
case kVK_RightCommand: return "Right ⌘";
case kVK_RightShift: return "Right ⇧";
case kVK_RightOption: return "Right ⌥";
case kVK_RightControl: return "Right ⌃";
case kVK_Function: return "fn";
case kVK_VolumeUp: return "Volume Up";
case kVK_VolumeDown: return "Volume Down";
case kVK_Mute: return "Mute";
case kVK_F1: return "F1";
case kVK_F2: return "F2";
case kVK_F3: return "F3";
case kVK_F4: return "F4";
case kVK_F5: return "F5";
case kVK_F6: return "F6";
case kVK_F7: return "F7";
case kVK_F8: return "F8";
case kVK_F9: return "F9";
case kVK_F10: return "F10";
case kVK_F11: return "F11";
case kVK_F12: return "F12";
case kVK_F13: return "F13";
case kVK_F14: return "F14";
case kVK_F15: return "F15";
case kVK_F16: return "F16";
case kVK_F17: return "F17";
case kVK_F18: return "F18";
case kVK_F19: return "F19";
case kVK_F20: return "F20";
case kVK_Help: return "Help";
case kVK_Home: return "";
case kVK_PageUp: return "";
case kVK_End: return "";
case kVK_PageDown: return "";
case kVK_LeftArrow: return "";
case kVK_RightArrow: return "";
case kVK_DownArrow: return "";
case kVK_UpArrow: return "";
case kVK_ISO_Section: return "Section";
case kVK_JIS_Yen: return "¥";
case kVK_JIS_Underscore: return "_";
case kVK_JIS_KeypadComma: return "Keypad ,";
case kVK_JIS_Eisu: return "英数";
case kVK_JIS_Kana: return "かな";
default: return "Key " + std::to_string(keysym);
switch (keysym)
{
case kVK_ANSI_A:
return "A";
case kVK_ANSI_B:
return "B";
case kVK_ANSI_C:
return "C";
case kVK_ANSI_D:
return "D";
case kVK_ANSI_E:
return "E";
case kVK_ANSI_F:
return "F";
case kVK_ANSI_G:
return "G";
case kVK_ANSI_H:
return "H";
case kVK_ANSI_I:
return "I";
case kVK_ANSI_J:
return "J";
case kVK_ANSI_K:
return "K";
case kVK_ANSI_L:
return "L";
case kVK_ANSI_M:
return "M";
case kVK_ANSI_N:
return "N";
case kVK_ANSI_O:
return "O";
case kVK_ANSI_P:
return "P";
case kVK_ANSI_Q:
return "Q";
case kVK_ANSI_R:
return "R";
case kVK_ANSI_S:
return "S";
case kVK_ANSI_T:
return "T";
case kVK_ANSI_U:
return "U";
case kVK_ANSI_V:
return "V";
case kVK_ANSI_W:
return "W";
case kVK_ANSI_X:
return "X";
case kVK_ANSI_Y:
return "Y";
case kVK_ANSI_Z:
return "Z";
case kVK_ANSI_0:
return "0";
case kVK_ANSI_1:
return "1";
case kVK_ANSI_2:
return "2";
case kVK_ANSI_3:
return "3";
case kVK_ANSI_4:
return "4";
case kVK_ANSI_5:
return "5";
case kVK_ANSI_6:
return "6";
case kVK_ANSI_7:
return "7";
case kVK_ANSI_8:
return "8";
case kVK_ANSI_9:
return "9";
case kVK_ANSI_Grave:
return "`";
case kVK_ANSI_Minus:
return "-";
case kVK_ANSI_Equal:
return "=";
case kVK_ANSI_LeftBracket:
return "[";
case kVK_ANSI_RightBracket:
return "]";
case kVK_ANSI_Backslash:
return "\\";
case kVK_ANSI_Semicolon:
return ";";
case kVK_ANSI_Quote:
return "'";
case kVK_ANSI_Comma:
return ",";
case kVK_ANSI_Period:
return ".";
case kVK_ANSI_Slash:
return "/";
case kVK_Escape:
return "";
case kVK_Tab:
return "";
case kVK_Delete:
return "";
case kVK_ForwardDelete:
return "";
case kVK_Return:
return "";
case kVK_Space:
return "";
case kVK_ANSI_KeypadDecimal:
return "Keypad .";
case kVK_ANSI_KeypadMultiply:
return "Keypad *";
case kVK_ANSI_KeypadPlus:
return "Keypad +";
case kVK_ANSI_KeypadClear:
return "";
case kVK_ANSI_KeypadDivide:
return "Keypad /";
case kVK_ANSI_KeypadEnter:
return "";
case kVK_ANSI_KeypadMinus:
return "Keypad -";
case kVK_ANSI_KeypadEquals:
return "Keypad =";
case kVK_ANSI_Keypad0:
return "Keypad 0";
case kVK_ANSI_Keypad1:
return "Keypad 1";
case kVK_ANSI_Keypad2:
return "Keypad 2";
case kVK_ANSI_Keypad3:
return "Keypad 3";
case kVK_ANSI_Keypad4:
return "Keypad 4";
case kVK_ANSI_Keypad5:
return "Keypad 5";
case kVK_ANSI_Keypad6:
return "Keypad 6";
case kVK_ANSI_Keypad7:
return "Keypad 7";
case kVK_ANSI_Keypad8:
return "Keypad 8";
case kVK_ANSI_Keypad9:
return "Keypad 9";
case kVK_Command:
return "Left ⌘";
case kVK_Shift:
return "Left ⇧";
case kVK_CapsLock:
return "";
case kVK_Option:
return "Left ⌥";
case kVK_Control:
return "Left ⌃";
case kVK_RightCommand:
return "Right ⌘";
case kVK_RightShift:
return "Right ⇧";
case kVK_RightOption:
return "Right ⌥";
case kVK_RightControl:
return "Right ⌃";
case kVK_Function:
return "fn";
case kVK_VolumeUp:
return "Volume Up";
case kVK_VolumeDown:
return "Volume Down";
case kVK_Mute:
return "Mute";
case kVK_F1:
return "F1";
case kVK_F2:
return "F2";
case kVK_F3:
return "F3";
case kVK_F4:
return "F4";
case kVK_F5:
return "F5";
case kVK_F6:
return "F6";
case kVK_F7:
return "F7";
case kVK_F8:
return "F8";
case kVK_F9:
return "F9";
case kVK_F10:
return "F10";
case kVK_F11:
return "F11";
case kVK_F12:
return "F12";
case kVK_F13:
return "F13";
case kVK_F14:
return "F14";
case kVK_F15:
return "F15";
case kVK_F16:
return "F16";
case kVK_F17:
return "F17";
case kVK_F18:
return "F18";
case kVK_F19:
return "F19";
case kVK_F20:
return "F20";
case kVK_Help:
return "Help";
case kVK_Home:
return "";
case kVK_PageUp:
return "";
case kVK_End:
return "";
case kVK_PageDown:
return "";
case kVK_LeftArrow:
return "";
case kVK_RightArrow:
return "";
case kVK_DownArrow:
return "";
case kVK_UpArrow:
return "";
case kVK_ISO_Section:
return "Section";
case kVK_JIS_Yen:
return "¥";
case kVK_JIS_Underscore:
return "_";
case kVK_JIS_KeypadComma:
return "Keypad ,";
case kVK_JIS_Eisu:
return "英数";
case kVK_JIS_Kana:
return "かな";
default:
return "Key " + std::to_string(keysym);
}
}
#else
static std::string KeyName(int pad, int key, int keysym)
{
// Mouse
if (keysym < 10) {
switch (keysym) {
if (keysym < 10)
{
switch (keysym)
{
case 0:
return "";
case 1:
@ -397,7 +522,8 @@ PADDialog::PADDialog()
// create a new Notebook
m_tab_gamepad = new wxNotebook(this, wxID_ANY);
for (int i = 0; i < GAMEPAD_NUMBER; ++i) {
for (int i = 0; i < GAMEPAD_NUMBER; ++i)
{
// Tabs panels
m_pan_tabs[i] = new opPanel(
m_tab_gamepad,
@ -415,7 +541,8 @@ PADDialog::PADDialog()
wxString(sstm.str().c_str(), wxConvUTF8) // Title
);
for (int j = 0; j < BUTTONS_LENGHT; ++j) {
for (int j = 0; j < BUTTONS_LENGHT; ++j)
{
// Gamepad buttons
m_bt_gamepad[i][j] = new wxButton(
m_pan_tabs[i], // Parent
@ -440,8 +567,10 @@ PADDialog::PADDialog()
Bind(wxEVT_BUTTON, &PADDialog::OnButtonClicked, this);
for (int i = 0; i < GAMEPAD_NUMBER; ++i) {
for (int j = 0; j < NB_IMG; ++j) {
for (int i = 0; i < GAMEPAD_NUMBER; ++i)
{
for (int j = 0; j < NB_IMG; ++j)
{
m_pressed[i][j] = false;
}
}
@ -464,29 +593,40 @@ void PADDialog::OnButtonClicked(wxCommandEvent &event)
wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId() - wxID_HIGHEST - 1; // get the real ID
int gamepad_id = m_tab_gamepad->GetSelection(); // get the tab ID (equivalent to the gamepad id)
if (bt_id >= 0 && bt_id <= PAD_R_LEFT) { // if the button ID is a gamepad button
if (bt_id >= 0 && bt_id <= PAD_R_LEFT)
{ // if the button ID is a gamepad button
bt_tmp->Disable(); // switch the button state to "Disable"
config_key(gamepad_id, bt_id);
bt_tmp->Enable(); // switch the button state to "Enable"
} else if (bt_id == Gamepad_config) { // If the button ID is equals to the Gamepad_config button ID
}
else if (bt_id == Gamepad_config)
{ // If the button ID is equals to the Gamepad_config button ID
GamepadConfiguration gamepad_config(gamepad_id, this);
gamepad_config.InitGamepadConfiguration();
gamepad_config.ShowModal();
} else if (bt_id == JoyL_config) { // If the button ID is equals to the JoyL_config button ID
}
else if (bt_id == JoyL_config)
{ // If the button ID is equals to the JoyL_config button ID
JoystickConfiguration joystick_config(gamepad_id, true, this);
joystick_config.InitJoystickConfiguration();
joystick_config.ShowModal();
} else if (bt_id == JoyR_config) { // If the button ID is equals to the JoyR_config button ID
}
else if (bt_id == JoyR_config)
{ // If the button ID is equals to the JoyR_config button ID
JoystickConfiguration joystick_config(gamepad_id, false, this);
joystick_config.InitJoystickConfiguration();
joystick_config.ShowModal();
} else if (bt_id == Set_all) { // If the button ID is equals to the Set_all button ID
for (int i = 0; i < MAX_KEYS; ++i) {
}
else if (bt_id == Set_all)
{ // If the button ID is equals to the Set_all button ID
for (int i = 0; i < MAX_KEYS; ++i)
{
bt_tmp = m_bt_gamepad[gamepad_id][i];
switch (i) {
switch (i)
{
case PAD_L_UP: // Left joystick (Up) ↑
m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_up);
break;
@ -518,7 +658,8 @@ void PADDialog::OnButtonClicked(wxCommandEvent &event)
m_pan_tabs[gamepad_id]->Refresh();
m_pan_tabs[gamepad_id]->Update();
config_key(gamepad_id, i);
switch (i) {
switch (i)
{
case PAD_L_UP: // Left joystick (Up) ↑
m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_up);
break;
@ -551,12 +692,18 @@ void PADDialog::OnButtonClicked(wxCommandEvent &event)
m_pan_tabs[gamepad_id]->Update();
usleep(500000); // give enough time to the user to release the button
}
} else if (bt_id == Ok) { // If the button ID is equals to the Ok button ID
}
else if (bt_id == Ok)
{ // If the button ID is equals to the Ok button ID
PADSaveConfig(); // Save the configuration
Close(); // Close the window
} else if (bt_id == Apply) { // If the button ID is equals to the Apply button ID
}
else if (bt_id == Apply)
{ // If the button ID is equals to the Apply button ID
PADSaveConfig(); // Save the configuration
} else if (bt_id == Cancel) { // If the button ID is equals to the cancel button ID
}
else if (bt_id == Cancel)
{ // If the button ID is equals to the cancel button ID
Close(); // Close the window
}
}
@ -570,11 +717,14 @@ void PADDialog::config_key(int pad, int key)
bool captured = false;
u32 key_pressed = 0;
while (!captured) {
if (PollForNewKeyboardKeys(key_pressed)) {
while (!captured)
{
if (PollForNewKeyboardKeys(key_pressed))
{
// special case for keyboard/mouse to handle multiple keys
// Note: key_pressed == 0 when ESC is hit to abort the capture
if (key_pressed > 0) {
if (key_pressed > 0)
{
clear_key(pad, key);
set_keyboard_key(pad, key_pressed, key);
m_simulatedKeys[pad][key] = key_pressed;
@ -600,9 +750,11 @@ void PADDialog::clear_key(int pad, int key)
// Set button values
void PADDialog::repopulate()
{
for (int gamepad_id = 0; gamepad_id < GAMEPAD_NUMBER; ++gamepad_id) {
for (int gamepad_id = 0; gamepad_id < GAMEPAD_NUMBER; ++gamepad_id)
{
// keyboard/mouse key
for (const auto &it : g_conf.keysym_map[gamepad_id]) {
for (const auto& it : g_conf.keysym_map[gamepad_id])
{
int keysym = it.first;
int key = it.second;
@ -617,7 +769,8 @@ void PADDialog::repopulate()
// Main
void DisplayDialog()
{
if (g_conf.ftw) {
if (g_conf.ftw)
{
wxString info("The PAD GUI is provided to map the keyboard/mouse to the virtual PS2 pad.\n\n"
"Gamepads/Joysticks are plug and play. The active gamepad can be selected in the 'Gamepad Configuration' panel.\n\n");

View File

@ -43,7 +43,8 @@
// e.g L2 → 0, triangle → 4, ...
// see PAD.h for more details about gamepad button id
enum gui_buttons {
enum gui_buttons
{
Analog = PAD_R_LEFT + 1, // Analog button (not yet supported ?)
JoyL_config, // Left Joystick Configuration
JoyR_config, // Right Joystick Configuration

View File

@ -81,7 +81,8 @@ opPanel::opPanel(wxWindow *parent,
m_picture[img_r_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get();
m_picture[img_r_arrow_left] = EmbeddedImage<res_arrow_left>().Get();
for (int i = 0; i < NB_IMG; ++i) {
for (int i = 0; i < NB_IMG; ++i)
{
m_show_image[i] = false;
HideImg(i);
}
@ -96,7 +97,8 @@ opPanel::opPanel(wxWindow *parent,
void opPanel::HideImg(int id)
{
if (id < NB_IMG) {
if (id < NB_IMG)
{
m_show_image[id] = false;
Refresh();
}
@ -104,7 +106,8 @@ void opPanel::HideImg(int id)
void opPanel::ShowImg(int id)
{
if (id < NB_IMG) {
if (id < NB_IMG)
{
m_show_image[id] = true;
Refresh();
}
@ -112,13 +115,20 @@ void opPanel::ShowImg(int id)
void opPanel::MoveJoystick(int axe, int value)
{
if (axe == 0) {
if (axe == 0)
{
m_left_cursor_x = value * 30 / 40000;
} else if (axe == 1) {
}
else if (axe == 1)
{
m_left_cursor_y = value * 30 / 40000;
} else if (axe == 2) {
}
else if (axe == 2)
{
m_right_cursor_x = value * 30 / 40000;
} else {
}
else
{
m_right_cursor_y = value * 30 / 40000;
}
}

View File

@ -22,7 +22,8 @@
#include "EmbeddedImage.h"
enum gui_img {
enum gui_img
{
img_l2,
img_r2,
img_l1,