2008-12-29 14:30:38 +00:00
|
|
|
#ifndef EVENTHANDER_H
|
|
|
|
#define EVENTHANDER_H 1
|
2009-01-03 23:33:45 +00:00
|
|
|
#include "Common.h"
|
2008-12-29 14:30:38 +00:00
|
|
|
#include <queue>
|
|
|
|
#include "Event.hpp"
|
|
|
|
|
2008-12-30 10:35:52 +00:00
|
|
|
typedef bool (*listenFuncPtr) (sf::Event);
|
2008-12-29 20:12:19 +00:00
|
|
|
enum InputType
|
|
|
|
{
|
|
|
|
KeyboardInput,
|
|
|
|
MouseInput,
|
|
|
|
JoystickInput
|
|
|
|
};
|
|
|
|
|
2008-12-30 10:35:52 +00:00
|
|
|
enum Modifiers {
|
|
|
|
UseAlt = 1,
|
|
|
|
UseShift = 2,
|
|
|
|
UseCtrl = 4
|
|
|
|
};
|
|
|
|
|
2008-12-29 20:12:19 +00:00
|
|
|
struct Keys
|
|
|
|
{
|
|
|
|
InputType inputType;
|
2008-12-30 10:35:52 +00:00
|
|
|
sf::Event::EventType eventType;
|
2008-12-29 20:12:19 +00:00
|
|
|
sf::Key::Code keyCode;
|
2008-12-30 10:35:52 +00:00
|
|
|
int mods;
|
2008-12-29 20:12:19 +00:00
|
|
|
sf::Mouse::Button mouseButton;
|
|
|
|
};
|
2008-12-29 14:30:38 +00:00
|
|
|
|
|
|
|
class EventHandler {
|
|
|
|
|
|
|
|
private:
|
2008-12-30 10:35:52 +00:00
|
|
|
listenFuncPtr keys[sf::Key::Count][8];
|
2008-12-29 21:47:45 +00:00
|
|
|
listenFuncPtr mouse[sf::Mouse::Count];
|
|
|
|
listenFuncPtr joys[sf::Joy::Count];
|
2008-12-30 10:35:52 +00:00
|
|
|
std::queue<sf::Event> eventQueue;
|
2008-12-29 14:30:38 +00:00
|
|
|
public:
|
2008-12-30 10:35:52 +00:00
|
|
|
bool RegisterEventListener(listenFuncPtr func, Keys key);
|
2009-01-02 14:10:52 +00:00
|
|
|
bool RemoveEventListener(Keys key);
|
2008-12-29 14:30:38 +00:00
|
|
|
void Update();
|
2008-12-30 10:35:52 +00:00
|
|
|
bool addEvent(sf::Event *e);
|
2008-12-29 20:12:19 +00:00
|
|
|
static bool TestEvent (Keys k, sf::Event e);
|
2009-01-03 23:33:45 +00:00
|
|
|
#if defined HAVE_WX && HAVE_WX
|
2009-01-02 14:10:52 +00:00
|
|
|
static sf::Key::Code wxCharCodeToSF(int id);
|
2009-01-03 23:33:45 +00:00
|
|
|
#endif
|
2009-01-02 14:10:52 +00:00
|
|
|
static void SFKeyToString(sf::Key::Code keycode, char *keyStr);
|
2008-12-29 14:30:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|