Somethin'

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1777 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2009-01-04 22:58:20 +00:00
parent b2e96e1ca5
commit 94fb0dc220
5 changed files with 193 additions and 204 deletions

View File

@ -4,16 +4,20 @@
#include <wx/wx.h> #include <wx/wx.h>
#endif #endif
bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) EventHandler::EventHandler() {
{ memset(keys, sizeof(listenFuncPtr) * (sf::Key::Escape+1)*8, 0);
if (key.inputType == KeyboardInput) memset(mouse, sizeof(listenFuncPtr) * (sf::Mouse::Count+1), 0);
{ memset(joys, sizeof(listenFuncPtr) * (sf::Joy::Count+1), 0);
if (keys[key.keyCode][key.mods]) }
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])
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)
{
if (mouse[key.mouseButton]) if (mouse[key.mouseButton])
return false; return false;
mouse[key.mouseButton] = func; mouse[key.mouseButton] = func;
@ -22,16 +26,12 @@ bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key)
return true; return true;
} }
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 (! 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)
{
if (! mouse[key.mouseButton]) if (! mouse[key.mouseButton])
return false; return false;
mouse[key.mouseButton] = NULL; mouse[key.mouseButton] = NULL;
@ -40,18 +40,15 @@ bool EventHandler::RemoveEventListener(Keys key)
return true; 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();
eventQueue.pop(); eventQueue.pop();
keys[ev.Key.Code][ev.Key.Alt+2*ev.Key.Shift+4*ev.Key.Control](ev); keys[ev.Key.Code][ev.Key.Alt+2*ev.Key.Shift+4*ev.Key.Control](ev);
} }
} }
bool EventHandler::addEvent(sf::Event *ev) bool EventHandler::addEvent(sf::Event *ev) {
{
eventQueue.push(*ev); eventQueue.push(*ev);
return true; return true;
} }
@ -162,8 +159,7 @@ sf::Key::Code EventHandler::wxCharCodeToSF(int id)
} }
#endif #endif
void EventHandler::SFKeyToString(sf::Key::Code 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;
@ -266,6 +262,11 @@ void EventHandler::SFKeyToString(sf::Key::Code keycode, char *keyStr)
case sf::Key::F14: sprintf(keyStr, "F14"); break; case sf::Key::F14: sprintf(keyStr, "F14"); break;
case sf::Key::F15: sprintf(keyStr, "F15"); break; case sf::Key::F15: sprintf(keyStr, "F15"); break;
case sf::Key::Pause: sprintf(keyStr, "Paues"); break; case sf::Key::Pause: sprintf(keyStr, "Paues"); break;
default: sprintf(keyStr, "%c", keycode); default:
if (keycode > sf::Key::Escape)
sprintf(keyStr, "Invalid Key");
else
sprintf(keyStr, "%c", keycode);
break;
} }
} }

View File

@ -12,8 +12,7 @@ enum InputType
JoystickInput JoystickInput
}; };
enum Modifiers enum Modifiers {
{
UseAlt = 1, UseAlt = 1,
UseShift = 2, UseShift = 2,
UseCtrl = 4 UseCtrl = 4
@ -28,15 +27,15 @@ struct Keys
sf::Mouse::Button mouseButton; sf::Mouse::Button mouseButton;
}; };
class EventHandler class EventHandler {
{
private:
listenFuncPtr keys[sf::Key::Count][8];
listenFuncPtr mouse[sf::Mouse::Count];
listenFuncPtr joys[sf::Joy::Count];
std::queue<sf::Event> eventQueue;
public: private:
listenFuncPtr keys[sf::Key::Escape+1][8];
listenFuncPtr mouse[sf::Mouse::Count+1];
listenFuncPtr joys[sf::Joy::Count+1];
std::queue<sf::Event> eventQueue;
public:
EventHandler();
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

@ -4,16 +4,12 @@ EventHandler *eventHandler = NULL;
namespace InputCommon namespace InputCommon
{ {
void Init() void Init() {
{
#if defined GLTEST && GLTEST
// init the event handler // init the event handler
eventHandler = new EventHandler(); eventHandler = new EventHandler();
#endif
} }
void Shutdown() void Shutdown() {
{
if (eventHandler) if (eventHandler)
delete eventHandler; delete eventHandler;
} }

View File

@ -65,8 +65,7 @@ ConfigDialog::~ConfigDialog()
} }
inline void AddControl(wxPanel *pan, wxButton **button, wxStaticBoxSizer *sizer, inline void AddControl(wxPanel *pan, wxButton **button, wxStaticBoxSizer *sizer,
const char *name, int ctl, int controller) const char *name, int ctl, int controller) {
{
wxBoxSizer *hButton = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *hButton = new wxBoxSizer(wxHORIZONTAL);
char keyStr[10] = {0}; char keyStr[10] = {0};
@ -83,8 +82,7 @@ inline void AddControl(wxPanel *pan, wxButton **button, wxStaticBoxSizer *sizer,
sizer->Add(hButton, 0, wxALIGN_RIGHT|wxALL); sizer->Add(hButton, 0, wxALIGN_RIGHT|wxALL);
} }
void ConfigDialog::CreateGUIControls() void ConfigDialog::CreateGUIControls() {
{
// Notebook // Notebook
m_Notebook = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize); m_Notebook = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize);
@ -117,8 +115,7 @@ void ConfigDialog::CreateGUIControls()
this->SetSizer(sMain); this->SetSizer(sMain);
this->Layout(); this->Layout();
for(int i = 0; i < 4; i++) for(int i = 0; i < 4; i++) {
{
sbDevice[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("Controller Settings")); sbDevice[i] = new wxStaticBoxSizer(wxVERTICAL, m_Controller[i], wxT("Controller Settings"));
sDevice[i] = new wxBoxSizer(wxHORIZONTAL); sDevice[i] = new wxBoxSizer(wxHORIZONTAL);
m_Attached[i] = new wxCheckBox(m_Controller[i], ID_ATTACHED, wxT("Controller attached"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); m_Attached[i] = new wxCheckBox(m_Controller[i], ID_ATTACHED, wxT("Controller attached"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
@ -185,13 +182,11 @@ void ConfigDialog::CreateGUIControls()
} }
} }
void ConfigDialog::OnClose(wxCloseEvent& event) void ConfigDialog::OnClose(wxCloseEvent& event) {
{
EndModal(0); EndModal(0);
} }
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();
@ -218,8 +213,7 @@ void ConfigDialog::ControllerSettingsChanged(wxCommandEvent& event)
{ {
int page = m_Notebook->GetSelection(); int page = m_Notebook->GetSelection();
switch (event.GetId()) switch (event.GetId()) {
{
case ID_ATTACHED: case ID_ATTACHED:
pad[page].bAttached = m_Attached[page]->GetValue(); pad[page].bAttached = m_Attached[page]->GetValue();
break; break;
@ -231,8 +225,7 @@ void ConfigDialog::ControllerSettingsChanged(wxCommandEvent& event)
void ConfigDialog::OnButtonClick(wxCommandEvent& event) void ConfigDialog::OnButtonClick(wxCommandEvent& event)
{ {
if(clickedButton) if(clickedButton) {
{
clickedButton->SetLabel(oldLabel); clickedButton->SetLabel(oldLabel);
} }
clickedButton = (wxButton *)event.GetEventObject(); clickedButton = (wxButton *)event.GetEventObject();

View File

@ -378,8 +378,8 @@ void LoadConfig()
file.Get(SectionName, controlNames[x], file.Get(SectionName, controlNames[x],
&key, (i==0)?defaultKeyForControl[x]:0); &key, (i==0)?defaultKeyForControl[x]:0);
pad[i].keyForControl[x] = (sf::Key::Code)key; // pad[i].keyForControl[x] = (sf::Key::Code)key;
registerKey(i, x, (sf::Key::Code)key);
} }
} }
} }