mirror of
https://github.com/libretro/scummvm.git
synced 2024-11-27 19:30:41 +00:00
Added proper saving/loading of mapped key modifiers. Fixed modifier recognition in a much less hackish manner, (but still using a minor hack as a stopgap until KeyState can be replaced as the primary lookup type for the keymapper).
svn-id: r43363
This commit is contained in:
parent
7d9890ff2e
commit
44e7980364
@ -127,6 +127,10 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
|
||||
ConfigManager::Domain::iterator it;
|
||||
String prefix = KEYMAP_KEY_PREFIX + _name + "_";
|
||||
|
||||
uint32 modId = 0;
|
||||
char hwId[HWKEY_ID_SIZE+1];
|
||||
memset(hwId,0,HWKEY_ID_SIZE+1);
|
||||
|
||||
for (it = _configDomain->begin(); it != _configDomain->end(); it++) {
|
||||
const String& key = it->_key;
|
||||
|
||||
@ -145,15 +149,17 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const HardwareKey *hwKey = hwKeys->findHardwareKey(it->_value.c_str());
|
||||
sscanf(it->_value.c_str(),"%d,%s",&modId,hwId);
|
||||
const HardwareKey *hwKey = hwKeys->findHardwareKey(hwId);
|
||||
|
||||
if (!hwKey) {
|
||||
warning("HardwareKey with ID %s not known", it->_value.c_str());
|
||||
_configDomain->erase(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
ua->mapKey(hwKey);
|
||||
HardwareKey *mappedKey = new HardwareKey(*hwKey);
|
||||
mappedKey->key.flags = modId;
|
||||
ua->mapKey(mappedKey);
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,13 +177,19 @@ void Keymap::saveMappings() {
|
||||
|
||||
String actId((*it)->id, (*it)->id + actIdLen);
|
||||
char hwId[HWKEY_ID_SIZE+1];
|
||||
|
||||
memset(hwId, 0, HWKEY_ID_SIZE+1);
|
||||
|
||||
char modId[4];
|
||||
memset(modId, 0, 4);
|
||||
|
||||
if ((*it)->getMappedKey()) {
|
||||
memcpy(hwId, (*it)->getMappedKey()->hwKeyId, HWKEY_ID_SIZE);
|
||||
sprintf(modId,"%d",(*it)->getMappedKey()->key.flags);
|
||||
}
|
||||
_configDomain->setVal(prefix + actId, hwId);
|
||||
String val = modId;
|
||||
val += ',';
|
||||
val += hwId;
|
||||
_configDomain->setVal(prefix + actId, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,18 +192,28 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) {
|
||||
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;
|
||||
|
||||
// Search for key in active keymap stack
|
||||
for (int i = _activeMaps.size() - 1; i >= 0; --i) {
|
||||
MapRecord mr = _activeMaps[i];
|
||||
|
||||
action = mr.keymap->getMappedAction(key);
|
||||
action = mr.keymap->getMappedAction(k);
|
||||
|
||||
if (action || mr.inherit == false)
|
||||
break;
|
||||
}
|
||||
|
||||
if (action)
|
||||
_keysDown[key] = action;
|
||||
_keysDown[k] = action;
|
||||
} else {
|
||||
HashMap<KeyState, Action*>::iterator it = _keysDown.find(key);
|
||||
|
||||
|
@ -239,15 +239,14 @@ void RemapDialog::handleKeyDown(Common::KeyState state) {
|
||||
void RemapDialog::handleKeyUp(Common::KeyState state) {
|
||||
if (_activeRemapAction) {
|
||||
const HardwareKey *hwkey = _keymapper->findHardwareKey(state);
|
||||
const HardwareMod *hwmod = _keymapper->findHardwareMod(state);
|
||||
|
||||
debug(0, "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
|
||||
debug( "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
|
||||
|
||||
if (hwkey) {
|
||||
HardwareKey *temphwkey = new HardwareKey(*hwkey);
|
||||
temphwkey->description = hwkey->description;
|
||||
temphwkey->key.flags = hwmod->modFlags;
|
||||
_activeRemapAction->mapKey(temphwkey);
|
||||
HardwareKey *mappedkey = new HardwareKey(*hwkey);
|
||||
mappedkey->description = hwkey->description;
|
||||
mappedkey->key.flags = (state.flags & hwkey->modMask);
|
||||
_activeRemapAction->mapKey(mappedkey);
|
||||
_activeRemapAction->getParent()->saveMappings();
|
||||
_changes = true;
|
||||
stopRemapping();
|
||||
@ -363,8 +362,21 @@ void RemapDialog::refreshKeymap() {
|
||||
const HardwareKey *mappedKey = info.action->getMappedKey();
|
||||
|
||||
if (mappedKey)
|
||||
widg.keyButton->setLabel(mappedKey->description);
|
||||
else
|
||||
{
|
||||
Common::String description = "";
|
||||
if (mappedKey->key.flags)
|
||||
{
|
||||
byte flags = mappedKey->key.flags;
|
||||
if (flags & KBD_CTRL)
|
||||
description += "Ctrl+";
|
||||
if (flags & KBD_SHIFT)
|
||||
description += "Shift+";
|
||||
if (flags & KBD_ALT)
|
||||
description += "Alt+";
|
||||
}
|
||||
description += mappedKey->description;
|
||||
widg.keyButton->setLabel(description);
|
||||
} else
|
||||
widg.keyButton->setLabel("-");
|
||||
|
||||
widg.actionText->setVisible(true);
|
||||
|
@ -267,7 +267,7 @@ struct KeyState {
|
||||
}
|
||||
|
||||
bool operator ==(const KeyState &x) const {
|
||||
return keycode == x.keycode && /*ascii == x.ascii && */flags == x.flags;
|
||||
return keycode == x.keycode && ascii == x.ascii && flags == x.flags;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user