aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorEugene Sandulenko2009-05-10 17:18:59 +0000
committerEugene Sandulenko2009-05-10 17:18:59 +0000
commit2cc77639715214573637375655442d2208898a38 (patch)
tree787ccf95ac9c7fc1cdbe0df86a309d26deb973bd /backends
parent7cd07d958193f591740c9e60225ae82833ac90c8 (diff)
downloadscummvm-rg350-2cc77639715214573637375655442d2208898a38.tar.gz
scummvm-rg350-2cc77639715214573637375655442d2208898a38.tar.bz2
scummvm-rg350-2cc77639715214573637375655442d2208898a38.zip
whitespaces
svn-id: r40424
Diffstat (limited to 'backends')
-rw-r--r--backends/keymapper/action.cpp8
-rw-r--r--backends/keymapper/action.h4
-rw-r--r--backends/keymapper/hardware-key.h4
-rw-r--r--backends/keymapper/keymap.cpp40
-rw-r--r--backends/keymapper/keymapper.cpp29
-rw-r--r--backends/keymapper/remap-dialog.cpp45
6 files changed, 125 insertions, 5 deletions
diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp
index ec2acb31b3..2541f60ddd 100644
--- a/backends/keymapper/action.cpp
+++ b/backends/keymapper/action.cpp
@@ -44,9 +44,13 @@ Action::Action(Keymap *boss, const char *i, String des, ActionType typ,
}
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 {
diff --git a/backends/keymapper/action.h b/backends/keymapper/action.h
index abf0fa0459..c5e306a4b8 100644
--- a/backends/keymapper/action.h
+++ b/backends/keymapper/action.h
@@ -74,6 +74,7 @@ public:
void addKeyEvent(const KeyState &ks) {
Event evt;
+
evt.type = EVENT_KEYDOWN;
evt.kbd = ks;
addEvent(evt);
@@ -81,18 +82,21 @@ public:
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);
}
diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h
index f42076f75b..d83d3d9073 100644
--- a/backends/keymapper/hardware-key.h
+++ b/backends/keymapper/hardware-key.h
@@ -75,6 +75,7 @@ public:
virtual ~HardwareKeySet() {
List<const HardwareKey*>::const_iterator it;
+
for (it = _keys.begin(); it != _keys.end(); it++)
delete *it;
}
@@ -86,6 +87,7 @@ public:
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 @@ public:
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 @@ private:
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);
diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp
index 4cb6b7f518..13be1ad8bc 100644
--- a/backends/keymapper/keymap.cpp
+++ b/backends/keymapper/keymap.cpp
@@ -35,8 +35,10 @@ namespace Common {
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(const Keymap& km) : _actions(km._actions), _keymap(), _configDoma
Keymap::~Keymap() {
List<Action*>::iterator it;
+
for (it = _actions.begin(); it != _actions.end(); it++)
delete *it;
}
@@ -52,12 +55,15 @@ Keymap::~Keymap() {
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::registerMapping(Action *action, const HardwareKey *hwKey) {
void Keymap::unregisterMapping(Action *action) {
const HardwareKey *hwKey = action->getMappedKey();
+
if (hwKey) {
_keymap.erase(hwKey->key);
}
@@ -79,6 +86,7 @@ Action *Keymap::getAction(const char *id) {
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 @@ Action *Keymap::findAction(const char *id) {
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::setConfigDomain(ConfigManager::Domain *dom) {
}
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::loadMappings(const HardwareKeySet *hwKeys) {
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 @@ bool Keymap::isComplete(const HardwareKeySet *hwKeys) {
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 @@ bool Keymap::isComplete(const HardwareKeySet *hwKeys) {
allMapped = false;
}
}
+
return allMapped || (numberMapped == hwKeys->size());
}
@@ -184,9 +211,11 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
// 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 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
// 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 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
}
} 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 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
// - 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 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
}
}
}
+
if (selectedKey != keys.end()) {
act->mapKey(*selectedKey);
keys.erase(selectedKey);
@@ -289,6 +326,7 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
Action *Keymap::getParentMappedAction(KeyState key) {
if (_parent) {
Action *act = _parent->getMappedAction(key);
+
if (act)
return act;
else
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp
index c6ed0fe024..56780f49af 100644
--- a/backends/keymapper/keymapper.cpp
+++ b/backends/keymapper/keymapper.cpp
@@ -33,19 +33,23 @@ namespace Common {
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 @@ Keymap *Keymapper::Domain::getKeymap(const String& name) {
Keymapper::Keymapper(EventManager *evtMgr)
: _eventMan(evtMgr), _enabled(true), _hardwareKeys(0) {
ConfigManager::Domain *confDom = ConfMan.getDomain(ConfigManager::kApplicationDomain);
+
_globalDomain.setConfigDomain(confDom);
}
@@ -65,6 +70,7 @@ Keymapper::~Keymapper() {
void Keymapper::registerHardwareKeySet(HardwareKeySet *keys) {
if (_hardwareKeys)
error("Hardware key set already registered!");
+
_hardwareKeys = keys;
}
@@ -82,17 +88,20 @@ void Keymapper::addGameKeymap(Keymap *keymap) {
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 @@ void Keymapper::cleanupGameKeymaps() {
// 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 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) {
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 @@ void Keymapper::executeAction(const Action *action, bool keyDown) {
// don't deliver other events on key up
if (!keyDown) continue;
}
+
evt.mouse = _eventMan->getMousePos();
_eventMan->pushEvent(evt);
}
diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp
index 5a61b9e7e1..169d85a353 100644
--- a/backends/keymapper/remap-dialog.cpp
+++ b/backends/keymapper/remap-dialog.cpp
@@ -58,6 +58,7 @@ RemapDialog::~RemapDialog() {
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 @@ void RemapDialog::open() {
Keymapper::Domain *_gameKeymaps = 0;
int keymapCount = 0;
+
if (_globalKeymaps->empty())
_globalKeymaps = 0;
else
@@ -74,6 +76,7 @@ void RemapDialog::open() {
if (ConfMan.getActiveDomain() != 0) {
_gameKeymaps = &_keymapper->getGameDomain();
+
if (_gameKeymaps->empty())
_gameKeymaps = 0;
else
@@ -86,6 +89,7 @@ void RemapDialog::open() {
Keymapper::Domain::iterator it;
uint32 idx = 0;
+
if (_globalKeymaps) {
if (divider)
_kmPopUp->appendEntry("");
@@ -95,6 +99,7 @@ void RemapDialog::open() {
}
divider = true;
}
+
if (_gameKeymaps) {
if (divider)
_kmPopUp->appendEntry("");
@@ -114,10 +119,13 @@ void RemapDialog::open() {
void RemapDialog::close() {
_kmPopUp->clearEntries();
+
free(_keymapTable);
_keymapTable = 0;
+
if (_changes)
ConfMan.flushToDisk();
+
Dialog::close();
}
@@ -149,9 +157,12 @@ void RemapDialog::reflowLayout() {
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 @@ void RemapDialog::reflowLayout() {
} 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::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 d
}
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::startRemapping(uint i) {
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::handleTickle() {
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 @@ void RemapDialog::loadKeymap() {
// 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 @@ void RemapDialog::loadKeymap() {
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 @@ void RemapDialog::loadKeymap() {
++keyIt;
}
}
- if (mr.inherit == false || freeKeys.empty()) break;
+
+ if (mr.inherit == false || freeKeys.empty())
+ break;
}
}
@@ -275,8 +304,10 @@ void RemapDialog::loadKeymap() {
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 @@ void RemapDialog::loadKeymap() {
_scrollBar->_currentPos = 0;
_scrollBar->_numEntries = (_currentActions.size() + _colCount - 1) / _colCount;
_scrollBar->recalc();
+
// force refresh
_topAction = -1;
refreshKeymap();
@@ -292,27 +324,36 @@ void RemapDialog::loadKeymap() {
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);