/** * @author: Thomas Brandého */ #ifndef KEYBINDINGS_H #define KEYBINDINGS_H #include #include #define NO_KEY -1 #define NO_ACTION -1 namespace input{ enum Source{NONE=-1,KEYBOARD,MOUSE,CONTROLLER,SOURCE_COUNT}; } struct Action { int action; input::Source source; int controller_id; static Action getNull(); bool isNull(){ return (action == NO_ACTION) && (source == input::NONE); } friend bool operator ==(const Action& action1, const Action& action2){ return (action1.action == action2.action) && (action1.source == action2.source); } }; struct Binding{ Action action; int key; int type; }; class IKeysMap{ public: enum {PRESSED, RELEASED, HOLD}; IKeysMap(); std::vector getBindings(Action action) const; protected: std::vector keys; }; class Context { public: Context(std::string name, std::vector actions); std::string getName(); std::vector getActions() const; private: std::string name; std::vector actions; }; class KeyBindings { public: KeyBindings(); KeyBindings(const Context &context, const IKeysMap &keysmap); Action getPressedAction(input::Source src,int key) const; Action getReleasedAction(input::Source src,int key) const; Action getHoldAction(input::Source src,int key) const; private: std::unordered_map> bindings_pressed; std::unordered_map> bindings_released; std::unordered_map> bindings_hold; void setPressedAction(int key, Action action); void setReleasedAction(int key, Action action); void setHoldAction(int key, Action action); void init_map_bindings(); }; #endif