[Scummvm-cvs-logs] SF.net SVN: scummvm:[40424] scummvm/trunk/backends/keymapper
sev at users.sourceforge.net
sev at users.sourceforge.net
Sun May 10 19:18:59 CEST 2009
Revision: 40424
http://scummvm.svn.sourceforge.net/scummvm/?rev=40424&view=rev
Author: sev
Date: 2009-05-10 17:18:59 +0000 (Sun, 10 May 2009)
Log Message:
-----------
whitespaces
Modified Paths:
--------------
scummvm/trunk/backends/keymapper/action.cpp
scummvm/trunk/backends/keymapper/action.h
scummvm/trunk/backends/keymapper/hardware-key.h
scummvm/trunk/backends/keymapper/keymap.cpp
scummvm/trunk/backends/keymapper/keymapper.cpp
scummvm/trunk/backends/keymapper/remap-dialog.cpp
Modified: scummvm/trunk/backends/keymapper/action.cpp
===================================================================
--- scummvm/trunk/backends/keymapper/action.cpp 2009-05-10 14:57:27 UTC (rev 40423)
+++ scummvm/trunk/backends/keymapper/action.cpp 2009-05-10 17:18:59 UTC (rev 40424)
@@ -44,9 +44,13 @@
}
void Action::mapKey(const HardwareKey *key) {
- if (_hwKey) _boss->unregisterMapping(this);
+ if (_hwKey)
+ _boss->unregisterMapping(this);
+
_hwKey = key;
- if (_hwKey) _boss->registerMapping(this, _hwKey);
+
+ if (_hwKey)
+ _boss->registerMapping(this, _hwKey);
}
const HardwareKey *Action::getMappedKey() const {
Modified: scummvm/trunk/backends/keymapper/action.h
===================================================================
--- scummvm/trunk/backends/keymapper/action.h 2009-05-10 14:57:27 UTC (rev 40423)
+++ scummvm/trunk/backends/keymapper/action.h 2009-05-10 17:18:59 UTC (rev 40424)
@@ -74,6 +74,7 @@
void addKeyEvent(const KeyState &ks) {
Event evt;
+
evt.type = EVENT_KEYDOWN;
evt.kbd = ks;
addEvent(evt);
@@ -81,18 +82,21 @@
void addLeftClickEvent() {
Event evt;
+
evt.type = EVENT_LBUTTONDOWN;
addEvent(evt);
}
void addMiddleClickEvent() {
Event evt;
+
evt.type = EVENT_MBUTTONDOWN;
addEvent(evt);
}
void addRightClickEvent() {
Event evt;
+
evt.type = EVENT_RBUTTONDOWN;
addEvent(evt);
}
Modified: scummvm/trunk/backends/keymapper/hardware-key.h
===================================================================
--- scummvm/trunk/backends/keymapper/hardware-key.h 2009-05-10 14:57:27 UTC (rev 40423)
+++ scummvm/trunk/backends/keymapper/hardware-key.h 2009-05-10 17:18:59 UTC (rev 40424)
@@ -75,6 +75,7 @@
virtual ~HardwareKeySet() {
List<const HardwareKey*>::const_iterator it;
+
for (it = _keys.begin(); it != _keys.end(); it++)
delete *it;
}
@@ -86,6 +87,7 @@
const HardwareKey *findHardwareKey(const char *id) const {
List<const HardwareKey*>::const_iterator it;
+
for (it = _keys.begin(); it != _keys.end(); it++) {
if (strncmp((*it)->hwKeyId, id, HWKEY_ID_SIZE) == 0)
return (*it);
@@ -95,6 +97,7 @@
const HardwareKey *findHardwareKey(const KeyState& keystate) const {
List<const HardwareKey*>::const_iterator it;
+
for (it = _keys.begin(); it != _keys.end(); it++) {
if ((*it)->key == keystate)
return (*it);
@@ -115,6 +118,7 @@
void checkForKey(HardwareKey *key) {
List<const HardwareKey*>::iterator it;
+
for (it = _keys.begin(); it != _keys.end(); it++) {
if (strncmp((*it)->hwKeyId, key->hwKeyId, HWKEY_ID_SIZE) == 0)
error("Error adding HardwareKey '%s' - id of %s already in use!", key->description.c_str(), key->hwKeyId);
Modified: scummvm/trunk/backends/keymapper/keymap.cpp
===================================================================
--- scummvm/trunk/backends/keymapper/keymap.cpp 2009-05-10 14:57:27 UTC (rev 40423)
+++ scummvm/trunk/backends/keymapper/keymap.cpp 2009-05-10 17:18:59 UTC (rev 40424)
@@ -35,8 +35,10 @@
Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap(), _configDomain(0) {
List<Action*>::iterator it;
+
for (it = _actions.begin(); it != _actions.end(); it++) {
const HardwareKey *hwKey = (*it)->getMappedKey();
+
if (hwKey) {
_keymap[hwKey->key] = *it;
}
@@ -45,6 +47,7 @@
Keymap::~Keymap() {
List<Action*>::iterator it;
+
for (it = _actions.begin(); it != _actions.end(); it++)
delete *it;
}
@@ -52,12 +55,15 @@
void Keymap::addAction(Action *action) {
if (findAction(action->id))
error("Action with id %s already in KeyMap!", action->id);
+
_actions.push_back(action);
}
void Keymap::registerMapping(Action *action, const HardwareKey *hwKey) {
HashMap<KeyState, Action*>::iterator it;
+
it = _keymap.find(hwKey->key);
+
// if key is already mapped to a different action then un-map it
if (it != _keymap.end() && action != it->_value) {
it->_value->mapKey(0);
@@ -68,6 +74,7 @@
void Keymap::unregisterMapping(Action *action) {
const HardwareKey *hwKey = action->getMappedKey();
+
if (hwKey) {
_keymap.erase(hwKey->key);
}
@@ -79,6 +86,7 @@
Action *Keymap::findAction(const char *id) {
List<Action*>::iterator it;
+
for (it = _actions.begin(); it != _actions.end(); it++) {
if (strncmp((*it)->id, id, ACTION_ID_SIZE) == 0)
return *it;
@@ -88,16 +96,20 @@
const Action *Keymap::findAction(const char *id) const {
List<Action*>::const_iterator it;
+
for (it = _actions.begin(); it != _actions.end(); it++) {
if (strncmp((*it)->id, id, ACTION_ID_SIZE) == 0)
return *it;
}
+
return 0;
}
Action *Keymap::getMappedAction(const KeyState& ks) const {
HashMap<KeyState, Action*>::iterator it;
+
it = _keymap.find(ks);
+
if (it == _keymap.end())
return 0;
else
@@ -109,25 +121,32 @@
}
void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
- if (!_configDomain) return;
+ if (!_configDomain)
+ return;
+
ConfigManager::Domain::iterator it;
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 *actionId = key.c_str() + prefix.size();
Action *ua = getAction(actionId);
+
if (!ua) {
warning("'%s' keymap does not contain Action with ID %s",
_name.c_str(), actionId);
_configDomain->erase(key);
+
continue;
}
const HardwareKey *hwKey = hwKeys->findHardwareKey(it->_value.c_str());
+
if (!hwKey) {
warning("HardwareKey with ID %s not known", it->_value.c_str());
_configDomain->erase(key);
@@ -141,14 +160,20 @@
void Keymap::saveMappings() {
if (!_configDomain)
return;
+
List<Action*>::const_iterator it;
String prefix = KEYMAP_KEY_PREFIX + _name + "_";
+
for (it = _actions.begin(); it != _actions.end(); it++) {
uint actIdLen = strlen((*it)->id);
+
actIdLen = (actIdLen > ACTION_ID_SIZE) ? ACTION_ID_SIZE : actIdLen;
+
String actId((*it)->id, (*it)->id + actIdLen);
char hwId[HWKEY_ID_SIZE+1];
+
memset(hwId, 0, HWKEY_ID_SIZE+1);
+
if ((*it)->getMappedKey()) {
memcpy(hwId, (*it)->getMappedKey()->hwKeyId, HWKEY_ID_SIZE);
}
@@ -160,6 +185,7 @@
List<Action*>::iterator it;
bool allMapped = true;
uint numberMapped = 0;
+
for (it = _actions.begin(); it != _actions.end(); it++) {
if ((*it)->getMappedKey()) {
numberMapped++;
@@ -167,6 +193,7 @@
allMapped = false;
}
}
+
return allMapped || (numberMapped == hwKeys->size());
}
@@ -184,9 +211,11 @@
// Remove actions and keys from local lists that have already been mapped.
actIt = actions.begin();
+
while (actIt != actions.end()) {
Action *act = *actIt;
const HardwareKey *key = act->getMappedKey();
+
if (key) {
keys.remove(key);
actIt = actions.erase(actIt);
@@ -212,13 +241,16 @@
// to these higher priority skipped actions.
uint skipped = 0;
actIt = actions.begin();
+
while (actIt != actions.end() && skipped < keys.size()) {
selectedKey = keys.end();
int matchRank = 0;
Action *act = *actIt;
+
for (keyIt = keys.begin(); keyIt != keys.end(); ++keyIt) {
if ((*keyIt)->preferredAction == act->type && act->type != kGenericActionType) {
Action *parentAct = getParentMappedAction((*keyIt)->key);
+
if (!parentAct) {
selectedKey = keyIt;
break;
@@ -228,6 +260,7 @@
}
} else if ((*keyIt)->type == act->preferredKey && act->preferredKey != kGenericKeyType && matchRank < 2) {
Action *parentAct = getParentMappedAction((*keyIt)->key);
+
if (!parentAct) {
selectedKey = keyIt;
matchRank = 2;
@@ -258,11 +291,14 @@
// - is guaranteed to match a key if they are not all used up
for (actIt = actions.begin(); actIt != actions.end(); ++actIt) {
selectedKey = keys.end();
+
int matchRank = 0;
int lowestPriority = 0;
Action *act = *actIt;
+
for (keyIt = keys.begin(); keyIt != keys.end(); ++keyIt) {
Action *parentAct = getParentMappedAction((*keyIt)->key);
+
if (!parentAct) {
selectedKey = keyIt;
break;
@@ -277,6 +313,7 @@
}
}
}
+
if (selectedKey != keys.end()) {
act->mapKey(*selectedKey);
keys.erase(selectedKey);
@@ -289,6 +326,7 @@
Action *Keymap::getParentMappedAction(KeyState key) {
if (_parent) {
Action *act = _parent->getMappedAction(key);
+
if (act)
return act;
else
Modified: scummvm/trunk/backends/keymapper/keymapper.cpp
===================================================================
--- scummvm/trunk/backends/keymapper/keymapper.cpp 2009-05-10 14:57:27 UTC (rev 40423)
+++ scummvm/trunk/backends/keymapper/keymapper.cpp 2009-05-10 17:18:59 UTC (rev 40424)
@@ -33,19 +33,23 @@
void Keymapper::Domain::addKeymap(Keymap *map) {
iterator it = find(map->getName());
+
if (it != end())
delete it->_value;
+
setVal(map->getName(), map);
}
void Keymapper::Domain::deleteAllKeyMaps() {
for (iterator it = begin(); it != end(); it++)
delete it->_value;
+
clear();
}
Keymap *Keymapper::Domain::getKeymap(const String& name) {
iterator it = find(name);
+
if (it != end())
return it->_value;
else
@@ -55,6 +59,7 @@
Keymapper::Keymapper(EventManager *evtMgr)
: _eventMan(evtMgr), _enabled(true), _hardwareKeys(0) {
ConfigManager::Domain *confDom = ConfMan.getDomain(ConfigManager::kApplicationDomain);
+
_globalDomain.setConfigDomain(confDom);
}
@@ -65,6 +70,7 @@
void Keymapper::registerHardwareKeySet(HardwareKeySet *keys) {
if (_hardwareKeys)
error("Hardware key set already registered!");
+
_hardwareKeys = keys;
}
@@ -82,17 +88,20 @@
cleanupGameKeymaps();
_gameDomain.setConfigDomain(ConfMan.getActiveDomain());
}
+
initKeymap(_gameDomain, keymap);
}
void Keymapper::initKeymap(Domain &domain, Keymap *map) {
map->setConfigDomain(domain.getConfigDomain());
map->loadMappings(_hardwareKeys);
+
if (map->isComplete(_hardwareKeys) == false) {
map->automaticMapping(_hardwareKeys);
map->saveMappings();
ConfMan.flushToDisk();
}
+
domain.addKeymap(map);
}
@@ -103,36 +112,44 @@
// Now restore the stack of active maps. Re-add all global keymaps, drop
// the game specific (=deleted) ones.
Stack<MapRecord> newStack;
+
for (int i = 0; i < _activeMaps.size(); i++) {
if (_activeMaps[i].global)
newStack.push(_activeMaps[i]);
}
+
_activeMaps = newStack;
}
Keymap *Keymapper::getKeymap(const String& name, bool &global) {
Keymap *keymap = _gameDomain.getKeymap(name);
global = false;
+
if (!keymap) {
keymap = _globalDomain.getKeymap(name);
global = true;
}
+
return keymap;
}
bool Keymapper::pushKeymap(const String& name, bool inherit) {
bool global;
Keymap *newMap = getKeymap(name, global);
+
if (!newMap) {
warning("Keymap '%s' not registered", name.c_str());
return false;
}
+
pushKeymap(newMap, inherit, global);
+
return true;
}
void Keymapper::pushKeymap(Keymap *newMap, bool inherit, bool global) {
MapRecord mr = {newMap, inherit, global};
+
_activeMaps.push(mr);
}
@@ -154,38 +171,49 @@
return false;
Action *action = 0;
+
if (keyDown) {
// 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);
+
if (action || mr.inherit == false)
break;
}
+
if (action)
_keysDown[key] = action;
} else {
HashMap<KeyState, Action*>::iterator it = _keysDown.find(key);
+
if (it != _keysDown.end()) {
action = it->_value;
_keysDown.erase(key);
}
}
+
if (!action)
return false;
+
executeAction(action, keyDown);
+
return true;
}
Action *Keymapper::getAction(const KeyState& key) {
Action *action = 0;
+
return action;
}
void Keymapper::executeAction(const Action *action, bool keyDown) {
List<Event>::const_iterator it;
+
for (it = action->events.begin(); it != action->events.end(); ++it) {
Event evt = *it;
+
switch (evt.type) {
case EVENT_KEYDOWN:
if (!keyDown) evt.type = EVENT_KEYUP;
@@ -215,6 +243,7 @@
// don't deliver other events on key up
if (!keyDown) continue;
}
+
evt.mouse = _eventMan->getMousePos();
_eventMan->pushEvent(evt);
}
Modified: scummvm/trunk/backends/keymapper/remap-dialog.cpp
===================================================================
--- scummvm/trunk/backends/keymapper/remap-dialog.cpp 2009-05-10 14:57:27 UTC (rev 40423)
+++ scummvm/trunk/backends/keymapper/remap-dialog.cpp 2009-05-10 17:18:59 UTC (rev 40424)
@@ -58,6 +58,7 @@
void RemapDialog::open() {
bool divider = false;
const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack();
+
if (!(activeKeymaps.size() > 0)) {
_kmPopUp->appendEntry(activeKeymaps.top().keymap->getName() + " (Active)");
divider = true;
@@ -67,6 +68,7 @@
Keymapper::Domain *_gameKeymaps = 0;
int keymapCount = 0;
+
if (_globalKeymaps->empty())
_globalKeymaps = 0;
else
@@ -74,6 +76,7 @@
if (ConfMan.getActiveDomain() != 0) {
_gameKeymaps = &_keymapper->getGameDomain();
+
if (_gameKeymaps->empty())
_gameKeymaps = 0;
else
@@ -86,6 +89,7 @@
Keymapper::Domain::iterator it;
uint32 idx = 0;
+
if (_globalKeymaps) {
if (divider)
_kmPopUp->appendEntry("");
@@ -95,6 +99,7 @@
}
divider = true;
}
+
if (_gameKeymaps) {
if (divider)
_kmPopUp->appendEntry("");
@@ -114,10 +119,13 @@
void RemapDialog::close() {
_kmPopUp->clearEntries();
+
free(_keymapTable);
_keymapTable = 0;
+
if (_changes)
ConfMan.flushToDisk();
+
Dialog::close();
}
@@ -149,9 +157,12 @@
uint textYOff = (buttonHeight - kLineHeight) / 2;
uint oldSize = _keymapWidgets.size();
uint newSize = _rowCount * _colCount;
+
_keymapWidgets.reserve(newSize);
+
for (uint i = 0; i < newSize; i++) {
ActionWidgets widg;
+
if (i >= _keymapWidgets.size()) {
widg.actionText =
new GUI::StaticTextWidget(this, 0, 0, 0, 0, "", Graphics::kTextAlignRight);
@@ -161,15 +172,19 @@
} else {
widg = _keymapWidgets[i];
}
+
uint x = areaX + (i % _colCount) * colWidth;
uint y = areaY + (i / _colCount) * (buttonHeight + spacing);
+
widg.actionText->resize(x, y + textYOff, labelWidth, kLineHeight);
widg.keyButton->resize(x + labelWidth, y, buttonWidth, buttonHeight);
}
while (oldSize > newSize) {
ActionWidgets widg = _keymapWidgets.remove_at(--oldSize);
+
removeWidget(widg.actionText);
delete widg.actionText;
+
removeWidget(widg.keyButton);
delete widg.keyButton;
}
@@ -190,7 +205,9 @@
}
void RemapDialog::startRemapping(uint i) {
- if (_topAction + i >= _currentActions.size()) return;
+ if (_topAction + i >= _currentActions.size())
+ return;
+
_remapTimeout = getMillis() + kRemapTimeoutDelay;
_activeRemapAction = _currentActions[_topAction + i].action;
_keymapWidgets[i].keyButton->setLabel("...");
@@ -201,14 +218,18 @@
void RemapDialog::stopRemapping() {
_topAction = -1;
+
refreshKeymap();
+
_activeRemapAction = 0;
+
_keymapper->setEnabled(true);
}
void RemapDialog::handleKeyUp(Common::KeyState state) {
if (_activeRemapAction) {
const HardwareKey *hwkey = _keymapper->findHardwareKey(state);
+
if (hwkey) {
_activeRemapAction->mapKey(hwkey);
// TODO: _activeRemapAction->getParent()->saveMappings();
@@ -236,6 +257,7 @@
void RemapDialog::loadKeymap() {
_currentActions.clear();
const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack();
+
if (!activeKeymaps.empty() && _kmPopUp->getSelected() == 0) {
// load active keymaps
@@ -244,10 +266,13 @@
// add most active keymap's keys
Keymapper::MapRecord top = activeKeymaps.top();
List<Action*>::iterator actIt;
+
for (actIt = top.keymap->getActions().begin(); actIt != top.keymap->getActions().end(); ++actIt) {
Action *act = *actIt;
ActionInfo info = {act, false, act->description};
+
_currentActions.push_back(info);
+
if (act->getMappedKey())
freeKeys.remove(act->getMappedKey());
}
@@ -257,8 +282,10 @@
for (int i = activeKeymaps.size() - 2; i >= 0; --i) {
Keymapper::MapRecord mr = activeKeymaps[i];
List<const HardwareKey*>::iterator keyIt = freeKeys.begin();
+
while (keyIt != freeKeys.end()) {
Action *act = mr.keymap->getMappedAction((*keyIt)->key);
+
if (act) {
ActionInfo info = {act, true, act->description + " (" + mr.keymap->getName() + ")"};
_currentActions.push_back(info);
@@ -267,7 +294,9 @@
++keyIt;
}
}
- if (mr.inherit == false || freeKeys.empty()) break;
+
+ if (mr.inherit == false || freeKeys.empty())
+ break;
}
}
@@ -275,8 +304,10 @@
Keymap *km = _keymapTable[_kmPopUp->getSelectedTag()];
List<Action*>::iterator it;
+
for (it = km->getActions().begin(); it != km->getActions().end(); it++) {
ActionInfo info = {*it, false, (*it)->description};
+
_currentActions.push_back(info);
}
}
@@ -285,6 +316,7 @@
_scrollBar->_currentPos = 0;
_scrollBar->_numEntries = (_currentActions.size() + _colCount - 1) / _colCount;
_scrollBar->recalc();
+
// force refresh
_topAction = -1;
refreshKeymap();
@@ -292,27 +324,36 @@
void RemapDialog::refreshKeymap() {
int newTopAction = _scrollBar->_currentPos * _colCount;
+
if (newTopAction == _topAction)
return;
+
_topAction = newTopAction;
//_container->draw();
_scrollBar->draw();
uint actionI = _topAction;
+
for (uint widgetI = 0; widgetI < _keymapWidgets.size(); widgetI++) {
ActionWidgets& widg = _keymapWidgets[widgetI];
+
if (actionI < _currentActions.size()) {
ActionInfo& info = _currentActions[actionI];
+
widg.actionText->setLabel(info.description + ": ");
widg.actionText->setEnabled(!info.inherited);
+
const HardwareKey *mappedKey = info.action->getMappedKey();
+
if (mappedKey)
widg.keyButton->setLabel(mappedKey->description);
else
widg.keyButton->setLabel("-");
+
widg.actionText->setVisible(true);
widg.keyButton->setVisible(true);
+
actionI++;
} else {
widg.actionText->setVisible(false);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list