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"
|
|
|
|
|
2009-01-05 17:46:36 +00:00
|
|
|
#define NUMKEYS 300
|
|
|
|
#define NUMMODS 8
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2009-01-04 22:58:20 +00:00
|
|
|
enum Modifiers {
|
2008-12-30 10:35:52 +00:00
|
|
|
UseAlt = 1,
|
|
|
|
UseShift = 2,
|
|
|
|
UseCtrl = 4
|
|
|
|
};
|
|
|
|
|
2009-01-05 17:46:36 +00:00
|
|
|
struct Keys {
|
2008-12-29 20:12:19 +00:00
|
|
|
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
|
|
|
|
2009-01-04 22:58:20 +00:00
|
|
|
class EventHandler {
|
|
|
|
|
2008-12-29 14:30:38 +00:00
|
|
|
private:
|
2009-01-05 17:46:36 +00:00
|
|
|
listenFuncPtr keys[NUMKEYS][NUMMODS];
|
2009-01-04 22:58:20 +00:00
|
|
|
listenFuncPtr mouse[sf::Mouse::Count+1];
|
|
|
|
listenFuncPtr joys[sf::Joy::Count+1];
|
2008-12-30 10:35:52 +00:00
|
|
|
std::queue<sf::Event> eventQueue;
|
2009-01-05 13:39:54 +00:00
|
|
|
static EventHandler *m_Instance;
|
2009-01-05 17:46:36 +00:00
|
|
|
|
|
|
|
protected:
|
2009-01-05 13:39:54 +00:00
|
|
|
EventHandler(const EventHandler&);
|
|
|
|
EventHandler& operator= (const EventHandler&);
|
2009-01-05 17:46:36 +00:00
|
|
|
|
2009-01-04 22:58:20 +00:00
|
|
|
EventHandler();
|
2009-01-05 13:39:54 +00:00
|
|
|
~EventHandler();
|
2009-01-05 17:46:36 +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();
|
2009-01-05 13:39:54 +00:00
|
|
|
static EventHandler *GetInstance();
|
2010-02-16 04:34:41 +00:00
|
|
|
static void Init();
|
|
|
|
static void Shutdown();
|
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
|