some more work on pad/event handler
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1733 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
dbd9d5fb2d
commit
a2a5d0a066
|
@ -15,6 +15,20 @@ bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EventHandler::RemoveEventListener(Keys key) {
|
||||||
|
if (key.inputType == KeyboardInput) {
|
||||||
|
if (! keys[key.keyCode][key.mods])
|
||||||
|
return false;
|
||||||
|
keys[key.keyCode][key.mods] = NULL;
|
||||||
|
} else if (key.inputType == MouseInput) {
|
||||||
|
if (! mouse[key.mouseButton])
|
||||||
|
return false;
|
||||||
|
mouse[key.mouseButton] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void EventHandler::Update() {
|
void EventHandler::Update() {
|
||||||
for (unsigned int i = 0; i < eventQueue.size();i++) {
|
for (unsigned int i = 0; i < eventQueue.size();i++) {
|
||||||
sf::Event ev = eventQueue.front();
|
sf::Event ev = eventQueue.front();
|
||||||
|
@ -45,9 +59,9 @@ bool EventHandler::TestEvent (Keys k, sf::Event e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Taken from wxw source code
|
// Taken from wxw source code
|
||||||
int EventHandler::wxCharCodeWXToSF(int id)
|
sf::Key::Code EventHandler::wxCharCodeToSF(int id)
|
||||||
{
|
{
|
||||||
int sfKey;
|
sf::Key::Code sfKey;
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
// case WXK_CANCEL: sfKey = sf::Key::Cancel; break;
|
// case WXK_CANCEL: sfKey = sf::Key::Cancel; break;
|
||||||
|
@ -121,13 +135,18 @@ int EventHandler::wxCharCodeWXToSF(int id)
|
||||||
case WXK_F15: sfKey = sf::Key::F15; break;
|
case WXK_F15: sfKey = sf::Key::F15; break;
|
||||||
// case WXK_NUMLOCK: sfKey = sf::Key::Num_Lock; break;
|
// case WXK_NUMLOCK: sfKey = sf::Key::Num_Lock; break;
|
||||||
// case WXK_SCROLL: sfKey = sf::Key::Scroll_Lock; break;
|
// case WXK_SCROLL: sfKey = sf::Key::Scroll_Lock; break;
|
||||||
default: sfKey = id <= 255 ? id : 0;
|
default:
|
||||||
|
if ((id >= 'a' && id <= 'z') ||
|
||||||
|
(id >= '0' && id <= '9'))
|
||||||
|
sfKey = (sf::Key::Code)id;
|
||||||
|
else
|
||||||
|
sfKey = sf::Key::Count; // Invalid key
|
||||||
}
|
}
|
||||||
|
|
||||||
return sfKey;
|
return sfKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandler::SFKeyToString(unsigned int keycode, char *keyStr) {
|
void EventHandler::SFKeyToString(sf::Key::Code keycode, char *keyStr) {
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
/* case sf::Key::A = 'a': sprintf(keyStr, "UP"); break;
|
/* case sf::Key::A = 'a': sprintf(keyStr, "UP"); break;
|
||||||
case sf::Key::B = 'b': sprintf(keyStr, "UP"); break;
|
case sf::Key::B = 'b': sprintf(keyStr, "UP"); break;
|
||||||
|
|
|
@ -35,11 +35,14 @@ private:
|
||||||
std::queue<sf::Event> eventQueue;
|
std::queue<sf::Event> eventQueue;
|
||||||
public:
|
public:
|
||||||
bool RegisterEventListener(listenFuncPtr func, Keys key);
|
bool RegisterEventListener(listenFuncPtr func, Keys key);
|
||||||
|
bool RemoveEventListener(Keys key);
|
||||||
void Update();
|
void Update();
|
||||||
bool addEvent(sf::Event *e);
|
bool addEvent(sf::Event *e);
|
||||||
static bool TestEvent (Keys k, sf::Event e);
|
static bool TestEvent (Keys k, sf::Event e);
|
||||||
static int wxCharCodeWXToSF(int id);
|
static sf::Key::Code wxCharCodeToSF(int id);
|
||||||
static void SFKeyToString(unsigned int keycode, char *keyStr);
|
static void SFKeyToString(sf::Key::Code keycode, char *keyStr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern EventHandler *eventHandler;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -195,12 +195,13 @@ void ConfigDialog::OnKeyDown(wxKeyEvent& event)
|
||||||
if(clickedButton != NULL) {
|
if(clickedButton != NULL) {
|
||||||
int page = m_Notebook->GetSelection();
|
int page = m_Notebook->GetSelection();
|
||||||
|
|
||||||
int sfcode = EventHandler::wxCharCodeWXToSF(event.GetKeyCode());
|
sf::Key::Code sfcode = EventHandler::wxCharCodeToSF(event.GetKeyCode());
|
||||||
char sfstr[100];
|
char sfstr[100];
|
||||||
EventHandler::SFKeyToString(sfcode, sfstr);
|
EventHandler::SFKeyToString(sfcode, sfstr);
|
||||||
|
|
||||||
pad[page].keyForControl[clickedButton->GetId()] = sfcode;
|
// pad[page].keyForControl[clickedButton->GetId()] = sfcode;
|
||||||
clickedButton->SetLabel(wxString::FromAscii(sfstr));
|
if (registerKey(page, clickedButton->GetId(), sfcode))
|
||||||
|
clickedButton->SetLabel(wxString::FromAscii(sfstr));
|
||||||
clickedButton->Disconnect();
|
clickedButton->Disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,37 @@ const SPADStatus& PlayRecord()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool registerKey(int nPad, int id, sf::Key::Code code, int mods) {
|
||||||
|
|
||||||
|
Keys key, oldKey;
|
||||||
|
|
||||||
|
key.inputType = KeyboardInput;
|
||||||
|
key.keyCode = code;
|
||||||
|
key.mods = mods;
|
||||||
|
|
||||||
|
if (!eventHandler->EventHandler::RegisterEventListener(ParseKeyEvent, key)) {
|
||||||
|
char codestr[100];
|
||||||
|
EventHandler::SFKeyToString(code, codestr);
|
||||||
|
PanicAlert("Failed to register %s, might be already in use", codestr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (pad[nPad].keyForControl[id] != 0) {
|
||||||
|
|
||||||
|
oldKey.inputType = KeyboardInput;
|
||||||
|
oldKey.keyCode = pad[nPad].keyForControl[id];
|
||||||
|
oldKey.mods = mods;
|
||||||
|
|
||||||
|
// Might be not be registered yet
|
||||||
|
eventHandler->EventHandler::RemoveEventListener(oldKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
pad[nPad].keyForControl[id] = code;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void LoadRecord()
|
void LoadRecord()
|
||||||
{
|
{
|
||||||
FILE* pStream = fopen("c:\\pad-record.bin", "rb");
|
FILE* pStream = fopen("c:\\pad-record.bin", "rb");
|
||||||
|
@ -195,39 +226,39 @@ void PAD_Shutdown()
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParseKeyEvent(sf::Event ev)
|
bool ParseKeyEvent(sf::Event ev) {
|
||||||
{
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
{
|
{
|
||||||
// Check if all is okay
|
// Check if all is okay
|
||||||
if ((_pPADStatus == NULL))
|
if ((_pPADStatus == NULL)) {
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef RECORD_REPLAY
|
#ifdef RECORD_REPLAY
|
||||||
*_pPADStatus = PlayRecord();
|
*_pPADStatus = PlayRecord();
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const int base = 0x80;
|
const int base = 0x80;
|
||||||
// Clear pad
|
// Clear pad
|
||||||
memset(_pPADStatus, 0, sizeof(SPADStatus));
|
memset(_pPADStatus, 0, sizeof(SPADStatus));
|
||||||
|
|
||||||
_pPADStatus->stickY = base;
|
_pPADStatus->stickY = base;
|
||||||
_pPADStatus->stickX = base;
|
_pPADStatus->stickX = base;
|
||||||
_pPADStatus->substickX = base;
|
_pPADStatus->substickX = base;
|
||||||
_pPADStatus->substickY = base;
|
_pPADStatus->substickY = base;
|
||||||
_pPADStatus->button |= PAD_USE_ORIGIN;
|
_pPADStatus->button |= PAD_USE_ORIGIN;
|
||||||
|
|
||||||
_pPADStatus->err = PAD_ERR_NONE;
|
_pPADStatus->err = PAD_ERR_NONE;
|
||||||
|
|
||||||
int stickvalue = (KeyStatus[CTL_HALFPRESS]) ? 40 : 100;
|
int stickvalue = (KeyStatus[CTL_HALFPRESS]) ? 40 : 100;
|
||||||
int triggervalue = (KeyStatus[CTL_HALFPRESS]) ? 100 : 255;
|
int triggervalue = (KeyStatus[CTL_HALFPRESS]) ? 100 : 255;
|
||||||
|
int sensevalue = (KeyStatus[CTL_HALFPRESS]) ? 100 : 255;
|
||||||
|
|
||||||
if (KeyStatus[CTL_MAINLEFT]){_pPADStatus->stickX -= stickvalue;}
|
if (KeyStatus[CTL_MAINLEFT]){_pPADStatus->stickX -= stickvalue;}
|
||||||
if (KeyStatus[CTL_MAINUP]){_pPADStatus->stickY += stickvalue;}
|
if (KeyStatus[CTL_MAINUP]){_pPADStatus->stickY += stickvalue;}
|
||||||
|
@ -246,12 +277,12 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
||||||
|
|
||||||
if (KeyStatus[CTL_A]) {
|
if (KeyStatus[CTL_A]) {
|
||||||
_pPADStatus->button |= PAD_BUTTON_A;
|
_pPADStatus->button |= PAD_BUTTON_A;
|
||||||
_pPADStatus->analogA = 255;
|
_pPADStatus->analogA = sensevalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KeyStatus[CTL_B]) {
|
if (KeyStatus[CTL_B]) {
|
||||||
_pPADStatus->button |= PAD_BUTTON_B;
|
_pPADStatus->button |= PAD_BUTTON_B;
|
||||||
_pPADStatus->analogB = 255;
|
_pPADStatus->analogB = sensevalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KeyStatus[CTL_X]){_pPADStatus->button |= PAD_BUTTON_X;}
|
if (KeyStatus[CTL_X]){_pPADStatus->button |= PAD_BUTTON_X;}
|
||||||
|
@ -327,7 +358,7 @@ void LoadConfig()
|
||||||
sf::Key::F,
|
sf::Key::F,
|
||||||
sf::Key::H,
|
sf::Key::H,
|
||||||
sf::Key::LShift, //halfpress
|
sf::Key::LShift, //halfpress
|
||||||
sf::Key::P
|
sf::Key::P // mic
|
||||||
};
|
};
|
||||||
|
|
||||||
IniFile file;
|
IniFile file;
|
||||||
|
@ -340,9 +371,12 @@ void LoadConfig()
|
||||||
file.Get(SectionName, "Attached", &pad[i].bAttached, i==0);
|
file.Get(SectionName, "Attached", &pad[i].bAttached, i==0);
|
||||||
file.Get(SectionName, "DisableOnBackground", &pad[i].bDisable, false);
|
file.Get(SectionName, "DisableOnBackground", &pad[i].bDisable, false);
|
||||||
for (int x = 0; x < NUMCONTROLS; x++) {
|
for (int x = 0; x < NUMCONTROLS; x++) {
|
||||||
file.Get(SectionName, controlNames[x],
|
int key;
|
||||||
&pad[i].keyForControl[x],
|
file.Get(SectionName, controlNames[x],
|
||||||
(i==0)?defaultKeyForControl[x]:0);
|
&key, (i==0)?defaultKeyForControl[x]:0);
|
||||||
|
|
||||||
|
pad[i].keyForControl[x] = (sf::Key::Code)key;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,12 +52,14 @@ enum
|
||||||
struct SPads {
|
struct SPads {
|
||||||
bool bAttached; // Pad is "attached" to the gamecube/wii
|
bool bAttached; // Pad is "attached" to the gamecube/wii
|
||||||
bool bDisable; // Disabled when dolphin isn't in focus
|
bool bDisable; // Disabled when dolphin isn't in focus
|
||||||
unsigned int keyForControl[NUMCONTROLS];// Keyboard mapping
|
sf::Key::Code keyForControl[NUMCONTROLS];// Keyboard mapping
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SPads pad[];
|
extern SPads pad[];
|
||||||
|
|
||||||
void LoadConfig();
|
void LoadConfig();
|
||||||
void SaveConfig();
|
void SaveConfig();
|
||||||
|
bool registerKey(int nPad, int id, sf::Key::Code code, int mods = 0);
|
||||||
|
bool ParseKeyEvent(sf::Event ev);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue