// remap.h #ifndef REMAP_H #define REMAP_H #include #include #include #include #include #include struct AxisTransform; /// Connects an AxisTransform with named input axes and an output axis struct AxisManipulator { std::vector inputs; std::string output; Ptr transform; AxisManipulator(Ptr transform, std::string out); AxisManipulator & input(std::string in); }; /// A means for stacked event filtering. /// An event filter receives events, can perform actions upon them and then /// decide whether the event should be passed to the next-higher stacked /// event filter. class IEventFilter : virtual public Object { public: /** Called whenever an event occurs. Can decide whether the event should be passed on. @param ev the event to dispatch @return true, if the event should be passed on, false otherwise */ virtual bool feedEvent(SDL_Event & ev) = 0; }; /// Enables events to trigger method calls. /// The organization into sheets makes it possible to switch between /// them. Each input context has a sheet associated with it. /// For example, while the player controls a car, a different sheet /// gets used as while he controls an airplane. /// EventRemapper allows multiple sheets to be active at once. If an event /// is triggered, only the latest-added sheet handling the event receives it. class EventSheet : public Object { typedef std::map OutMap; OutMap outmap; public: ~EventSheet(); void map(const char *action, const ActionSlot & slot); bool triggerAction(const char *action); }; class EventRemapper : public SigObject { public: enum ButtonType { KEYBOARD_KEY, MOUSE_BUTTON, JOYSTICK_BUTTON }; /// A Structure that defines a control on a specific device of a specific /// type. The hierarchy is type->device->button struct Button { inline Button( ButtonType type, int device, int button ) : type(type) , device(device) , button(button) { } ButtonType type; int device; int button; inline bool operator< (const Button& other) const { return type < other.type || type == other.type && ( device < other.device || device == other.device && button < other.button); } std::string getFriendlyName() const; }; typedef int JoystickIndex; typedef int AxisIndex, HatIndex; typedef std::pair JoystickAxis; /////////////////////////////////////////////////////////////////////// EventRemapper(); ~EventRemapper(); /// Resets every button mapping to the initial state void clearButtonMappings(); /// Resets all joystick axis mappings void clearJoystickAxisMappings(); /// Removes all registered event filters void clearEventFilters(); /// Removes all axis manipulators void clearAxisManipulators(); /////////////////////////////////////////////////////////////////////// // Meta-information about actions and axes /////////////////////////////////////////////////////////////////////// typedef std::string Name; typedef std::string FriendlyName; typedef std::string Description; typedef std::pair DictionaryEntry; /// Dictionary associates a (human-readable) friendly name and a /// longer description with an action or axis name. typedef std::map Dictionary; /// Public Dictionary containing friendly names and descriptions for actions Dictionary action_dict; /// Public Dictionary containing friendly names and descriptions for axes Dictionary axis_dict; /////////////////////////////////////////////////////////////////////// // Querying functions /////////////////////////////////////////////////////////////////////// /// Returns the list of all known actions std::vector getActions(); /// Queries which buttons are mapped to a specific action std::vector