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

@ -28,10 +28,10 @@ std::vector<std::unique_ptr<GamePad>> s_vgamePad;
/**
* Find every interesting devices and create right structure for them(depend on backend)
**/
void GamePad::EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad)
void GamePad::EnumerateGamePads(std::vector<std::unique_ptr<GamePad>>& vgamePad)
{
#ifdef SDL_BUILD
JoystickInfo::EnumerateJoysticks(vgamePad);
JoystickInfo::EnumerateJoysticks(vgamePad);
#endif
}
@ -40,33 +40,34 @@ void GamePad::EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad)
**/
void GamePad::DoRumble(unsigned type, unsigned pad)
{
int index = uid_to_index(pad);
if (index >= 0)
s_vgamePad[index]->Rumble(type, pad);
int index = uid_to_index(pad);
if (index >= 0)
s_vgamePad[index]->Rumble(type, pad);
}
size_t GamePad::index_to_uid(int index)
{
if ((index >= 0) && (index < (int)s_vgamePad.size()))
return s_vgamePad[index]->GetUniqueIdentifier();
else
return 0;
if ((index >= 0) && (index < (int)s_vgamePad.size()))
return s_vgamePad[index]->GetUniqueIdentifier();
else
return 0;
}
int GamePad::uid_to_index(int pad)
{
size_t uid = g_conf.get_joy_uid(pad);
size_t uid = g_conf.get_joy_uid(pad);
for (int i = 0; i < (int)s_vgamePad.size(); ++i) {
if (s_vgamePad[i]->GetUniqueIdentifier() == uid)
return i;
}
for (int i = 0; i < (int)s_vgamePad.size(); ++i)
{
if (s_vgamePad[i]->GetUniqueIdentifier() == uid)
return i;
}
// Current uid wasn't found maybe the pad was unplugged. Or
// user didn't select it. Fallback to 1st pad for
// 1st player. And 2nd pad for 2nd player.
if ((int)s_vgamePad.size() > pad)
return pad;
// Current uid wasn't found maybe the pad was unplugged. Or
// user didn't select it. Fallback to 1st pad for
// 1st player. And 2nd pad for 2nd player.
if ((int)s_vgamePad.size() > pad)
return pad;
return -1;
return -1;
}

View File

@ -25,66 +25,66 @@
class GamePad
{
public:
GamePad()
: m_deadzone(1500)
, m_no_error(false)
{
}
GamePad()
: m_deadzone(1500)
, m_no_error(false)
{
}
virtual ~GamePad()
{
}
virtual ~GamePad()
{
}
GamePad(const GamePad &); // copy constructor
GamePad &operator=(const GamePad &); // assignment
GamePad(const GamePad&); // copy constructor
GamePad& operator=(const GamePad&); // assignment
/*
/*
* Find every interesting devices and create right structure for them(depend on backend)
*/
static void EnumerateGamePads(std::vector<std::unique_ptr<GamePad>> &vgamePad);
static void EnumerateGamePads(std::vector<std::unique_ptr<GamePad>>& vgamePad);
/*
/*
* Update state of every attached devices
*/
virtual void UpdateGamePadState() = 0;
virtual void UpdateGamePadState() = 0;
/*
/*
* Causes devices to rumble
* Rumble will differ according to type which is either 0(small motor) or 1(big motor)
*/
virtual void Rumble(unsigned type, unsigned pad) {}
/*
virtual void Rumble(unsigned type, unsigned pad) {}
/*
* Safely dispatch to the Rumble method above
*/
static void DoRumble(unsigned type, unsigned pad);
static void DoRumble(unsigned type, unsigned pad);
/*
/*
* Used for GUI checkbox to give feedback to the user
*/
virtual bool TestForce(float strength = 0.6) { return false; }
virtual bool TestForce(float strength = 0.6) { return false; }
virtual const char *GetName() = 0;
virtual const char* GetName() = 0;
virtual int GetInput(gamePadValues input) = 0;
virtual int GetInput(gamePadValues input) = 0;
int GetDeadzone()
{
return m_deadzone;
}
int GetDeadzone()
{
return m_deadzone;
}
virtual size_t GetUniqueIdentifier() = 0;
virtual size_t GetUniqueIdentifier() = 0;
static size_t index_to_uid(int index);
static int uid_to_index(int pad);
static size_t index_to_uid(int index);
static int uid_to_index(int pad);
bool IsProperlyInitialized()
{
return m_no_error;
}
bool IsProperlyInitialized()
{
return m_no_error;
}
protected:
int m_deadzone;
bool m_no_error;
int m_deadzone;
bool m_no_error;
};
extern std::vector<std::unique_ptr<GamePad>> s_vgamePad;

View File

@ -17,176 +17,187 @@
void KeyStatus::Init()
{
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 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++) {
m_button_pressure[pad][index] = 0xFF;
m_internal_button_pressure[pad][index] = 0xFF;
}
for (int index = 0; index < MAX_KEYS; index++)
{
m_button_pressure[pad][index] = 0xFF;
m_internal_button_pressure[pad][index] = 0xFF;
}
m_analog[pad].lx = m_analog_released_val;
m_analog[pad].ly = m_analog_released_val;
m_analog[pad].rx = m_analog_released_val;
m_analog[pad].ry = m_analog_released_val;
m_internal_analog_kbd[pad].lx = m_analog_released_val;
m_internal_analog_kbd[pad].ly = m_analog_released_val;
m_internal_analog_kbd[pad].rx = m_analog_released_val;
m_internal_analog_kbd[pad].ry = m_analog_released_val;
m_internal_analog_joy[pad].lx = m_analog_released_val;
m_internal_analog_joy[pad].ly = m_analog_released_val;
m_internal_analog_joy[pad].rx = m_analog_released_val;
m_internal_analog_joy[pad].ry = m_analog_released_val;
}
m_analog[pad].lx = m_analog_released_val;
m_analog[pad].ly = m_analog_released_val;
m_analog[pad].rx = m_analog_released_val;
m_analog[pad].ry = m_analog_released_val;
m_internal_analog_kbd[pad].lx = m_analog_released_val;
m_internal_analog_kbd[pad].ly = m_analog_released_val;
m_internal_analog_kbd[pad].rx = m_analog_released_val;
m_internal_analog_kbd[pad].ry = m_analog_released_val;
m_internal_analog_joy[pad].lx = m_analog_released_val;
m_internal_analog_joy[pad].ly = m_analog_released_val;
m_internal_analog_joy[pad].rx = m_analog_released_val;
m_internal_analog_joy[pad].ry = m_analog_released_val;
}
}
void KeyStatus::press(u32 pad, u32 index, s32 value)
{
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 {
// clamp value
if (value > MAX_ANALOG_VALUE)
value = MAX_ANALOG_VALUE;
else if (value < -MAX_ANALOG_VALUE)
value = -MAX_ANALOG_VALUE;
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
{
// clamp value
if (value > MAX_ANALOG_VALUE)
value = MAX_ANALOG_VALUE;
else if (value < -MAX_ANALOG_VALUE)
value = -MAX_ANALOG_VALUE;
// Left -> -- -> Right
// Value range : FFFF8002 -> 0 -> 7FFE
// Force range : 80 -> 0 -> 7F
// Normal mode : expect value 0 -> 80 -> FF
// Reverse mode: expect value FF -> 7F -> 0
u8 force = (value / 256);
if (analog_is_reversed(pad, index))
analog_set(pad, index, m_analog_released_val - force);
else
analog_set(pad, index, m_analog_released_val + force);
}
// Left -> -- -> Right
// Value range : FFFF8002 -> 0 -> 7FFE
// Force range : 80 -> 0 -> 7F
// Normal mode : expect value 0 -> 80 -> FF
// Reverse mode: expect value FF -> 7F -> 0
u8 force = (value / 256);
if (analog_is_reversed(pad, index))
analog_set(pad, index, m_analog_released_val - force);
else
analog_set(pad, index, m_analog_released_val + force);
}
}
void KeyStatus::release(u32 pad, u32 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 {
analog_set(pad, index, m_analog_released_val);
}
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
{
analog_set(pad, index, m_analog_released_val);
}
}
u16 KeyStatus::get(u32 pad)
{
return m_button[pad];
return m_button[pad];
}
void KeyStatus::analog_set(u32 pad, u32 index, u8 value)
{
PADAnalog *m_internal_analog_ref;
if (m_state_acces[pad])
m_internal_analog_ref = &m_internal_analog_kbd[pad];
else
m_internal_analog_ref = &m_internal_analog_joy[pad];
PADAnalog* m_internal_analog_ref;
if (m_state_acces[pad])
m_internal_analog_ref = &m_internal_analog_kbd[pad];
else
m_internal_analog_ref = &m_internal_analog_joy[pad];
switch (index) {
case PAD_R_LEFT:
case PAD_R_RIGHT:
m_internal_analog_ref->rx = value;
break;
switch (index)
{
case PAD_R_LEFT:
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_DOWN:
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_LEFT:
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_DOWN:
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) {
case PAD_L_RIGHT:
case PAD_L_LEFT:
return (g_conf.pad_options[pad].reverse_lx);
switch (index)
{
case PAD_L_RIGHT:
case PAD_L_LEFT:
return (g_conf.pad_options[pad].reverse_lx);
case PAD_R_LEFT:
case PAD_R_RIGHT:
return (g_conf.pad_options[pad].reverse_rx);
case PAD_R_LEFT:
case PAD_R_RIGHT:
return (g_conf.pad_options[pad].reverse_rx);
case PAD_L_UP:
case PAD_L_DOWN:
return (g_conf.pad_options[pad].reverse_ly);
case PAD_L_UP:
case PAD_L_DOWN:
return (g_conf.pad_options[pad].reverse_ly);
case PAD_R_DOWN:
case PAD_R_UP:
return (g_conf.pad_options[pad].reverse_ry);
case PAD_R_DOWN:
case PAD_R_UP:
return (g_conf.pad_options[pad].reverse_ry);
default:
return false;
}
default:
return false;
}
}
u8 KeyStatus::get(u32 pad, u32 index)
{
switch (index) {
case PAD_R_LEFT:
case PAD_R_RIGHT:
return m_analog[pad].rx;
switch (index)
{
case PAD_R_LEFT:
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_DOWN:
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_LEFT:
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_DOWN:
case PAD_L_UP:
return m_analog[pad].ly;
default:
return m_button_pressure[pad][index];
}
default:
return m_button_pressure[pad][index];
}
}
u8 KeyStatus::analog_merge(u8 kbd, u8 joy)
{
if (kbd != m_analog_released_val)
return kbd;
else
return joy;
if (kbd != m_analog_released_val)
return kbd;
else
return joy;
}
void KeyStatus::commit_status(u32 pad)
{
m_button[pad] = m_internal_button_kbd[pad] & m_internal_button_joy[pad];
m_button[pad] = m_internal_button_kbd[pad] & m_internal_button_joy[pad];
for (int index = 0; index < MAX_KEYS; index++)
m_button_pressure[pad][index] = m_internal_button_pressure[pad][index];
for (int index = 0; index < MAX_KEYS; index++)
m_button_pressure[pad][index] = m_internal_button_pressure[pad][index];
m_analog[pad].lx = analog_merge(m_internal_analog_kbd[pad].lx, m_internal_analog_joy[pad].lx);
m_analog[pad].ly = analog_merge(m_internal_analog_kbd[pad].ly, m_internal_analog_joy[pad].ly);
m_analog[pad].rx = analog_merge(m_internal_analog_kbd[pad].rx, m_internal_analog_joy[pad].rx);
m_analog[pad].ry = analog_merge(m_internal_analog_kbd[pad].ry, m_internal_analog_joy[pad].ry);
m_analog[pad].lx = analog_merge(m_internal_analog_kbd[pad].lx, m_internal_analog_joy[pad].lx);
m_analog[pad].ly = analog_merge(m_internal_analog_kbd[pad].ly, m_internal_analog_joy[pad].ly);
m_analog[pad].rx = analog_merge(m_internal_analog_kbd[pad].rx, m_internal_analog_joy[pad].rx);
m_analog[pad].ry = analog_merge(m_internal_analog_kbd[pad].ry, m_internal_analog_joy[pad].ry);
}

View File

@ -20,8 +20,8 @@
typedef struct
{
u8 lx, ly;
u8 rx, ry;
u8 lx, ly;
u8 rx, ry;
} PADAnalog;
#define MAX_ANALOG_VALUE 32766
@ -29,44 +29,44 @@ typedef struct
class KeyStatus
{
private:
const u8 m_analog_released_val;
const u8 m_analog_released_val;
u16 m_button[GAMEPAD_NUMBER];
u16 m_internal_button_kbd[GAMEPAD_NUMBER];
u16 m_internal_button_joy[GAMEPAD_NUMBER];
u16 m_button[GAMEPAD_NUMBER];
u16 m_internal_button_kbd[GAMEPAD_NUMBER];
u16 m_internal_button_joy[GAMEPAD_NUMBER];
u8 m_button_pressure[GAMEPAD_NUMBER][MAX_KEYS];
u8 m_internal_button_pressure[GAMEPAD_NUMBER][MAX_KEYS];
u8 m_button_pressure[GAMEPAD_NUMBER][MAX_KEYS];
u8 m_internal_button_pressure[GAMEPAD_NUMBER][MAX_KEYS];
bool m_state_acces[GAMEPAD_NUMBER];
bool m_state_acces[GAMEPAD_NUMBER];
PADAnalog m_analog[GAMEPAD_NUMBER];
PADAnalog m_internal_analog_kbd[GAMEPAD_NUMBER];
PADAnalog m_internal_analog_joy[GAMEPAD_NUMBER];
PADAnalog m_analog[GAMEPAD_NUMBER];
PADAnalog m_internal_analog_kbd[GAMEPAD_NUMBER];
PADAnalog m_internal_analog_joy[GAMEPAD_NUMBER];
void analog_set(u32 pad, u32 index, u8 value);
bool analog_is_reversed(u32 pad, u32 index);
u8 analog_merge(u8 kbd, u8 joy);
void analog_set(u32 pad, u32 index, u8 value);
bool analog_is_reversed(u32 pad, u32 index);
u8 analog_merge(u8 kbd, u8 joy);
public:
KeyStatus()
: m_analog_released_val(0x7F)
{
Init();
}
void Init();
KeyStatus()
: m_analog_released_val(0x7F)
{
Init();
}
void Init();
void keyboard_state_acces(u32 pad) { m_state_acces[pad] = true; }
void joystick_state_acces(u32 pad) { m_state_acces[pad] = false; }
void keyboard_state_acces(u32 pad) { m_state_acces[pad] = true; }
void joystick_state_acces(u32 pad) { m_state_acces[pad] = false; }
void press(u32 pad, u32 index, s32 value = 0xFF);
void release(u32 pad, u32 index);
void press(u32 pad, u32 index, s32 value = 0xFF);
void release(u32 pad, u32 index);
u16 get(u32 pad);
u8 get(u32 pad, u32 index);
u16 get(u32 pad);
u8 get(u32 pad, u32 index);
void commit_status(u32 pad);
void commit_status(u32 pad);
};
extern KeyStatus g_key_status;

View File

@ -41,240 +41,255 @@ static keyEvent s_event;
std::string s_padstrIniPath("inis/");
std::string s_padstrLogPath("logs/");
FILE *padLog = NULL;
FILE* padLog = NULL;
KeyStatus g_key_status;
MtQueue<keyEvent> g_ev_fifo;
void __LogToConsole(const char *fmt, ...)
void __LogToConsole(const char* fmt, ...)
{
va_list list;
va_list list;
va_start(list, fmt);
va_start(list, fmt);
if (padLog != NULL)
vfprintf(padLog, fmt, list);
if (padLog != NULL)
vfprintf(padLog, fmt, list);
printf("OnePAD: ");
vprintf(fmt, list);
va_end(list);
printf("OnePAD: ");
vprintf(fmt, list);
va_end(list);
}
void initLogging()
{
#ifdef PAD_LOG
if (padLog)
return;
if (padLog)
return;
const std::string LogFile(s_padstrLogPath + "padLog.txt");
padLog = fopen(LogFile.c_str(), "w");
const std::string LogFile(s_padstrLogPath + "padLog.txt");
padLog = fopen(LogFile.c_str(), "w");
if (padLog)
setvbuf(padLog, NULL, _IONBF, 0);
if (padLog)
setvbuf(padLog, NULL, _IONBF, 0);
PAD_LOG("PADinit\n");
PAD_LOG("PADinit\n");
#endif
}
void CloseLogging()
{
#ifdef PAD_LOG
if (padLog) {
fclose(padLog);
padLog = NULL;
}
if (padLog)
{
fclose(padLog);
padLog = NULL;
}
#endif
}
s32 PADinit()
{
initLogging();
initLogging();
PADLoadConfig();
PADLoadConfig();
Pad::reset_all();
Pad::reset_all();
query.reset();
query.reset();
for (int port = 0; port < 2; port++)
slots[port] = 0;
for (int port = 0; port < 2; port++)
slots[port] = 0;
return 0;
return 0;
}
void PADshutdown()
{
CloseLogging();
CloseLogging();
}
s32 PADopen(void *pDsp)
s32 PADopen(void* pDsp)
{
memset(&event, 0, sizeof(event));
g_key_status.Init();
memset(&event, 0, sizeof(event));
g_key_status.Init();
g_ev_fifo.reset();
g_ev_fifo.reset();
#if defined(__unix__) || defined(__APPLE__)
GamePad::EnumerateGamePads(s_vgamePad);
GamePad::EnumerateGamePads(s_vgamePad);
#endif
return _PADopen(pDsp);
return _PADopen(pDsp);
}
void PADsetSettingsDir(const char *dir)
void PADsetSettingsDir(const char* dir)
{
// Get the path to the ini directory.
s_padstrIniPath = (dir == NULL) ? "inis/" : dir;
// Get the path to the ini directory.
s_padstrIniPath = (dir == NULL) ? "inis/" : dir;
}
void PADsetLogDir(const char *dir)
void PADsetLogDir(const char* dir)
{
// Get the path to the log directory.
s_padstrLogPath = (dir == NULL) ? "logs/" : dir;
// Get the path to the log directory.
s_padstrLogPath = (dir == NULL) ? "logs/" : dir;
// Reload the log file after updated the path
CloseLogging();
initLogging();
// Reload the log file after updated the path
CloseLogging();
initLogging();
}
void PADclose()
{
_PADclose();
_PADclose();
}
u32 PADquery()
{
return 3; // both
return 3; // both
}
s32 PADsetSlot(u8 port, u8 slot)
{
port--;
slot--;
if (port > 1 || slot > 3) {
return 0;
}
// Even if no pad there, record the slot, as it is the active slot regardless.
slots[port] = slot;
port--;
slot--;
if (port > 1 || slot > 3)
{
return 0;
}
// Even if no pad there, record the slot, as it is the active slot regardless.
slots[port] = slot;
return 1;
return 1;
}
s32 PADfreeze(int mode, freezeData *data)
s32 PADfreeze(int mode, freezeData* data)
{
if (!data)
return -1;
if (!data)
return -1;
if (mode == FREEZE_SIZE) {
data->size = sizeof(PadPluginFreezeData);
if (mode == FREEZE_SIZE)
{
data->size = sizeof(PadPluginFreezeData);
}
else if (mode == FREEZE_LOAD)
{
PadPluginFreezeData* pdata = (PadPluginFreezeData*)(data->data);
} else if (mode == FREEZE_LOAD) {
PadPluginFreezeData *pdata = (PadPluginFreezeData *)(data->data);
Pad::stop_vibrate_all();
Pad::stop_vibrate_all();
if (data->size != sizeof(PadPluginFreezeData) || pdata->version != PAD_SAVE_STATE_VERSION ||
strncmp(pdata->format, "OnePad", sizeof(pdata->format)))
return 0;
if (data->size != sizeof(PadPluginFreezeData) || pdata->version != PAD_SAVE_STATE_VERSION ||
strncmp(pdata->format, "OnePad", sizeof(pdata->format)))
return 0;
query = pdata->query;
if (pdata->query.slot < 4)
{
query = pdata->query;
}
query = pdata->query;
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++)
{
u8 mode = pdata->padData[port][slot].mode;
// 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++) {
u8 mode = pdata->padData[port][slot].mode;
if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE)
{
break;
}
if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) {
break;
}
memcpy(&pads[port][slot], &pdata->padData[port][slot], sizeof(PadFreezeData));
}
memcpy(&pads[port][slot], &pdata->padData[port][slot], sizeof(PadFreezeData));
}
if (pdata->slot[port] < 4)
slots[port] = pdata->slot[port];
}
}
else if (mode == FREEZE_SAVE)
{
if (data->size != sizeof(PadPluginFreezeData))
return 0;
if (pdata->slot[port] < 4)
slots[port] = pdata->slot[port];
}
PadPluginFreezeData* pdata = (PadPluginFreezeData*)(data->data);
} else if (mode == FREEZE_SAVE) {
if (data->size != sizeof(PadPluginFreezeData))
return 0;
// Tales of the Abyss - pad fix
// - PCSX2 only saves port0 (save #1), then port1 (save #2)
PadPluginFreezeData *pdata = (PadPluginFreezeData *)(data->data);
memset(pdata, 0, data->size);
strncpy(pdata->format, "OnePad", sizeof(pdata->format));
pdata->version = PAD_SAVE_STATE_VERSION;
pdata->query = query;
// Tales of the Abyss - pad fix
// - PCSX2 only saves port0 (save #1), then port1 (save #2)
for (int port = 0; port < 2; port++)
{
for (int slot = 0; slot < 4; slot++)
{
pdata->padData[port][slot] = pads[port][slot];
}
memset(pdata, 0, data->size);
strncpy(pdata->format, "OnePad", sizeof(pdata->format));
pdata->version = PAD_SAVE_STATE_VERSION;
pdata->query = query;
pdata->slot[port] = slots[port];
}
}
else
{
return -1;
}
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 {
return -1;
}
return 0;
return 0;
}
u8 PADstartPoll(int pad)
{
return pad_start_poll(pad);
return pad_start_poll(pad);
}
u8 PADpoll(u8 value)
{
return pad_poll(value);
return pad_poll(value);
}
// PADkeyEvent is called every vsync (return NULL if no event)
keyEvent * PADkeyEvent()
keyEvent* PADkeyEvent()
{
#ifdef SDL_BUILD
// Take the opportunity to handle hot plugging here
SDL_Event events;
while (SDL_PollEvent(&events)) {
switch (events.type) {
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
GamePad::EnumerateGamePads(s_vgamePad);
break;
default:
break;
}
}
// Take the opportunity to handle hot plugging here
SDL_Event events;
while (SDL_PollEvent(&events))
{
switch (events.type)
{
case SDL_CONTROLLERDEVICEADDED:
case SDL_CONTROLLERDEVICEREMOVED:
GamePad::EnumerateGamePads(s_vgamePad);
break;
default:
break;
}
}
#endif
if (g_ev_fifo.size() == 0) {
// PAD_LOG("No events in queue, returning empty event\n");
s_event = event;
event.evt = 0;
event.key = 0;
return &s_event;
}
s_event = g_ev_fifo.dequeue();
AnalyzeKeyEvent(s_event);
// PAD_LOG("Returning Event. Event Type: %d, Key: %d\n", s_event.evt, s_event.key);
return &s_event;
if (g_ev_fifo.size() == 0)
{
// PAD_LOG("No events in queue, returning empty event\n");
s_event = event;
event.evt = 0;
event.key = 0;
return &s_event;
}
s_event = g_ev_fifo.dequeue();
AnalyzeKeyEvent(s_event);
// PAD_LOG("Returning Event. Event Type: %d, Key: %d\n", s_event.evt, s_event.key);
return &s_event;
}
#if defined(__unix__)
void PADWriteEvent(keyEvent &evt)
void PADWriteEvent(keyEvent& evt)
{
// if (evt.evt != 6) { // Skip mouse move events for logging
// PAD_LOG("Pushing Event. Event Type: %d, Key: %d\n", evt.evt, evt.key);
// }
g_ev_fifo.push(evt);
// if (evt.evt != 6) { // Skip mouse move events for logging
// PAD_LOG("Pushing Event. Event Type: %d, Key: %d\n", evt.evt, evt.key);
// }
g_ev_fifo.push(evt);
}
#endif

View File

@ -43,55 +43,58 @@
#define PADdefs
enum PadOptions {
PADOPTION_FORCEFEEDBACK = 0x1,
PADOPTION_REVERSELX = 0x2,
PADOPTION_REVERSELY = 0x4,
PADOPTION_REVERSERX = 0x8,
PADOPTION_REVERSERY = 0x10,
PADOPTION_MOUSE_L = 0x20,
PADOPTION_MOUSE_R = 0x40,
enum PadOptions
{
PADOPTION_FORCEFEEDBACK = 0x1,
PADOPTION_REVERSELX = 0x2,
PADOPTION_REVERSELY = 0x4,
PADOPTION_REVERSERX = 0x8,
PADOPTION_REVERSERY = 0x10,
PADOPTION_MOUSE_L = 0x20,
PADOPTION_MOUSE_R = 0x40,
};
enum PadCommands {
CMD_SET_VREF_PARAM = 0x40,
CMD_QUERY_DS2_ANALOG_MODE = 0x41,
CMD_READ_DATA_AND_VIBRATE = 0x42,
CMD_CONFIG_MODE = 0x43,
CMD_SET_MODE_AND_LOCK = 0x44,
CMD_QUERY_MODEL_AND_MODE = 0x45,
CMD_QUERY_ACT = 0x46, // ??
CMD_QUERY_COMB = 0x47, // ??
CMD_QUERY_MODE = 0x4C, // QUERY_MODE ??
CMD_VIBRATION_TOGGLE = 0x4D,
CMD_SET_DS2_NATIVE_MODE = 0x4F // SET_DS2_NATIVE_MODE
enum PadCommands
{
CMD_SET_VREF_PARAM = 0x40,
CMD_QUERY_DS2_ANALOG_MODE = 0x41,
CMD_READ_DATA_AND_VIBRATE = 0x42,
CMD_CONFIG_MODE = 0x43,
CMD_SET_MODE_AND_LOCK = 0x44,
CMD_QUERY_MODEL_AND_MODE = 0x45,
CMD_QUERY_ACT = 0x46, // ??
CMD_QUERY_COMB = 0x47, // ??
CMD_QUERY_MODE = 0x4C, // QUERY_MODE ??
CMD_VIBRATION_TOGGLE = 0x4D,
CMD_SET_DS2_NATIVE_MODE = 0x4F // SET_DS2_NATIVE_MODE
};
enum gamePadValues {
PAD_L2 = 0, // L2 button
PAD_R2, // R2 button
PAD_L1, // L1 button
PAD_R1, // R1 button
PAD_TRIANGLE, // Triangle button ▲
PAD_CIRCLE, // Circle button ●
PAD_CROSS, // Cross button ✖
PAD_SQUARE, // Square button ■
PAD_SELECT, // Select button
PAD_L3, // Left joystick button (L3)
PAD_R3, // Right joystick button (R3)
PAD_START, // Start button
PAD_UP, // Directional pad ↑
PAD_RIGHT, // Directional pad →
PAD_DOWN, // Directional pad ↓
PAD_LEFT, // Directional pad ←
PAD_L_UP, // Left joystick (Up) ↑
PAD_L_RIGHT, // Left joystick (Right) →
PAD_L_DOWN, // Left joystick (Down) ↓
PAD_L_LEFT, // Left joystick (Left) ←
PAD_R_UP, // Right joystick (Up) ↑
PAD_R_RIGHT, // Right joystick (Right) →
PAD_R_DOWN, // Right joystick (Down) ↓
PAD_R_LEFT // Right joystick (Left) ←
enum gamePadValues
{
PAD_L2 = 0, // L2 button
PAD_R2, // R2 button
PAD_L1, // L1 button
PAD_R1, // R1 button
PAD_TRIANGLE, // Triangle button ▲
PAD_CIRCLE, // Circle button ●
PAD_CROSS, // Cross button ✖
PAD_SQUARE, // Square button ■
PAD_SELECT, // Select button
PAD_L3, // Left joystick button (L3)
PAD_R3, // Right joystick button (R3)
PAD_START, // Start button
PAD_UP, // Directional pad ↑
PAD_RIGHT, // Directional pad →
PAD_DOWN, // Directional pad ↓
PAD_LEFT, // Directional pad ←
PAD_L_UP, // Left joystick (Up) ↑
PAD_L_RIGHT, // Left joystick (Right) →
PAD_L_DOWN, // Left joystick (Down) ↓
PAD_L_LEFT, // Left joystick (Left) ←
PAD_R_UP, // Right joystick (Up) ↑
PAD_R_RIGHT, // Right joystick (Right) →
PAD_R_DOWN, // Right joystick (Down) ↓
PAD_R_LEFT // Right joystick (Left) ←
};
#if defined(__unix__) || defined(__APPLE__)
@ -102,7 +105,7 @@ enum gamePadValues {
#include "KeyStatus.h"
#include "mt_queue.h"
extern FILE *padLog;
extern FILE* padLog;
extern void initLogging();
//#define PAD_LOG __Log
@ -111,31 +114,31 @@ extern void initLogging();
extern keyEvent event;
extern MtQueue<keyEvent> g_ev_fifo;
s32 _PADopen(void *pDsp);
s32 _PADopen(void* pDsp);
void _PADclose();
void PADsetMode(int pad, int mode);
void __LogToConsole(const char *fmt, ...);
void __LogToConsole(const char* fmt, ...);
void PADLoadConfig();
void PADSaveConfig();
void SysMessage(char *fmt, ...);
void SysMessage(char* fmt, ...);
s32 PADinit();
void PADshutdown();
s32 PADopen(void *pDsp);
void PADsetSettingsDir(const char *dir);
void PADsetLogDir(const char *dir);
s32 PADopen(void* pDsp);
void PADsetSettingsDir(const char* dir);
void PADsetLogDir(const char* dir);
void PADclose();
u32 PADquery();
s32 PADsetSlot(u8 port, u8 slot);
s32 PADfreeze(int mode, freezeData *data);
s32 PADfreeze(int mode, freezeData* data);
u8 PADstartPoll(int pad);
u8 PADpoll(u8 value);
keyEvent * PADkeyEvent();
keyEvent* PADkeyEvent();
void PADupdate(int pad);
void PADconfigure();
#if defined(__unix__)
void PADWriteEvent(keyEvent &evt);
void PADWriteEvent(keyEvent& evt);
#endif

View File

@ -22,263 +22,284 @@
//////////////////////////
// opens handles to all possible joysticks
void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjoysticks)
void JoystickInfo::EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>>& vjoysticks)
{
uint32_t flag = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER;
uint32_t flag = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER;
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");
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");
if (SDL_Init(flag) < 0)
return;
if (SDL_Init(flag) < 0)
return;
// WTF! Give me back the control of my system
struct sigaction action = {};
action.sa_handler = SIG_DFL;
sigaction(SIGINT, &action, nullptr);
sigaction(SIGTERM, &action, nullptr);
// WTF! Give me back the control of my system
struct sigaction action = {};
action.sa_handler = SIG_DFL;
sigaction(SIGINT, &action, nullptr);
sigaction(SIGTERM, &action, nullptr);
SDL_JoystickEventState(SDL_QUERY);
SDL_GameControllerEventState(SDL_QUERY);
SDL_EventState(SDL_CONTROLLERDEVICEADDED, SDL_ENABLE);
SDL_EventState(SDL_CONTROLLERDEVICEREMOVED, SDL_ENABLE);
SDL_JoystickEventState(SDL_QUERY);
SDL_GameControllerEventState(SDL_QUERY);
SDL_EventState(SDL_CONTROLLERDEVICEADDED, SDL_ENABLE);
SDL_EventState(SDL_CONTROLLERDEVICEREMOVED, SDL_ENABLE);
{ // Support as much Joystick as possible
GBytes *bytes = g_resource_lookup_data(PAD_res_get_resource(), "/PAD/res/game_controller_db.txt", G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr);
{ // Support as much Joystick as possible
GBytes* bytes = g_resource_lookup_data(PAD_res_get_resource(), "/PAD/res/game_controller_db.txt", G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr);
size_t size = 0;
// SDL forget to add const for SDL_RWFromMem API...
void *data = const_cast<void *>(g_bytes_get_data(bytes, &size));
size_t size = 0;
// SDL forget to add const for SDL_RWFromMem API...
void* data = const_cast<void*>(g_bytes_get_data(bytes, &size));
SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(data, size), 1);
SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(data, size), 1);
g_bytes_unref(bytes);
g_bytes_unref(bytes);
// Add user mapping too
for (auto const &map : g_conf.sdl2_mapping)
SDL_GameControllerAddMapping(map.c_str());
}
}
// Add user mapping too
for (auto const& map : g_conf.sdl2_mapping)
SDL_GameControllerAddMapping(map.c_str());
}
}
vjoysticks.clear();
vjoysticks.clear();
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())
vjoysticks.pop_back();
}
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())
vjoysticks.pop_back();
}
}
void JoystickInfo::Rumble(unsigned type, unsigned pad)
{
if (type >= m_effects_id.size())
return;
if (type >= m_effects_id.size())
return;
if (!(g_conf.pad_options[pad].forcefeedback))
return;
if (!(g_conf.pad_options[pad].forcefeedback))
return;
if (m_haptic == nullptr)
return;
if (m_haptic == nullptr)
return;
int id = m_effects_id[type];
if (SDL_HapticRunEffect(m_haptic, id, 1) != 0) {
fprintf(stderr, "ERROR: Effect is not working! %s, id is %d\n", SDL_GetError(), id);
}
int id = m_effects_id[type];
if (SDL_HapticRunEffect(m_haptic, id, 1) != 0)
{
fprintf(stderr, "ERROR: Effect is not working! %s, id is %d\n", SDL_GetError(), id);
}
}
JoystickInfo::~JoystickInfo()
{
// Haptic must be closed before the joystick
if (m_haptic != nullptr) {
for (const auto &eid : m_effects_id) {
if (eid >= 0)
SDL_HapticDestroyEffect(m_haptic, eid);
}
// Haptic must be closed before the joystick
if (m_haptic != nullptr)
{
for (const auto& eid : m_effects_id)
{
if (eid >= 0)
SDL_HapticDestroyEffect(m_haptic, eid);
}
SDL_HapticClose(m_haptic);
}
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)
SDL_GameControllerClose(m_controller);
// Version before 2.0.4 are bugged, JoystickClose crashes randomly
// Note: GameControllerClose calls JoystickClose)
SDL_GameControllerClose(m_controller);
#endif
}
}
}
JoystickInfo::JoystickInfo(int id)
: GamePad()
, m_controller(nullptr)
, m_haptic(nullptr)
, m_unique_id(0)
: GamePad()
, m_controller(nullptr)
, m_haptic(nullptr)
, m_unique_id(0)
{
SDL_Joystick *joy = nullptr;
m_effects_id.fill(-1);
// Values are hardcoded currently but it could be later extended to allow remapping of the buttons
m_pad_to_sdl[PAD_L2] = SDL_CONTROLLER_AXIS_TRIGGERLEFT;
m_pad_to_sdl[PAD_R2] = SDL_CONTROLLER_AXIS_TRIGGERRIGHT;
m_pad_to_sdl[PAD_L1] = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
m_pad_to_sdl[PAD_R1] = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
m_pad_to_sdl[PAD_TRIANGLE] = SDL_CONTROLLER_BUTTON_Y;
m_pad_to_sdl[PAD_CIRCLE] = SDL_CONTROLLER_BUTTON_B;
m_pad_to_sdl[PAD_CROSS] = SDL_CONTROLLER_BUTTON_A;
m_pad_to_sdl[PAD_SQUARE] = SDL_CONTROLLER_BUTTON_X;
m_pad_to_sdl[PAD_SELECT] = SDL_CONTROLLER_BUTTON_BACK;
m_pad_to_sdl[PAD_L3] = SDL_CONTROLLER_BUTTON_LEFTSTICK;
m_pad_to_sdl[PAD_R3] = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
m_pad_to_sdl[PAD_START] = SDL_CONTROLLER_BUTTON_START;
m_pad_to_sdl[PAD_UP] = SDL_CONTROLLER_BUTTON_DPAD_UP;
m_pad_to_sdl[PAD_RIGHT] = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
m_pad_to_sdl[PAD_DOWN] = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
m_pad_to_sdl[PAD_LEFT] = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
m_pad_to_sdl[PAD_L_UP] = SDL_CONTROLLER_AXIS_LEFTY;
m_pad_to_sdl[PAD_L_RIGHT] = SDL_CONTROLLER_AXIS_LEFTX;
m_pad_to_sdl[PAD_L_DOWN] = SDL_CONTROLLER_AXIS_LEFTY;
m_pad_to_sdl[PAD_L_LEFT] = SDL_CONTROLLER_AXIS_LEFTX;
m_pad_to_sdl[PAD_R_UP] = SDL_CONTROLLER_AXIS_RIGHTY;
m_pad_to_sdl[PAD_R_RIGHT] = SDL_CONTROLLER_AXIS_RIGHTX;
m_pad_to_sdl[PAD_R_DOWN] = SDL_CONTROLLER_AXIS_RIGHTY;
m_pad_to_sdl[PAD_R_LEFT] = SDL_CONTROLLER_AXIS_RIGHTX;
SDL_Joystick* joy = nullptr;
m_effects_id.fill(-1);
// Values are hardcoded currently but it could be later extended to allow remapping of the buttons
m_pad_to_sdl[PAD_L2] = SDL_CONTROLLER_AXIS_TRIGGERLEFT;
m_pad_to_sdl[PAD_R2] = SDL_CONTROLLER_AXIS_TRIGGERRIGHT;
m_pad_to_sdl[PAD_L1] = SDL_CONTROLLER_BUTTON_LEFTSHOULDER;
m_pad_to_sdl[PAD_R1] = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER;
m_pad_to_sdl[PAD_TRIANGLE] = SDL_CONTROLLER_BUTTON_Y;
m_pad_to_sdl[PAD_CIRCLE] = SDL_CONTROLLER_BUTTON_B;
m_pad_to_sdl[PAD_CROSS] = SDL_CONTROLLER_BUTTON_A;
m_pad_to_sdl[PAD_SQUARE] = SDL_CONTROLLER_BUTTON_X;
m_pad_to_sdl[PAD_SELECT] = SDL_CONTROLLER_BUTTON_BACK;
m_pad_to_sdl[PAD_L3] = SDL_CONTROLLER_BUTTON_LEFTSTICK;
m_pad_to_sdl[PAD_R3] = SDL_CONTROLLER_BUTTON_RIGHTSTICK;
m_pad_to_sdl[PAD_START] = SDL_CONTROLLER_BUTTON_START;
m_pad_to_sdl[PAD_UP] = SDL_CONTROLLER_BUTTON_DPAD_UP;
m_pad_to_sdl[PAD_RIGHT] = SDL_CONTROLLER_BUTTON_DPAD_RIGHT;
m_pad_to_sdl[PAD_DOWN] = SDL_CONTROLLER_BUTTON_DPAD_DOWN;
m_pad_to_sdl[PAD_LEFT] = SDL_CONTROLLER_BUTTON_DPAD_LEFT;
m_pad_to_sdl[PAD_L_UP] = SDL_CONTROLLER_AXIS_LEFTY;
m_pad_to_sdl[PAD_L_RIGHT] = SDL_CONTROLLER_AXIS_LEFTX;
m_pad_to_sdl[PAD_L_DOWN] = SDL_CONTROLLER_AXIS_LEFTY;
m_pad_to_sdl[PAD_L_LEFT] = SDL_CONTROLLER_AXIS_LEFTX;
m_pad_to_sdl[PAD_R_UP] = SDL_CONTROLLER_AXIS_RIGHTY;
m_pad_to_sdl[PAD_R_RIGHT] = SDL_CONTROLLER_AXIS_RIGHTX;
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)) {
m_controller = SDL_GameControllerOpen(id);
joy = SDL_GameControllerGetJoystick(m_controller);
} else {
joy = SDL_JoystickOpen(id);
}
if (SDL_IsGameController(id))
{
m_controller = SDL_GameControllerOpen(id);
joy = SDL_GameControllerGetJoystick(m_controller);
}
else
{
joy = SDL_JoystickOpen(id);
}
if (joy == nullptr) {
fprintf(stderr, "PAD: failed to open joystick %d\n", id);
return;
}
if (joy == nullptr)
{
fprintf(stderr, "PAD: failed to open joystick %d\n", id);
return;
}
// Collect Device Information
char guid[64];
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, 64);
const char *devname = SDL_JoystickNameForIndex(id);
// Collect Device Information
char guid[64];
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, 64);
const char* devname = SDL_JoystickNameForIndex(id);
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"
"Please report it to us (https://github.com/PCSX2/pcsx2/issues) so we can add your joystick to our internal database.",
devname, guid);
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"
"Please report it to us (https://github.com/PCSX2/pcsx2/issues) so we can add your joystick to our internal database.",
devname, guid);
#if SDL_MINOR_VERSION >= 4 // Version before 2.0.4 are bugged, JoystickClose crashes randomly
SDL_JoystickClose(joy);
SDL_JoystickClose(joy);
#endif
return;
}
return;
}
std::hash<std::string> hash_me;
m_unique_id = hash_me(std::string(guid));
std::hash<std::string> hash_me;
m_unique_id = hash_me(std::string(guid));
// Default haptic effect
SDL_HapticEffect effects[NB_EFFECT];
for (int i = 0; i < NB_EFFECT; i++) {
SDL_HapticEffect effect;
memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
SDL_HapticDirection direction;
direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
direction.dir[0] = 18000;
effect.periodic.direction = direction;
effect.periodic.period = 10;
effect.periodic.magnitude = (Sint16)(g_conf.get_ff_intensity()); // Effect at maximum instensity
effect.periodic.offset = 0;
effect.periodic.phase = 18000;
effect.periodic.length = 125; // 125ms feels quite near to original
effect.periodic.delay = 0;
effect.periodic.attack_length = 0;
/* Sine and triangle are quite probably the best, don't change that lightly and if you do
// Default haptic effect
SDL_HapticEffect effects[NB_EFFECT];
for (int i = 0; i < NB_EFFECT; i++)
{
SDL_HapticEffect effect;
memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
SDL_HapticDirection direction;
direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
direction.dir[0] = 18000;
effect.periodic.direction = direction;
effect.periodic.period = 10;
effect.periodic.magnitude = (Sint16)(g_conf.get_ff_intensity()); // Effect at maximum instensity
effect.periodic.offset = 0;
effect.periodic.phase = 18000;
effect.periodic.length = 125; // 125ms feels quite near to original
effect.periodic.delay = 0;
effect.periodic.attack_length = 0;
/* 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) {
/* Effect for small motor */
/* Sine seems to be the only effect making little motor from DS3/4 react
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 {
/** Effect for big motor **/
effect.type = SDL_HAPTIC_TRIANGLE;
}
effect.type = SDL_HAPTIC_SINE;
}
else
{
/** Effect for big motor **/
effect.type = SDL_HAPTIC_TRIANGLE;
}
effects[i] = effect;
}
effects[i] = effect;
}
if (SDL_JoystickIsHaptic(joy)) {
m_haptic = SDL_HapticOpenFromJoystick(joy);
if (SDL_JoystickIsHaptic(joy))
{
m_haptic = SDL_HapticOpenFromJoystick(joy);
for (auto &eid : m_effects_id) {
eid = SDL_HapticNewEffect(m_haptic, &effects[0]);
if (eid < 0) {
fprintf(stderr, "ERROR: Effect is not uploaded! %s\n", SDL_GetError());
m_haptic = nullptr;
break;
}
}
}
for (auto& eid : m_effects_id)
{
eid = SDL_HapticNewEffect(m_haptic, &effects[0]);
if (eid < 0)
{
fprintf(stderr, "ERROR: Effect is not uploaded! %s\n", SDL_GetError());
m_haptic = nullptr;
break;
}
}
}
fprintf(stdout, "PAD: controller (%s) detected%s, GUID:%s\n",
devname, m_haptic ? " with rumble support" : "", guid);
fprintf(stdout, "PAD: controller (%s) detected%s, GUID:%s\n",
devname, m_haptic ? " with rumble support" : "", guid);
m_no_error = true;
m_no_error = true;
}
const char *JoystickInfo::GetName()
const char* JoystickInfo::GetName()
{
return SDL_JoystickName(SDL_GameControllerGetJoystick(m_controller));
return SDL_JoystickName(SDL_GameControllerGetJoystick(m_controller));
}
size_t JoystickInfo::GetUniqueIdentifier()
{
return m_unique_id;
return m_unique_id;
}
bool JoystickInfo::TestForce(float strength = 0.60)
{
// This code just use standard rumble to check that SDL handles the pad correctly! --3kinox
if (m_haptic == nullptr)
return false; // Otherwise, core dump!
// This code just use standard rumble to check that SDL handles the pad correctly! --3kinox
if (m_haptic == nullptr)
return false; // Otherwise, core dump!
SDL_HapticRumbleInit(m_haptic);
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) {
fprintf(stderr, "ERROR: Rumble is not working! %s\n", SDL_GetError());
return false;
}
// 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)
{
fprintf(stderr, "ERROR: Rumble is not working! %s\n", SDL_GetError());
return false;
}
return true;
return true;
}
int JoystickInfo::GetInput(gamePadValues input)
{
float k = g_conf.get_sensibility() / 100.0; // convert sensibility to float
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)) {
int value = SDL_GameControllerGetAxis(m_controller, (SDL_GameControllerAxis)m_pad_to_sdl[input]);
value *= k;
return (abs(value) > m_deadzone) ? value : 0;
}
// Handle analog inputs which range from -32k to +32k. Range conversion is handled later in the controller
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) {
int value = SDL_GameControllerGetAxis(m_controller, (SDL_GameControllerAxis)m_pad_to_sdl[input]);
return (value > m_deadzone) ? value / 128 : 0;
}
// Handle triggers which range from 0 to +32k. They must be converted to 0-255 range
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;
}
// Remain buttons
int value = SDL_GameControllerGetButton(m_controller, (SDL_GameControllerButton)m_pad_to_sdl[input]);
return value ? 0xFF : 0; // Max pressure
// Remain buttons
int value = SDL_GameControllerGetButton(m_controller, (SDL_GameControllerButton)m_pad_to_sdl[input]);
return value ? 0xFF : 0; // Max pressure
}
void JoystickInfo::UpdateGamePadState()
{
SDL_GameControllerUpdate();
SDL_GameControllerUpdate();
}

View File

@ -26,32 +26,32 @@
class JoystickInfo : public GamePad
{
public:
JoystickInfo(int id);
~JoystickInfo();
JoystickInfo(int id);
~JoystickInfo();
JoystickInfo(const JoystickInfo &) = delete; // copy constructor
JoystickInfo &operator=(const JoystickInfo &) = delete; // assignment
JoystickInfo(const JoystickInfo&) = delete; // copy constructor
JoystickInfo& operator=(const JoystickInfo&) = delete; // assignment
// opens handles to all possible joysticks
static void EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>> &vjoysticks);
// opens handles to all possible joysticks
static void EnumerateJoysticks(std::vector<std::unique_ptr<GamePad>>& vjoysticks);
void Rumble(unsigned type, unsigned pad) override;
void Rumble(unsigned type, unsigned pad) override;
bool TestForce(float) override;
bool TestForce(float) override;
const char *GetName() final;
const char* GetName() final;
int GetInput(gamePadValues input) final;
int GetInput(gamePadValues input) final;
void UpdateGamePadState() final;
void UpdateGamePadState() final;
size_t GetUniqueIdentifier() final;
size_t GetUniqueIdentifier() final;
private:
SDL_GameController *m_controller;
SDL_Haptic *m_haptic;
std::array<int, NB_EFFECT> m_effects_id;
size_t m_unique_id;
std::array<int, MAX_KEYS> m_pad_to_sdl;
SDL_GameController* m_controller;
SDL_Haptic* m_haptic;
std::array<int, NB_EFFECT> m_effects_id;
size_t m_unique_id;
std::array<int, MAX_KEYS> m_pad_to_sdl;
};

View File

@ -14,25 +14,25 @@
*/
template <class T>
static void __forceinline set_bit(T &value, int bit)
static void __forceinline set_bit(T& value, int bit)
{
value |= (1 << bit);
value |= (1 << bit);
}
template <class T>
static void __forceinline clear_bit(T &value, int bit)
static void __forceinline clear_bit(T& value, int bit)
{
value &= ~(1 << bit);
value &= ~(1 << bit);
}
template <class T>
static void __forceinline toggle_bit(T &value, int bit)
static void __forceinline toggle_bit(T& value, int bit)
{
value ^= (1 << bit);
value ^= (1 << bit);
}
template <class T>
static bool __forceinline test_bit(T &value, int bit)
static bool __forceinline test_bit(T& value, int bit)
{
return (value & (1 << bit));
return (value & (1 << bit));
}

View File

@ -18,21 +18,21 @@
__forceinline void set_keyboard_key(int pad, int keysym, int index)
{
g_conf.keysym_map[pad][keysym] = index;
g_conf.keysym_map[pad][keysym] = index;
}
__forceinline int get_keyboard_key(int pad, int keysym)
{
// You must use find instead of []
// [] will create an element if the key does not exist and return 0
std::map<u32, u32>::iterator it = g_conf.keysym_map[pad].find(keysym);
if (it != g_conf.keysym_map[pad].end())
return it->second;
else
return -1;
// You must use find instead of []
// [] will create an element if the key does not exist and return 0
std::map<u32, u32>::iterator it = g_conf.keysym_map[pad].find(keysym);
if (it != g_conf.keysym_map[pad].end())
return it->second;
else
return -1;
}
__forceinline bool IsAnalogKey(int index)
{
return ((index >= PAD_L_UP) && (index <= PAD_R_LEFT));
return ((index >= PAD_L_UP) && (index <= PAD_R_LEFT));
}

View File

@ -24,101 +24,103 @@ extern bool IsAnalogKey(int index);
class PADconf
{
u32 ff_intensity;
u32 sensibility;
u32 ff_intensity;
u32 sensibility;
public:
union
{
struct
{
u16 forcefeedback : 1;
u16 reverse_lx : 1;
u16 reverse_ly : 1;
u16 reverse_rx : 1;
u16 reverse_ry : 1;
u16 mouse_l : 1;
u16 mouse_r : 1;
u16 _free : 9; // The 9 remaining bits are unused, do what you wish with them ;)
} pad_options[GAMEPAD_NUMBER]; // One for each pads
u32 packed_options; // Only first 8 bits of each 16 bits series are really used, rest is padding
};
union
{
struct
{
u16 forcefeedback : 1;
u16 reverse_lx : 1;
u16 reverse_ly : 1;
u16 reverse_rx : 1;
u16 reverse_ry : 1;
u16 mouse_l : 1;
u16 mouse_r : 1;
u16 _free : 9; // The 9 remaining bits are unused, do what you wish with them ;)
} pad_options[GAMEPAD_NUMBER]; // One for each pads
u32 packed_options; // Only first 8 bits of each 16 bits series are really used, rest is padding
};
u32 log;
u32 ftw;
std::map<u32, u32> keysym_map[GAMEPAD_NUMBER];
std::array<size_t, GAMEPAD_NUMBER> unique_id;
std::vector<std::string> sdl2_mapping;
u32 log;
u32 ftw;
std::map<u32, u32> keysym_map[GAMEPAD_NUMBER];
std::array<size_t, GAMEPAD_NUMBER> unique_id;
std::vector<std::string> sdl2_mapping;
PADconf() { init(); }
PADconf() { init(); }
void init()
{
log = 0;
ftw = 1;
packed_options = 0;
ff_intensity = 0x7FFF; // set it at max value by default
sensibility = 100;
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
keysym_map[pad].clear();
}
unique_id.fill(0);
sdl2_mapping.clear();
}
void init()
{
log = 0;
ftw = 1;
packed_options = 0;
ff_intensity = 0x7FFF; // set it at max value by default
sensibility = 100;
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
{
keysym_map[pad].clear();
}
unique_id.fill(0);
sdl2_mapping.clear();
}
void set_joy_uid(u32 pad, size_t uid)
{
if (pad < GAMEPAD_NUMBER)
unique_id[pad] = uid;
}
void set_joy_uid(u32 pad, size_t uid)
{
if (pad < GAMEPAD_NUMBER)
unique_id[pad] = uid;
}
size_t get_joy_uid(u32 pad)
{
if (pad < GAMEPAD_NUMBER)
return unique_id[pad];
else
return 0;
}
size_t get_joy_uid(u32 pad)
{
if (pad < GAMEPAD_NUMBER)
return unique_id[pad];
else
return 0;
}
/**
/**
* Return (a copy of) private memner ff_instensity
**/
u32 get_ff_intensity()
{
return ff_intensity;
}
u32 get_ff_intensity()
{
return ff_intensity;
}
/**
/**
* Set intensity while checking that the new value is within
* valid range, more than 0x7FFF will cause pad not to rumble(and less than 0 is obviously bad)
**/
void set_ff_intensity(u32 new_intensity)
{
if (new_intensity <= 0x7FFF) {
ff_intensity = new_intensity;
}
}
void set_ff_intensity(u32 new_intensity)
{
if (new_intensity <= 0x7FFF)
{
ff_intensity = new_intensity;
}
}
/**
/**
* Set sensibility value.
* There will be an upper range, and less than 0 is obviously wrong.
* We are doing object oriented code, so members are definitely not supposed to be public.
**/
void set_sensibility(u32 new_sensibility)
{
if (new_sensibility > 0)
{
sensibility = new_sensibility;
}
else
{
sensibility = 1;
}
}
void set_sensibility(u32 new_sensibility)
{
if (new_sensibility > 0)
{
sensibility = new_sensibility;
}
else
{
sensibility = 1;
}
}
u32 get_sensibility()
{
return sensibility;
}
u32 get_sensibility()
{
return sensibility;
}
};
extern PADconf g_conf;

View File

@ -23,104 +23,107 @@ extern std::string s_padstrIniPath;
void DefaultKeyboardValues()
{
set_keyboard_key(0, XK_a, PAD_L2);
set_keyboard_key(0, XK_semicolon, PAD_R2);
set_keyboard_key(0, XK_w, PAD_L1);
set_keyboard_key(0, XK_p, PAD_R1);
set_keyboard_key(0, XK_i, PAD_TRIANGLE);
set_keyboard_key(0, XK_l, PAD_CIRCLE);
set_keyboard_key(0, XK_k, PAD_CROSS);
set_keyboard_key(0, XK_j, PAD_SQUARE);
set_keyboard_key(0, XK_v, PAD_SELECT);
set_keyboard_key(0, XK_n, PAD_START);
set_keyboard_key(0, XK_e, PAD_UP);
set_keyboard_key(0, XK_f, PAD_RIGHT);
set_keyboard_key(0, XK_d, PAD_DOWN);
set_keyboard_key(0, XK_s, PAD_LEFT);
set_keyboard_key(0, XK_a, PAD_L2);
set_keyboard_key(0, XK_semicolon, PAD_R2);
set_keyboard_key(0, XK_w, PAD_L1);
set_keyboard_key(0, XK_p, PAD_R1);
set_keyboard_key(0, XK_i, PAD_TRIANGLE);
set_keyboard_key(0, XK_l, PAD_CIRCLE);
set_keyboard_key(0, XK_k, PAD_CROSS);
set_keyboard_key(0, XK_j, PAD_SQUARE);
set_keyboard_key(0, XK_v, PAD_SELECT);
set_keyboard_key(0, XK_n, PAD_START);
set_keyboard_key(0, XK_e, PAD_UP);
set_keyboard_key(0, XK_f, PAD_RIGHT);
set_keyboard_key(0, XK_d, PAD_DOWN);
set_keyboard_key(0, XK_s, PAD_LEFT);
}
void PADSaveConfig()
{
FILE *f;
FILE* f;
const std::string iniFile(s_padstrIniPath + "PAD.ini");
f = fopen(iniFile.c_str(), "w");
if (f == NULL) {
printf("PAD: failed to save ini %s\n", iniFile.c_str());
return;
}
const std::string iniFile(s_padstrIniPath + "PAD.ini");
f = fopen(iniFile.c_str(), "w");
if (f == NULL)
{
printf("PAD: failed to save ini %s\n", iniFile.c_str());
return;
}
fprintf(f, "first_time_wizard = %d\n", g_conf.ftw);
fprintf(f, "log = %d\n", g_conf.log);
fprintf(f, "options = %d\n", g_conf.packed_options);
fprintf(f, "mouse_sensibility = %d\n", g_conf.get_sensibility());
fprintf(f, "ff_intensity = %d\n", g_conf.get_ff_intensity());
fprintf(f, "uid[0] = %zu\n", g_conf.get_joy_uid(0));
fprintf(f, "uid[1] = %zu\n", g_conf.get_joy_uid(1));
fprintf(f, "first_time_wizard = %d\n", g_conf.ftw);
fprintf(f, "log = %d\n", g_conf.log);
fprintf(f, "options = %d\n", g_conf.packed_options);
fprintf(f, "mouse_sensibility = %d\n", g_conf.get_sensibility());
fprintf(f, "ff_intensity = %d\n", g_conf.get_ff_intensity());
fprintf(f, "uid[0] = %zu\n", g_conf.get_joy_uid(0));
fprintf(f, "uid[1] = %zu\n", g_conf.get_joy_uid(1));
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
for (auto const &it : g_conf.keysym_map[pad])
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it.first, it.second);
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
for (auto const& it : g_conf.keysym_map[pad])
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it.first, it.second);
for (auto const &it : g_conf.sdl2_mapping)
fprintf(f, "SDL2 = %s\n", it.c_str());
for (auto const& it : g_conf.sdl2_mapping)
fprintf(f, "SDL2 = %s\n", it.c_str());
fclose(f);
fclose(f);
}
void PADLoadConfig()
{
FILE *f;
bool have_user_setting = false;
FILE* f;
bool have_user_setting = false;
g_conf.init();
g_conf.init();
const std::string iniFile(s_padstrIniPath + "PAD.ini");
f = fopen(iniFile.c_str(), "r");
if (f == NULL) {
printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
PADSaveConfig(); //save and return
return;
}
const std::string iniFile(s_padstrIniPath + "PAD.ini");
f = fopen(iniFile.c_str(), "r");
if (f == NULL)
{
printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
PADSaveConfig(); //save and return
return;
}
u32 value;
u32 value;
if (fscanf(f, "first_time_wizard = %u\n", &value) == 1)
g_conf.ftw = value;
if (fscanf(f, "first_time_wizard = %u\n", &value) == 1)
g_conf.ftw = value;
if (fscanf(f, "log = %u\n", &value) == 1)
g_conf.log = value;
if (fscanf(f, "log = %u\n", &value) == 1)
g_conf.log = value;
if (fscanf(f, "options = %u\n", &value) == 1)
g_conf.packed_options = value;
if (fscanf(f, "options = %u\n", &value) == 1)
g_conf.packed_options = value;
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 1)
g_conf.set_sensibility(value);
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 1)
g_conf.set_sensibility(value);
if (fscanf(f, "ff_intensity = %u\n", &value) == 1)
g_conf.set_ff_intensity(value);
if (fscanf(f, "ff_intensity = %u\n", &value) == 1)
g_conf.set_ff_intensity(value);
size_t uid;
if (fscanf(f, "uid[0] = %zu\n", &uid) == 1)
g_conf.set_joy_uid(0, uid);
if (fscanf(f, "uid[1] = %zu\n", &uid) == 1)
g_conf.set_joy_uid(1, uid);
size_t uid;
if (fscanf(f, "uid[0] = %zu\n", &uid) == 1)
g_conf.set_joy_uid(0, uid);
if (fscanf(f, "uid[1] = %zu\n", &uid) == 1)
g_conf.set_joy_uid(1, uid);
u32 pad;
u32 keysym;
u32 index;
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;
}
u32 pad;
u32 keysym;
u32 index;
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;
}
char sdl2[512];
while (fscanf(f, "SDL2 = %511[^\n]\n", sdl2) == 1)
g_conf.sdl2_mapping.push_back(std::string(sdl2));
char sdl2[512];
while (fscanf(f, "SDL2 = %511[^\n]\n", sdl2) == 1)
g_conf.sdl2_mapping.push_back(std::string(sdl2));
if (!have_user_setting)
DefaultKeyboardValues();
if (!have_user_setting)
DefaultKeyboardValues();
fclose(f);
fclose(f);
}

View File

@ -28,36 +28,41 @@
#include "keyboard.h"
#ifdef _WIN32
char *KeysymToChar(int keysym)
char* KeysymToChar(int keysym)
{
LPWORD temp;
LPWORD temp;
ToAscii((UINT)keysym, NULL, NULL, temp, NULL);
return (char *)temp;
ToAscii((UINT)keysym, NULL, NULL, temp, NULL);
return (char*)temp;
}
#endif
/// g_key_status.press but with proper handling for analog buttons
static void PressButton(u32 pad, u32 button) {
// Analog controls.
if (IsAnalogKey(button)) {
switch (button) {
case PAD_R_LEFT:
case PAD_R_UP:
case PAD_L_LEFT:
case PAD_L_UP:
g_key_status.press(pad, button, -MAX_ANALOG_VALUE);
break;
case PAD_R_RIGHT:
case PAD_R_DOWN:
case PAD_L_RIGHT:
case PAD_L_DOWN:
g_key_status.press(pad, button, MAX_ANALOG_VALUE);
break;
}
} else {
g_key_status.press(pad, button);
}
static void PressButton(u32 pad, u32 button)
{
// Analog controls.
if (IsAnalogKey(button))
{
switch (button)
{
case PAD_R_LEFT:
case PAD_R_UP:
case PAD_L_LEFT:
case PAD_L_UP:
g_key_status.press(pad, button, -MAX_ANALOG_VALUE);
break;
case PAD_R_RIGHT:
case PAD_R_DOWN:
case PAD_L_RIGHT:
case PAD_L_DOWN:
g_key_status.press(pad, button, MAX_ANALOG_VALUE);
break;
}
}
else
{
g_key_status.press(pad, button);
}
}
#if defined(__APPLE__)
@ -69,41 +74,54 @@ 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++) {
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) {
bool state;
if (key.first >> 16 == 0) {
state = CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key.first);
} else {
state = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, (CGMouseButton)(key.first & 0xFFFF));
}
if (state) PressButton(pad, key.second);
}
}
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)
{
bool state;
if (key.first >> 16 == 0)
{
state = CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, key.first);
}
else
{
state = CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, (CGMouseButton)(key.first & 0xFFFF));
}
if (state)
PressButton(pad, key.second);
}
}
}
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)) {
pkey = key == kVK_Escape ? 0 : key;
return true;
}
}
for (auto btn : {kCGMouseButtonLeft, kCGMouseButtonCenter, kCGMouseButtonRight}) {
if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, btn)) {
pkey = btn | (1 << 16);
return true;
}
}
return false;
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))
{
pkey = key == kVK_Escape ? 0 : key;
return true;
}
}
for (auto btn : {kCGMouseButtonLeft, kCGMouseButtonCenter, kCGMouseButtonRight})
{
if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, btn))
{
pkey = btn | (1 << 16);
return true;
}
}
return false;
}
#elif defined(__unix__)
static bool s_grab_input = false;
@ -111,243 +129,265 @@ static bool s_Shift = false;
static unsigned int s_previous_mouse_x = 0;
static unsigned int s_previous_mouse_y = 0;
void AnalyzeKeyEvent(keyEvent &evt)
void AnalyzeKeyEvent(keyEvent& evt)
{
KeySym key = (KeySym)evt.key;
int pad = 0;
int index = -1;
KeySym key = (KeySym)evt.key;
int pad = 0;
int index = -1;
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
int tmp_index = get_keyboard_key(cpad, key);
if (tmp_index != -1) {
pad = cpad;
index = tmp_index;
}
}
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++)
{
int tmp_index = get_keyboard_key(cpad, key);
if (tmp_index != -1)
{
pad = cpad;
index = tmp_index;
}
}
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_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 {
s_grab_input = false;
XUngrabPointer(GSdsp, CurrentTime);
XUngrabKeyboard(GSdsp, CurrentTime);
}
}
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_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
{
s_grab_input = false;
XUngrabPointer(GSdsp, CurrentTime);
XUngrabKeyboard(GSdsp, CurrentTime);
}
}
if (index != -1)
PressButton(pad, index);
if (index != -1)
PressButton(pad, index);
//PAD_LOG("Key pressed:%d\n", index);
//PAD_LOG("Key pressed:%d\n", index);
event.evt = KEYPRESS;
event.key = key;
break;
event.evt = KEYPRESS;
event.key = key;
break;
case KeyRelease:
if (key == XK_Shift_R || key == XK_Shift_L)
s_Shift = false;
case KeyRelease:
if (key == XK_Shift_R || key == XK_Shift_L)
s_Shift = false;
if (index != -1)
g_key_status.release(pad, index);
if (index != -1)
g_key_status.release(pad, index);
event.evt = KEYRELEASE;
event.key = key;
break;
event.evt = KEYRELEASE;
event.key = key;
break;
case FocusIn:
break;
case FocusIn:
break;
case FocusOut:
s_Shift = false;
break;
case FocusOut:
s_Shift = false;
break;
case ButtonPress:
if (index != -1)
g_key_status.press(pad, index);
break;
case ButtonPress:
if (index != -1)
g_key_status.press(pad, index);
break;
case ButtonRelease:
if (index != -1)
g_key_status.release(pad, index);
break;
case ButtonRelease:
if (index != -1)
g_key_status.release(pad, index);
break;
case MotionNotify:
// FIXME: How to handle when the mouse does not move, no event generated!!!
// 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) {
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) {
pad_x = PAD_R_RIGHT;
pad_y = PAD_R_UP;
} else {
pad_x = PAD_L_RIGHT;
pad_y = PAD_L_UP;
}
case MotionNotify:
// FIXME: How to handle when the mouse does not move, no event generated!!!
// 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)
{
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)
{
pad_x = PAD_R_RIGHT;
pad_y = PAD_R_UP;
}
else
{
pad_x = PAD_L_RIGHT;
pad_y = PAD_L_UP;
}
unsigned x = evt.key & 0xFFFF;
unsigned int value = (s_previous_mouse_x > x) ? s_previous_mouse_x - x : x - s_previous_mouse_x;
value *= g_conf.get_sensibility();
unsigned x = evt.key & 0xFFFF;
unsigned int value = (s_previous_mouse_x > x) ? s_previous_mouse_x - x : x - s_previous_mouse_x;
value *= g_conf.get_sensibility();
if (x == 0)
g_key_status.press(pad, pad_x, -MAX_ANALOG_VALUE);
else if (x == 0xFFFF)
g_key_status.press(pad, pad_x, MAX_ANALOG_VALUE);
else if (x < (s_previous_mouse_x - 2))
g_key_status.press(pad, pad_x, -value);
else if (x > (s_previous_mouse_x + 2))
g_key_status.press(pad, pad_x, value);
else
g_key_status.release(pad, pad_x);
if (x == 0)
g_key_status.press(pad, pad_x, -MAX_ANALOG_VALUE);
else if (x == 0xFFFF)
g_key_status.press(pad, pad_x, MAX_ANALOG_VALUE);
else if (x < (s_previous_mouse_x - 2))
g_key_status.press(pad, pad_x, -value);
else if (x > (s_previous_mouse_x + 2))
g_key_status.press(pad, pad_x, value);
else
g_key_status.release(pad, pad_x);
unsigned y = evt.key >> 16;
value = (s_previous_mouse_y > y) ? s_previous_mouse_y - y : y - s_previous_mouse_y;
value *= g_conf.get_sensibility();
unsigned y = evt.key >> 16;
value = (s_previous_mouse_y > y) ? s_previous_mouse_y - y : y - s_previous_mouse_y;
value *= g_conf.get_sensibility();
if (y == 0)
g_key_status.press(pad, pad_y, -MAX_ANALOG_VALUE);
else if (y == 0xFFFF)
g_key_status.press(pad, pad_y, MAX_ANALOG_VALUE);
else if (y < (s_previous_mouse_y - 2))
g_key_status.press(pad, pad_y, -value);
else if (y > (s_previous_mouse_y + 2))
g_key_status.press(pad, pad_y, value);
else
g_key_status.release(pad, pad_y);
if (y == 0)
g_key_status.press(pad, pad_y, -MAX_ANALOG_VALUE);
else if (y == 0xFFFF)
g_key_status.press(pad, pad_y, MAX_ANALOG_VALUE);
else if (y < (s_previous_mouse_y - 2))
g_key_status.press(pad, pad_y, -value);
else if (y > (s_previous_mouse_y + 2))
g_key_status.press(pad, pad_y, value);
else
g_key_status.release(pad, pad_y);
s_previous_mouse_x = x;
s_previous_mouse_y = y;
}
s_previous_mouse_x = x;
s_previous_mouse_y = y;
}
break;
}
break;
}
}
void UpdateKeyboardInput()
{
keyEvent evt = {0};
XEvent E = {0};
keyEvent evt = {0};
XEvent E = {0};
// Keyboard input send by PCSX2
g_ev_fifo.consume_all(AnalyzeKeyEvent);
// Keyboard input send by PCSX2
g_ev_fifo.consume_all(AnalyzeKeyEvent);
// keyboard input
while (XPending(GSdsp) > 0) {
XNextEvent(GSdsp, &E);
// keyboard input
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) {
case MotionNotify:
evt.key = (E.xbutton.x & 0xFFFF) | (E.xbutton.y << 16);
break;
case ButtonRelease:
case ButtonPress:
evt.key = E.xbutton.button;
break;
default:
evt.key = (int)XLookupKeysym(&E.xkey, 0);
}
// 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)
{
case MotionNotify:
evt.key = (E.xbutton.x & 0xFFFF) | (E.xbutton.y << 16);
break;
case ButtonRelease:
case ButtonPress:
evt.key = E.xbutton.button;
break;
default:
evt.key = (int)XLookupKeysym(&E.xkey, 0);
}
AnalyzeKeyEvent(evt);
}
AnalyzeKeyEvent(evt);
}
}
bool PollForNewKeyboardKeys(u32 &pkey)
bool PollForNewKeyboardKeys(u32& pkey)
{
GdkEvent *ev = gdk_event_get();
GdkEvent* ev = gdk_event_get();
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) {
pkey = ev->button.button;
return true;
}
}
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)
{
pkey = ev->button.button;
return true;
}
}
return false;
return false;
}
#else
LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static bool lbutton = false, rbutton = false;
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
{
g_key_status.keyboard_state_acces(pad);
}
static bool lbutton = false, rbutton = false;
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
{
g_key_status.keyboard_state_acces(pad);
}
switch (msg) {
case WM_KEYDOWN:
if (lParam & 0x40000000)
return TRUE;
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++) {
assert(0);
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)) {
g_key_status.press(pad, i);
break;
}
#endif
}
}
}
}
event.evt = KEYPRESS;
event.key = wParam;
break;
event.evt = KEYPRESS;
event.key = wParam;
break;
case WM_KEYUP:
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
for (int i = 0; i < MAX_KEYS; i++) {
assert(0);
case WM_KEYUP:
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)) {
g_key_status.release(pad, i);
break;
}
#endif
}
}
}
}
event.evt = KEYRELEASE;
event.key = wParam;
break;
event.evt = KEYRELEASE;
event.key = wParam;
break;
case WM_DESTROY:
case WM_QUIT:
event.evt = KEYPRESS;
event.key = VK_ESCAPE;
return GSwndProc(hWnd, msg, wParam, lParam);
case WM_DESTROY:
case WM_QUIT:
event.evt = KEYPRESS;
event.key = VK_ESCAPE;
return GSwndProc(hWnd, msg, wParam, lParam);
default:
return GSwndProc(hWnd, msg, wParam, lParam);
}
default:
return GSwndProc(hWnd, msg, wParam, lParam);
}
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
g_key_status.commit_status(pad);
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
g_key_status.commit_status(pad);
return TRUE;
return TRUE;
}
#endif

View File

@ -24,17 +24,17 @@
#if defined(__unix__) || defined(__APPLE__)
extern void AnalyzeKeyEvent(keyEvent &evt);
extern void AnalyzeKeyEvent(keyEvent& evt);
extern void UpdateKeyboardInput();
extern bool PollForNewKeyboardKeys(u32 &pkey);
extern bool PollForNewKeyboardKeys(u32& pkey);
#ifndef __APPLE__
extern Display *GSdsp;
extern Display* GSdsp;
extern Window GSwin;
#endif
#else
extern char *KeysymToChar(int keysym);
extern char* KeysymToChar(int keysym);
extern WNDPROC GSwndProc;
extern HWND GShwnd;

View File

@ -23,102 +23,106 @@
#include "wx_dialog/dialog.h"
#ifndef __APPLE__
Display *GSdsp;
Display* GSdsp;
Window GSwin;
#endif
static void SysMessage(const char *fmt, ...)
static void SysMessage(const char* fmt, ...)
{
va_list list;
char msg[512];
va_list list;
char msg[512];
va_start(list, fmt);
vsprintf(msg, fmt, list);
va_end(list);
va_start(list, 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;
wxMessageDialog dialog(nullptr, msg, "Info", wxOK);
dialog.ShowModal();
wxMessageDialog dialog(nullptr, msg, "Info", wxOK);
dialog.ShowModal();
}
s32 _PADopen(void *pDsp)
s32 _PADopen(void* pDsp)
{
#ifndef __APPLE__
GSdsp = *(Display **)pDsp;
GSwin = (Window) * (((u32 *)pDsp) + 1);
GSdsp = *(Display**)pDsp;
GSwin = (Window) * (((u32*)pDsp) + 1);
#endif
return 0;
return 0;
}
void _PADclose()
{
s_vgamePad.clear();
s_vgamePad.clear();
}
void PollForJoystickInput(int cpad)
{
int index = GamePad::uid_to_index(cpad);
if (index < 0)
return;
int index = GamePad::uid_to_index(cpad);
if (index < 0)
return;
auto &gamePad = s_vgamePad[index];
auto& gamePad = s_vgamePad[index];
gamePad->UpdateGamePadState();
gamePad->UpdateGamePadState();
for (int i = 0; i < MAX_KEYS; i++) {
s32 value = gamePad->GetInput((gamePadValues)i);
if (value != 0)
g_key_status.press(cpad, i, value);
else
g_key_status.release(cpad, 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);
else
g_key_status.release(cpad, i);
}
}
void PADupdate(int pad)
{
#ifndef __APPLE__
// Gamepad inputs don't count as an activity. Therefore screensaver will
// be fired after a couple of minute.
// Emulate an user activity
static int count = 0;
count++;
if ((count & 0xFFF) == 0) {
// 1 call every 4096 Vsync is enough
XResetScreenSaver(GSdsp);
}
// Gamepad inputs don't count as an activity. Therefore screensaver will
// be fired after a couple of minute.
// Emulate an user activity
static int count = 0;
count++;
if ((count & 0xFFF) == 0)
{
// 1 call every 4096 Vsync is enough
XResetScreenSaver(GSdsp);
}
#endif
// Actually PADupdate is always call with pad == 0. So you need to update both
// pads -- Gregory
// Actually PADupdate is always call with pad == 0. So you need to update both
// pads -- Gregory
// 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++) {
g_key_status.keyboard_state_acces(cpad);
}
UpdateKeyboardInput();
// 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++)
{
g_key_status.keyboard_state_acces(cpad);
}
UpdateKeyboardInput();
// Get joystick state + Commit
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
g_key_status.joystick_state_acces(cpad);
// Get joystick state + Commit
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++)
{
g_key_status.joystick_state_acces(cpad);
PollForJoystickInput(cpad);
PollForJoystickInput(cpad);
g_key_status.commit_status(cpad);
}
g_key_status.commit_status(cpad);
}
Pad::rumble_all();
Pad::rumble_all();
}
void PADconfigure()
{
ScopedCoreThreadPause paused_core;
PADLoadConfig();
ScopedCoreThreadPause paused_core;
PADLoadConfig();
DisplayDialog();
paused_core.AllowResume();
return;
DisplayDialog();
paused_core.AllowResume();
return;
}

File diff suppressed because it is too large Load Diff

View File

@ -3,5 +3,5 @@
#include <gio/gio.h>
extern GResource *PAD_res_get_resource (void);
extern GResource* PAD_res_get_resource(void);
#endif

View File

@ -29,8 +29,8 @@ static const u8 setNativeMode[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A};
static u8 queryMaskMode[7] = {0x5A, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x5A};
static const u8 queryAct[2][7] = {
{0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A},
{0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14}};
{0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A},
{0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14}};
QueryInfo query;
Pad pads[2][4];
@ -42,29 +42,30 @@ int slots[2] = {0, 0};
void QueryInfo::reset()
{
port = 0;
slot = 0;
lastByte = 1;
currentCommand = 0;
numBytes = 0;
queryDone = 1;
memset(response, 0xF3, sizeof(response));
port = 0;
slot = 0;
lastByte = 1;
currentCommand = 0;
numBytes = 0;
queryDone = 1;
memset(response, 0xF3, sizeof(response));
}
u8 QueryInfo::start_poll(int _port)
{
if (port > 1) {
reset();
return 0;
}
if (port > 1)
{
reset();
return 0;
}
queryDone = 0;
port = _port;
slot = slots[port];
numBytes = 2;
lastByte = 0;
queryDone = 0;
port = _port;
slot = slots[port];
numBytes = 2;
lastByte = 0;
return 0xFF;
return 0xFF;
}
//////////////////////////////////////////////////////////////////////
@ -73,7 +74,7 @@ u8 QueryInfo::start_poll(int _port)
void Pad::set_mode(int _mode)
{
mode = _mode;
mode = _mode;
#if 0
fprintf(stdout, "OnePad: set new pad mode=");
@ -90,38 +91,40 @@ void Pad::set_mode(int _mode)
void Pad::set_vibrate(int motor, u8 val)
{
nextVibrate[motor] = val;
nextVibrate[motor] = val;
}
void Pad::reset_vibrate()
{
set_vibrate(0, 0);
set_vibrate(1, 0);
memset(vibrate, 0xFF, sizeof(vibrate));
vibrate[0] = 0x5A;
set_vibrate(0, 0);
set_vibrate(1, 0);
memset(vibrate, 0xFF, sizeof(vibrate));
vibrate[0] = 0x5A;
}
void Pad::reset()
{
memset(this, 0, sizeof(PadFreezeData));
memset(this, 0, sizeof(PadFreezeData));
set_mode(MODE_DIGITAL);
umask[0] = umask[1] = 0xFF;
set_mode(MODE_DIGITAL);
umask[0] = umask[1] = 0xFF;
// Sets up vibrate variable.
reset_vibrate();
// Sets up vibrate variable.
reset_vibrate();
}
void Pad::rumble(unsigned port)
{
for (unsigned motor = 0; motor < 2; motor++) {
// TODO: Probably be better to send all of these at once.
if (nextVibrate[motor] | currentVibrate[motor]) {
currentVibrate[motor] = nextVibrate[motor];
for (unsigned motor = 0; motor < 2; motor++)
{
// TODO: Probably be better to send all of these at once.
if (nextVibrate[motor] | currentVibrate[motor])
{
currentVibrate[motor] = nextVibrate[motor];
GamePad::DoRumble(motor, port);
}
}
GamePad::DoRumble(motor, port);
}
}
}
void Pad::stop_vibrate_all()
@ -132,24 +135,24 @@ void Pad::stop_vibrate_all()
SetVibrate(i&1, i>>1, 1, 0);
}
#endif
// FIXME equivalent ?
for (int port = 0; port < 2; port++)
for (int slot = 0; slot < 4; slot++)
pads[port][slot].reset_vibrate();
// FIXME equivalent ?
for (int port = 0; port < 2; port++)
for (int slot = 0; slot < 4; slot++)
pads[port][slot].reset_vibrate();
}
void Pad::reset_all()
{
for (int port = 0; port < 2; port++)
for (int slot = 0; slot < 4; slot++)
pads[port][slot].reset();
for (int port = 0; port < 2; port++)
for (int slot = 0; slot < 4; slot++)
pads[port][slot].reset();
}
void Pad::rumble_all()
{
for (unsigned port = 0; port < 2; port++)
for (unsigned slot = 0; slot < 4; slot++)
pads[port][slot].rumble(port);
for (unsigned port = 0; port < 2; port++)
for (unsigned slot = 0; slot < 4; slot++)
pads[port][slot].rumble(port);
}
//////////////////////////////////////////////////////////////////////
@ -163,41 +166,47 @@ inline bool IsDualshock2()
return config.padConfigs[query.port][query.slot].type == Dualshock2Pad ||
(config.padConfigs[query.port][query.slot].type == GuitarPad && config.GH2);
#else
return true;
return true;
#endif
}
u8 pad_start_poll(u8 pad)
{
return query.start_poll(pad - 1);
return query.start_poll(pad - 1);
}
u8 pad_poll(u8 value)
{
if (query.lastByte + 1 >= query.numBytes) {
return 0;
}
if (query.lastByte && query.queryDone) {
return query.response[++query.lastByte];
}
if (query.lastByte + 1 >= query.numBytes)
{
return 0;
}
if (query.lastByte && query.queryDone)
{
return query.response[++query.lastByte];
}
Pad *pad = &pads[query.port][query.slot];
Pad* pad = &pads[query.port][query.slot];
if (query.lastByte == 0) {
query.lastByte++;
query.currentCommand = value;
if (query.lastByte == 0)
{
query.lastByte++;
query.currentCommand = value;
switch (value) {
case CMD_CONFIG_MODE:
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)
switch (value)
{
case CMD_CONFIG_MODE:
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: {
query.response[2] = 0x5A;
case CMD_READ_DATA_AND_VIBRATE:
{
query.response[2] = 0x5A;
#if 0
int i;
Update(query.port, query.slot);
@ -234,39 +243,41 @@ u8 pad_poll(u8 value)
b1=b1 & 0x1f;
#endif
uint16_t buttons = g_key_status.get(query.port);
uint16_t buttons = g_key_status.get(query.port);
query.numBytes = 5;
query.numBytes = 5;
query.response[3] = (buttons >> 8) & 0xFF;
query.response[4] = (buttons >> 0) & 0xFF;
query.response[3] = (buttons >> 8) & 0xFF;
query.response[4] = (buttons >> 0) & 0xFF;
if (pad->mode != MODE_DIGITAL) { // ANALOG || DS2 native
query.numBytes = 9;
if (pad->mode != MODE_DIGITAL)
{ // ANALOG || DS2 native
query.numBytes = 9;
query.response[5] = g_key_status.get(query.port, PAD_R_RIGHT);
query.response[6] = g_key_status.get(query.port, PAD_R_UP);
query.response[7] = g_key_status.get(query.port, PAD_L_RIGHT);
query.response[8] = g_key_status.get(query.port, PAD_L_UP);
query.response[5] = g_key_status.get(query.port, PAD_R_RIGHT);
query.response[6] = g_key_status.get(query.port, PAD_R_UP);
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
query.numBytes = 21;
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;
query.response[10] = !test_bit(buttons, 15) ? g_key_status.get(query.port, PAD_LEFT) : 0;
query.response[11] = !test_bit(buttons, 12) ? g_key_status.get(query.port, PAD_UP) : 0;
query.response[12] = !test_bit(buttons, 14) ? g_key_status.get(query.port, PAD_DOWN) : 0;
query.response[9] = !test_bit(buttons, 13) ? g_key_status.get(query.port, PAD_RIGHT) : 0;
query.response[10] = !test_bit(buttons, 15) ? g_key_status.get(query.port, PAD_LEFT) : 0;
query.response[11] = !test_bit(buttons, 12) ? g_key_status.get(query.port, PAD_UP) : 0;
query.response[12] = !test_bit(buttons, 14) ? g_key_status.get(query.port, PAD_DOWN) : 0;
query.response[13] = !test_bit(buttons, 4) ? g_key_status.get(query.port, PAD_TRIANGLE) : 0;
query.response[14] = !test_bit(buttons, 5) ? g_key_status.get(query.port, PAD_CIRCLE) : 0;
query.response[15] = !test_bit(buttons, 6) ? g_key_status.get(query.port, PAD_CROSS) : 0;
query.response[16] = !test_bit(buttons, 7) ? g_key_status.get(query.port, PAD_SQUARE) : 0;
query.response[17] = !test_bit(buttons, 2) ? g_key_status.get(query.port, PAD_L1) : 0;
query.response[18] = !test_bit(buttons, 3) ? g_key_status.get(query.port, PAD_R1) : 0;
query.response[19] = !test_bit(buttons, 0) ? g_key_status.get(query.port, PAD_L2) : 0;
query.response[20] = !test_bit(buttons, 1) ? g_key_status.get(query.port, PAD_R2) : 0;
}
}
query.response[13] = !test_bit(buttons, 4) ? g_key_status.get(query.port, PAD_TRIANGLE) : 0;
query.response[14] = !test_bit(buttons, 5) ? g_key_status.get(query.port, PAD_CIRCLE) : 0;
query.response[15] = !test_bit(buttons, 6) ? g_key_status.get(query.port, PAD_CROSS) : 0;
query.response[16] = !test_bit(buttons, 7) ? g_key_status.get(query.port, PAD_SQUARE) : 0;
query.response[17] = !test_bit(buttons, 2) ? g_key_status.get(query.port, PAD_L1) : 0;
query.response[18] = !test_bit(buttons, 3) ? g_key_status.get(query.port, PAD_R1) : 0;
query.response[19] = !test_bit(buttons, 0) ? g_key_status.get(query.port, PAD_L2) : 0;
query.response[20] = !test_bit(buttons, 1) ? g_key_status.get(query.port, PAD_R2) : 0;
}
}
#if 0
query.response[3] = b1;
@ -303,160 +314,184 @@ u8 pad_poll(u8 value)
}
}
#endif
}
}
query.lastByte = 1;
return pad->mode;
query.lastByte = 1;
return pad->mode;
case CMD_SET_VREF_PARAM:
query.set_final_result(noclue);
break;
case CMD_SET_VREF_PARAM:
query.set_final_result(noclue);
break;
case CMD_QUERY_DS2_ANALOG_MODE:
// Right? Wrong? No clue.
if (pad->mode == MODE_DIGITAL) {
queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0;
queryMaskMode[6] = 0x00;
} else {
queryMaskMode[1] = pad->umask[0];
queryMaskMode[2] = pad->umask[1];
queryMaskMode[3] = 0x03;
// Not entirely sure about this.
//queryMaskMode[3] = 0x01 | (pad->mode == MODE_DS2_NATIVE)*2;
queryMaskMode[6] = 0x5A;
}
query.set_final_result(queryMaskMode);
break;
case CMD_QUERY_DS2_ANALOG_MODE:
// Right? Wrong? No clue.
if (pad->mode == MODE_DIGITAL)
{
queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0;
queryMaskMode[6] = 0x00;
}
else
{
queryMaskMode[1] = pad->umask[0];
queryMaskMode[2] = pad->umask[1];
queryMaskMode[3] = 0x03;
// Not entirely sure about this.
//queryMaskMode[3] = 0x01 | (pad->mode == MODE_DS2_NATIVE)*2;
queryMaskMode[6] = 0x5A;
}
query.set_final_result(queryMaskMode);
break;
case CMD_SET_MODE_AND_LOCK:
query.set_result(setMode);
pad->reset_vibrate();
break;
case CMD_SET_MODE_AND_LOCK:
query.set_result(setMode);
pad->reset_vibrate();
break;
case CMD_QUERY_MODEL_AND_MODE:
if (IsDualshock2()) {
query.set_final_result(queryModelDS2);
} else {
query.set_final_result(queryModelDS1);
}
// Not digital mode.
query.response[5] = (pad->mode & 0xF) != 1;
break;
case CMD_QUERY_MODEL_AND_MODE:
if (IsDualshock2())
{
query.set_final_result(queryModelDS2);
}
else
{
query.set_final_result(queryModelDS1);
}
// Not digital mode.
query.response[5] = (pad->mode & 0xF) != 1;
break;
case CMD_QUERY_ACT:
query.set_result(queryAct[0]);
break;
case CMD_QUERY_ACT:
query.set_result(queryAct[0]);
break;
case CMD_QUERY_COMB:
query.set_final_result(queryComb);
break;
case CMD_QUERY_COMB:
query.set_final_result(queryComb);
break;
case CMD_QUERY_MODE:
query.set_result(queryMode);
break;
case CMD_QUERY_MODE:
query.set_result(queryMode);
break;
case CMD_VIBRATION_TOGGLE:
memcpy(query.response + 2, pad->vibrate, 7);
query.numBytes = 9;
//query.set_result(pad->vibrate); // warning copy 7b not 8 (but it is really important?)
pad->reset_vibrate();
break;
case CMD_VIBRATION_TOGGLE:
memcpy(query.response + 2, pad->vibrate, 7);
query.numBytes = 9;
//query.set_result(pad->vibrate); // warning copy 7b not 8 (but it is really important?)
pad->reset_vibrate();
break;
case CMD_SET_DS2_NATIVE_MODE:
if (IsDualshock2()) {
query.set_result(setNativeMode);
} else {
query.set_final_result(setNativeMode);
}
break;
case CMD_SET_DS2_NATIVE_MODE:
if (IsDualshock2())
{
query.set_result(setNativeMode);
}
else
{
query.set_final_result(setNativeMode);
}
break;
default:
query.numBytes = 0;
query.queryDone = 1;
break;
}
default:
query.numBytes = 0;
query.queryDone = 1;
break;
}
return 0xF3;
return 0xF3;
}
else
{
query.lastByte++;
} else {
query.lastByte++;
switch (query.currentCommand)
{
case CMD_READ_DATA_AND_VIBRATE:
if (query.lastByte == pad->vibrateI[0])
pad->set_vibrate(1, 255 * (value & 1));
else if (query.lastByte == pad->vibrateI[1])
pad->set_vibrate(0, value);
switch (query.currentCommand) {
case CMD_READ_DATA_AND_VIBRATE:
if (query.lastByte == pad->vibrateI[0])
pad->set_vibrate(1, 255 * (value & 1));
else if (query.lastByte == pad->vibrateI[1])
pad->set_vibrate(0, value);
break;
break;
case CMD_CONFIG_MODE:
if (query.lastByte == 3)
{
query.queryDone = 1;
pad->config = value;
}
break;
case CMD_CONFIG_MODE:
if (query.lastByte == 3) {
query.queryDone = 1;
pad->config = value;
}
break;
case CMD_SET_MODE_AND_LOCK:
if (query.lastByte == 3 && value < 2)
{
pad->set_mode(value ? MODE_ANALOG : MODE_DIGITAL);
}
else if (query.lastByte == 4)
{
if (value == 3)
pad->modeLock = 3;
else
pad->modeLock = 0;
case CMD_SET_MODE_AND_LOCK:
if (query.lastByte == 3 && value < 2) {
pad->set_mode(value ? MODE_ANALOG : MODE_DIGITAL);
} else if (query.lastByte == 4) {
if (value == 3)
pad->modeLock = 3;
else
pad->modeLock = 0;
query.queryDone = 1;
}
break;
query.queryDone = 1;
}
break;
case CMD_QUERY_ACT:
if (query.lastByte == 3)
{
if (value < 2)
query.set_result(queryAct[value]);
// bunch of 0's
// else query.set_result(setMode);
query.queryDone = 1;
}
break;
case CMD_QUERY_ACT:
if (query.lastByte == 3) {
if (value < 2)
query.set_result(queryAct[value]);
// bunch of 0's
// else query.set_result(setMode);
query.queryDone = 1;
}
break;
case CMD_QUERY_MODE:
if (query.lastByte == 3 && value < 2)
{
query.response[6] = 4 + value * 3;
query.queryDone = 1;
}
// bunch of 0's
//else data = setMode;
break;
case CMD_QUERY_MODE:
if (query.lastByte == 3 && value < 2) {
query.response[6] = 4 + value * 3;
query.queryDone = 1;
}
// bunch of 0's
//else data = setMode;
break;
case CMD_VIBRATION_TOGGLE:
if (query.lastByte >= 3)
{
if (value == 0)
{
pad->vibrateI[0] = (u8)query.lastByte;
}
else if (value == 1)
{
pad->vibrateI[1] = (u8)query.lastByte;
}
pad->vibrate[query.lastByte - 2] = value;
}
break;
case CMD_VIBRATION_TOGGLE:
if (query.lastByte >= 3) {
if (value == 0) {
pad->vibrateI[0] = (u8)query.lastByte;
} else if (value == 1) {
pad->vibrateI[1] = (u8)query.lastByte;
}
pad->vibrate[query.lastByte - 2] = value;
}
break;
case CMD_SET_DS2_NATIVE_MODE:
if (query.lastByte == 3 || query.lastByte == 4)
{
pad->umask[query.lastByte - 3] = value;
}
else if (query.lastByte == 5)
{
if (!(value & 1))
pad->set_mode(MODE_DIGITAL);
else if (!(value & 2))
pad->set_mode(MODE_ANALOG);
else
pad->set_mode(MODE_DS2_NATIVE);
}
break;
case CMD_SET_DS2_NATIVE_MODE:
if (query.lastByte == 3 || query.lastByte == 4) {
pad->umask[query.lastByte - 3] = value;
} else if (query.lastByte == 5) {
if (!(value & 1))
pad->set_mode(MODE_DIGITAL);
else if (!(value & 2))
pad->set_mode(MODE_ANALOG);
else
pad->set_mode(MODE_DS2_NATIVE);
}
break;
default:
return 0;
}
default:
return 0;
}
return query.response[query.lastByte];
}
return query.response[query.lastByte];
}
}

View File

@ -22,87 +22,87 @@
// The state of the PS2 bus
struct QueryInfo
{
u8 port;
u8 slot;
u8 lastByte;
u8 currentCommand;
u8 numBytes;
u8 queryDone;
u8 response[42];
u8 port;
u8 slot;
u8 lastByte;
u8 currentCommand;
u8 numBytes;
u8 queryDone;
u8 response[42];
void reset();
u8 start_poll(int port);
void reset();
u8 start_poll(int port);
template <size_t S>
void set_result(const u8 (&rsp)[S])
{
memcpy(response + 2, rsp, S);
numBytes = 2 + S;
}
template <size_t S>
void set_result(const u8 (&rsp)[S])
{
memcpy(response + 2, rsp, S);
numBytes = 2 + S;
}
template <size_t S>
void set_final_result(const u8 (&rsp)[S])
{
set_result(rsp);
queryDone = 1;
}
template <size_t S>
void set_final_result(const u8 (&rsp)[S])
{
set_result(rsp);
queryDone = 1;
}
};
// Freeze data, for a single pad. Basically has all pad state that
// a PS2 can set.
struct PadFreezeData
{
// Digital / Analog / DS2 Native
u8 mode;
// Digital / Analog / DS2 Native
u8 mode;
u8 modeLock;
u8 modeLock;
// In config mode
u8 config;
// In config mode
u8 config;
u8 vibrate[8];
u8 umask[2];
u8 vibrate[8];
u8 umask[2];
// Vibration indices.
u8 vibrateI[2];
// Vibration indices.
u8 vibrateI[2];
// Last vibration value sent to controller.
// Only used so as not to call vibration
// functions when old and new values are both 0.
u8 currentVibrate[2];
// Last vibration value sent to controller.
// Only used so as not to call vibration
// functions when old and new values are both 0.
u8 currentVibrate[2];
// Next vibrate val to send to controller. If next and current are
// both 0, nothing is sent to the controller. Otherwise, it's sent
// on every update.
u8 nextVibrate[2];
// Next vibrate val to send to controller. If next and current are
// both 0, nothing is sent to the controller. Otherwise, it's sent
// on every update.
u8 nextVibrate[2];
};
class Pad : public PadFreezeData
{
public:
// Lilypad store here the state of PC pad
// Lilypad store here the state of PC pad
void rumble(unsigned port);
void set_vibrate(int motor, u8 val);
void reset_vibrate();
void reset();
void rumble(unsigned port);
void set_vibrate(int motor, u8 val);
void reset_vibrate();
void reset();
void set_mode(int mode);
void set_mode(int mode);
static void reset_all();
static void stop_vibrate_all();
static void rumble_all();
static void reset_all();
static void stop_vibrate_all();
static void rumble_all();
};
// Full state to manage save state
struct PadPluginFreezeData
{
char format[8];
u32 version;
// active slot for port
u8 slot[2];
PadFreezeData padData[2][4];
QueryInfo query;
char format[8];
u32 version;
// active slot for port
u8 slot[2];
PadFreezeData padData[2][4];
QueryInfo query;
};
extern QueryInfo query;

View File

@ -15,49 +15,50 @@
#include "GamepadConfiguration.h"
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent)
: wxDialog(parent, wxID_ANY, _T("Gamepad"), wxDefaultPosition, wxDefaultSize,
wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow* parent)
: wxDialog(parent, wxID_ANY, _T("Gamepad"), wxDefaultPosition, wxDefaultSize,
wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
m_pad_id = pad;
m_pad_id = pad;
wxBoxSizer *gamepad_box = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* gamepad_box = new wxBoxSizer(wxVERTICAL);
wxArrayString choices;
for (const auto &j : s_vgamePad) {
choices.Add(j->GetName());
}
wxArrayString choices;
for (const auto& j : s_vgamePad)
{
choices.Add(j->GetName());
}
m_joy_map = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
m_cb_rumble = new wxCheckBox(this, enable_rumble_id, _T("&Enable rumble"));
m_joy_map = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
m_cb_rumble = new wxCheckBox(this, enable_rumble_id, _T("&Enable rumble"));
wxStaticBoxSizer *rumble_box = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Rumble intensity"));
m_sl_rumble_intensity = new wxSlider(this, rumble_slider_id, 0, 0, 0x7FFF, wxDefaultPosition, wxDefaultSize,
wxSL_HORIZONTAL | wxSL_LABELS | wxSL_BOTTOM);
wxStaticBoxSizer* rumble_box = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Rumble intensity"));
m_sl_rumble_intensity = new wxSlider(this, rumble_slider_id, 0, 0, 0x7FFF, wxDefaultPosition, wxDefaultSize,
wxSL_HORIZONTAL | wxSL_LABELS | wxSL_BOTTOM);
wxStaticBoxSizer *joy_box = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Joystick sensibility"));
m_sl_joystick_sensibility = new wxSlider(this, joy_slider_id, 0, 0, 200, wxDefaultPosition, wxDefaultSize,
wxSL_HORIZONTAL | wxSL_LABELS | wxSL_BOTTOM);
wxStaticBoxSizer* joy_box = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Joystick sensibility"));
m_sl_joystick_sensibility = new wxSlider(this, joy_slider_id, 0, 0, 200, wxDefaultPosition, wxDefaultSize,
wxSL_HORIZONTAL | wxSL_LABELS | wxSL_BOTTOM);
gamepad_box->Add(m_joy_map, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(m_cb_rumble, wxSizerFlags().Expand());
gamepad_box->Add(m_joy_map, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(m_cb_rumble, wxSizerFlags().Expand());
rumble_box->Add(m_sl_rumble_intensity, wxSizerFlags().Expand().Border(wxALL, 5));
joy_box->Add(m_sl_joystick_sensibility, wxSizerFlags().Expand().Border(wxALL, 5));
rumble_box->Add(m_sl_rumble_intensity, wxSizerFlags().Expand().Border(wxALL, 5));
joy_box->Add(m_sl_joystick_sensibility, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(rumble_box, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(joy_box, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(rumble_box, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(joy_box, wxSizerFlags().Expand().Border(wxALL, 5));
gamepad_box->Add(CreateSeparatedButtonSizer(wxOK), wxSizerFlags().Right().Border(wxALL, 5));
gamepad_box->Add(CreateSeparatedButtonSizer(wxOK), wxSizerFlags().Right().Border(wxALL, 5));
Bind(wxEVT_BUTTON, &GamepadConfiguration::OnOk, this, wxID_OK);
Bind(wxEVT_SCROLL_THUMBRELEASE, &GamepadConfiguration::OnSliderReleased, this);
Bind(wxEVT_CHECKBOX, &GamepadConfiguration::OnCheckboxChange, this);
Bind(wxEVT_CHOICE, &GamepadConfiguration::OnChoiceChange, this);
Bind(wxEVT_BUTTON, &GamepadConfiguration::OnOk, this, wxID_OK);
Bind(wxEVT_SCROLL_THUMBRELEASE, &GamepadConfiguration::OnSliderReleased, this);
Bind(wxEVT_CHECKBOX, &GamepadConfiguration::OnCheckboxChange, this);
Bind(wxEVT_CHOICE, &GamepadConfiguration::OnChoiceChange, this);
repopulate();
repopulate();
SetSizerAndFit(gamepad_box);
SetSizerAndFit(gamepad_box);
}
/**
@ -67,37 +68,40 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent)
*/
void GamepadConfiguration::InitGamepadConfiguration()
{
repopulate(); // Set label and fit simulated key array
/*
repopulate(); // Set label and fit simulated key array
/*
* Check if there exist at least one pad available
* if the pad id is 0, you need at least 1 gamepad connected,
* 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)
* May be better to create a new function in order to check only that
*/
// Bad idea. Some connected devices might support rumble but not all connected devices.
// 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 {
wxMessageBox(L"No gamepad detected.");
m_sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider
m_cb_rumble->Disable(); // disable the rumble checkbox
m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
}
// Bad idea. Some connected devices might support rumble but not all connected devices.
// 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
{
wxMessageBox(L"No gamepad detected.");
m_sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider
m_cb_rumble->Disable(); // disable the rumble checkbox
m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
}
}
void GamepadConfiguration::OnOk(wxCommandEvent &event)
void GamepadConfiguration::OnOk(wxCommandEvent& event)
{
Destroy();
Destroy();
}
/**
@ -105,59 +109,59 @@ void GamepadConfiguration::OnOk(wxCommandEvent &event)
* @FIXME The current solution can't change the joystick sensibility and the rumble intensity
* for a specific gamepad. The same value is used for both
*/
void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
void GamepadConfiguration::OnSliderReleased(wxCommandEvent& event)
{
wxSlider *sl_tmp = (wxSlider *)event.GetEventObject();
int sl_id = sl_tmp->GetId();
wxSlider* sl_tmp = (wxSlider*)event.GetEventObject();
int sl_id = sl_tmp->GetId();
if (sl_id == rumble_slider_id)
{
g_conf.set_ff_intensity(m_sl_rumble_intensity->GetValue());
if (sl_id == rumble_slider_id)
{
g_conf.set_ff_intensity(m_sl_rumble_intensity->GetValue());
// convert in a float value between 0 and 1, and run rumble feedback.
// 0 to 1 scales to 0x0 to 0x7FFF
s_vgamePad[m_pad_id]->TestForce(m_sl_rumble_intensity->GetValue() / 0x7FFF);
}
else if (sl_id == joy_slider_id)
{
g_conf.set_sensibility(m_sl_joystick_sensibility->GetValue());
}
// convert in a float value between 0 and 1, and run rumble feedback.
// 0 to 1 scales to 0x0 to 0x7FFF
s_vgamePad[m_pad_id]->TestForce(m_sl_rumble_intensity->GetValue() / 0x7FFF);
}
else if (sl_id == joy_slider_id)
{
g_conf.set_sensibility(m_sl_joystick_sensibility->GetValue());
}
}
/**
* Checkbox event, called when the value of the checkbox change
*/
void GamepadConfiguration::OnCheckboxChange(wxCommandEvent &event)
void GamepadConfiguration::OnCheckboxChange(wxCommandEvent& event)
{
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
wxCheckBox* cb_tmp = (wxCheckBox*)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
if (cb_id == enable_rumble_id)
{
g_conf.pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
if (m_cb_rumble->GetValue())
{
s_vgamePad[m_pad_id]->TestForce();
m_sl_rumble_intensity->Enable();
}
else
{
m_sl_rumble_intensity->Disable();
}
}
if (cb_id == enable_rumble_id)
{
g_conf.pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
if (m_cb_rumble->GetValue())
{
s_vgamePad[m_pad_id]->TestForce();
m_sl_rumble_intensity->Enable();
}
else
{
m_sl_rumble_intensity->Disable();
}
}
}
/*
* Checkbox event, called when the value of the choice box change
*/
void GamepadConfiguration::OnChoiceChange(wxCommandEvent &event)
void GamepadConfiguration::OnChoiceChange(wxCommandEvent& event)
{
wxChoice *choice_tmp = (wxChoice *)event.GetEventObject();
int id = choice_tmp->GetSelection();
if (id != wxNOT_FOUND)
{
g_conf.set_joy_uid(m_pad_id, GamePad::index_to_uid(id));
}
wxChoice* choice_tmp = (wxChoice*)event.GetEventObject();
int id = choice_tmp->GetSelection();
if (id != wxNOT_FOUND)
{
g_conf.set_joy_uid(m_pad_id, GamePad::index_to_uid(id));
}
}
/****************************************/
@ -167,15 +171,15 @@ void GamepadConfiguration::OnChoiceChange(wxCommandEvent &event)
// Set button values
void GamepadConfiguration::repopulate()
{
m_cb_rumble->SetValue(g_conf.pad_options[m_pad_id].forcefeedback);
m_cb_rumble->SetValue(g_conf.pad_options[m_pad_id].forcefeedback);
m_sl_rumble_intensity->SetValue(g_conf.get_ff_intensity());
m_sl_joystick_sensibility->SetValue(g_conf.get_sensibility());
m_sl_rumble_intensity->SetValue(g_conf.get_ff_intensity());
m_sl_joystick_sensibility->SetValue(g_conf.get_sensibility());
u32 joyid = GamePad::uid_to_index(m_pad_id);
if (joyid < m_joy_map->GetCount() && !m_joy_map->IsEmpty())
m_joy_map->SetSelection(joyid);
u32 joyid = GamePad::uid_to_index(m_pad_id);
if (joyid < m_joy_map->GetCount() && !m_joy_map->IsEmpty())
m_joy_map->SetSelection(joyid);
// enable rumble intensity slider if the checkbox is checked
m_sl_rumble_intensity->Enable(m_cb_rumble->GetValue());
// enable rumble intensity slider if the checkbox is checked
m_sl_rumble_intensity->Enable(m_cb_rumble->GetValue());
}

View File

@ -30,24 +30,24 @@ static const s32 enable_rumble_id = wxID_HIGHEST + 200 + 3;
class GamepadConfiguration : public wxDialog
{
wxCheckBox *m_cb_rumble;
wxSlider *m_sl_rumble_intensity, *m_sl_joystick_sensibility;
wxChoice *m_joy_map;
wxCheckBox* m_cb_rumble;
wxSlider *m_sl_rumble_intensity, *m_sl_joystick_sensibility;
wxChoice* m_joy_map;
u32 m_pad_id;
u32 m_pad_id;
// Methods
void repopulate();
// Methods
void repopulate();
// Events
void OnOk(wxCommandEvent &);
void OnSliderReleased(wxCommandEvent &);
void OnCheckboxChange(wxCommandEvent &);
void OnChoiceChange(wxCommandEvent &);
// Events
void OnOk(wxCommandEvent&);
void OnSliderReleased(wxCommandEvent&);
void OnCheckboxChange(wxCommandEvent&);
void OnChoiceChange(wxCommandEvent&);
public:
GamepadConfiguration(int, wxWindow *);
void InitGamepadConfiguration();
GamepadConfiguration(int, wxWindow*);
void InitGamepadConfiguration();
};
#endif // __GAMEPADCONFIGURATION_H__

View File

@ -16,52 +16,51 @@
#include "JoystickConfiguration.h"
// Constructor of JoystickConfiguration
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent)
: wxDialog(parent, wxID_ANY, _T("Joystick configuration"), wxDefaultPosition, wxDefaultSize,
wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow* parent)
: wxDialog(parent, wxID_ANY, _T("Joystick configuration"), wxDefaultPosition, wxDefaultSize,
wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
m_init_reverse_Lx = m_init_reverse_Ly =
m_init_reverse_Rx = m_init_reverse_Ry =
m_init_mouse_Ljoy = m_init_mouse_Rjoy = false;
m_init_reverse_Lx = m_init_reverse_Ly =
m_init_reverse_Rx = m_init_reverse_Ry =
m_init_mouse_Ljoy = m_init_mouse_Rjoy = false;
m_pad_id = pad;
m_isForLeftJoystick = left;
m_pad_id = pad;
m_isForLeftJoystick = left;
wxBoxSizer *joy_conf_box = new wxBoxSizer(wxVERTICAL);
wxBoxSizer* joy_conf_box = new wxBoxSizer(wxVERTICAL);
if (m_isForLeftJoystick)
{
m_cb_reverse_Lx = new wxCheckBox(this, Lx_check_id, _T("Reverse Lx"));
m_cb_reverse_Ly = new wxCheckBox(this, Ly_check_id, _T("Reverse Ly"));
m_cb_mouse_Ljoy = new wxCheckBox(this, Ljoy_check_id, _T("Use mouse for left analog joystick"));
if (m_isForLeftJoystick)
{
m_cb_reverse_Lx = new wxCheckBox(this, Lx_check_id, _T("Reverse Lx"));
m_cb_reverse_Ly = new wxCheckBox(this, Ly_check_id, _T("Reverse Ly"));
m_cb_mouse_Ljoy = new wxCheckBox(this, Ljoy_check_id, _T("Use mouse for left analog joystick"));
joy_conf_box->Add(m_cb_reverse_Lx, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Ly, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_mouse_Ljoy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Lx, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Ly, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
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;
m_cb_reverse_Rx = m_cb_reverse_Ry = m_cb_mouse_Rjoy = nullptr;
}
else
{
m_cb_reverse_Rx = new wxCheckBox(this, Rx_check_id, _T("Reverse Rx"));
m_cb_reverse_Ry = new wxCheckBox(this, Ry_check_id, _T("Reverse Ry"));
m_cb_mouse_Rjoy = new wxCheckBox(this, Rjoy_check_id, _T("Use mouse for right analog joystick"));
}
else
{
m_cb_reverse_Rx = new wxCheckBox(this, Rx_check_id, _T("Reverse Rx"));
m_cb_reverse_Ry = new wxCheckBox(this, Ry_check_id, _T("Reverse Ry"));
m_cb_mouse_Rjoy = new wxCheckBox(this, Rjoy_check_id, _T("Use mouse for right analog joystick"));
joy_conf_box->Add(m_cb_reverse_Rx, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Ry, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_mouse_Rjoy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Rx, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_reverse_Ry, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
joy_conf_box->Add(m_cb_mouse_Rjoy, wxSizerFlags().Expand().Border(wxLEFT | wxRIGHT, 5));
m_cb_reverse_Lx = m_cb_reverse_Ly = m_cb_mouse_Ljoy = nullptr;
}
m_cb_reverse_Lx = m_cb_reverse_Ly = m_cb_mouse_Ljoy = nullptr;
}
joy_conf_box->Add(CreateSeparatedButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Border(wxALL, 5).Right());
joy_conf_box->Add(CreateSeparatedButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Border(wxALL, 5).Right());
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnOk, this, wxID_OK);
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnCancel, this, wxID_CANCEL);
Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this);
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnOk, this, wxID_OK);
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnCancel, this, wxID_CANCEL);
Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this);
SetSizerAndFit(joy_conf_box);
SetSizerAndFit(joy_conf_box);
}
/**
@ -70,92 +69,93 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
*/
void JoystickConfiguration::InitJoystickConfiguration()
{
repopulate(); // Set label and fit simulated key array
/*
repopulate(); // Set label and fit simulated key array
/*
* Check if there exist at least one pad available
* if the pad id is 0, you need at least 1 gamepad connected,
* 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.empty())
wxMessageBox(L"No gamepad detected.");
else
wxMessageBox(L"No second gamepad detected.");
if (s_vgamePad.size() < m_pad_id + 1)
{
if (s_vgamePad.empty())
wxMessageBox(L"No gamepad detected.");
else
wxMessageBox(L"No second gamepad detected.");
// disable all checkboxes
if (m_isForLeftJoystick)
{
m_cb_reverse_Lx->Disable();
m_cb_reverse_Ly->Disable();
}
else
{
m_cb_reverse_Rx->Disable();
m_cb_reverse_Ry->Disable();
}
}
// disable all checkboxes
if (m_isForLeftJoystick)
{
m_cb_reverse_Lx->Disable();
m_cb_reverse_Ly->Disable();
}
else
{
m_cb_reverse_Rx->Disable();
m_cb_reverse_Ry->Disable();
}
}
}
void JoystickConfiguration::OnOk(wxCommandEvent &event)
void JoystickConfiguration::OnOk(wxCommandEvent& event)
{
Destroy();
Destroy();
}
void JoystickConfiguration::OnCancel(wxCommandEvent &event)
void JoystickConfiguration::OnCancel(wxCommandEvent& event)
{
reset();
Destroy();
reset();
Destroy();
}
/**
* Checkbox event, called when the value of the checkbox change
*/
void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event)
void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
{
wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
wxCheckBox* cb_tmp = (wxCheckBox*)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId();
if (m_isForLeftJoystick)
{
switch (cb_id)
{
case Lx_check_id:
g_conf.pad_options[m_pad_id].reverse_lx = m_cb_reverse_Lx->GetValue();
break;
if (m_isForLeftJoystick)
{
switch (cb_id)
{
case Lx_check_id:
g_conf.pad_options[m_pad_id].reverse_lx = m_cb_reverse_Lx->GetValue();
break;
case Ly_check_id:
g_conf.pad_options[m_pad_id].reverse_ly = m_cb_reverse_Ly->GetValue();
break;
case Ly_check_id:
g_conf.pad_options[m_pad_id].reverse_ly = m_cb_reverse_Ly->GetValue();
break;
case Ljoy_check_id:
g_conf.pad_options[m_pad_id].mouse_l = m_cb_mouse_Ljoy->GetValue();
break;
case Ljoy_check_id:
g_conf.pad_options[m_pad_id].mouse_l = m_cb_mouse_Ljoy->GetValue();
break;
default:
break;
}
}
else
{
switch (cb_id)
{
case Rx_check_id:
g_conf.pad_options[m_pad_id].reverse_rx = m_cb_reverse_Rx->GetValue();
break;
default:
break;
}
}
else
{
switch (cb_id)
{
case Rx_check_id:
g_conf.pad_options[m_pad_id].reverse_rx = m_cb_reverse_Rx->GetValue();
break;
case Ry_check_id:
g_conf.pad_options[m_pad_id].reverse_ry = m_cb_reverse_Ry->GetValue();
break;
case Ry_check_id:
g_conf.pad_options[m_pad_id].reverse_ry = m_cb_reverse_Ry->GetValue();
break;
case Rjoy_check_id:
g_conf.pad_options[m_pad_id].mouse_r = m_cb_mouse_Rjoy->GetValue();
break;
case Rjoy_check_id:
g_conf.pad_options[m_pad_id].mouse_r = m_cb_mouse_Rjoy->GetValue();
break;
default:
break;
}
}
default:
break;
}
}
}
/****************************************/
@ -165,43 +165,43 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event)
// Reset checkbox and slider values
void JoystickConfiguration::reset()
{
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
{
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);
}
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
{
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);
}
}
// Set button values
void JoystickConfiguration::repopulate()
{
if (m_isForLeftJoystick)
{
m_init_reverse_Lx = g_conf.pad_options[m_pad_id].reverse_lx;
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
if (m_isForLeftJoystick)
{
m_init_reverse_Lx = g_conf.pad_options[m_pad_id].reverse_lx;
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
m_init_reverse_Ly = g_conf.pad_options[m_pad_id].reverse_ly;
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
m_init_reverse_Ly = g_conf.pad_options[m_pad_id].reverse_ly;
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
m_init_mouse_Ljoy = g_conf.pad_options[m_pad_id].mouse_l;
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
}
else
{
m_init_reverse_Rx = g_conf.pad_options[m_pad_id].reverse_rx;
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
m_init_mouse_Ljoy = g_conf.pad_options[m_pad_id].mouse_l;
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
}
else
{
m_init_reverse_Rx = g_conf.pad_options[m_pad_id].reverse_rx;
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
m_init_reverse_Ry = g_conf.pad_options[m_pad_id].reverse_ry;
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
m_init_reverse_Ry = g_conf.pad_options[m_pad_id].reverse_ry;
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
m_init_mouse_Rjoy = g_conf.pad_options[m_pad_id].mouse_r;
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
}
m_init_mouse_Rjoy = g_conf.pad_options[m_pad_id].mouse_r;
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
}
}

View File

@ -34,27 +34,27 @@ static const s32 Rjoy_check_id = wxID_HIGHEST + 100 + 6;
class JoystickConfiguration : public wxDialog
{
wxCheckBox *m_cb_reverse_Lx, *m_cb_reverse_Ly, *m_cb_reverse_Rx, *m_cb_reverse_Ry,
*m_cb_mouse_Ljoy, // Use mouse for left joystick
*m_cb_mouse_Rjoy; // Use mouse for right joystick
wxCheckBox *m_cb_reverse_Lx, *m_cb_reverse_Ly, *m_cb_reverse_Rx, *m_cb_reverse_Ry,
*m_cb_mouse_Ljoy, // Use mouse for left joystick
*m_cb_mouse_Rjoy; // Use mouse for right joystick
u32 m_pad_id;
// isForLeftJoystick -> true is for Left Joystick, false is for Right Joystick
bool m_init_reverse_Lx, m_init_reverse_Ly, m_init_reverse_Rx, m_init_reverse_Ry,
m_init_mouse_Ljoy, m_init_mouse_Rjoy, m_isForLeftJoystick;
u32 m_pad_id;
// isForLeftJoystick -> true is for Left Joystick, false is for Right Joystick
bool m_init_reverse_Lx, m_init_reverse_Ly, m_init_reverse_Rx, m_init_reverse_Ry,
m_init_mouse_Ljoy, m_init_mouse_Rjoy, m_isForLeftJoystick;
// Methods
void repopulate();
void reset();
// Methods
void repopulate();
void reset();
// Events
void OnCheckboxChange(wxCommandEvent &);
void OnOk(wxCommandEvent &);
void OnCancel(wxCommandEvent &);
// Events
void OnCheckboxChange(wxCommandEvent&);
void OnOk(wxCommandEvent&);
void OnCancel(wxCommandEvent&);
public:
JoystickConfiguration(int, bool, wxWindow *);
void InitJoystickConfiguration();
JoystickConfiguration(int, bool, wxWindow*);
void InitJoystickConfiguration();
};
#endif // __JOYSTICKCONFIGURATION_H__

File diff suppressed because it is too large Load Diff

View File

@ -43,15 +43,16 @@
// e.g L2 → 0, triangle → 4, ...
// see PAD.h for more details about gamepad button id
enum gui_buttons {
Analog = PAD_R_LEFT + 1, // Analog button (not yet supported ?)
JoyL_config, // Left Joystick Configuration
JoyR_config, // Right Joystick Configuration
Gamepad_config, // Gamepad Configuration
Set_all, // Set all buttons
Apply, // Apply modifications without exit
Ok, // Apply modifications and exit
Cancel // Exit without apply modificatons
enum gui_buttons
{
Analog = PAD_R_LEFT + 1, // Analog button (not yet supported ?)
JoyL_config, // Left Joystick Configuration
JoyR_config, // Right Joystick Configuration
Gamepad_config, // Gamepad Configuration
Set_all, // Set all buttons
Apply, // Apply modifications without exit
Ok, // Apply modifications and exit
Cancel // Exit without apply modificatons
};
#define BUTTONS_LENGHT 32 // numbers of buttons on the gamepad
@ -61,32 +62,32 @@ enum gui_buttons {
class PADDialog : public wxDialog
{
// Panels
opPanel *m_pan_tabs[GAMEPAD_NUMBER]; // Gamepad Tabs box
// Notebooks
wxNotebook *m_tab_gamepad; // Joysticks Tabs
// Buttons
wxButton *m_bt_gamepad[GAMEPAD_NUMBER][BUTTONS_LENGHT]; // Joystick button use to modify the button mapping
// Contain all simulated key
u32 m_simulatedKeys[GAMEPAD_NUMBER][MAX_KEYS];
// Timer
wxTimer m_time_update_gui;
// Check if the gui must display feddback image
bool m_pressed[GAMEPAD_NUMBER][NB_IMG];
// Panels
opPanel* m_pan_tabs[GAMEPAD_NUMBER]; // Gamepad Tabs box
// Notebooks
wxNotebook* m_tab_gamepad; // Joysticks Tabs
// Buttons
wxButton* m_bt_gamepad[GAMEPAD_NUMBER][BUTTONS_LENGHT]; // Joystick button use to modify the button mapping
// Contain all simulated key
u32 m_simulatedKeys[GAMEPAD_NUMBER][MAX_KEYS];
// Timer
wxTimer m_time_update_gui;
// Check if the gui must display feddback image
bool m_pressed[GAMEPAD_NUMBER][NB_IMG];
// methods
void config_key(int, int);
void clear_key(int, int);
void repopulate();
// methods
void config_key(int, int);
void clear_key(int, int);
void repopulate();
// Events
void OnButtonClicked(wxCommandEvent &);
void JoystickEvent(wxTimerEvent &);
// Events
void OnButtonClicked(wxCommandEvent&);
void JoystickEvent(wxTimerEvent&);
public:
PADDialog();
void InitDialog();
void show();
PADDialog();
void InitDialog();
void show();
};
extern void DisplayDialog(); // Main function

View File

@ -38,196 +38,206 @@
#include "ImgHeader/arrow_bottom.h"
#include "ImgHeader/arrow_left.h"
opPanel::opPanel(wxWindow *parent,
wxWindowID id = wxID_ANY,
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize)
: wxPanel(parent, id, pos, size)
opPanel::opPanel(wxWindow* parent,
wxWindowID id = wxID_ANY,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize)
: wxPanel(parent, id, pos, size)
{
m_picture[img_background] = EmbeddedImage<res_dualshock2>().Get();
m_picture[img_background] = EmbeddedImage<res_dualshock2>().Get();
m_picture[img_start] = EmbeddedImage<res_start>().Get();
m_picture[img_select] = EmbeddedImage<res_select>().Get();
m_picture[img_analog] = EmbeddedImage<res_analog>().Get();
m_picture[img_start] = EmbeddedImage<res_start>().Get();
m_picture[img_select] = EmbeddedImage<res_select>().Get();
m_picture[img_analog] = EmbeddedImage<res_analog>().Get();
m_picture[img_dp_left] = EmbeddedImage<res_dp_left>().Get();
m_picture[img_dp_right] = EmbeddedImage<res_dp_right>().Get();
m_picture[img_dp_up] = EmbeddedImage<res_dp_up>().Get();
m_picture[img_dp_bottom] = EmbeddedImage<res_dp_bottom>().Get();
m_picture[img_dp_left] = EmbeddedImage<res_dp_left>().Get();
m_picture[img_dp_right] = EmbeddedImage<res_dp_right>().Get();
m_picture[img_dp_up] = EmbeddedImage<res_dp_up>().Get();
m_picture[img_dp_bottom] = EmbeddedImage<res_dp_bottom>().Get();
m_picture[img_square] = EmbeddedImage<res_square>().Get();
m_picture[img_circle] = EmbeddedImage<res_circle>().Get();
m_picture[img_cross] = EmbeddedImage<res_cross>().Get();
m_picture[img_triangle] = EmbeddedImage<res_triangle>().Get();
m_picture[img_square] = EmbeddedImage<res_square>().Get();
m_picture[img_circle] = EmbeddedImage<res_circle>().Get();
m_picture[img_cross] = EmbeddedImage<res_cross>().Get();
m_picture[img_triangle] = EmbeddedImage<res_triangle>().Get();
m_picture[img_l1] = EmbeddedImage<res_l1>().Get();
m_picture[img_l3] = EmbeddedImage<res_l3>().Get();
m_picture[img_l2] = EmbeddedImage<res_l2>().Get();
m_picture[img_l1] = EmbeddedImage<res_l1>().Get();
m_picture[img_l3] = EmbeddedImage<res_l3>().Get();
m_picture[img_l2] = EmbeddedImage<res_l2>().Get();
m_picture[img_r1] = EmbeddedImage<res_r1>().Get();
m_picture[img_r3] = EmbeddedImage<res_r3>().Get();
m_picture[img_r2] = EmbeddedImage<res_r2>().Get();
m_picture[img_r1] = EmbeddedImage<res_r1>().Get();
m_picture[img_r3] = EmbeddedImage<res_r3>().Get();
m_picture[img_r2] = EmbeddedImage<res_r2>().Get();
m_picture[img_left_cursor] = EmbeddedImage<res_joystick_cursor>().Get();
m_picture[img_right_cursor] = EmbeddedImage<res_joystick_cursor>().Get();
m_picture[img_left_cursor] = EmbeddedImage<res_joystick_cursor>().Get();
m_picture[img_right_cursor] = EmbeddedImage<res_joystick_cursor>().Get();
m_picture[img_l_arrow_up] = EmbeddedImage<res_arrow_up>().Get();
m_picture[img_l_arrow_right] = EmbeddedImage<res_arrow_right>().Get();
m_picture[img_l_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get();
m_picture[img_l_arrow_left] = EmbeddedImage<res_arrow_left>().Get();
m_picture[img_l_arrow_up] = EmbeddedImage<res_arrow_up>().Get();
m_picture[img_l_arrow_right] = EmbeddedImage<res_arrow_right>().Get();
m_picture[img_l_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get();
m_picture[img_l_arrow_left] = EmbeddedImage<res_arrow_left>().Get();
m_picture[img_r_arrow_up] = EmbeddedImage<res_arrow_up>().Get();
m_picture[img_r_arrow_right] = EmbeddedImage<res_arrow_right>().Get();
m_picture[img_r_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get();
m_picture[img_r_arrow_left] = EmbeddedImage<res_arrow_left>().Get();
m_picture[img_r_arrow_up] = EmbeddedImage<res_arrow_up>().Get();
m_picture[img_r_arrow_right] = EmbeddedImage<res_arrow_right>().Get();
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) {
m_show_image[i] = false;
HideImg(i);
}
ShowImg(img_background);
m_show_image[img_background] = true;
for (int i = 0; i < NB_IMG; ++i)
{
m_show_image[i] = false;
HideImg(i);
}
ShowImg(img_background);
m_show_image[img_background] = true;
m_left_cursor_x = 0;
m_left_cursor_y = 0;
m_right_cursor_x = 0;
m_right_cursor_y = 0;
m_left_cursor_x = 0;
m_left_cursor_y = 0;
m_right_cursor_x = 0;
m_right_cursor_y = 0;
}
void opPanel::HideImg(int id)
{
if (id < NB_IMG) {
m_show_image[id] = false;
Refresh();
}
if (id < NB_IMG)
{
m_show_image[id] = false;
Refresh();
}
}
void opPanel::ShowImg(int id)
{
if (id < NB_IMG) {
m_show_image[id] = true;
Refresh();
}
if (id < NB_IMG)
{
m_show_image[id] = true;
Refresh();
}
}
void opPanel::MoveJoystick(int axe, int value)
{
if (axe == 0) {
m_left_cursor_x = value * 30 / 40000;
} else if (axe == 1) {
m_left_cursor_y = value * 30 / 40000;
} else if (axe == 2) {
m_right_cursor_x = value * 30 / 40000;
} else {
m_right_cursor_y = value * 30 / 40000;
}
if (axe == 0)
{
m_left_cursor_x = value * 30 / 40000;
}
else if (axe == 1)
{
m_left_cursor_y = value * 30 / 40000;
}
else if (axe == 2)
{
m_right_cursor_x = value * 30 / 40000;
}
else
{
m_right_cursor_y = value * 30 / 40000;
}
}
wxBEGIN_EVENT_TABLE(opPanel, wxPanel)
EVT_PAINT(opPanel::OnPaint)
wxEND_EVENT_TABLE()
EVT_PAINT(opPanel::OnPaint)
wxEND_EVENT_TABLE()
void opPanel::OnPaint(wxPaintEvent &event)
void opPanel::OnPaint(wxPaintEvent& event)
{
wxPaintDC dc(this);
wxPaintDC dc(this);
wxMemoryDC temp_background, temp_start, temp_select, temp_analog, temp_dp_left,
temp_dp_right, temp_dp_up, temp_dp_bottom, temp_l1, temp_r1, temp_L3, temp_l2_2,
temp_R3, temp_r2_2, temp_square, temp_circle, temp_cross, temp_triangle,
temp_left_cursor, temp_right_cursor, temp_l_arrow_up, temp_l_arrow_right,
temp_l_arrow_bottom, temp_l_arrow_left, temp_r_arrow_up, temp_r_arrow_right,
temp_r_arrow_bottom, temp_r_arrow_left;
wxMemoryDC temp_background, temp_start, temp_select, temp_analog, temp_dp_left,
temp_dp_right, temp_dp_up, temp_dp_bottom, temp_l1, temp_r1, temp_L3, temp_l2_2,
temp_R3, temp_r2_2, temp_square, temp_circle, temp_cross, temp_triangle,
temp_left_cursor, temp_right_cursor, temp_l_arrow_up, temp_l_arrow_right,
temp_l_arrow_bottom, temp_l_arrow_left, temp_r_arrow_up, temp_r_arrow_right,
temp_r_arrow_bottom, temp_r_arrow_left;
temp_background.SelectObject(m_picture[img_background]);
temp_start.SelectObject(m_picture[img_start]);
temp_select.SelectObject(m_picture[img_select]);
temp_analog.SelectObject(m_picture[img_analog]);
temp_dp_left.SelectObject(m_picture[img_dp_left]);
temp_background.SelectObject(m_picture[img_background]);
temp_start.SelectObject(m_picture[img_start]);
temp_select.SelectObject(m_picture[img_select]);
temp_analog.SelectObject(m_picture[img_analog]);
temp_dp_left.SelectObject(m_picture[img_dp_left]);
temp_dp_right.SelectObject(m_picture[img_dp_right]);
temp_dp_up.SelectObject(m_picture[img_dp_up]);
temp_dp_bottom.SelectObject(m_picture[img_dp_bottom]);
temp_l1.SelectObject(m_picture[img_l1]);
temp_r1.SelectObject(m_picture[img_r1]);
temp_L3.SelectObject(m_picture[img_l3]);
temp_l2_2.SelectObject(m_picture[img_l2]);
temp_dp_right.SelectObject(m_picture[img_dp_right]);
temp_dp_up.SelectObject(m_picture[img_dp_up]);
temp_dp_bottom.SelectObject(m_picture[img_dp_bottom]);
temp_l1.SelectObject(m_picture[img_l1]);
temp_r1.SelectObject(m_picture[img_r1]);
temp_L3.SelectObject(m_picture[img_l3]);
temp_l2_2.SelectObject(m_picture[img_l2]);
temp_R3.SelectObject(m_picture[img_r3]);
temp_r2_2.SelectObject(m_picture[img_r2]);
temp_square.SelectObject(m_picture[img_square]);
temp_circle.SelectObject(m_picture[img_circle]);
temp_cross.SelectObject(m_picture[img_cross]);
temp_triangle.SelectObject(m_picture[img_triangle]);
temp_R3.SelectObject(m_picture[img_r3]);
temp_r2_2.SelectObject(m_picture[img_r2]);
temp_square.SelectObject(m_picture[img_square]);
temp_circle.SelectObject(m_picture[img_circle]);
temp_cross.SelectObject(m_picture[img_cross]);
temp_triangle.SelectObject(m_picture[img_triangle]);
temp_left_cursor.SelectObject(m_picture[img_left_cursor]);
temp_right_cursor.SelectObject(m_picture[img_right_cursor]);
temp_left_cursor.SelectObject(m_picture[img_left_cursor]);
temp_right_cursor.SelectObject(m_picture[img_right_cursor]);
temp_l_arrow_up.SelectObject(m_picture[img_l_arrow_up]);
temp_l_arrow_right.SelectObject(m_picture[img_l_arrow_right]);
temp_l_arrow_bottom.SelectObject(m_picture[img_l_arrow_bottom]);
temp_l_arrow_left.SelectObject(m_picture[img_l_arrow_left]);
temp_l_arrow_up.SelectObject(m_picture[img_l_arrow_up]);
temp_l_arrow_right.SelectObject(m_picture[img_l_arrow_right]);
temp_l_arrow_bottom.SelectObject(m_picture[img_l_arrow_bottom]);
temp_l_arrow_left.SelectObject(m_picture[img_l_arrow_left]);
temp_r_arrow_up.SelectObject(m_picture[img_r_arrow_up]);
temp_r_arrow_right.SelectObject(m_picture[img_r_arrow_right]);
temp_r_arrow_bottom.SelectObject(m_picture[img_r_arrow_bottom]);
temp_r_arrow_left.SelectObject(m_picture[img_r_arrow_left]);
temp_r_arrow_up.SelectObject(m_picture[img_r_arrow_up]);
temp_r_arrow_right.SelectObject(m_picture[img_r_arrow_right]);
temp_r_arrow_bottom.SelectObject(m_picture[img_r_arrow_bottom]);
temp_r_arrow_left.SelectObject(m_picture[img_r_arrow_left]);
if (m_show_image[img_background])
dc.Blit(wxPoint(0, 0), temp_background.GetSize(), &temp_background, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_start])
dc.Blit(wxPoint(526, 296), temp_start.GetSize(), &temp_start, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_select])
dc.Blit(wxPoint(450, 297), temp_select.GetSize(), &temp_select, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_analog])
dc.Blit(wxPoint(489, 358), temp_analog.GetSize(), &temp_analog, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_dp_left])
dc.Blit(wxPoint(334, 292), temp_dp_left.GetSize(), &temp_dp_left, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_dp_right])
dc.Blit(wxPoint(378, 292), temp_dp_right.GetSize(), &temp_dp_right, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_dp_up])
dc.Blit(wxPoint(358, 269), temp_dp_up.GetSize(), &temp_dp_up, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_dp_bottom])
dc.Blit(wxPoint(358, 312), temp_dp_bottom.GetSize(), &temp_dp_bottom, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l1])
dc.Blit(wxPoint(343, 186), temp_l1.GetSize(), &temp_l1, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r1])
dc.Blit(wxPoint(593, 186), temp_r1.GetSize(), &temp_r1, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l3])
dc.Blit(wxPoint(409, 344), temp_L3.GetSize(), &temp_L3, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l2])
dc.Blit(wxPoint(346, 158), temp_l2_2.GetSize(), &temp_l2_2, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r3])
dc.Blit(wxPoint(525, 344), temp_R3.GetSize(), &temp_R3, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r2])
dc.Blit(wxPoint(582, 158), temp_r2_2.GetSize(), &temp_r2_2, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_square])
dc.Blit(wxPoint(573, 287), temp_square.GetSize(), &temp_square, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_circle])
dc.Blit(wxPoint(647, 287), temp_circle.GetSize(), &temp_circle, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_cross])
dc.Blit(wxPoint(610, 324), temp_cross.GetSize(), &temp_cross, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_triangle])
dc.Blit(wxPoint(610, 250), temp_triangle.GetSize(), &temp_triangle, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_left_cursor])
dc.Blit(wxPoint(439 + m_left_cursor_x, 374 + m_left_cursor_y), temp_left_cursor.GetSize(), &temp_left_cursor, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_right_cursor])
dc.Blit(wxPoint(555 + m_right_cursor_x, 374 + m_right_cursor_y), temp_right_cursor.GetSize(), &temp_right_cursor, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_background])
dc.Blit(wxPoint(0, 0), temp_background.GetSize(), &temp_background, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_start])
dc.Blit(wxPoint(526, 296), temp_start.GetSize(), &temp_start, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_select])
dc.Blit(wxPoint(450, 297), temp_select.GetSize(), &temp_select, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_analog])
dc.Blit(wxPoint(489, 358), temp_analog.GetSize(), &temp_analog, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_dp_left])
dc.Blit(wxPoint(334, 292), temp_dp_left.GetSize(), &temp_dp_left, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_dp_right])
dc.Blit(wxPoint(378, 292), temp_dp_right.GetSize(), &temp_dp_right, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_dp_up])
dc.Blit(wxPoint(358, 269), temp_dp_up.GetSize(), &temp_dp_up, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_dp_bottom])
dc.Blit(wxPoint(358, 312), temp_dp_bottom.GetSize(), &temp_dp_bottom, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l1])
dc.Blit(wxPoint(343, 186), temp_l1.GetSize(), &temp_l1, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r1])
dc.Blit(wxPoint(593, 186), temp_r1.GetSize(), &temp_r1, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l3])
dc.Blit(wxPoint(409, 344), temp_L3.GetSize(), &temp_L3, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l2])
dc.Blit(wxPoint(346, 158), temp_l2_2.GetSize(), &temp_l2_2, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r3])
dc.Blit(wxPoint(525, 344), temp_R3.GetSize(), &temp_R3, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r2])
dc.Blit(wxPoint(582, 158), temp_r2_2.GetSize(), &temp_r2_2, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_square])
dc.Blit(wxPoint(573, 287), temp_square.GetSize(), &temp_square, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_circle])
dc.Blit(wxPoint(647, 287), temp_circle.GetSize(), &temp_circle, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_cross])
dc.Blit(wxPoint(610, 324), temp_cross.GetSize(), &temp_cross, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_triangle])
dc.Blit(wxPoint(610, 250), temp_triangle.GetSize(), &temp_triangle, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_left_cursor])
dc.Blit(wxPoint(439 + m_left_cursor_x, 374 + m_left_cursor_y), temp_left_cursor.GetSize(), &temp_left_cursor, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_right_cursor])
dc.Blit(wxPoint(555 + m_right_cursor_x, 374 + m_right_cursor_y), temp_right_cursor.GetSize(), &temp_right_cursor, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l_arrow_up])
dc.Blit(wxPoint(433, 357), temp_l_arrow_up.GetSize(), &temp_l_arrow_up, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l_arrow_right])
dc.Blit(wxPoint(423, 368), temp_l_arrow_right.GetSize(), &temp_l_arrow_right, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l_arrow_bottom])
dc.Blit(wxPoint(433, 357), temp_l_arrow_bottom.GetSize(), &temp_l_arrow_bottom, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l_arrow_left])
dc.Blit(wxPoint(423, 368), temp_l_arrow_left.GetSize(), &temp_l_arrow_left, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l_arrow_up])
dc.Blit(wxPoint(433, 357), temp_l_arrow_up.GetSize(), &temp_l_arrow_up, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l_arrow_right])
dc.Blit(wxPoint(423, 368), temp_l_arrow_right.GetSize(), &temp_l_arrow_right, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l_arrow_bottom])
dc.Blit(wxPoint(433, 357), temp_l_arrow_bottom.GetSize(), &temp_l_arrow_bottom, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_l_arrow_left])
dc.Blit(wxPoint(423, 368), temp_l_arrow_left.GetSize(), &temp_l_arrow_left, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r_arrow_up])
dc.Blit(wxPoint(548, 357), temp_r_arrow_up.GetSize(), &temp_r_arrow_up, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r_arrow_right])
dc.Blit(wxPoint(539, 368), temp_r_arrow_right.GetSize(), &temp_r_arrow_right, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r_arrow_bottom])
dc.Blit(wxPoint(548, 357), temp_r_arrow_bottom.GetSize(), &temp_r_arrow_bottom, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r_arrow_left])
dc.Blit(wxPoint(539, 368), temp_r_arrow_left.GetSize(), &temp_r_arrow_left, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r_arrow_up])
dc.Blit(wxPoint(548, 357), temp_r_arrow_up.GetSize(), &temp_r_arrow_up, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r_arrow_right])
dc.Blit(wxPoint(539, 368), temp_r_arrow_right.GetSize(), &temp_r_arrow_right, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r_arrow_bottom])
dc.Blit(wxPoint(548, 357), temp_r_arrow_bottom.GetSize(), &temp_r_arrow_bottom, wxPoint(0, 0), wxCOPY, true);
if (m_show_image[img_r_arrow_left])
dc.Blit(wxPoint(539, 368), temp_r_arrow_left.GetSize(), &temp_r_arrow_left, wxPoint(0, 0), wxCOPY, true);
}

View File

@ -22,52 +22,53 @@
#include "EmbeddedImage.h"
enum gui_img {
img_l2,
img_r2,
img_l1,
img_r1,
img_triangle,
img_circle,
img_cross,
img_square,
img_select,
img_l3,
img_r3,
img_start,
img_dp_up,
img_dp_right,
img_dp_bottom,
img_dp_left,
img_left_cursor,
img_right_cursor,
img_analog,
img_background, // background pic
img_l_arrow_up,
img_l_arrow_right,
img_l_arrow_bottom,
img_l_arrow_left,
img_r_arrow_up,
img_r_arrow_right,
img_r_arrow_bottom,
img_r_arrow_left
enum gui_img
{
img_l2,
img_r2,
img_l1,
img_r1,
img_triangle,
img_circle,
img_cross,
img_square,
img_select,
img_l3,
img_r3,
img_start,
img_dp_up,
img_dp_right,
img_dp_bottom,
img_dp_left,
img_left_cursor,
img_right_cursor,
img_analog,
img_background, // background pic
img_l_arrow_up,
img_l_arrow_right,
img_l_arrow_bottom,
img_l_arrow_left,
img_r_arrow_up,
img_r_arrow_right,
img_r_arrow_bottom,
img_r_arrow_left
};
#define NB_IMG 28
class opPanel : public wxPanel
{
wxBitmap m_picture[NB_IMG];
bool m_show_image[NB_IMG];
int m_left_cursor_x, m_left_cursor_y, m_right_cursor_x, m_right_cursor_y;
wxDECLARE_EVENT_TABLE();
void OnPaint(wxPaintEvent &event);
wxBitmap m_picture[NB_IMG];
bool m_show_image[NB_IMG];
int m_left_cursor_x, m_left_cursor_y, m_right_cursor_x, m_right_cursor_y;
wxDECLARE_EVENT_TABLE();
void OnPaint(wxPaintEvent& event);
public:
opPanel(wxWindow *, wxWindowID, const wxPoint &, const wxSize &);
void HideImg(int);
void ShowImg(int);
void MoveJoystick(int, int);
opPanel(wxWindow*, wxWindowID, const wxPoint&, const wxSize&);
void HideImg(int);
void ShowImg(int);
void MoveJoystick(int, int);
};
#endif // __OPPANEL_H__