mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
some code fix
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1796 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
a533a9dc3d
commit
f156361104
@ -7,33 +7,37 @@
|
||||
EventHandler *EventHandler::m_Instance = 0;
|
||||
|
||||
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(joys, sizeof(listenFuncPtr) * (sf::Joy::Count+1), 0);
|
||||
|
||||
}
|
||||
|
||||
EventHandler::~EventHandler() {
|
||||
}
|
||||
|
||||
EventHandler::EventHandler *GetInstance() {
|
||||
if (! EventHandler::m_Instance)
|
||||
EventHandler::m_Instance = new EventHandler();
|
||||
EventHandler *EventHandler::GetInstance() {
|
||||
if (! m_Instance)
|
||||
m_Instance = new EventHandler();
|
||||
|
||||
return EventHandler::m_Instance;
|
||||
return m_Instance;
|
||||
}
|
||||
|
||||
void EventHandler::Destroy() {
|
||||
if (EventHandler::m_Instance)
|
||||
delete EventHandler::m_Instance;
|
||||
if (m_Instance)
|
||||
delete m_Instance;
|
||||
|
||||
EventHandler::m_Instance = 0;
|
||||
m_Instance = 0;
|
||||
}
|
||||
|
||||
bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) {
|
||||
if (key.inputType == KeyboardInput) {
|
||||
fprintf(stderr, "Registering %d\n", key.keyCode);
|
||||
if (key.keyCode == sf::Key::Count ||
|
||||
key.keyCode >= sf::Key::Escape || keys[key.keyCode][key.mods])
|
||||
// fprintf(stderr, "Registering %d:%d %p\n", key.keyCode, key.mods, func);
|
||||
if (key.keyCode == sf::Key::Count || key.mods >= NUMMODS ||
|
||||
key.keyCode >= NUMKEYS || keys[key.keyCode][key.mods])
|
||||
return false;
|
||||
keys[key.keyCode][key.mods] = func;
|
||||
} else if (key.inputType == MouseInput) {
|
||||
@ -47,7 +51,8 @@ bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) {
|
||||
|
||||
bool EventHandler::RemoveEventListener(Keys key) {
|
||||
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;
|
||||
keys[key.keyCode][key.mods] = NULL;
|
||||
} 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_SCROLL: sfKey = sf::Key::Scroll_Lock; break;
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
@ -4,6 +4,9 @@
|
||||
#include <queue>
|
||||
#include "Event.hpp"
|
||||
|
||||
#define NUMKEYS 300
|
||||
#define NUMMODS 8
|
||||
|
||||
typedef bool (*listenFuncPtr) (sf::Event);
|
||||
enum InputType
|
||||
{
|
||||
@ -18,8 +21,7 @@ enum Modifiers {
|
||||
UseCtrl = 4
|
||||
};
|
||||
|
||||
struct Keys
|
||||
{
|
||||
struct Keys {
|
||||
InputType inputType;
|
||||
sf::Event::EventType eventType;
|
||||
sf::Key::Code keyCode;
|
||||
@ -30,20 +32,21 @@ struct Keys
|
||||
class EventHandler {
|
||||
|
||||
private:
|
||||
listenFuncPtr keys[sf::Key::Escape+1][8];
|
||||
listenFuncPtr keys[NUMKEYS][NUMMODS];
|
||||
listenFuncPtr mouse[sf::Mouse::Count+1];
|
||||
listenFuncPtr joys[sf::Joy::Count+1];
|
||||
std::queue<sf::Event> eventQueue;
|
||||
public:
|
||||
static EventHandler *m_Instance;
|
||||
|
||||
// protected:
|
||||
|
||||
protected:
|
||||
EventHandler(const EventHandler&);
|
||||
EventHandler& operator= (const EventHandler&);
|
||||
|
||||
|
||||
EventHandler();
|
||||
~EventHandler();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
bool RegisterEventListener(listenFuncPtr func, Keys key);
|
||||
bool RemoveEventListener(Keys key);
|
||||
void Update();
|
||||
|
@ -6,7 +6,7 @@ namespace InputCommon
|
||||
{
|
||||
void Init() {
|
||||
// init the event handler
|
||||
//EventHandler::GetInstance();
|
||||
EventHandler::GetInstance();
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
|
@ -189,7 +189,8 @@ void ConfigDialog::OnClose(wxCloseEvent& event) {
|
||||
void ConfigDialog::OnKeyDown(wxKeyEvent& event) {
|
||||
if(clickedButton != NULL) {
|
||||
int page = m_Notebook->GetSelection();
|
||||
|
||||
|
||||
fprintf(stderr, "Got key code %d\n",event.GetKeyCode());
|
||||
sf::Key::Code sfcode = EventHandler::wxCharCodeToSF(event.GetKeyCode());
|
||||
char sfstr[100];
|
||||
EventHandler::SFKeyToString(sfcode, sfstr);
|
||||
|
@ -115,7 +115,7 @@ bool registerKey(int nPad, int id, sf::Key::Code code, int mods) {
|
||||
oldKey.mods = mods;
|
||||
|
||||
// Might be not be registered yet
|
||||
eventHandler->RemoveEventListener(oldKey);
|
||||
// eventHandler->RemoveEventListener(oldKey);
|
||||
}
|
||||
|
||||
pad[nPad].keyForControl[id] = code;
|
||||
@ -373,7 +373,7 @@ void LoadConfig()
|
||||
IniFile 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];
|
||||
sprintf(SectionName, "PAD%i", i+1);
|
||||
|
||||
@ -395,19 +395,17 @@ void SaveConfig()
|
||||
{
|
||||
IniFile file;
|
||||
file.Load(FULL_CONFIG_DIR EPAD_CONFIG_FILE);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
char SectionName[32];
|
||||
sprintf(SectionName, "PAD%i", i+1);
|
||||
|
||||
file.Set(SectionName, "Attached", pad[i].bAttached);
|
||||
file.Set(SectionName, "DisableOnBackground", pad[i].bDisable);
|
||||
|
||||
for (int x = 0; x < NUMCONTROLS; x++)
|
||||
{
|
||||
file.Set(SectionName, controlNames[x], pad[i].keyForControl[x]);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++) {
|
||||
char SectionName[32];
|
||||
sprintf(SectionName, "PAD%i", i+1);
|
||||
|
||||
file.Set(SectionName, "Attached", pad[i].bAttached);
|
||||
file.Set(SectionName, "DisableOnBackground", pad[i].bDisable);
|
||||
|
||||
for (int x = 0; x < NUMCONTROLS; x++) {
|
||||
file.Set(SectionName, controlNames[x], pad[i].keyForControl[x]);
|
||||
}
|
||||
}
|
||||
file.Save(FULL_CONFIG_DIR EPAD_CONFIG_FILE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user