diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/common/hardware-key.h | 95 | ||||
-rw-r--r-- | backends/common/keymap-manager.cpp | 14 | ||||
-rw-r--r-- | backends/common/keymap-manager.h | 1 | ||||
-rw-r--r-- | backends/common/keymap.h | 101 | ||||
-rw-r--r-- | backends/common/keymapper.cpp | 31 | ||||
-rw-r--r-- | backends/common/keymapper.h | 20 | ||||
-rw-r--r-- | backends/common/user-action.h | 70 |
7 files changed, 224 insertions, 108 deletions
diff --git a/backends/common/hardware-key.h b/backends/common/hardware-key.h new file mode 100644 index 0000000000..de1984dc31 --- /dev/null +++ b/backends/common/hardware-key.h @@ -0,0 +1,95 @@ +#ifndef COMMON_HARDWAREKEY +#define COMMON_HARDWAREKEY + +#include "backends/common/user-action.h" + +namespace Common { + +/** +* Describes an available hardware key +*/ +struct HardwareKey { + /** unique id used for saving/loading to config */ + int32 id; + /** Human readable description */ + String description; + /** + * The KeyState that is generated by the back-end + * when this hardware key is pressed. + */ + KeyState key; + + UserActionCategory preferredCategory; + UserActionType preferredType; + int16 group; + + HardwareKey(KeyState ks = KeyState(), String des = "", + UserActionCategory cat = kGenericUserActionCategory, + UserActionType ty = kGenericUserActionType, int gr = 0) { + key = ks; + description = des; + preferredCategory = cat; + preferredType = ty; + group = gr; + } +}; + + +/** + * Simple class to encapsulate a device's set of HardwareKeys. + * Each device should extend this and call addHardwareKey a number of times + * in its constructor to define the device's available keys. + */ +class HardwareKeySet { +public: + + HardwareKeySet() {} + ~HardwareKeySet() { + List<HardwareKey*>::iterator it; + for (it = _keys.begin(); it != _keys.end(); it++) + delete *it; + } + + void addHardwareKey(HardwareKey *key) { + checkForKey(key); + _keys.push_back(key); + } + + const HardwareKey *findHardwareKey(int32 id) const { + List<HardwareKey*>::iterator it; + for (it = _keys.begin(); it != _keys.end(); it++) { + if ((*it)->id == id) + return (*it); + } + return 0; + } + + const HardwareKey *findHardwareKey(const KeyState& keystate) const { + List<HardwareKey*>::iterator it; + for (it = _keys.begin(); it != _keys.end(); it++) { + if ((*it)->key == keystate) + return (*it); + } + return 0; + } + + +private: + + void checkForKey(HardwareKey *key) { + List<HardwareKey*>::iterator it; + for (it = _keys.begin(); it != _keys.end(); it++) { + if ((*it)->id == key->id) + error("HardwareKey with id %d already given!\n", key->id); + else if ((*it)->key == key->key) + error("HardwareKey with same KeyState already given!\n"); + } + } + + List<HardwareKey*> _keys; +}; + + +} // end of namespace Common + +#endif
\ No newline at end of file diff --git a/backends/common/keymap-manager.cpp b/backends/common/keymap-manager.cpp index d52615faea..6f60018abe 100644 --- a/backends/common/keymap-manager.cpp +++ b/backends/common/keymap-manager.cpp @@ -1,15 +1,19 @@ #include "backends/common/keymap-manager.h" -#define GLOBAL_ID "GLOBAL" +#define GLOBAL_ID_STR "___GLOBAL" namespace Common { +KeymapManager::KeymapManager() { + +} + bool KeymapManager::registerSuperGlobalKeymap(const Keymap& map) { - return registerKeymap(GLOBAL_ID, GLOBAL_ID, map); + return registerKeymap(GLOBAL_ID_STR, GLOBAL_ID_STR, map); } bool KeymapManager::registerGlobalKeymap(const String& name, const Keymap& map) { - return registerKeymap(name, GLOBAL_ID, map); + return registerKeymap(name, GLOBAL_ID_STR, map); } bool KeymapManager::registerKeymap(const String& name, const String& domain, const Keymap& map) { @@ -26,11 +30,11 @@ bool KeymapManager::registerKeymap(const String& name, const String& domain, con } bool KeymapManager::unregisterSuperGlobalKeymap() { - return unregisterKeymap(GLOBAL_ID, GLOBAL_ID); + return unregisterKeymap(GLOBAL_ID_STR, GLOBAL_ID_STR); } bool KeymapManager::unregisterGlobalKeymap(const String& name) { - return unregisterKeymap(name, GLOBAL_ID); + return unregisterKeymap(name, GLOBAL_ID_STR); } bool KeymapManager::unregisterKeymap(const String& name, const String& domain) { diff --git a/backends/common/keymap-manager.h b/backends/common/keymap-manager.h index f5878a2467..d9c97d7de1 100644 --- a/backends/common/keymap-manager.h +++ b/backends/common/keymap-manager.h @@ -2,6 +2,7 @@ #define COMMON_KEYMAP_MANAGER #include "backends/common/keymap.h" +#include "common/list.h" namespace Common { diff --git a/backends/common/keymap.h b/backends/common/keymap.h index c03e2e03d5..a2e204827e 100644 --- a/backends/common/keymap.h +++ b/backends/common/keymap.h @@ -1,110 +1,15 @@ #ifndef COMMON_KEYMAP #define COMMON_KEYMAP +#include "backends/common/hardware-key.h" +#include "backends/common/user-action.h" #include "common/array.h" -#include "common/events.h" +#include "common/keyboard.h" #include "common/func.h" #include "common/hashmap.h" -#include "common/list.h" namespace Common { -enum UserActionType { - kGenericUserActionType, - - // common actions - kDirectionUpUserAction, - kDirectionDownUserAction, - kDirectionLeftUserAction, - kDirectionRightUserAction, - kLeftClickUserAction, - kRightClickUserAction, - kSaveUserAction, - kMenuUserAction, - - kUserActionTypeMax -}; - -enum UserActionCategory { - kGenericUserActionCategory, - // classes of action - probably need to be slightly more specific than this - kInGameUserAction, // effects the actual gameplay - kSystemUserAction, //show a menu / change volume / etc - - kUserActionCategoryMax -}; - -/** -* Describes an available hardware key -*/ -struct HardwareKey { - /** unique id used for saving/loading to config */ - int32 id; - /** Human readable description */ - String description; - /** - * The KeyState that is generated by the back-end - * when this hardware key is pressed. - */ - KeyState key; - - UserActionCategory preferredCategory; - UserActionType preferredType; - int16 group; - - HardwareKey(KeyState ks = KeyState(), String des = "", - UserActionCategory cat = kGenericUserActionCategory, - UserActionType ty = kGenericUserActionType, int gr = 0) { - key = ks; - description = des; - preferredCategory = cat; - preferredType = ty; - group = gr; - } -}; - -struct UserAction { - /** unique id used for saving/loading to config */ - int32 id; - /** Human readable description */ - String description; - /** Events to be sent when mapped key is pressed */ - List<Event> events; - UserActionCategory category; - UserActionType type; - int priority; - int group; - int flags; - - HardwareKey *hwKey; - - UserAction( String des = "", - UserActionCategory cat = kGenericUserActionCategory, - UserActionType ty = kGenericUserActionType, - int pr = 0, int gr = 0, int fl = 0 ) { - description = des; - category = cat; - type = ty; - priority = pr; - group = gr; - flags = fl; - hwKey = 0; - } -}; - -/** - * EqualTo function for KeyState - */ -template<> struct EqualTo<KeyState> - : public BinaryFunction<KeyState, KeyState, bool> { - - bool operator()(const KeyState &x, const KeyState &y) const { - return (x.keycode == y.keycode) - && (x.ascii == y.ascii) - && (x.flags == y.flags); - } -}; - /** * Hash function for KeyState */ diff --git a/backends/common/keymapper.cpp b/backends/common/keymapper.cpp new file mode 100644 index 0000000000..4edd64aa44 --- /dev/null +++ b/backends/common/keymapper.cpp @@ -0,0 +1,31 @@ +#include "backends/common/keymapper.h" +#include "backends/common/keymap-manager.h" + +namespace Common { + +Keymapper::Keymapper(EventManager *evtMgr) { + _eventMan = evtMgr; + _keymapMan = new KeymapManager(); + _currentMap = 0; + _hardwareKeys = 0; +} + +void Keymapper::registerHardwareKeySet(HardwareKeySet *keys) { + if (_hardwareKeys) + error("Hardware key set already registered!\n"); + _hardwareKeys = keys; +} + +const HardwareKeySet *Keymapper::getHardwareKeySet() { + return _hardwareKeys; +} + +void Keymapper::addGlobalKeyMap(const String& name, Keymap& keymap) { + _keymapMan->registerGlobalKeymap(name, keymap); +} + +void Keymapper::addGameKeyMap(const String& gameid, const String& name, Keymap& keymap) { + _keymapMan->registerKeymap(name, gameid, keymap); +} + +} // end of namespace Common diff --git a/backends/common/keymapper.h b/backends/common/keymapper.h index 1b3518c224..4f25ea37ff 100644 --- a/backends/common/keymapper.h +++ b/backends/common/keymapper.h @@ -1,23 +1,33 @@ #ifndef COMMON_KEYMAPPER #define COMMON_KEYMAPPER -#include "backends/common/keymap-manager.h" +#include "backends/common/keymap.h" +#include "common/list.h" namespace Common { +class KeymapManager; + class Keymapper { public: - Keymapper(); + Keymapper(EventManager *eventMan); - void addHardwareKey(const HardwareKey& key); + void registerHardwareKeySet(HardwareKeySet *keys); + const HardwareKeySet *getHardwareKeySet(); void addGlobalKeyMap(const String& name, Keymap& keymap); + void addGameKeyMap(const String& gameid, const String& name, Keymap& keymap); private: - KeymapManager _manager; + typedef List<HardwareKey*>::iterator Iterator; + + EventManager *_eventMan; + KeymapManager *_keymapMan; + + Keymap *_currentMap; - List<HardwareKey*> _hardwareKeys; + const HardwareKeySet *_hardwareKeys; }; diff --git a/backends/common/user-action.h b/backends/common/user-action.h new file mode 100644 index 0000000000..31b5473708 --- /dev/null +++ b/backends/common/user-action.h @@ -0,0 +1,70 @@ +#ifndef COMMON_USERACTION +#define COMMON_USERACTION + +#include "common/events.h" +#include "common/list.h" +#include "common/str.h" + +namespace Common { + +struct HardwareKey; + +enum UserActionType { + kGenericUserActionType, + + // common actions + kDirectionUpUserAction, + kDirectionDownUserAction, + kDirectionLeftUserAction, + kDirectionRightUserAction, + kLeftClickUserAction, + kRightClickUserAction, + kSaveUserAction, + kMenuUserAction, + + kUserActionTypeMax +}; + +enum UserActionCategory { + kGenericUserActionCategory, + // classes of action - probably need to be slightly more specific than this + kInGameUserAction, // effects the actual gameplay + kSystemUserAction, //show a menu / change volume / etc + + kUserActionCategoryMax +}; + +struct UserAction { + /** unique id used for saving/loading to config */ + int32 id; + /** Human readable description */ + String description; + /** Events to be sent when mapped key is pressed */ + List<Event> events; + + UserActionCategory category; + UserActionType type; + int priority; + int group; + int flags; + + /** Hardware key that is mapped to this UserAction */ + HardwareKey *hwKey; + + UserAction( String des = "", + UserActionCategory cat = kGenericUserActionCategory, + UserActionType ty = kGenericUserActionType, + int pr = 0, int gr = 0, int fl = 0 ) { + description = des; + category = cat; + type = ty; + priority = pr; + group = gr; + flags = fl; + hwKey = 0; + } +}; + +} // end of namespace Common + +#endif
\ No newline at end of file |