reformat onepad

This commit is contained in:
Clang Format 2016-09-04 14:10:02 +02:00 committed by Gregory Hainaut
parent 0abf686406
commit f06f44c30a
25 changed files with 2226 additions and 2291 deletions

View File

@ -53,5 +53,3 @@ void GamePad::UpdateGamePadState()
SDL_JoystickUpdate(); // No need to make yet another function call for that
#endif
}

View File

@ -13,8 +13,15 @@
class GamePad
{
public:
GamePad() : devname(""), _id(-1), numbuttons(0), numaxes(0), numhats(0),
deadzone(1500), pad(-1) {
GamePad()
: devname("")
, _id(-1)
, numbuttons(0)
, numaxes(0)
, numhats(0)
, deadzone(1500)
, pad(-1)
{
vbuttonstate.clear();
vaxisstate.clear();
vhatstate.clear();

View File

@ -102,28 +102,35 @@ 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; break;
case PAD_R_RIGHT:
m_internal_analog_ref->rx = value;
break;
case PAD_R_DOWN:
case PAD_R_UP: m_internal_analog_ref->ry = value; break;
case PAD_R_UP:
m_internal_analog_ref->ry = value;
break;
case PAD_L_LEFT:
case PAD_L_RIGHT: m_internal_analog_ref->lx = value; break;
case PAD_L_RIGHT:
m_internal_analog_ref->lx = value;
break;
case PAD_L_DOWN:
case PAD_L_UP: m_internal_analog_ref->ly = value; break;
case PAD_L_UP:
m_internal_analog_ref->ly = value;
break;
default: break;
default:
break;
}
}
bool KeyStatus::analog_is_reversed(u32 pad, u32 index)
{
switch (index)
{
switch (index) {
case PAD_L_RIGHT:
case PAD_L_LEFT:
return (conf->pad_options[pad].reverse_lx);
@ -140,27 +147,32 @@ bool KeyStatus::analog_is_reversed(u32 pad, u32 index)
case PAD_R_UP:
return (conf->pad_options[pad].reverse_ry);
default: return false;
default:
return false;
}
}
u8 KeyStatus::get(u32 pad, u32 index)
{
switch (index)
{
switch (index) {
case PAD_R_LEFT:
case PAD_R_RIGHT: return m_analog[pad].rx;
case PAD_R_RIGHT:
return m_analog[pad].rx;
case PAD_R_DOWN:
case PAD_R_UP: return m_analog[pad].ry;
case PAD_R_UP:
return m_analog[pad].ry;
case PAD_L_LEFT:
case PAD_L_RIGHT: return m_analog[pad].lx;
case PAD_L_RIGHT:
return m_analog[pad].lx;
case PAD_L_DOWN:
case PAD_L_UP: return m_analog[pad].ly;
case PAD_L_UP:
return m_analog[pad].ly;
default: return m_button_pressure[pad][index];
default:
return m_button_pressure[pad][index];
}
}

View File

@ -55,7 +55,11 @@ class KeyStatus
u8 analog_merge(u8 kbd, u8 joy);
public:
KeyStatus() : m_analog_released_val(0x7F) { Init(); }
KeyStatus()
: m_analog_released_val(0x7F)
{
Init();
}
void Init();
void keyboard_state_acces(u32 pad) { m_state_acces[pad] = true; }

View File

@ -20,7 +20,8 @@
#include "GamepadConfiguration.h"
// Construtor of GamepadConfiguration
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxDialog(
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent)
: wxDialog(
parent, // Parent
wxID_ANY, // ID
_T("Gamepad configuration"), // Title
@ -30,8 +31,7 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxDialog
wxSYSTEM_MENU |
wxCAPTION |
wxCLOSE_BOX |
wxCLIP_CHILDREN
)
wxCLIP_CHILDREN)
{
m_pad_id = pad;
@ -137,23 +137,19 @@ void GamepadConfiguration::InitGamepadConfiguration()
* if the pad id is 1, you need at least 2 gamepad 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)
* May be better to create a new function in order to check only that
*/
if(!s_vgamePad[m_pad_id]->TestForce(0.001f))
{
if (!s_vgamePad[m_pad_id]->TestForce(0.001f)) {
wxMessageBox(L"Rumble is not available for your device.");
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
@ -220,25 +216,17 @@ void GamepadConfiguration::OnCheckboxChange(wxCommandEvent& event)
{
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
if(cb_id == m_cb_rumble->GetId())
{
if (cb_id == m_cb_rumble->GetId()) {
conf->pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
if(m_cb_rumble->GetValue())
{
if (m_cb_rumble->GetValue()) {
s_vgamePad[m_pad_id]->TestForce();
m_sl_rumble_intensity->Enable();
}
else
{
} else {
m_sl_rumble_intensity->Disable();
}
}
else if(cb_id == m_cb_hack_sixaxis_usb->GetId())
{
} else if (cb_id == m_cb_hack_sixaxis_usb->GetId()) {
conf->pad_options[m_pad_id].sixaxis_usb = (m_cb_hack_sixaxis_usb->GetValue()) ? (u32)1 : (u32)0;
}
else if(cb_id == m_cb_hack_sixaxis_pressure->GetId())
{
} else if (cb_id == m_cb_hack_sixaxis_pressure->GetId()) {
conf->pad_options[m_pad_id].sixaxis_pressure = (m_cb_hack_sixaxis_pressure->GetValue()) ? (u32)1 : (u32)0;
}
}

View File

@ -20,7 +20,8 @@
#include "JoystickConfiguration.h"
// Construtor of JoystickConfiguration
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent) : wxDialog(
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent)
: wxDialog(
parent, // Parent
wxID_ANY, // ID
_T("Gamepad configuration"), // Title
@ -30,8 +31,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
wxSYSTEM_MENU |
wxCAPTION |
wxCLOSE_BOX |
wxCLIP_CHILDREN
)
wxCLIP_CHILDREN)
{
m_pad_id = pad;
@ -43,8 +43,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
wxSize(300, 200) // Size
);
if(m_isForLeftJoystick)
{
if (m_isForLeftJoystick) {
m_cb_reverse_Lx = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
@ -65,9 +64,7 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
_T("Use mouse for left analog joystick"), // Label
wxPoint(20, 60) // Position
);
}
else
{
} else {
m_cb_reverse_Rx = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
@ -123,17 +120,13 @@ void JoystickConfiguration::InitJoystickConfiguration()
* if the pad id is 1, you need at least 2 gamepad 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) {
wxMessageBox(L"No gamepad detected.");
// disable all checkbox
if(m_isForLeftJoystick)
{
if (m_isForLeftJoystick) {
m_cb_reverse_Lx->Disable();
m_cb_reverse_Ly->Disable();
}
else
{
} else {
m_cb_reverse_Rx->Disable();
m_cb_reverse_Ry->Disable();
}
@ -168,38 +161,25 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
bool val;
if(m_isForLeftJoystick)
{
if(cb_id == m_cb_reverse_Ly->GetId())
{
if (m_isForLeftJoystick) {
if (cb_id == m_cb_reverse_Ly->GetId()) {
val = m_cb_reverse_Ly->GetValue();
conf->pad_options[m_pad_id].reverse_ly = val;
}
else if(cb_id == m_cb_reverse_Lx->GetId())
{
} else if (cb_id == m_cb_reverse_Lx->GetId()) {
val = m_cb_reverse_Lx->GetValue();
conf->pad_options[m_pad_id].reverse_lx = val;
}
else if(cb_id == m_cb_mouse_Ljoy->GetId())
{
} else if (cb_id == m_cb_mouse_Ljoy->GetId()) {
val = m_cb_mouse_Ljoy->GetValue();
conf->pad_options[m_pad_id].mouse_l = val;
}
}
else
{
if(cb_id == m_cb_reverse_Ry->GetId())
{
} else {
if (cb_id == m_cb_reverse_Ry->GetId()) {
val = m_cb_reverse_Ry->GetValue();
conf->pad_options[m_pad_id].reverse_ry = val;
}
else if(cb_id == m_cb_reverse_Rx->GetId())
{
} else if (cb_id == m_cb_reverse_Rx->GetId()) {
val = m_cb_reverse_Rx->GetValue();
conf->pad_options[m_pad_id].reverse_rx = val;
}
else if(cb_id == m_cb_mouse_Rjoy->GetId())
{
} else if (cb_id == m_cb_mouse_Rjoy->GetId()) {
val = m_cb_mouse_Rjoy->GetValue();
conf->pad_options[m_pad_id].mouse_r = val;
}
@ -213,14 +193,11 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
// Reset checkbox and slider values
void JoystickConfiguration::reset()
{
if(m_isForLeftJoystick)
{
if (m_isForLeftJoystick) {
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
}
else
{
} else {
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
@ -231,8 +208,7 @@ void JoystickConfiguration::reset()
void JoystickConfiguration::repopulate()
{
bool val;
if(m_isForLeftJoystick)
{
if (m_isForLeftJoystick) {
val = conf->pad_options[m_pad_id].reverse_lx;
m_init_reverse_Lx = val;
m_cb_reverse_Lx->SetValue(val);
@ -244,9 +220,7 @@ void JoystickConfiguration::repopulate()
val = conf->pad_options[m_pad_id].mouse_l;
m_init_mouse_Ljoy = val;
m_cb_mouse_Ljoy->SetValue(val);
}
else
{
} else {
val = conf->pad_options[m_pad_id].reverse_rx;
m_init_reverse_Rx = val;
m_cb_reverse_Rx->SetValue(val);

View File

@ -20,7 +20,8 @@
#include "dialog.h"
// Construtor of Dialog
Dialog::Dialog() : wxDialog( NULL, // Parent
Dialog::Dialog()
: wxDialog(NULL, // Parent
wxID_ANY, // ID
_T("OnePad configuration"), // Title
wxDefaultPosition, // Position
@ -29,8 +30,7 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
wxSYSTEM_MENU |
wxCAPTION |
wxCLOSE_BOX |
wxCLIP_CHILDREN
)
wxCLIP_CHILDREN)
{
/*
@ -236,15 +236,13 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
// 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,
wxID_ANY,
wxDefaultPosition,
wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT)
);
wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT));
// Add new page
// Define label
std::stringstream sstm;
@ -256,8 +254,7 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
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
@ -286,10 +283,8 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
Bind(wxEVT_TIMER, &Dialog::JoystickEvent, this);
m_time_update_gui.Start(UPDATE_TIME, wxTIMER_CONTINUOUS);
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;
}
}
@ -332,11 +327,9 @@ void Dialog::OnButtonClicked(wxCommandEvent &event)
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)
{
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;
@ -368,8 +361,7 @@ void Dialog::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;
@ -421,43 +413,32 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
std::map<u32, int>::iterator it2;
SDL_JoystickEventState(SDL_ENABLE);
SDL_Event events;
while(SDL_PollEvent(&events))
{
switch(events.type)
{
while (SDL_PollEvent(&events)) {
switch (events.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
break;
case SDL_JOYAXISMOTION:
if(events.jaxis.which < GAMEPAD_NUMBER)
{
if (events.jaxis.which < GAMEPAD_NUMBER) {
key = axis_to_key(false, (events.jaxis.value < 0), events.jaxis.axis);
it = m_map_images[events.jaxis.which].find(key);
if(it != m_map_images[events.jaxis.which].end())
{
if (it != m_map_images[events.jaxis.which].end()) {
map = m_map_images[events.jaxis.which][key];
if(events.jaxis.value == 0)
{
if (events.jaxis.value == 0) {
if (map >= PAD_L_UP && map <= PAD_L_LEFT)
m_pan_tabs[events.jaxis.which]->HideImg(img_left_cursor);
else if (map >= PAD_R_UP && map <= PAD_R_LEFT)
m_pan_tabs[events.jaxis.which]->HideImg(img_right_cursor);
else if (map < PAD_L_UP)
m_pan_tabs[events.jaxis.which]->HideImg(map);
}
else
{
if(map >= PAD_L_UP && map <= PAD_L_LEFT)
{
} else {
if (map >= PAD_L_UP && map <= PAD_L_LEFT) {
m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value);
m_pan_tabs[events.jaxis.which]->ShowImg(img_left_cursor);
}
else if(map >= PAD_R_UP && map <= PAD_R_LEFT)
{
} else if (map >= PAD_R_UP && map <= PAD_R_LEFT) {
m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value);
m_pan_tabs[events.jaxis.which]->ShowImg(img_right_cursor);
}
else if(map < PAD_L_UP) { // if this is not a joystick
} else if (map < PAD_L_UP) { // if this is not a joystick
m_pan_tabs[events.jaxis.which]->ShowImg(map);
}
}
@ -466,8 +447,7 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
// Hack Dualshock 4 (L2, R2)
key = axis_to_key(false, (events.jaxis.value > 0), events.jaxis.axis);
it2 = m_map_images[events.jaxis.which].find(key);
if(it2 != m_map_images[events.jaxis.which].end())
{
if (it2 != m_map_images[events.jaxis.which].end()) {
map = m_map_images[events.jaxis.which][key];
if (map < PAD_L_UP) { // if this is not a joystick
m_pan_tabs[events.jaxis.which]->HideImg(map);
@ -477,63 +457,53 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
}
break;
case SDL_JOYBUTTONDOWN:
if(events.jbutton.which < GAMEPAD_NUMBER)
{
if (events.jbutton.which < GAMEPAD_NUMBER) {
key = button_to_key(events.jbutton.button);
it = m_map_images[events.jbutton.which].find(key);
if(it != m_map_images[events.jbutton.which].end())
{
if (it != m_map_images[events.jbutton.which].end()) {
map = m_map_images[events.jbutton.which][key];
m_pan_tabs[events.jbutton.which]->ShowImg(map);
}
}
break;
case SDL_JOYBUTTONUP:
if(events.jbutton.which < GAMEPAD_NUMBER)
{
if (events.jbutton.which < GAMEPAD_NUMBER) {
key = button_to_key(events.jbutton.button);
it = m_map_images[events.jbutton.which].find(key);
if(it != m_map_images[events.jbutton.which].end())
{
if (it != m_map_images[events.jbutton.which].end()) {
map = m_map_images[events.jbutton.which][key];
m_pan_tabs[events.jbutton.which]->HideImg(map);
}
}
break;
case SDL_JOYHATMOTION:
if(events.jhat.which < GAMEPAD_NUMBER)
{
switch(events.jhat.value)
{
if (events.jhat.which < GAMEPAD_NUMBER) {
switch (events.jhat.value) {
case SDL_HAT_UP:
key = hat_to_key(events.jhat.value, events.jhat.hat);
it = m_map_images[events.jhat.which].find(key);
if(it != m_map_images[events.jhat.which].end())
{
if (it != m_map_images[events.jhat.which].end()) {
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_up);
}
break;
case SDL_HAT_DOWN:
key = hat_to_key(events.jhat.value, events.jhat.hat);
it = m_map_images[events.jhat.which].find(key);
if(it != m_map_images[events.jhat.which].end())
{
if (it != m_map_images[events.jhat.which].end()) {
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_bottom);
}
break;
case SDL_HAT_RIGHT:
key = hat_to_key(events.jhat.value, events.jhat.hat);
it = m_map_images[events.jhat.which].find(key);
if(it != m_map_images[events.jhat.which].end())
{
if (it != m_map_images[events.jhat.which].end()) {
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_right);
}
break;
case SDL_HAT_LEFT:
key = hat_to_key(events.jhat.value, events.jhat.hat);
it = m_map_images[events.jhat.which].find(key);
if(it != m_map_images[events.jhat.which].end())
{
if (it != m_map_images[events.jhat.which].end()) {
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_left);
}
break;
@ -563,45 +533,34 @@ void Dialog::config_key(int pad, int key)
// I don't have any guarantee that not-yet-pressed state is egual to released state
GamePad::UpdateReleaseState();
while (!captured)
{
while (!captured) {
vector<GamePad *>::iterator itjoy;
if (PollX11KeyboardMouseEvent(key_pressed))
{
if (PollX11KeyboardMouseEvent(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_keyboad_key(pad, key_pressed, key);
m_simulatedKeys[pad][key] = key_pressed;
m_map_images[pad][key_pressed] = key;
}
captured = true;
}
else
{
} else {
GamePad::UpdateGamePadState();
itjoy = s_vgamePad.begin();
while ((itjoy != s_vgamePad.end()) && (!captured))
{
if ((*itjoy)->PollButtons(key_pressed))
{
while ((itjoy != s_vgamePad.end()) && (!captured)) {
if ((*itjoy)->PollButtons(key_pressed)) {
clear_key(pad, key);
set_key(pad, key, key_pressed);
m_map_images[pad][key_pressed] = key;
captured = true;
}
else if((*itjoy)->PollAxes(key_pressed))
{
} else if ((*itjoy)->PollAxes(key_pressed)) {
clear_key(pad, key);
set_key(pad, key, key_pressed);
m_map_images[pad][key_pressed] = key;
captured = true;
}
else if((*itjoy)->PollHats(key_pressed))
{
} else if ((*itjoy)->PollHats(key_pressed)) {
clear_key(pad, key);
set_key(pad, key, key_pressed);
m_map_images[pad][key_pressed] = key;
@ -612,8 +571,7 @@ void Dialog::config_key(int pad, int key)
}
}
m_bt_gamepad[pad][key]->SetLabel(
KeyName(pad, key, m_simulatedKeys[pad][key]).c_str()
);
KeyName(pad, key, m_simulatedKeys[pad][key]).c_str());
}
void Dialog::clear_key(int pad, int key)
@ -632,8 +590,7 @@ void Dialog::clear_key(int pad, int key)
int val = get_key(pad, key);
std::map<u32, int>::iterator it2;
it2 = m_map_images[pad].find(val);
if(it2 != m_map_images[pad].end())
{
if (it2 != m_map_images[pad].end()) {
m_map_images[pad].erase(it2);
}
@ -647,15 +604,11 @@ void Dialog::clear_key(int pad, int key)
// Set button values
void Dialog::repopulate()
{
for(int gamepad_id=0; gamepad_id<GAMEPAD_NUMBER; ++gamepad_id)
{
for (int key = 0; key < MAX_KEYS; key++)
{
if (get_key(gamepad_id, key) != 0)
{
for (int gamepad_id = 0; gamepad_id < GAMEPAD_NUMBER; ++gamepad_id) {
for (int key = 0; key < MAX_KEYS; key++) {
if (get_key(gamepad_id, key) != 0) {
m_bt_gamepad[gamepad_id][key]->SetLabel(
KeyName(gamepad_id, key).c_str()
);
KeyName(gamepad_id, key).c_str());
m_map_images[gamepad_id][get_key(gamepad_id, key)] = key;
}
@ -664,14 +617,12 @@ void Dialog::repopulate()
// keyboard/mouse key
map<u32, u32>::iterator it;
for (it = conf->keysym_map[gamepad_id].begin();
it != conf->keysym_map[gamepad_id].end(); ++it)
{
it != conf->keysym_map[gamepad_id].end(); ++it) {
int keysym = it->first;
int key = it->second;
m_bt_gamepad[gamepad_id][key]->SetLabel(
KeyName(gamepad_id, key, keysym).c_str()
);
KeyName(gamepad_id, key, keysym).c_str());
m_simulatedKeys[gamepad_id][key] = keysym;
m_map_images[gamepad_id][keysym] = key;

View File

@ -37,41 +37,43 @@ string KeyName(int pad, int key, int keysym)
if (keysym < 10) {
// mouse
switch (keysym) {
case 1: sprintf(&tmp[0], "Mouse Left"); break;
case 2: sprintf(&tmp[0], "Mouse Middle"); break;
case 3: sprintf(&tmp[0], "Mouse Right"); break;
case 1:
sprintf(&tmp[0], "Mouse Left");
break;
case 2:
sprintf(&tmp[0], "Mouse Middle");
break;
case 3:
sprintf(&tmp[0], "Mouse Right");
break;
default: // Use only number for extra button
sprintf(&tmp[0], "Mouse %d", keysym);
}
} else {
// keyboard
char *pstr = XKeysymToString(keysym);
if (pstr != NULL) tmp = pstr;
if (pstr != NULL)
tmp = pstr;
}
} else {
// joystick
KeyType k = type_of_joykey(pad, key);
switch (k)
{
case PAD_JOYBUTTONS:
{
switch (k) {
case PAD_JOYBUTTONS: {
int button = key_to_button(pad, key);
sprintf(&tmp[0], "JBut %d", button);
break;
}
case PAD_AXIS:
{
case PAD_AXIS: {
if (key_to_axis_type(pad, key))
sprintf(&tmp[0], "JAxis %d Full", key_to_axis(pad, key));
else
sprintf(&tmp[0], "JAxis %d Half%s", key_to_axis(pad, key), key_to_axis_sign(pad, key) ? "-" : "+");
break;
}
case PAD_HAT:
{
case PAD_HAT: {
int axis = key_to_axis(pad, key);
switch(key_to_hat_dir(pad, key))
{
switch (key_to_hat_dir(pad, key)) {
case HAT_UP:
sprintf(&tmp[0], "JPOVU-%d", axis);
break;
@ -90,7 +92,8 @@ string KeyName(int pad, int key, int keysym)
}
break;
}
default: break;
default:
break;
}
}
@ -121,8 +124,7 @@ void SaveConfig()
const std::string iniFile(s_strIniPath + "OnePAD.ini");
f = fopen(iniFile.c_str(), "w");
if (f == NULL)
{
if (f == NULL) {
printf("OnePAD: failed to save ini %s\n", iniFile.c_str());
return;
}
@ -133,10 +135,8 @@ void SaveConfig()
fprintf(f, "joy_pad_map = %d\n", conf->joyid_map);
fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity());
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
for (int key = 0; key < MAX_KEYS; key++)
{
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
for (int key = 0; key < MAX_KEYS; key++) {
fprintf(f, "[%d][%d] = 0x%x\n", pad, key, get_key(pad, key));
}
}
@ -162,35 +162,39 @@ void LoadConfig()
const std::string iniFile(s_strIniPath + "OnePAD.ini");
f = fopen(iniFile.c_str(), "r");
if (f == NULL)
{
if (f == NULL) {
printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
SaveConfig(); //save and return
return;
}
u32 value;
if (fscanf(f, "log = %u\n", &value) == 0) goto error;
if (fscanf(f, "log = %u\n", &value) == 0)
goto error;
conf->log = value;
if (fscanf(f, "options = %u\n", &value) == 0) goto error;
if (fscanf(f, "options = %u\n", &value) == 0)
goto error;
conf->packed_options = value;
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0) goto error;
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0)
goto error;
conf->set_sensibility(value);
if (fscanf(f, "joy_pad_map = %u\n", &value) == 0) goto error;
if (fscanf(f, "joy_pad_map = %u\n", &value) == 0)
goto error;
conf->joyid_map = value;
if (fscanf(f, "ff_intensity = %u\n", &value) == 0) goto error;
if (fscanf(f, "ff_intensity = %u\n", &value) == 0)
goto error;
conf->set_ff_intensity(value);
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
for (int key = 0; key < MAX_KEYS; key++)
{
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
for (int key = 0; key < MAX_KEYS; key++) {
sprintf(str, "[%d][%d] = 0x%%x\n", pad, key);
u32 temp = 0;
if (fscanf(f, str, &temp) == 0) temp = 0;
if (fscanf(f, str, &temp) == 0)
temp = 0;
set_key(pad, key, temp);
if (temp && pad == 0) have_user_setting = true;
if (temp && pad == 0)
have_user_setting = true;
}
}
@ -199,12 +203,13 @@ void LoadConfig()
u32 index;
while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) != EOF) {
set_keyboad_key(pad & 1, keysym, index);
if(pad == 0) have_user_setting = true;
if (pad == 0)
have_user_setting = true;
}
if (!have_user_setting) DefaultKeyboardValues();
if (!have_user_setting)
DefaultKeyboardValues();
error:
fclose(f);
}

View File

@ -40,7 +40,8 @@ void SysMessage(const char *fmt, ...)
vsprintf(msg, fmt, list);
va_end(list);
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0;
if (msg[strlen(msg) - 1] == '\n')
msg[strlen(msg) - 1] = 0;
GtkWidget *dialog;
dialog = gtk_message_dialog_new(NULL,
@ -52,12 +53,14 @@ void SysMessage(const char *fmt, ...)
gtk_widget_destroy(dialog);
}
EXPORT_C_(void) PADabout()
EXPORT_C_(void)
PADabout()
{
SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42.");
}
EXPORT_C_(s32) PADtest()
EXPORT_C_(s32)
PADtest()
{
return 0;
}
@ -78,8 +81,7 @@ void _PADclose()
vector<GamePad *>::iterator it = s_vgamePad.begin();
// Delete everything in the vector vjoysticks.
while (it != s_vgamePad.end())
{
while (it != s_vgamePad.end()) {
delete *it;
++it;
}
@ -90,17 +92,15 @@ void _PADclose()
void PollForJoystickInput(int cpad)
{
int joyid = conf->get_joyid(cpad);
if (!GamePadIdWithinBounds(joyid)) return;
if (!GamePadIdWithinBounds(joyid))
return;
GamePad::UpdateGamePadState();
for (int i = 0; i < MAX_KEYS; i++)
{
for (int i = 0; i < MAX_KEYS; i++) {
GamePad *gamePad = s_vgamePad[joyid];
switch (type_of_joykey(cpad, i))
{
case PAD_JOYBUTTONS:
{
switch (type_of_joykey(cpad, i)) {
case PAD_JOYBUTTONS: {
int value = gamePad->GetButton(key_to_button(cpad, i));
if (value)
@ -110,8 +110,7 @@ void PollForJoystickInput(int cpad)
break;
}
case PAD_HAT:
{
case PAD_HAT: {
int value = gamePad->GetHat(key_to_axis(cpad, i));
// key_to_hat_dir and SDL_JoystickGetHat are a 4 bits bitmap, one for each directions. Only 1 bit can be high for
@ -124,8 +123,7 @@ void PollForJoystickInput(int cpad)
break;
}
case PAD_AXIS:
{
case PAD_AXIS: {
int value = gamePad->GetAxisFromKey(cpad, i);
bool sign = key_to_axis_sign(cpad, i);
bool full_axis = key_to_axis_type(cpad, i);
@ -154,12 +152,14 @@ void PollForJoystickInput(int cpad)
}
}
}
default: break;
default:
break;
}
}
}
EXPORT_C_(void) PADupdate(int pad)
EXPORT_C_(void)
PADupdate(int pad)
{
// Gamepad inputs don't count as an activity. Therefore screensaver will
// be fired after a couple of minute.
@ -193,7 +193,8 @@ EXPORT_C_(void) PADupdate(int pad)
Pad::rumble_all();
}
EXPORT_C_(void) PADconfigure()
EXPORT_C_(void)
PADconfigure()
{
LoadConfig();

View File

@ -45,8 +45,8 @@
opPanel::opPanel(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size=wxDefaultSize
): wxPanel( parent, id, pos, size)
const wxSize &size = wxDefaultSize)
: wxPanel(parent, id, pos, size)
{
m_picture[img_background] = EmbeddedImage<res_dualshock2>().Get();
@ -85,8 +85,7 @@ 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);
}
@ -101,8 +100,7 @@ opPanel::opPanel(wxWindow *parent,
void opPanel::HideImg(int id)
{
if(id < NB_IMG)
{
if (id < NB_IMG) {
m_show_image[id] = false;
Refresh();
}
@ -110,8 +108,7 @@ void opPanel::HideImg(int id)
void opPanel::ShowImg(int id)
{
if(id < NB_IMG)
{
if (id < NB_IMG) {
m_show_image[id] = true;
Refresh();
}
@ -119,20 +116,13 @@ 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

@ -35,8 +35,7 @@ void JoystickInfo::UpdateReleaseState()
SDL_JoystickUpdate();
// Save everything in the vector s_vjoysticks.
while (itjoy != s_vgamePad.end())
{
while (itjoy != s_vgamePad.end()) {
(*itjoy)->SaveState();
++itjoy;
}
@ -46,19 +45,20 @@ void JoystickInfo::UpdateReleaseState()
void JoystickInfo::EnumerateJoysticks(vector<GamePad *> &vjoysticks)
{
if (!s_bSDLInit)
{
if (!s_bSDLInit) {
#if SDL_MAJOR_VERSION >= 2
// Tell SDL to catch event even if the windows isn't focussed
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
if (SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_HAPTIC|SDL_INIT_EVENTS) < 0) return;
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_EVENTS) < 0)
return;
// WTF! Give me back the control of my system
struct sigaction action = {0};
action.sa_handler = SIG_DFL;
sigaction(SIGINT, &action, NULL);
sigaction(SIGTERM, &action, NULL);
#else
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) return;
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
return;
#endif
SDL_JoystickEventState(SDL_QUERY);
s_bSDLInit = true;
@ -67,16 +67,14 @@ void JoystickInfo::EnumerateJoysticks(vector<GamePad*>& vjoysticks)
vector<GamePad *>::iterator it = vjoysticks.begin();
// Delete everything in the vector vjoysticks.
while (it != vjoysticks.end())
{
while (it != vjoysticks.end()) {
delete *it;
++it;
}
vjoysticks.resize(SDL_NumJoysticks());
for (int i = 0; i < (int)vjoysticks.size(); ++i)
{
for (int i = 0; i < (int)vjoysticks.size(); ++i) {
vjoysticks[i] = new JoystickInfo();
vjoysticks[i]->Init(i);
}
@ -85,8 +83,7 @@ void JoystickInfo::EnumerateJoysticks(vector<GamePad*>& vjoysticks)
void JoystickInfo::GenerateDefaultEffect()
{
#if SDL_MAJOR_VERSION >= 2
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;
@ -107,14 +104,16 @@ void JoystickInfo::GenerateDefaultEffect()
void JoystickInfo::Rumble(int type, int pad)
{
if (type > 1) return;
if ( !(conf->pad_options[pad].forcefeedback) ) return;
if (type > 1)
return;
if (!(conf->pad_options[pad].forcefeedback))
return;
#if SDL_MAJOR_VERSION >= 2
if (haptic == NULL) return;
if (haptic == NULL)
return;
if(first)
{// If done multiple times, device memory will be filled
if (first) { // If done multiple times, device memory will be filled
first = 0;
GenerateDefaultEffect();
/** Sine and triangle are quite probably the best, don't change that lightly and if you do
@ -126,24 +125,21 @@ void JoystickInfo::Rumble(int type, int pad)
**/
effects[0].type = SDL_HAPTIC_SINE;
effects_id[0] = SDL_HapticNewEffect(haptic, &effects[0]);
if(effects_id[0] < 0)
{
if (effects_id[0] < 0) {
fprintf(stderr, "ERROR: Effect is not uploaded! %s, id is %d\n", SDL_GetError(), effects_id[0]);
}
/** Effect for big motor **/
effects[1].type = SDL_HAPTIC_TRIANGLE;
effects_id[1] = SDL_HapticNewEffect(haptic, &effects[1]);
if(effects_id[1] < 0)
{
if (effects_id[1] < 0) {
fprintf(stderr, "ERROR: Effect is not uploaded! %s, id is %d\n", SDL_GetError(), effects_id[1]);
}
}
int id;
id = effects_id[type];
if(SDL_HapticRunEffect(haptic, id, 1) != 0)
{
if (SDL_HapticRunEffect(haptic, id, 1) != 0) {
fprintf(stderr, "ERROR: Effect is not working! %s, id is %d\n", SDL_GetError(), id);
}
#endif
@ -151,8 +147,7 @@ void JoystickInfo::Rumble(int type, int pad)
void JoystickInfo::Destroy()
{
if (joy != NULL)
{
if (joy != NULL) {
#if SDL_MAJOR_VERSION >= 2
// Haptic must be closed before the joystick
if (haptic != NULL) {
@ -163,10 +158,12 @@ void JoystickInfo::Destroy()
#if SDL_MAJOR_VERSION >= 2
#if SDL_MINOR_VERSION >= 4 // Version before 2.0.4 are bugged, JoystickClose crashes randomly
if (joy) SDL_JoystickClose(joy);
if (joy)
SDL_JoystickClose(joy);
#endif
#else
if (SDL_JoystickOpened(_id)) SDL_JoystickClose(joy);
if (SDL_JoystickOpened(_id))
SDL_JoystickClose(joy);
#endif
joy = NULL;
}
@ -178,8 +175,7 @@ bool JoystickInfo::Init(int id)
_id = id;
joy = SDL_JoystickOpen(id);
if (joy == NULL)
{
if (joy == NULL) {
PAD_LOG("failed to open joystick %d\n", id);
return false;
}
@ -244,8 +240,7 @@ bool JoystickInfo::TestForce(float strength=0.60)
return false; // Otherwise, core dump!
SDL_HapticRumbleInit(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( haptic, strength, 400 ) != 0)
{
if (SDL_HapticRumblePlay(haptic, strength, 400) != 0) {
fprintf(stderr, "ERROR: Rumble is not working! %s\n", SDL_GetError());
return false;
}
@ -258,11 +253,9 @@ bool JoystickInfo::TestForce(float strength=0.60)
bool JoystickInfo::PollButtons(u32 &pkey)
{
// MAKE sure to look for changes in the state!!
for (int i = 0; i < GetNumButtons(); ++i)
{
for (int i = 0; i < GetNumButtons(); ++i) {
int but = SDL_JoystickGetButton(GetJoy(), i);
if (but != GetButtonState(i))
{
if (but != GetButtonState(i)) {
// Pressure sensitive button are detected as both button (digital) and axes (analog). So better
// drop the button to emulate the pressure sensiblity of the ds2 :)
// Trick: detect the release of the button. It avoid all races condition between axes and buttons :)
@ -285,8 +278,7 @@ bool JoystickInfo::PollAxes(u32 &pkey)
{
u32 found_hack = devname.find(string("PLAYSTATION(R)3"));
for (int i = 0; i < GetNumAxes(); ++i)
{
for (int i = 0; i < GetNumAxes(); ++i) {
// Sixaxis, dualshock3 hack
if (found_hack != string::npos) {
// The analog mode of the hat button is quite erratic. Values can be in half- axis
@ -304,8 +296,7 @@ bool JoystickInfo::PollAxes(u32 &pkey)
if (abs(value - old_value) < 0x1000)
continue;
if (value != old_value)
{
if (value != old_value) {
PAD_LOG("Change in joystick %d: %d.\n", i, value);
// There are several kinds of axes
// Half+: 0 (release) -> 32768
@ -317,15 +308,12 @@ bool JoystickInfo::PollAxes(u32 &pkey)
// Normally, old_value contains the release state so it can be used to detect the types of axis.
bool is_full_axis = (old_value < full_axis_ceil) ? true : false;
if ((!is_full_axis && abs(value) <= half_axis_ceil)
|| (is_full_axis && value <= full_axis_ceil)) // we don't want this
if ((!is_full_axis && abs(value) <= half_axis_ceil) || (is_full_axis && value <= full_axis_ceil)) // we don't want this
{
continue;
}
if ((!is_full_axis && abs(value) > half_axis_ceil)
|| (is_full_axis && value > full_axis_ceil))
{
if ((!is_full_axis && abs(value) > half_axis_ceil) || (is_full_axis && value > full_axis_ceil)) {
bool sign = (value < 0);
pkey = axis_to_key(is_full_axis, sign, i);
@ -339,14 +327,11 @@ bool JoystickInfo::PollAxes(u32 &pkey)
bool JoystickInfo::PollHats(u32 &pkey)
{
for (int i = 0; i < GetNumHats(); ++i)
{
for (int i = 0; i < GetNumHats(); ++i) {
int value = SDL_JoystickGetHat(GetJoy(), i);
if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED))
{
switch (value)
{
if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED)) {
switch (value) {
case SDL_HAT_UP:
case SDL_HAT_RIGHT:
case SDL_HAT_DOWN:

View File

@ -34,7 +34,10 @@
class JoystickInfo : GamePad
{
public:
JoystickInfo() : GamePad(), joy(NULL) {
JoystickInfo()
: GamePad()
, joy(NULL)
{
#if SDL_MAJOR_VERSION >= 2
haptic = NULL;
first = true;

View File

@ -52,10 +52,14 @@ __forceinline KeyType type_of_joykey(int pad, int index)
{
int key = get_key(pad, index);
if (key >= 0x10000 && key < 0x20000) return PAD_JOYBUTTONS;
else if (key >= 0x20000 && key < 0x30000) return PAD_AXIS;
else if (key >= 0x30000 && key < 0x40000) return PAD_HAT;
else return PAD_NULL;
if (key >= 0x10000 && key < 0x20000)
return PAD_JOYBUTTONS;
else if (key >= 0x20000 && key < 0x30000)
return PAD_AXIS;
else if (key >= 0x30000 && key < 0x40000)
return PAD_HAT;
else
return PAD_NULL;
}
__forceinline bool IsAnalogKey(int index)

View File

@ -23,8 +23,7 @@
#include <string.h> // for memset
#define MAX_KEYS 24
enum KeyType
{
enum KeyType {
PAD_JOYBUTTONS = 0,
PAD_AXIS,
PAD_HAT,
@ -54,9 +53,12 @@ class PADconf
{
u32 ff_intensity;
u32 sensibility;
public:
union {
struct {
union
{
struct
{
u16 forcefeedback : 1;
u16 reverse_lx : 1;
u16 reverse_ly : 1;
@ -78,25 +80,27 @@ class PADconf
PADconf() { init(); }
void init() {
void init()
{
memset(&keys, 0, sizeof(keys));
log = packed_options = joyid_map = 0;
ff_intensity = 0x7FFF; // set it at max value by default
sensibility = 500;
for (int pad = 0; pad < GAMEPAD_NUMBER ; pad++)
{
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
keysym_map[pad].clear();
set_joyid((u32)pad, (u32)pad); // define id mapping for each gamepad
}
}
void set_joyid(u32 pad, u32 joy_id) {
void set_joyid(u32 pad, u32 joy_id)
{
int shift = 8 * pad;
joyid_map &= ~(0xFF << shift); // clear
joyid_map |= (joy_id & 0xFF) << shift; // set
}
u32 get_joyid(u32 pad) {
u32 get_joyid(u32 pad)
{
int shift = 8 * pad;
return ((joyid_map >> shift) & 0xFF);
}
@ -115,8 +119,7 @@ class PADconf
**/
void set_ff_intensity(u32 new_intensity)
{
if(new_intensity <= 0x7FFF)
{
if (new_intensity <= 0x7FFF) {
ff_intensity = new_intensity;
}
}
@ -128,8 +131,7 @@ class PADconf
**/
void set_sensibility(u32 new_sensibility)
{
if(sensibility > 0)
{
if (sensibility > 0) {
sensibility = new_sensibility;
}
}

View File

@ -41,8 +41,7 @@ char* KeysymToChar(int keysym)
void SetAutoRepeat(bool autorep)
{
#if defined(__unix__)
if (toggleAutoRepeat)
{
if (toggleAutoRepeat) {
if (autorep)
XAutoRepeatOn(GSdsp);
else
@ -70,15 +69,15 @@ void AnalyzeKeyEvent(keyEvent &evt)
}
}
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
// 1/ Does not need to detect full-screen
// 2/ Can use a debugger in full-screen
// 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_Shift_R || key == XK_Shift_L)
s_Shift = true;
if (key == XK_F12 && s_Shift) {
if (!s_grab_input) {
s_grab_input = true;
@ -92,10 +91,8 @@ void AnalyzeKeyEvent(keyEvent &evt)
}
// Analog controls.
if (IsAnalogKey(index))
{
switch (index)
{
if (IsAnalogKey(index)) {
switch (index) {
case PAD_R_LEFT:
case PAD_R_UP:
case PAD_L_LEFT:
@ -119,7 +116,8 @@ void AnalyzeKeyEvent(keyEvent &evt)
break;
case KeyRelease:
if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false;
if (key == XK_Shift_R || key == XK_Shift_L)
s_Shift = false;
if (index != -1)
key_status->release(pad, index);
@ -217,8 +215,7 @@ void PollForX11KeyboardInput()
}
// keyboard input
while (XPending(GSdsp) > 0)
{
while (XPending(GSdsp) > 0) {
XNextEvent(GSdsp, &E);
// Change the format of the structure to be compatible with GSOpen2
@ -244,8 +241,7 @@ bool PollX11KeyboardMouseEvent(u32 &pkey)
{
GdkEvent *ev = gdk_event_get();
if (ev != NULL)
{
if (ev != NULL) {
if (ev->type == GDK_KEY_PRESS) {
pkey = ev->key.keyval != GDK_KEY_Escape ? ev->key.keyval : 0;
return true;
@ -264,17 +260,14 @@ LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
static bool lbutton = false, rbutton = false;
key_status->keyboard_state_acces(cpad);
switch (msg)
{
switch (msg) {
case WM_KEYDOWN:
if (lParam & 0x40000000) return TRUE;
if (lParam & 0x40000000)
return TRUE;
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
{
for (int i = 0; i < MAX_KEYS; i++)
{
if (wParam == get_key(pad, i))
{
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
for (int i = 0; i < MAX_KEYS; i++) {
if (wParam == get_key(pad, i)) {
key_status->press(pad, i);
break;
}
@ -286,12 +279,9 @@ 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++)
{
if (wParam == get_key(pad,i))
{
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
for (int i = 0; i < MAX_KEYS; i++) {
if (wParam == get_key(pad, i)) {
key_status->release(pad, i);
break;
}

View File

@ -79,24 +79,27 @@ static void InitLibraryName()
#elif defined(PCSX2_DEVBUILD)
"-Dev"
#endif
, SVN_REV,
SVN_MODS ? "m" : ""
);
,
SVN_REV,
SVN_MODS ? "m" : "");
#endif
}
EXPORT_C_(u32) PS2EgetLibType()
EXPORT_C_(u32)
PS2EgetLibType()
{
return PS2E_LT_PAD;
}
EXPORT_C_(char*) PS2EgetLibName()
EXPORT_C_(char *)
PS2EgetLibName()
{
InitLibraryName();
return libraryName;
}
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
EXPORT_C_(u32)
PS2EgetLibVersion2(u32 type)
{
return (version << 16) | (revision << 8) | build;
}
@ -105,7 +108,8 @@ void __Log(const char *fmt, ...)
{
va_list list;
if (padLog == NULL) return;
if (padLog == NULL)
return;
va_start(list, fmt);
vfprintf(padLog, fmt, list);
va_end(list);
@ -117,7 +121,8 @@ void __LogToConsole(const char *fmt, ...)
va_start(list, fmt);
if (padLog != NULL) vfprintf(padLog, fmt, list);
if (padLog != NULL)
vfprintf(padLog, fmt, list);
printf("OnePAD: ");
vprintf(fmt, list);
@ -127,7 +132,8 @@ void __LogToConsole(const char *fmt, ...)
void initLogging()
{
#ifdef PAD_LOG
if (padLog) return;
if (padLog)
return;
const std::string LogFile(s_strLogPath + "padLog.txt");
padLog = fopen(LogFile.c_str(), "w");
@ -142,8 +148,7 @@ void initLogging()
void CloseLogging()
{
#ifdef PAD_LOG
if (padLog)
{
if (padLog) {
fclose(padLog);
padLog = NULL;
}
@ -157,7 +162,8 @@ void clearPAD(int pad)
set_key(pad, key, 0);
}
EXPORT_C_(s32) PADinit(u32 flags)
EXPORT_C_(s32)
PADinit(u32 flags)
{
initLogging();
@ -175,7 +181,8 @@ EXPORT_C_(s32) PADinit(u32 flags)
return 0;
}
EXPORT_C_(void) PADshutdown()
EXPORT_C_(void)
PADshutdown()
{
CloseLogging();
@ -186,12 +193,14 @@ EXPORT_C_(void) PADshutdown()
key_status = nullptr;
}
EXPORT_C_(s32) PADopen(void *pDsp)
EXPORT_C_(s32)
PADopen(void *pDsp)
{
memset(&event, 0, sizeof(event));
key_status->Init();
while (!ev_fifo.empty()) ev_fifo.pop();
while (!ev_fifo.empty())
ev_fifo.pop();
pthread_spin_init(&mutex_KeyEvent, PTHREAD_PROCESS_PRIVATE);
mutex_WasInit = true;
@ -201,13 +210,15 @@ EXPORT_C_(s32) PADopen(void *pDsp)
return _PADopen(pDsp);
}
EXPORT_C_(void) PADsetSettingsDir(const char* dir)
EXPORT_C_(void)
PADsetSettingsDir(const char *dir)
{
// Get the path to the ini directory.
s_strIniPath = (dir == NULL) ? "inis/" : dir;
}
EXPORT_C_(void) PADsetLogDir(const char* dir)
EXPORT_C_(void)
PADsetLogDir(const char *dir)
{
// Get the path to the log directory.
s_strLogPath = (dir == NULL) ? "logs/" : dir;
@ -217,20 +228,24 @@ EXPORT_C_(void) PADsetLogDir(const char* dir)
initLogging();
}
EXPORT_C_(void) PADclose()
EXPORT_C_(void)
PADclose()
{
while (!ev_fifo.empty()) ev_fifo.pop();
while (!ev_fifo.empty())
ev_fifo.pop();
mutex_WasInit = false;
pthread_spin_destroy(&mutex_KeyEvent);
_PADclose();
}
EXPORT_C_(u32) PADquery()
EXPORT_C_(u32)
PADquery()
{
return 3; // both
}
EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot)
EXPORT_C_(s32)
PADsetSlot(u8 port, u8 slot)
{
port--;
slot--;
@ -243,7 +258,8 @@ EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot)
return 1;
}
EXPORT_C_(s32) PADfreeze(int mode, freezeData *data)
EXPORT_C_(s32)
PADfreeze(int mode, freezeData *data)
{
if (!data)
return -1;
@ -283,7 +299,8 @@ EXPORT_C_(s32) PADfreeze(int mode, freezeData *data)
}
} else if (mode == FREEZE_SAVE) {
if (data->size != sizeof(PadPluginFreezeData)) return 0;
if (data->size != sizeof(PadPluginFreezeData))
return 0;
PadPluginFreezeData *pdata = (PadPluginFreezeData *)(data->data);
@ -310,18 +327,21 @@ EXPORT_C_(s32) PADfreeze(int mode, freezeData *data)
return 0;
}
EXPORT_C_(u8) PADstartPoll(int pad)
EXPORT_C_(u8)
PADstartPoll(int pad)
{
return pad_start_poll(pad);
}
EXPORT_C_(u8) PADpoll(u8 value)
EXPORT_C_(u8)
PADpoll(u8 value)
{
return pad_poll(value);
}
// PADkeyEvent is called every vsync (return NULL if no event)
EXPORT_C_(keyEvent*) PADkeyEvent()
EXPORT_C_(keyEvent *)
PADkeyEvent()
{
s_event = event;
event.evt = 0;
@ -330,7 +350,8 @@ EXPORT_C_(keyEvent*) PADkeyEvent()
}
#if defined(__unix__)
EXPORT_C_(void) PADWriteEvent(keyEvent &evt)
EXPORT_C_(void)
PADWriteEvent(keyEvent &evt)
{
// This function call be called before PADopen. Therefore we cann't
// guarantee that the spin lock was initialized

View File

@ -62,8 +62,7 @@ using namespace std;
#define EXPORT_C_(type) extern "C" __attribute__((stdcall, externally_visible, visibility("default"))) type
#endif
enum PadOptions
{
enum PadOptions {
PADOPTION_FORCEFEEDBACK = 0x1,
PADOPTION_REVERSELX = 0x2,
PADOPTION_REVERSELY = 0x4,
@ -82,8 +81,7 @@ extern bool toggleAutoRepeat;
#define PAD_LOG __Log
//#define PAD_LOG __LogToConsole
enum PadCommands
{
enum PadCommands {
CMD_SET_VREF_PARAM = 0x40,
CMD_QUERY_DS2_ANALOG_MODE = 0x41,
CMD_READ_DATA_AND_VIBRATE = 0x42,
@ -97,8 +95,7 @@ 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

@ -159,7 +159,8 @@ void Pad::rumble_all()
// Pad implementation
//////////////////////////////////////////////////////////////////////
inline bool IsDualshock2() {
inline bool IsDualshock2()
{
// FIXME
#if 0
return config.padConfigs[query.port][query.slot].type == Dualshock2Pad ||
@ -197,8 +198,7 @@ u8 pad_poll(u8 value)
}
break;
case CMD_READ_DATA_AND_VIBRATE:
{
case CMD_READ_DATA_AND_VIBRATE: {
query.response[2] = 0x5A;
#if 0
int i;
@ -319,8 +319,7 @@ u8 pad_poll(u8 value)
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;
@ -415,7 +414,8 @@ u8 pad_poll(u8 value)
case CMD_QUERY_ACT:
if (query.lastByte == 3) {
if (value<2) query.set_result(queryAct[value]);
if (value < 2)
query.set_result(queryAct[value]);
// bunch of 0's
// else query.set_result(setMode);
query.queryDone = 1;
@ -435,8 +435,7 @@ u8 pad_poll(u8 value)
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;

View File

@ -26,7 +26,8 @@
#define MODE_DS2_NATIVE 0x79
// The state of the PS2 bus
struct QueryInfo {
struct QueryInfo
{
u8 port;
u8 slot;
u8 lastByte;
@ -55,7 +56,8 @@ struct QueryInfo {
// Freeze data, for a single pad. Basically has all pad state that
// a PS2 can set.
struct PadFreezeData {
struct PadFreezeData
{
// Digital / Analog / DS2 Native
u8 mode;
@ -81,7 +83,8 @@ struct PadFreezeData {
u8 nextVibrate[2];
};
class Pad : public PadFreezeData {
class Pad : public PadFreezeData
{
public:
// Lilypad store here the state of PC pad
@ -98,7 +101,8 @@ public:
};
// Full state to manage save state
struct PadPluginFreezeData {
struct PadPluginFreezeData
{
char format[8];
u32 version;
// active slot for port