diff options
author | Stephen Kennedy | 2008-08-18 10:07:11 +0000 |
---|---|---|
committer | Stephen Kennedy | 2008-08-18 10:07:11 +0000 |
commit | d92909203b56d9b3fa6c4989bdeb83dbed5b94d5 (patch) | |
tree | 350de91c678c790dde49487804b02e1bb317f1d2 /backends/keymapper | |
parent | 63c4a61032bd97b478de9cbf82510f461d08f653 (diff) | |
download | scummvm-rg350-d92909203b56d9b3fa6c4989bdeb83dbed5b94d5.tar.gz scummvm-rg350-d92909203b56d9b3fa6c4989bdeb83dbed5b94d5.tar.bz2 scummvm-rg350-d92909203b56d9b3fa6c4989bdeb83dbed5b94d5.zip |
- proper init of virtual keyboard now implemented (involved added EventManager::init() which is called after screen has been initialised)
- changed HardwareKey / Action id field to an array of 4 chars instead of int32. Means that the keymap key/value pairs in config file are more readable.
svn-id: r33986
Diffstat (limited to 'backends/keymapper')
-rw-r--r-- | backends/keymapper/action.cpp | 8 | ||||
-rw-r--r-- | backends/keymapper/action.h | 6 | ||||
-rw-r--r-- | backends/keymapper/hardware-key.h | 21 | ||||
-rw-r--r-- | backends/keymapper/keymap.cpp | 55 | ||||
-rw-r--r-- | backends/keymapper/keymap.h | 6 |
5 files changed, 46 insertions, 50 deletions
diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp index de1c5b7b43..f1566a75f2 100644 --- a/backends/keymapper/action.cpp +++ b/backends/keymapper/action.cpp @@ -28,11 +28,15 @@ namespace Common { -Action::Action(Keymap *boss, int32 i, String des, ActionCategory cat, +Action::Action(Keymap *boss, const char *i, String des, ActionCategory cat, ActionType typ, int pri, int grp, int flg) - : _boss(boss), id(i), description(des), category(cat), type(typ), + : _boss(boss), description(des), category(cat), type(typ), priority(pri), group(grp), flags(flg), _hwKey(0) { + assert(i); assert(_boss); + + strncpy(id, i, ACTION_ID_SIZE); + _boss->addAction(this); } diff --git a/backends/keymapper/action.h b/backends/keymapper/action.h index cc1b4c7262..835ae5007f 100644 --- a/backends/keymapper/action.h +++ b/backends/keymapper/action.h @@ -68,9 +68,11 @@ enum ActionCategory { kActionCategoryMax }; +#define ACTION_ID_SIZE (4) + struct Action { /** unique id used for saving/loading to config */ - int32 id; + char id[ACTION_ID_SIZE]; /** Human readable description */ String description; @@ -88,7 +90,7 @@ private: Keymap *_boss; public: - Action(Keymap *boss, int32 id, String des = "", + Action(Keymap *boss, const char *id, String des = "", ActionCategory cat = kGenericActionCategory, ActionType typ = kGenericActionType, int pri = 0, int grp = 0, int flg = 0 ); diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h index 8807e6db9f..85badae3cc 100644 --- a/backends/keymapper/hardware-key.h +++ b/backends/keymapper/hardware-key.h @@ -30,12 +30,14 @@ namespace Common { +#define HWKEY_ID_SIZE (4) + /** * Describes an available hardware key */ struct HardwareKey { /** unique id used for saving/loading to config */ - int32 id; + char id[HWKEY_ID_SIZE]; /** Human readable description */ String description; /** @@ -48,15 +50,12 @@ struct HardwareKey { ActionType preferredType; int16 group; - HardwareKey(int32 i, KeyState ks = KeyState(), String des = "", + HardwareKey(const char *i, KeyState ks = KeyState(), String des = "", ActionCategory cat = kGenericActionCategory, - ActionType ty = kGenericActionType, int gr = 0) { - id = i; - key = ks; - description = des; - preferredCategory = cat; - preferredType = ty; - group = gr; + ActionType ty = kGenericActionType, int gr = 0) + : key(ks), description(des), preferredCategory(cat), preferredType(ty), group(gr) { + assert(i); + strncpy(id, i, HWKEY_ID_SIZE); } }; @@ -82,10 +81,10 @@ public: ++_count; } - const HardwareKey *findHardwareKey(int32 id) const { + const HardwareKey *findHardwareKey(const char *id) const { List<const HardwareKey*>::iterator it; for (it = _keys.begin(); it != _keys.end(); it++) { - if ((*it)->id == id) + if (strncmp((*it)->id, id, HWKEY_ID_SIZE) == 0) return (*it); } return 0; diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index 5b6addd8a6..6a4e946210 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -26,6 +26,8 @@ #include "backends/keymapper/keymap.h" #include "backends/keymapper/hardware-key.h" +#define KEYMAP_KEY_PREFIX "keymap_" + namespace Common { Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap(), _configDomain(0) { @@ -68,23 +70,23 @@ void Keymap::unregisterMapping(Action *action) { } } -Action *Keymap::getAction(int32 id) { +Action *Keymap::getAction(const char *id) { return findAction(id); } -Action *Keymap::findAction(int32 id) { +Action *Keymap::findAction(const char *id) { List<Action*>::iterator it; for (it = _actions.begin(); it != _actions.end(); it++) { - if ((*it)->id == id) + if (strncmp((*it)->id, id, ACTION_ID_SIZE) == 0) return *it; } return 0; } -const Action *Keymap::findAction(int32 id) const { +const Action *Keymap::findAction(const char *id) const { List<Action*>::const_iterator it; for (it = _actions.begin(); it != _actions.end(); it++) { - if ((*it)->id == id) + if (strncmp((*it)->id, id, ACTION_ID_SIZE) == 0) return *it; } return 0; @@ -106,37 +108,25 @@ void Keymap::setConfigDomain(ConfigManager::Domain *dom) { void Keymap::loadMappings(const HardwareKeySet *hwKeys) { if (!_configDomain) return; ConfigManager::Domain::iterator it; - String prefix = "km_" + _name + "_"; + String prefix = KEYMAP_KEY_PREFIX + _name + "_"; for (it = _configDomain->begin(); it != _configDomain->end(); it++) { const String& key = it->_key; if (!key.hasPrefix(prefix.c_str())) continue; // parse Action ID - const char *actionIdStart = key.c_str() + prefix.size(); - char *err; - int32 actionId = (int32) strtol(actionIdStart, &err, 0); - if (err == actionIdStart) { - warning("'%s' is not a valid Action ID", err); - continue; - } + const char *actionId = key.c_str() + prefix.size(); Action *ua = getAction(actionId); if (!ua) { - warning("'%s' keymap does not contain Action with ID %d", - _name.c_str(), (int)actionId); + warning("'%s' keymap does not contain Action with ID %s", + _name.c_str(), actionId); _configDomain->erase(key); continue; } - // parse HardwareKey ID - int32 hwKeyId = (int32) strtol(it->_value.c_str(), &err, 0); - if (err == it->_value.c_str()) { - warning("'%s' is not a valid HardwareKey ID", err); - continue; - } - const HardwareKey *hwKey = hwKeys->findHardwareKey(hwKeyId); + const HardwareKey *hwKey = hwKeys->findHardwareKey(it->_value.c_str()); if (!hwKey) { - warning("HardwareKey with ID %d not known", (int)hwKeyId); + warning("HardwareKey with ID %s not known", it->_value.c_str()); _configDomain->erase(key); continue; } @@ -148,16 +138,17 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) { void Keymap::saveMappings() { if (!_configDomain) return; List<Action*>::const_iterator it; - char buf[12]; - String prefix = "km_" + _name + "_"; + String prefix = KEYMAP_KEY_PREFIX + _name + "_"; for (it = _actions.begin(); it != _actions.end(); it++) { - sprintf(buf, "%d", (*it)->id); - String key = prefix + buf; - if ((*it)->getMappedKey()) - sprintf(buf, "%d", (*it)->getMappedKey()->id); - else - strcpy(buf, ""); - _configDomain->setVal(key, buf); + uint actIdLen = strnlen((*it)->id, ACTION_ID_SIZE); + String actId((*it)->id, (*it)->id + actIdLen); + if ((*it)->getMappedKey()) { + uint hwIdLen = strnlen((*it)->getMappedKey()->id, HWKEY_ID_SIZE); + String hwId((*it)->getMappedKey()->id, (*it)->getMappedKey()->id + hwIdLen); + _configDomain->setVal(prefix + actId, hwId); + } else { + _configDomain->setVal(prefix + actId, ""); + } } } diff --git a/backends/keymapper/keymap.h b/backends/keymapper/keymap.h index bb4aff960d..3dda238373 100644 --- a/backends/keymapper/keymap.h +++ b/backends/keymapper/keymap.h @@ -61,7 +61,7 @@ public: * @param id id of Action to retrieve * @return Pointer to the Action or 0 if not found */ - Action *getAction(int32 id); + Action *getAction(const char *id); /** * Get the list of all the Actions contained in this Keymap @@ -124,8 +124,8 @@ private: */ void unregisterMapping(Action *action); - Action *findAction(int32 id); - const Action *findAction(int32 id) const; + Action *findAction(const char *id); + const Action *findAction(const char *id) const; void internalMapKey(Action *action, HardwareKey *hwKey); |