more event handler stuff
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1721 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
e8949267f0
commit
443e505154
|
@ -1,6 +1,34 @@
|
||||||
#include "EventHandler.h"
|
#include "EventHandler.h"
|
||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
|
|
||||||
|
bool EventHandler::RegisterEventListener(listenFuncPtr func, Keys key) {
|
||||||
|
if (key.inputType == KeyboardInput) {
|
||||||
|
if (keys[key.keyCode][key.mods])
|
||||||
|
return false;
|
||||||
|
keys[key.keyCode][key.mods] = func;
|
||||||
|
} else if (key.inputType == MouseInput) {
|
||||||
|
if (mouse[key.mouseButton])
|
||||||
|
return false;
|
||||||
|
mouse[key.mouseButton] = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
eventQueue.push(*ev);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool EventHandler::TestEvent (Keys k, sf::Event e)
|
bool EventHandler::TestEvent (Keys k, sf::Event e)
|
||||||
{
|
{
|
||||||
//Mouse event
|
//Mouse event
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include "Event.hpp"
|
#include "Event.hpp"
|
||||||
|
|
||||||
typedef bool (*listenFuncPtr) (sf::Event *);
|
typedef bool (*listenFuncPtr) (sf::Event);
|
||||||
enum InputType
|
enum InputType
|
||||||
{
|
{
|
||||||
KeyboardInput,
|
KeyboardInput,
|
||||||
|
@ -11,25 +11,32 @@ enum InputType
|
||||||
JoystickInput
|
JoystickInput
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum Modifiers {
|
||||||
|
UseAlt = 1,
|
||||||
|
UseShift = 2,
|
||||||
|
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;
|
||||||
|
int mods;
|
||||||
sf::Mouse::Button mouseButton;
|
sf::Mouse::Button mouseButton;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventHandler {
|
class EventHandler {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
listenFuncPtr keys[sf::Key::Count][6];
|
listenFuncPtr keys[sf::Key::Count][8];
|
||||||
listenFuncPtr mouse[sf::Mouse::Count];
|
listenFuncPtr mouse[sf::Mouse::Count];
|
||||||
listenFuncPtr joys[sf::Joy::Count];
|
listenFuncPtr joys[sf::Joy::Count];
|
||||||
std::queue<Keys> eventQueue;
|
std::queue<sf::Event> eventQueue;
|
||||||
public:
|
public:
|
||||||
bool RegisterEventListener(listenFuncPtr func, int event, int type);
|
bool RegisterEventListener(listenFuncPtr func, Keys key);
|
||||||
void Update();
|
void Update();
|
||||||
bool addEvent(sf::Event *);
|
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 int wxCharCodeWXToSF(int id);
|
||||||
static void SFKeyToString(unsigned int keycode, char *keyStr);
|
static void SFKeyToString(unsigned int keycode, char *keyStr);
|
||||||
|
|
|
@ -305,12 +305,8 @@ void LoadConfig()
|
||||||
char SectionName[32];
|
char SectionName[32];
|
||||||
sprintf(SectionName, "PAD%i", i+1);
|
sprintf(SectionName, "PAD%i", i+1);
|
||||||
|
|
||||||
file.Get(SectionName, "UseXPad", &pad[i].bEnableXPad, i==0);
|
|
||||||
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);
|
||||||
file.Get(SectionName, "Rumble", &pad[i].bRumble, true);
|
|
||||||
file.Get(SectionName, "XPad#", &pad[i].XPadPlayer);
|
|
||||||
|
|
||||||
for (int x = 0; x < NUMCONTROLS; x++) {
|
for (int x = 0; x < NUMCONTROLS; x++) {
|
||||||
file.Get(SectionName, controlNames[x],
|
file.Get(SectionName, controlNames[x],
|
||||||
&pad[i].keyForControl[x],
|
&pad[i].keyForControl[x],
|
||||||
|
@ -330,11 +326,8 @@ void SaveConfig()
|
||||||
char SectionName[32];
|
char SectionName[32];
|
||||||
sprintf(SectionName, "PAD%i", i+1);
|
sprintf(SectionName, "PAD%i", i+1);
|
||||||
|
|
||||||
file.Set(SectionName, "UseXPad", pad[i].bEnableXPad);
|
|
||||||
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);
|
||||||
file.Set(SectionName, "Rumble", pad[i].bRumble);
|
|
||||||
file.Set(SectionName, "XPad#", pad[i].XPadPlayer);
|
|
||||||
|
|
||||||
for (int x = 0; x < NUMCONTROLS; x++)
|
for (int x = 0; x < NUMCONTROLS; x++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,11 +75,8 @@ static const char* controlNames[] =
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SPads {
|
struct SPads {
|
||||||
bool bEnableXPad; // Use an XPad in addition to the keyboard?
|
|
||||||
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
|
||||||
bool bRumble; // Rumble for xpad
|
|
||||||
int XPadPlayer; // Player# of the xpad
|
|
||||||
unsigned int keyForControl[NUMCONTROLS];// Keyboard mapping
|
unsigned int keyForControl[NUMCONTROLS];// Keyboard mapping
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue