コード例 #1
0
ファイル: remap-dialog.cpp プロジェクト: St0rmcrow/scummvm
void RemapDialog::loadKeymap() {
	_currentActions.clear();
	const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack();

	if (!activeKeymaps.empty() && _kmPopUp->getSelected() == 0) {
		// load active keymaps

		List<const HardwareKey*> freeKeys(_keymapper->getHardwareKeys());

		// 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());
		}

		// loop through remaining finding mappings for unmapped keys
		if (top.inherit) {
			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);
						freeKeys.erase(keyIt++);
					} else {
						++keyIt;
					}
				}

				if (mr.inherit == false || freeKeys.empty())
					break;
			}
		}

	} else if (_kmPopUp->getSelected() != -1) {
		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);
		}
	}

	// refresh scroll bar
	_scrollBar->_currentPos = 0;
	_scrollBar->_numEntries = (_currentActions.size() + _colCount - 1) / _colCount;
	_scrollBar->recalc();

	// force refresh
	_topAction = -1;
	refreshKeymap();
}
コード例 #2
0
ファイル: remap-dialog.cpp プロジェクト: 0xf1sh/scummvm
void RemapDialog::loadKeymap() {
	_currentActions.clear();
	const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack();

	debug(3, "RemapDialog::loadKeymap active keymaps: %u", activeKeymaps.size());

	if (!activeKeymaps.empty() && _kmPopUp->getSelected() == 0) {
		// This is the "effective" view which shows all effective actions:
		// - all of the topmost keymap action
		// - all mapped actions that are reachable

		List<const HardwareInput *> freeInputs(_keymapper->getHardwareInputs());

		int topIndex = activeKeymaps.size() - 1;

		// This is a WORKAROUND for changing the popup list selected item and changing it back
		// to the top entry. Upon changing it back, the top keymap is always "gui".
		if (!_topKeymapIsGui && activeKeymaps[topIndex].keymap->getName() == kGuiKeymapName)
			--topIndex;

		// add most active keymap's keys
		Keymapper::MapRecord top = activeKeymaps[topIndex];
		List<Action *>::iterator actIt;
		debug(3, "RemapDialog::loadKeymap top keymap: %s", top.keymap->getName().c_str());
		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->getMappedInput())
				freeInputs.remove(act->getMappedInput());
		}

		// loop through remaining finding mappings for unmapped keys
		if (top.transparent && topIndex >= 0) {
			for (int i = topIndex - 1; i >= 0; --i) {
				Keymapper::MapRecord mr = activeKeymaps[i];
				debug(3, "RemapDialog::loadKeymap keymap: %s", mr.keymap->getName().c_str());
				List<const HardwareInput *>::iterator inputIt = freeInputs.begin();
				const HardwareInput *input = *inputIt;
				while (inputIt != freeInputs.end()) {

					Action *act = 0;
					if (input->type == kHardwareInputTypeKeyboard)
						act = mr.keymap->getMappedAction(input->key);
					else if (input->type == kHardwareInputTypeGeneric)
						act = mr.keymap->getMappedAction(input->inputCode);

					if (act) {
						ActionInfo info = {act, true, act->description + " (" + mr.keymap->getName() + ")"};
						_currentActions.push_back(info);
						freeInputs.erase(inputIt);
					} else {
						++inputIt;
					}
				}

				if (mr.transparent == false || freeInputs.empty())
					break;
			}
		}

	} else if (_kmPopUp->getSelected() != -1) {
		// This is the regular view of a keymap that isn't the topmost one.
		// It shows all of that keymap's actions

		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);
		}
	}

	// refresh scroll bar
	_scrollBar->_currentPos = 0;
	_scrollBar->_numEntries = _currentActions.size();
	_scrollBar->recalc();

	// force refresh
	_topAction = -1;
	refreshKeymap();
}
コード例 #3
0
void RemapDialog::loadKeymap() {
	_currentActions.clear();
	const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack();

	debug(3, "RemapDialog::loadKeymap active keymaps: %u", activeKeymaps.size());

	if (!activeKeymaps.empty() && _kmPopUp->getSelected() == 0) {
		// load active keymaps

		List<const HardwareKey*> freeKeys(_keymapper->getHardwareKeys());

		int topIndex = activeKeymaps.size() - 1;
		// skip the top gui keymap since it is for the keymapper itself
		// TODO: Don't use the keymap name as a way to discriminate GUI maps
		if (topIndex > 0 && activeKeymaps[topIndex].keymap->getName().equals(kGuiKeymapName))
			--topIndex;

		// add most active keymap's keys
		Keymapper::MapRecord top = activeKeymaps[topIndex];
		List<Action*>::iterator actIt;
		debug(3, "RemapDialog::loadKeymap top keymap: %s", top.keymap->getName().c_str());
		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());
		}

		// loop through remaining finding mappings for unmapped keys
		if (top.transparent && topIndex >= 0) {
			for (int i = topIndex - 1; i >= 0; --i) {
				Keymapper::MapRecord mr = activeKeymaps[i];
				debug(3, "RemapDialog::loadKeymap keymap: %s", mr.keymap->getName().c_str());
				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);
						freeKeys.erase(keyIt++);
					} else {
						++keyIt;
					}
				}

				if (mr.transparent == false || freeKeys.empty())
					break;
			}
		}

	} else if (_kmPopUp->getSelected() != -1) {
		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);
		}
	}

	// refresh scroll bar
	_scrollBar->_currentPos = 0;
	_scrollBar->_numEntries = _currentActions.size();
	_scrollBar->recalc();

	// force refresh
	_topAction = -1;
	refreshKeymap();
}