some code fix

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1796 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2009-01-05 17:46:36 +00:00
parent a533a9dc3d
commit f156361104
5 changed files with 56 additions and 43 deletions

View File

@ -7,33 +7,37 @@
EventHandler *EventHandler::m_Instance = 0; EventHandler *EventHandler::m_Instance = 0;
EventHandler::EventHandler() { EventHandler::EventHandler() {
memset(keys, sizeof(listenFuncPtr) * (sf::Key::Escape+1)*8, 0); for (int i=0; i<NUMKEYS; i++)
for (int j=0; j<NUMMODS; j++)
keys[i][j] = NULL;
// memset(keys, sizeof(listenFuncPtr) * NUMKEYS*NUMMODS, 0);
memset(mouse, sizeof(listenFuncPtr) * (sf::Mouse::Count+1), 0); memset(mouse, sizeof(listenFuncPtr) * (sf::Mouse::Count+1), 0);
memset(joys, sizeof(listenFuncPtr) * (sf::Joy::Count+1), 0); memset(joys, sizeof(listenFuncPtr) * (sf::Joy::Count+1), 0);
} }
EventHandler::~EventHandler() { EventHandler::~EventHandler() {
} }
EventHandler::EventHandler *GetInstance() { EventHandler *EventHandler::GetInstance() {
if (! EventHandler::m_Instance) if (! m_Instance)
EventHandler::m_Instance = new EventHandler(); m_Instance = new EventHandler();
return EventHandler::m_Instance; return m_Instance;
} }
void EventHandler::Destroy() { void EventHandler::Destroy() {
if (EventHandler::m_Instance) if (m_Instance)
delete EventHandler::m_Instance; delete m_Instance;
EventHandler::m_Instance = 0; m_Instance = 0;
} }
bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) { bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) {
if (key.inputType == KeyboardInput) { if (key.inputType == KeyboardInput) {
fprintf(stderr, "Registering %d\n", key.keyCode); // fprintf(stderr, "Registering %d:%d %p\n", key.keyCode, key.mods, func);
if (key.keyCode == sf::Key::Count || if (key.keyCode == sf::Key::Count || key.mods >= NUMMODS ||
key.keyCode >= sf::Key::Escape || keys[key.keyCode][key.mods]) key.keyCode >= NUMKEYS || keys[key.keyCode][key.mods])
return false; return false;
keys[key.keyCode][key.mods] = func; keys[key.keyCode][key.mods] = func;
} else if (key.inputType == MouseInput) { } else if (key.inputType == MouseInput) {
@ -47,7 +51,8 @@ bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) {
bool EventHandler::RemoveEventListener(Keys key) { bool EventHandler::RemoveEventListener(Keys key) {
if (key.inputType == KeyboardInput) { if (key.inputType == KeyboardInput) {
if ((key.keyCode == sf::Key::Count || key.keyCode >= sf::Key::Escape) && ! keys[key.keyCode][key.mods]) if ((key.keyCode == sf::Key::Count || key.keyCode >= NUMKEYS
|| key.mods >= NUMMODS) && ! keys[key.keyCode][key.mods])
return false; return false;
keys[key.keyCode][key.mods] = NULL; keys[key.keyCode][key.mods] = NULL;
} else if (key.inputType == MouseInput) { } else if (key.inputType == MouseInput) {
@ -167,13 +172,19 @@ sf::Key::Code EventHandler::wxCharCodeToSF(int id)
// 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: default:
if ((id >= 'a' && id <= 'z') ||
(id >= '0' && id <= '9'))
sfKey = (sf::Key::Code)id;
else
sfKey = sf::Key::Count; // Invalid key
}
// To lower (will tolower work on windows?)
if (id >= 'A' && id <= 'Z')
id = id - 'A' + 'a';
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;
} }
#endif #endif

View File

@ -4,6 +4,9 @@
#include <queue> #include <queue>
#include "Event.hpp" #include "Event.hpp"
#define NUMKEYS 300
#define NUMMODS 8
typedef bool (*listenFuncPtr) (sf::Event); typedef bool (*listenFuncPtr) (sf::Event);
enum InputType enum InputType
{ {
@ -18,8 +21,7 @@ enum Modifiers {
UseCtrl = 4 UseCtrl = 4
}; };
struct Keys struct Keys {
{
InputType inputType; InputType inputType;
sf::Event::EventType eventType; sf::Event::EventType eventType;
sf::Key::Code keyCode; sf::Key::Code keyCode;
@ -30,20 +32,21 @@ struct Keys
class EventHandler { class EventHandler {
private: private:
listenFuncPtr keys[sf::Key::Escape+1][8]; listenFuncPtr keys[NUMKEYS][NUMMODS];
listenFuncPtr mouse[sf::Mouse::Count+1]; listenFuncPtr mouse[sf::Mouse::Count+1];
listenFuncPtr joys[sf::Joy::Count+1]; listenFuncPtr joys[sf::Joy::Count+1];
std::queue<sf::Event> eventQueue; std::queue<sf::Event> eventQueue;
public:
static EventHandler *m_Instance; static EventHandler *m_Instance;
// protected: protected:
EventHandler(const EventHandler&); EventHandler(const EventHandler&);
EventHandler& operator= (const EventHandler&); EventHandler& operator= (const EventHandler&);
EventHandler(); EventHandler();
~EventHandler(); ~EventHandler();
public:
bool RegisterEventListener(listenFuncPtr func, Keys key); bool RegisterEventListener(listenFuncPtr func, Keys key);
bool RemoveEventListener(Keys key); bool RemoveEventListener(Keys key);
void Update(); void Update();

View File

@ -6,7 +6,7 @@ namespace InputCommon
{ {
void Init() { void Init() {
// init the event handler // init the event handler
//EventHandler::GetInstance(); EventHandler::GetInstance();
} }
void Shutdown() { void Shutdown() {

View File

@ -189,7 +189,8 @@ void ConfigDialog::OnClose(wxCloseEvent& event) {
void ConfigDialog::OnKeyDown(wxKeyEvent& event) { void ConfigDialog::OnKeyDown(wxKeyEvent& event) {
if(clickedButton != NULL) { if(clickedButton != NULL) {
int page = m_Notebook->GetSelection(); int page = m_Notebook->GetSelection();
fprintf(stderr, "Got key code %d\n",event.GetKeyCode());
sf::Key::Code sfcode = EventHandler::wxCharCodeToSF(event.GetKeyCode()); sf::Key::Code sfcode = EventHandler::wxCharCodeToSF(event.GetKeyCode());
char sfstr[100]; char sfstr[100];
EventHandler::SFKeyToString(sfcode, sfstr); EventHandler::SFKeyToString(sfcode, sfstr);

View File

@ -115,7 +115,7 @@ bool registerKey(int nPad, int id, sf::Key::Code code, int mods) {
oldKey.mods = mods; oldKey.mods = mods;
// Might be not be registered yet // Might be not be registered yet
eventHandler->RemoveEventListener(oldKey); // eventHandler->RemoveEventListener(oldKey);
} }
pad[nPad].keyForControl[id] = code; pad[nPad].keyForControl[id] = code;
@ -373,7 +373,7 @@ void LoadConfig()
IniFile file; IniFile file;
file.Load(FULL_CONFIG_DIR EPAD_CONFIG_FILE); file.Load(FULL_CONFIG_DIR EPAD_CONFIG_FILE);
for(int i = 0; i < 4; i++) { for(int i = 0; i < 1; i++) {
char SectionName[32]; char SectionName[32];
sprintf(SectionName, "PAD%i", i+1); sprintf(SectionName, "PAD%i", i+1);
@ -395,19 +395,17 @@ void SaveConfig()
{ {
IniFile file; IniFile file;
file.Load(FULL_CONFIG_DIR EPAD_CONFIG_FILE); file.Load(FULL_CONFIG_DIR EPAD_CONFIG_FILE);
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++) {
{ char SectionName[32];
char SectionName[32]; sprintf(SectionName, "PAD%i", i+1);
sprintf(SectionName, "PAD%i", i+1);
file.Set(SectionName, "Attached", pad[i].bAttached);
file.Set(SectionName, "Attached", pad[i].bAttached); file.Set(SectionName, "DisableOnBackground", pad[i].bDisable);
file.Set(SectionName, "DisableOnBackground", pad[i].bDisable);
for (int x = 0; x < NUMCONTROLS; x++) {
for (int x = 0; x < NUMCONTROLS; x++) file.Set(SectionName, controlNames[x], pad[i].keyForControl[x]);
{ }
file.Set(SectionName, controlNames[x], pad[i].keyForControl[x]);
}
} }
file.Save(FULL_CONFIG_DIR EPAD_CONFIG_FILE); file.Save(FULL_CONFIG_DIR EPAD_CONFIG_FILE);
} }