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>
#endif
bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key)
{
if (key.inputType == KeyboardInput)
{
if (keys[key.keyCode][key.mods])
EventHandler::EventHandler() {
memset(keys, sizeof(listenFuncPtr) * (sf::Key::Escape+1)*8, 0);
memset(mouse, sizeof(listenFuncPtr) * (sf::Mouse::Count+1), 0);
memset(joys, sizeof(listenFuncPtr) * (sf::Joy::Count+1), 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])
return false;
keys[key.keyCode][key.mods] = func;
}
else if (key.inputType == MouseInput)
{
} else if (key.inputType == MouseInput) {
if (mouse[key.mouseButton])
return false;
mouse[key.mouseButton] = func;
@ -22,16 +26,12 @@ bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key)
return true;
}
bool EventHandler::RemoveEventListener(Keys key)
{
if (key.inputType == KeyboardInput)
{
if (! keys[key.keyCode][key.mods])
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])
return false;
keys[key.keyCode][key.mods] = NULL;
}
else if (key.inputType == MouseInput)
{
} else if (key.inputType == MouseInput) {
if (! mouse[key.mouseButton])
return false;
mouse[key.mouseButton] = NULL;
@ -40,18 +40,15 @@ bool EventHandler::RemoveEventListener(Keys key)
return true;
}
void EventHandler::Update()
{
for (unsigned int i = 0; i < eventQueue.size();i++)
{
void EventHandler::Update() {
for (unsigned int i = 0; i < eventQueue.size();i++) {
sf::Event ev = eventQueue.front();
eventQueue.pop();
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);
return true;
}
@ -162,8 +159,7 @@ sf::Key::Code EventHandler::wxCharCodeToSF(int id)
}
#endif
void EventHandler::SFKeyToString(sf::Key::Code keycode, char *keyStr)
{
void EventHandler::SFKeyToString(sf::Key::Code keycode, char *keyStr) {
switch (keycode) {
/* case sf::Key::A = 'a': 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::F15: sprintf(keyStr, "F15"); 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
};
enum Modifiers
{
enum Modifiers {
UseAlt = 1,
UseShift = 2,
UseCtrl = 4
@ -28,15 +27,15 @@ struct Keys
sf::Mouse::Button mouseButton;
};
class EventHandler
{
private:
listenFuncPtr keys[sf::Key::Count][8];
listenFuncPtr mouse[sf::Mouse::Count];
listenFuncPtr joys[sf::Joy::Count];
std::queue<sf::Event> eventQueue;
class EventHandler {
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 RemoveEventListener(Keys key);
void Update();

View File

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

View File

@ -65,8 +65,7 @@ ConfigDialog::~ConfigDialog()
}
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);
char keyStr[10] = {0};
@ -83,8 +82,7 @@ inline void AddControl(wxPanel *pan, wxButton **button, wxStaticBoxSizer *sizer,
sizer->Add(hButton, 0, wxALIGN_RIGHT|wxALL);
}
void ConfigDialog::CreateGUIControls()
{
void ConfigDialog::CreateGUIControls() {
// Notebook
m_Notebook = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize);
@ -117,8 +115,7 @@ void ConfigDialog::CreateGUIControls()
this->SetSizer(sMain);
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"));
sDevice[i] = new wxBoxSizer(wxHORIZONTAL);
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);
}
void ConfigDialog::OnKeyDown(wxKeyEvent& event)
{
void ConfigDialog::OnKeyDown(wxKeyEvent& event) {
if(clickedButton != NULL) {
int page = m_Notebook->GetSelection();
@ -218,8 +213,7 @@ void ConfigDialog::ControllerSettingsChanged(wxCommandEvent& event)
{
int page = m_Notebook->GetSelection();
switch (event.GetId())
{
switch (event.GetId()) {
case ID_ATTACHED:
pad[page].bAttached = m_Attached[page]->GetValue();
break;
@ -231,8 +225,7 @@ void ConfigDialog::ControllerSettingsChanged(wxCommandEvent& event)
void ConfigDialog::OnButtonClick(wxCommandEvent& event)
{
if(clickedButton)
{
if(clickedButton) {
clickedButton->SetLabel(oldLabel);
}
clickedButton = (wxButton *)event.GetEventObject();

View File

@ -378,8 +378,8 @@ void LoadConfig()
file.Get(SectionName, controlNames[x],
&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);
}
}
}