aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJody Northup2009-08-16 07:40:13 +0000
committerJody Northup2009-08-16 07:40:13 +0000
commitcbffcb609f752edcc3f086521c9e0c75b5ee4cc4 (patch)
treee212df62509a74330dd231bd652cc9ff583c5fb5
parent43d57fd333afa54f4e85f30e2ef8231444988066 (diff)
downloadscummvm-rg350-cbffcb609f752edcc3f086521c9e0c75b5ee4cc4.tar.gz
scummvm-rg350-cbffcb609f752edcc3f086521c9e0c75b5ee4cc4.tar.bz2
scummvm-rg350-cbffcb609f752edcc3f086521c9e0c75b5ee4cc4.zip
Replaced KeyStates with ActionKeys in the keymapper, removed SDL ASCII code mismatch workaround hacks, fixed the memory leaks I had previously created.
svn-id: r43430
-rw-r--r--backends/keymapper/action.cpp17
-rw-r--r--backends/keymapper/action.h4
-rw-r--r--backends/keymapper/hardware-key.h19
-rw-r--r--backends/keymapper/keymap.cpp12
-rw-r--r--backends/keymapper/keymap.h6
-rw-r--r--backends/keymapper/keymapper.cpp22
-rw-r--r--backends/keymapper/keymapper.h6
-rw-r--r--backends/keymapper/remap-dialog.cpp9
-rw-r--r--backends/platform/sdl/hardwarekeys.cpp2
9 files changed, 48 insertions, 49 deletions
diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp
index 3feb593f19..1f4efbf457 100644
--- a/backends/keymapper/action.cpp
+++ b/backends/keymapper/action.cpp
@@ -43,14 +43,21 @@ Action::Action(Keymap *boss, const char *i, String des, ActionType typ,
_boss->addAction(this);
}
-void Action::mapKey(const HardwareKey *key) {
+void Action::mapKey(const HardwareKey *key, byte flags) {
if (_hwKey)
+ {
_boss->unregisterMapping(this);
+ delete _hwKey;
+ }
- _hwKey = key;
-
- if (_hwKey)
- _boss->registerMapping(this, _hwKey);
+ if (key) {
+ _hwKey = new HardwareKey(*key);
+ if (flags)
+ _hwKey->key.flags = flags & _hwKey->modMask;
+ if (_hwKey)
+ _boss->registerMapping(this, _hwKey);
+ } else
+ _hwKey = NULL;
}
const HardwareKey *Action::getMappedKey() const {
diff --git a/backends/keymapper/action.h b/backends/keymapper/action.h
index 31576e2960..c49518b605 100644
--- a/backends/keymapper/action.h
+++ b/backends/keymapper/action.h
@@ -59,7 +59,7 @@ struct Action {
private:
/** Hardware key that is mapped to this Action */
- const HardwareKey *_hwKey;
+ HardwareKey *_hwKey;
Keymap *_boss;
public:
@@ -105,7 +105,7 @@ public:
return _boss;
}
- void mapKey(const HardwareKey *key);
+ void mapKey(const HardwareKey *key, byte flags = 0);
const HardwareKey *getMappedKey() const;
};
diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h
index 94e6589a17..70168def2d 100644
--- a/backends/keymapper/hardware-key.h
+++ b/backends/keymapper/hardware-key.h
@@ -49,6 +49,17 @@ struct ActionKey {
KeyCode keycode;
byte flags;
+ ActionKey () {
+ keycode = KEYCODE_INVALID;
+ flags = 0;
+ }
+
+ ActionKey (const KeyState &key) {
+ keycode = key.keycode;
+ flags = key.flags;
+ }
+
+
ActionKey (KeyCode ky, byte f) {
keycode = ky;
flags = f;
@@ -75,7 +86,7 @@ struct HardwareKey {
* The KeyState that is generated by the back-end
* when this hardware key is pressed.
*/
- KeyState key;
+ ActionKey key;
KeyType type;
ActionType preferredAction;
@@ -83,7 +94,7 @@ struct HardwareKey {
// Mask of modifiers that can possibly apply to this key.
byte modMask;
- HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "", byte mods = ~0,
+ HardwareKey(const char *i, ActionKey ky = ActionKey(), String desc = "", byte mods = ~0,
KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType)
: key(ky), description(desc), type(typ), preferredAction(prefAct), modMask(mods) {
assert(i);
@@ -150,7 +161,7 @@ public:
return 0;
}
- const HardwareKey *findHardwareKey(const KeyState& keystate) const {
+ const HardwareKey *findHardwareKey(const ActionKey& keystate) const {
List<const HardwareKey*>::const_iterator it;
for (it = _keys.begin(); it != _keys.end(); it++) {
@@ -170,7 +181,7 @@ public:
return 0;
}
- const HardwareMod *findHardwareMod(const KeyState& keystate) const {
+ const HardwareMod *findHardwareMod(const ActionKey& keystate) const {
List<const HardwareMod*>::const_iterator it;
for (it = _mods.begin(); it != _mods.end(); it++) {
diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp
index fe6f133254..9d8b6046cd 100644
--- a/backends/keymapper/keymap.cpp
+++ b/backends/keymapper/keymap.cpp
@@ -60,7 +60,7 @@ void Keymap::addAction(Action *action) {
}
void Keymap::registerMapping(Action *action, const HardwareKey *hwKey) {
- HashMap<KeyState, Action*>::iterator it;
+ HashMap<ActionKey, Action*>::iterator it;
it = _keymap.find(hwKey->key);
@@ -105,8 +105,8 @@ const Action *Keymap::findAction(const char *id) const {
return 0;
}
-Action *Keymap::getMappedAction(const KeyState& ks) const {
- HashMap<KeyState, Action*>::iterator it;
+Action *Keymap::getMappedAction(const ActionKey& ks) const {
+ HashMap<ActionKey, Action*>::iterator it;
it = _keymap.find(ks);
@@ -157,9 +157,7 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
_configDomain->erase(key);
continue;
}
- HardwareKey *mappedKey = new HardwareKey(*hwKey);
- mappedKey->key.flags = modId;
- ua->mapKey(mappedKey);
+ ua->mapKey(hwKey,modId);
}
}
@@ -335,7 +333,7 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
}
}
-Action *Keymap::getParentMappedAction(KeyState key) {
+Action *Keymap::getParentMappedAction(const ActionKey &key) {
if (_parent) {
Action *act = _parent->getMappedAction(key);
diff --git a/backends/keymapper/keymap.h b/backends/keymapper/keymap.h
index 5bb277c924..f4ad8d110d 100644
--- a/backends/keymapper/keymap.h
+++ b/backends/keymapper/keymap.h
@@ -89,7 +89,7 @@ public:
* @param key the key that is mapped to the required Action
* @return a pointer to the Action or 0 if no
*/
- Action *getMappedAction(const KeyState& ks) const;
+ Action *getMappedAction(const ActionKey& ks) const;
void setConfigDomain(ConfigManager::Domain *dom);
@@ -147,12 +147,12 @@ private:
void internalMapKey(Action *action, HardwareKey *hwKey);
- Action *getParentMappedAction(KeyState key);
+ Action *getParentMappedAction(const ActionKey &key);
String _name;
Keymap *_parent;
List<Action*> _actions;
- HashMap<KeyState, Action*> _keymap;
+ HashMap<ActionKey, Action*> _keymap;
ConfigManager::Domain *_configDomain;
};
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp
index d101e8e0d2..704affb3fe 100644
--- a/backends/keymapper/keymapper.cpp
+++ b/backends/keymapper/keymapper.cpp
@@ -190,33 +190,21 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) {
return false;
Action *action = 0;
-
if (keyDown) {
- // HACK: Temporary fix for modifier recognition, get the hwkey's keystate
- // to correct for keydown and keyup generating different ascii codes in SDL
- // to be solved more permanently by using a structure other than KeyState
-
- const HardwareKey *hwkey = findHardwareKey(key);
- if (!hwkey)
- return false;
-
- KeyState k = hwkey->key;
- k.flags = key.flags & hwkey->modMask;
-
// Search for key in active keymap stack
for (int i = _activeMaps.size() - 1; i >= 0; --i) {
MapRecord mr = _activeMaps[i];
- action = mr.keymap->getMappedAction(k);
+ action = mr.keymap->getMappedAction(key);
if (action || mr.inherit == false)
break;
}
if (action)
- _keysDown[k] = action;
+ _keysDown[key] = action;
} else {
- HashMap<KeyState, Action*>::iterator it = _keysDown.find(key);
+ HashMap<ActionKey, Action*>::iterator it = _keysDown.find(key);
if (it != _keysDown.end()) {
action = it->_value;
@@ -279,11 +267,11 @@ void Keymapper::executeAction(const Action *action, bool keyDown) {
}
}
-const HardwareKey *Keymapper::findHardwareKey(const KeyState& key) {
+const HardwareKey *Keymapper::findHardwareKey(const ActionKey& key) {
return (_hardwareKeys) ? _hardwareKeys->findHardwareKey(key) : 0;
}
-const HardwareMod *Keymapper::findHardwareMod(const KeyState& key) {
+const HardwareMod *Keymapper::findHardwareMod(const ActionKey& key) {
return (_hardwareKeys) ? _hardwareKeys->findHardwareMod(key) : 0;
}
diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h
index af3314f8f5..24c76fb09f 100644
--- a/backends/keymapper/keymapper.h
+++ b/backends/keymapper/keymapper.h
@@ -168,12 +168,12 @@ public:
/**
* Return a HardwareKey pointer for the given key state
*/
- const HardwareKey *findHardwareKey(const KeyState& key);
+ const HardwareKey *findHardwareKey(const ActionKey& key);
/**
* Return a HardwareMod pointer for the given key state
*/
- const HardwareMod *findHardwareMod(const KeyState& key);
+ const HardwareMod *findHardwareMod(const ActionKey& key);
Domain& getGlobalDomain() { return _globalDomain; }
Domain& getGameDomain() { return _gameDomain; }
@@ -198,7 +198,7 @@ private:
bool _enabled;
Stack<MapRecord> _activeMaps;
- HashMap<KeyState, Action*> _keysDown;
+ HashMap<ActionKey, Action*> _keysDown;
};
diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp
index 323790a700..0a93785c08 100644
--- a/backends/keymapper/remap-dialog.cpp
+++ b/backends/keymapper/remap-dialog.cpp
@@ -243,14 +243,9 @@ void RemapDialog::handleKeyUp(Common::KeyState state) {
debug( "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
if (hwkey) {
- //FIXME: this leaks memory and there's no good way to get this pointer again as
- //a non-const. this should be done differently when we switch to actionKeys.
- HardwareKey *mappedkey = new HardwareKey(*hwkey);
- mappedkey->description = hwkey->description;
- mappedkey->key.flags = (state.flags & hwkey->modMask);
-
- _activeRemapAction->mapKey(mappedkey);
+ _activeRemapAction->mapKey(hwkey,state.flags);
_activeRemapAction->getParent()->saveMappings();
+
_changes = true;
stopRemapping();
}
diff --git a/backends/platform/sdl/hardwarekeys.cpp b/backends/platform/sdl/hardwarekeys.cpp
index 506e71d092..af9b0ba319 100644
--- a/backends/platform/sdl/hardwarekeys.cpp
+++ b/backends/platform/sdl/hardwarekeys.cpp
@@ -227,7 +227,7 @@ Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() {
snprintf(fullKeyId, 50, "%s", key->hwId);
snprintf(fullKeyDesc, 100, "%s", key->desc);
- keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, 0), fullKeyDesc, key->modableMask, key->preferredAction));
+ keySet->addHardwareKey(new HardwareKey(fullKeyId, ActionKey(key->keycode, 0), fullKeyDesc, key->modableMask, key->preferredAction));
}
keySetInited = true;