[Scummvm-cvs-logs] SF.net SVN: scummvm:[33821] scummvm/branches/gsoc2008-vkeybd

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Wed Aug 13 13:46:09 CEST 2008


Revision: 33821
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33821&view=rev
Author:   kenny-d
Date:     2008-08-13 11:46:08 +0000 (Wed, 13 Aug 2008)

Log Message:
-----------
Keymapper WIP:
* Improved automatic mapping algorithm
* Remap dialog overhaul - now displays active keymap(s)

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/hardware-key.h
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.h
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.h
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.h
    scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/events.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/sdl.cpp

Property Changed:
----------------
    scummvm/branches/gsoc2008-vkeybd/dists/msvc8/

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/hardware-key.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/hardware-key.h	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/hardware-key.h	2008-08-13 11:46:08 UTC (rev 33821)
@@ -71,7 +71,7 @@
 
 	HardwareKeySet() {}
 	virtual ~HardwareKeySet() {
-		List<HardwareKey*>::iterator it;
+		List<const HardwareKey*>::iterator it;
 		for (it = _keys.begin(); it != _keys.end(); it++)
 			delete *it;
 	}
@@ -82,7 +82,7 @@
 	}
 
 	const HardwareKey *findHardwareKey(int32 id) const {
-		List<HardwareKey*>::iterator it;
+		List<const HardwareKey*>::iterator it;
 		for (it = _keys.begin(); it != _keys.end(); it++) {
 			if ((*it)->id == id)
 				return (*it);
@@ -91,7 +91,7 @@
 	}
 
 	const HardwareKey *findHardwareKey(const KeyState& keystate) const {
-		List<HardwareKey*>::iterator it;
+		List<const HardwareKey*>::iterator it;
 		for (it = _keys.begin(); it != _keys.end(); it++) {
 			if ((*it)->key == keystate)
 				return (*it);
@@ -99,7 +99,7 @@
 		return 0;
 	}
 
-	List<HardwareKey*> getHardwareKeys() const {
+	List<const HardwareKey*> getHardwareKeys() const {
 		return _keys;
 	}
 
@@ -111,7 +111,7 @@
 private:
 
 	void checkForKey(HardwareKey *key) {
-		List<HardwareKey*>::iterator it;
+		List<const HardwareKey*>::iterator it;
 		for (it = _keys.begin(); it != _keys.end(); it++) {
 			if ((*it)->id == key->id)
 				error("Error adding HardwareKey '%s' - id of %d already in use!", key->description.c_str(), key->id);
@@ -120,7 +120,7 @@
 		}
 	}
 
-	List<HardwareKey*> _keys;
+	List<const HardwareKey*> _keys;
 };
 
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.cpp	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.cpp	2008-08-13 11:46:08 UTC (rev 33821)
@@ -95,22 +95,36 @@
 void KeymapManager::automaticMap(Keymap *map) {
 	List<Action*> actions(map->getActions()), unmapped;
 	List<Action*>::iterator actIt;
-	List<HardwareKey*> keys = _hardwareKeys->getHardwareKeys();
-	List<HardwareKey*>::iterator keyIt, selectedKey;
+	List<const HardwareKey*> keys = _hardwareKeys->getHardwareKeys();
+	List<const HardwareKey*>::iterator keyIt, selectedKey;
 
 	// sort by priority
 	ActionPriorityComp priorityComp;
 	sort(actions.begin(), actions.end(), priorityComp);
-
+	
 	for (actIt = actions.begin(); actIt != actions.end(); actIt++) {
 		selectedKey = keys.end();
+		int keyScore = 0;
 		Action *act = *actIt;
 		for (keyIt = keys.begin(); keyIt != keys.end(); keyIt++) {
 			if ((*keyIt)->preferredType == act->type) {
-				selectedKey = keyIt;
-				break;
-			} else if ((*keyIt)->preferredCategory == act->category && selectedKey == keys.end()) {
-				selectedKey = keyIt;
+				Action *parentAct = getParentMappedAction(map, (*keyIt)->key);
+				if (!parentAct) {
+					selectedKey = keyIt;
+					break;
+				} else if (parentAct->priority <= act->priority && keyScore < 3) {
+					selectedKey = keyIt;
+					keyScore = 3;
+				}
+			} else if ((*keyIt)->preferredCategory == act->category && keyScore < 2) {
+				Action *parentAct = getParentMappedAction(map, (*keyIt)->key);
+				if (!parentAct) {
+					selectedKey = keyIt;
+					keyScore = 2;
+				} else if (parentAct->priority <= act->priority && keyScore < 1) {
+					selectedKey = keyIt;
+					keyScore = 1;
+				}
 			}
 		}
 		if (selectedKey != keys.end()) {
@@ -120,11 +134,46 @@
 			unmapped.push_back(act);
 	}
 
-	actIt = unmapped.begin();
-	keyIt = keys.begin();
-	while (actIt != unmapped.end() && keyIt != keys.end())
-		(*actIt)->mapKey(*keyIt);
+	for (actIt = unmapped.begin(); actIt != unmapped.end(); actIt++) {
+		selectedKey = keys.end();
+		int keyScore = 0;
+		int lowestPriority = 0; //dummy value
+		Action *act = *actIt;
+		for (keyIt = keys.begin(); keyIt != keys.end(); keyIt++) {
+			Action *parentAct = getParentMappedAction(map, (*keyIt)->key);
+			if (!parentAct) {
+				selectedKey = keyIt;
+				break;
+			} else if (keyScore < 2) {
+				if (parentAct->priority <= act->priority) {
+					keyScore = 2;
+					selectedKey = keyIt;
+				} else if (parentAct->priority < lowestPriority || keyScore == 0) {
+					keyScore = 1;
+					lowestPriority = parentAct->priority;
+					selectedKey = keyIt;
+				}
+			}
+		}
+		if (selectedKey != keys.end()) {
+			act->mapKey(*selectedKey);
+			keys.erase(selectedKey);
+		} else // no keys left 
+			return;
+	}
+}
 
+Action *KeymapManager::getParentMappedAction(Keymap *map, KeyState key) {
+	Keymap *parent = map->getParent();
+	if (parent) {
+		Action *act = parent->getMappedAction(key);
+		if (act)
+			return act;
+		else
+			return getParentMappedAction(parent, key);
+	} else {
+		return 0;
+	}
 }
 
 Keymap *KeymapManager::getKeymap(const String& name) {

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.h	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap-manager.h	2008-08-13 11:46:08 UTC (rev 33821)
@@ -92,6 +92,7 @@
 
 	void initKeymap(ConfigManager::Domain *domain, Keymap *keymap);
 	void automaticMap(Keymap *map);
+	Action *getParentMappedAction(Keymap *map, KeyState key);
 
 	Domain _globalDomain;
 	Domain _gameDomain;

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.cpp	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.cpp	2008-08-13 11:46:08 UTC (rev 33821)
@@ -50,10 +50,6 @@
 	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) {
-		HashMap<KeyState, Action*>::iterator it2;
-		for (it2 = _keymap.begin(); it2 != _keymap.end(); it2++) {
-			printf("%d\n", it2->_value);
-		}
 		it->_value->mapKey(0);
 	}
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.h	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymap.h	2008-08-13 11:46:08 UTC (rev 33821)
@@ -51,7 +51,7 @@
 
 class Keymap {
 public:
-	Keymap(const String& na) : _name(na) {}
+	Keymap(const String& name, Keymap *parent = 0) : _name(name), _parent(parent) {}
 	Keymap(const Keymap& km);
 
 public:
@@ -80,7 +80,7 @@
 	 * @return		a pointer to the Action or 0 if no
 	 */
 	Action *getMappedAction(const KeyState& ks) const;
-
+	
 	/**
 	 * Load this keymap's mappings from the given config domain and hardware key set
 	 * @param domain	config domain to load keymap from
@@ -101,6 +101,7 @@
 	bool isComplete(const HardwareKeySet *hwKeys);
 
 	const String& getName() { return _name; }
+	Keymap *getParent() { return _parent; }
 
 private:
 	friend struct Action;
@@ -125,6 +126,7 @@
 	void internalMapKey(Action *action, HardwareKey *hwKey);
 
 	String _name;
+	Keymap *_parent;
 	List<Action*> _actions;
 	HashMap<KeyState, Action*> _keymap; 
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/keymapper.cpp	2008-08-13 11:46:08 UTC (rev 33821)
@@ -87,7 +87,7 @@
 	if (_activeMaps.empty()) return false;
 
 	Action *action = 0;
-	for (int i = _activeMaps.size() - 1; !action && i >= 0; i++) {
+	for (int i = _activeMaps.size() - 1; !action && i >= 0; --i) {
 		MapRecord mr = _activeMaps[i];
 		action = mr.keymap->getMappedAction(key);
 		if (mr.inherit == false) break;
@@ -95,7 +95,7 @@
 	if (!action) return false;
 
 	List<Event>::iterator it;
-	for (it = action->events.begin(); it != action->events.end(); it++) {
+	for (it = action->events.begin(); it != action->events.end(); ++it) {
 		Event evt = *it;
 		bool pushEvent = true;
 		switch (evt.type) {

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp	2008-08-13 11:46:08 UTC (rev 33821)
@@ -35,7 +35,7 @@
 };
 
 RemapDialog::RemapDialog()
-	: Dialog("remap"), _activeRemap(0), _currentActions(0), _topRow(0) {
+	: Dialog("remap"), _activeRemapAction(0), _topAction(0) {
 
 	const int screenW = g_system->getOverlayWidth();
 	const int screenH = g_system->getOverlayHeight();
@@ -44,32 +44,32 @@
 	assert(_keymapper);
 	_activeKeymaps = &_keymapper->_activeMaps;
 
+
+	KeymapManager::Domain *_globalKeymaps = &_keymapper->_keymapMan->getGlobalDomain();
+	KeymapManager::Domain *_gameKeymaps = 0;
 	int keymapCount = 0;
-	_globalKeymaps = &_keymapper->_keymapMan->getGlobalDomain();
-	if (_globalKeymaps->count() == 0)
+	if (_globalKeymaps->count() == 0) {
 		_globalKeymaps = 0;
-	else
+	} else {
 		keymapCount += _globalKeymaps->count();
+	}
 	if (ConfMan.getActiveDomain() != 0) {
 		_gameKeymaps = &_keymapper->_keymapMan->getGameDomain();
-		if (_gameKeymaps->count() == 0)
+		if (_gameKeymaps->count() == 0) {
 			_gameKeymaps = 0;
-		else
+		} else {
 			keymapCount += _gameKeymaps->count();
-	} else
-		_gameKeymaps = 0;
-
+		}
+	}
 	_keymapTable = (Keymap**)malloc(sizeof(Keymap*) * keymapCount);
 
 	int labelWidth = g_gui.evaluator()->getVar("remap_popup_labelW");
 	_kmPopUp = new GUI::PopUpWidget(this, "remap_popup", "Keymap: ", labelWidth);
-
 	if (_activeKeymaps->size() > 0) {
 		_kmPopUp->appendEntry(_activeKeymaps->top().keymap->getName() + " (Active)");
 	}
 	KeymapManager::Domain::iterator it;
 	uint32 idx = 0;
-
 	if (_globalKeymaps) {
 		_kmPopUp->appendEntry("");
 		for (it = _globalKeymaps->begin(); it != _globalKeymaps->end(); it++) {
@@ -85,31 +85,7 @@
 		}
 	}
 
-	int scrollbarWidth;
-	if (g_gui.getWidgetSize() == GUI::kBigWidgetSize) {
-		_buttonHeight = GUI::kBigButtonHeight;
-		scrollbarWidth = GUI::kBigScrollBarWidth;
-	} else {
-		_buttonHeight = GUI::kButtonHeight;
-		scrollbarWidth = GUI::kNormalScrollBarWidth;
-	}
-
-	_colCount = g_gui.evaluator()->getVar("remap_col_count");
-	_spacing = g_gui.evaluator()->getVar("remap_spacing");
-	_keymapArea.left = g_gui.evaluator()->getVar("remap_keymap_area.x");
-	_keymapArea.top = g_gui.evaluator()->getVar("remap_keymap_area.y");
-	_keymapArea.setWidth(g_gui.evaluator()->getVar("remap_keymap_area.w"));
-	_keymapArea.setHeight(g_gui.evaluator()->getVar("remap_keymap_area.h"));
-	_colWidth = (_keymapArea.width() - scrollbarWidth - _colCount * _spacing) / _colCount;
-	_rowCount = (_keymapArea.height() + _spacing) / (_buttonHeight + _spacing);
-	_keymapArea.setHeight(_rowCount * (_buttonHeight + _spacing) - _spacing);
-
-	_scrollBar = new GUI::ScrollBarWidget(this, 
-		_keymapArea.right - scrollbarWidth, _keymapArea.top,
-		scrollbarWidth,	_keymapArea.height());
-	_scrollBar->_entriesPerPage = _rowCount;
-	_scrollBar->_numEntries = 1;
-	_scrollBar->recalc();
+	setupWidgets();
 }
 
 RemapDialog::~RemapDialog() {
@@ -124,34 +100,37 @@
 }
 
 void RemapDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
-	if (cmd >= kRemapCmd && cmd < kRemapCmd + _keymapMappings.size()) {
-		startRemapping(&_keymapMappings[cmd - kRemapCmd]);
+	if (cmd >= kRemapCmd && cmd < kRemapCmd + _keymapWidgets.size()) {
+		startRemapping(cmd - kRemapCmd);
 	} else if (cmd == GUI::kPopUpItemSelectedCmd) {
 		loadKeymap();
 	} else if (cmd == GUI::kSetPositionCmd) {
-		if (data != _topRow) refreshKeymap();
+		refreshKeymap();
 	} else {
 		GUI::Dialog::handleCommand(sender, cmd, data);
 	}
 }
 
-void RemapDialog::startRemapping(Mapping *remap) {
-	_activeRemap = remap;
-	_activeRemap->keyButton->setLabel("...");
+void RemapDialog::startRemapping(uint i) {
+
+	_activeRemapAction = _currentActions[_topAction + i].action;
+	_keymapWidgets[i].keyButton->setLabel("...");
+	_keymapWidgets[i].keyButton->draw();
+
 	_keymapper->setEnabled(false);
 }
 
 void RemapDialog::stopRemapping() {
 	refreshKeymap();
-	_activeRemap = 0;
+	_activeRemapAction = 0;
 	_keymapper->setEnabled(true);
 }
 
-void RemapDialog::handleKeyDown(Common::KeyState state) {
-	if (_activeRemap) {
+void RemapDialog::handleKeyUp(Common::KeyState state) {
+	if (_activeRemapAction) {
 		const HardwareKey *hwkey = _keymapper->getHardwareKey(state);
 		if (hwkey) {
-			_activeRemap->action->mapKey(hwkey);
+			_activeRemapAction->mapKey(hwkey);
 			stopRemapping();
 		}
 	} else {
@@ -161,94 +140,135 @@
 }
 
 void RemapDialog::loadKeymap() {
+	_currentActions.clear();
 	if (_activeKeymaps->size() > 0 && _kmPopUp->getSelected() == 0) {
-		// TODO: show active keymaps (with inherited mappings)
+		List<const HardwareKey*> freeKeys (_keymapper->_keymapMan->getHardwareKeySet()->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()];
-		_currentActions = &km->getActions();
-		
-		int actionCount = _currentActions->size();
-		int maxActions = _colCount * _rowCount;
-		if (actionCount < maxActions)
-			setupWidgets(actionCount);
-		else
-			setupWidgets(maxActions);
-		
-		// refresh scroll bar
-		_scrollBar->_currentPos = 0;
-		_scrollBar->_numEntries = (actionCount + _colCount - 1) / _colCount;
-		_scrollBar->recalc();
 
-		_topRow = 0;
-		_topAction = _currentActions->begin();
-	} else {
-		_currentActions = 0;
-		setupWidgets(0);
+		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();
-
 }
 
 void RemapDialog::refreshKeymap() {
-	uint newTopRow = _scrollBar->_currentPos;
-	while (newTopRow < _topRow) {
-		for (uint i = 0; i < _colCount; i++)
-			_topAction--;
-		_topRow--;
+	int newTopAction = _scrollBar->_currentPos * _colCount;
+	if (newTopAction == _topAction) return;
+	_topAction = newTopAction;
+
+	//_container->draw();
+	_scrollBar->draw();
+
+	uint widgetI = 0;
+	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->clearFlags(GUI::WIDGET_INVISIBLE);
+			widg.keyButton->clearFlags(GUI::WIDGET_INVISIBLE);
+			actionI++; 
+		} else {
+			widg.actionText->setFlags(GUI::WIDGET_INVISIBLE);
+			widg.keyButton->setFlags(GUI::WIDGET_INVISIBLE);
+		}
+		//widg.actionText->draw();
+		//widg.keyButton->draw();
 	}
-	while (newTopRow > _topRow) {
-		for (uint i = 0; i < _colCount; i++)
-			_topAction++;
-		_topRow++;
-	}
-	uint idx = 0;
-	uint max = _keymapMappings.size();
-	List<Action*>::iterator it;
-	for (it = _topAction; it != _currentActions->end() && idx < max; it++, idx++) {
-		Mapping& ma = _keymapMappings[idx];
-		ma.action = *it;
-		ma.actionText->setLabel(ma.action->description + ": ");
-		const HardwareKey *mappedKey = ma.action->getMappedKey();
-		if (mappedKey)
-			ma.keyButton->setLabel(mappedKey->description);
-		else
-			ma.keyButton->setLabel("-");
-		_keymapMappings[idx].actionText->clearFlags(GUI::WIDGET_INVISIBLE);
-		_keymapMappings[idx].keyButton->clearFlags(GUI::WIDGET_INVISIBLE);
-	}
-	while (idx < max) {
-		_keymapMappings[idx].actionText->setFlags(GUI::WIDGET_INVISIBLE);
-		_keymapMappings[idx].keyButton->setFlags(GUI::WIDGET_INVISIBLE);
-		idx++;
-	}
+	// need to redraw entire Dialog so that invisible 
+	// widgets disappear
 	draw();
 }
 
-void RemapDialog::setupWidgets(uint newNum) {
-	uint num = _keymapMappings.size();
-	if (num == newNum) return;
+void RemapDialog::setupWidgets() {
 
-	uint textYOff = (_buttonHeight - kLineHeight) / 2;
-	while (num < newNum) {
-		uint x = _keymapArea.left + (num % _colCount) * (_colWidth + _spacing);
-		uint y = _keymapArea.top + (num / _colCount) * (_buttonHeight + _spacing);
-		Mapping ma;
-		ma.action = 0;
-		ma.actionText = new GUI::StaticTextWidget(this, x, y + textYOff, 
-			_colWidth / 2, kLineHeight, "", Graphics::kTextAlignRight);
-		ma.keyButton = new GUI::ButtonWidget(this, x + _colWidth / 2,
-			y, _colWidth / 2, _buttonHeight, "", kRemapCmd + num);
-		_keymapMappings.push_back(ma);
-		num++;
+	int scrollbarWidth, buttonHeight;
+	if (g_gui.getWidgetSize() == GUI::kBigWidgetSize) {
+		buttonHeight = GUI::kBigButtonHeight;
+		scrollbarWidth = GUI::kBigScrollBarWidth;
+	} else {
+		buttonHeight = GUI::kButtonHeight;
+		scrollbarWidth = GUI::kNormalScrollBarWidth;
 	}
-	while (num > newNum) {
-		Mapping ma = _keymapMappings.remove_at(num - 1);
-		removeWidget(ma.actionText);
-		delete ma.actionText;
-		removeWidget(ma.keyButton);
-		delete ma.keyButton;
-		num--;
+	int areaX = g_gui.evaluator()->getVar("remap_keymap_area.x");
+	int areaY = g_gui.evaluator()->getVar("remap_keymap_area.y");
+	int areaW = g_gui.evaluator()->getVar("remap_keymap_area.w");
+	int areaH = g_gui.evaluator()->getVar("remap_keymap_area.h");
+	int spacing = g_gui.evaluator()->getVar("remap_spacing");
+
+	_colCount = g_gui.evaluator()->getVar("remap_col_count");
+	_rowCount = (areaH + spacing) / (buttonHeight + spacing);
+	int colWidth = (areaW - scrollbarWidth - _colCount * spacing) / _colCount;
+
+	//_container = new GUI::ContainerWidget(this, areaX, areaY, areaW, areaH);
+	//_container->setHints(GUI::THEME_HINT_USE_SHADOW);
+
+	_scrollBar = new GUI::ScrollBarWidget(this, 
+		areaX + areaW - scrollbarWidth, areaY, scrollbarWidth, areaH);
+	_scrollBar->_entriesPerPage = _rowCount;
+	_scrollBar->_numEntries = 1;
+	_scrollBar->recalc();
+
+	uint textYOff = (buttonHeight - kLineHeight) / 2;
+	int n = _rowCount * _colCount;
+	for (int i = 0; i < n; i++) {
+		uint x = areaX + (i % _colCount) * (colWidth + spacing);
+		uint y = areaY + (i / _colCount) * (buttonHeight + spacing);
+		ActionWidgets widg;
+		widg.actionText = new GUI::StaticTextWidget(this, x, y + textYOff, 
+			colWidth / 2, kLineHeight, "", Graphics::kTextAlignRight);
+		widg.keyButton = new GUI::ButtonWidget(this, x + colWidth / 2,
+			y, colWidth / 2, buttonHeight, "", kRemapCmd + i);
+		_keymapWidgets.push_back(widg);
 	}
 }
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.h	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.h	2008-08-13 11:46:08 UTC (rev 33821)
@@ -41,44 +41,42 @@
 	virtual ~RemapDialog();
 	virtual void open();
 	virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
-	virtual void handleKeyDown(Common::KeyState state);
+	virtual void handleKeyUp(Common::KeyState state);
 
 protected:
-	struct Mapping {
-		Action *action;
+	struct ActionWidgets {
 		GUI::StaticTextWidget *actionText;
 		GUI::ButtonWidget *keyButton;
 	};
+	struct ActionInfo {
+		Action *action;
+		bool inherited;
+		String description;
+	};
 
 	void loadKeymap();
 	void refreshKeymap();
-	void setupWidgets(uint num);
-	void startRemapping(Mapping *remap);
+	void setupWidgets();
+	void startRemapping(uint i);
 	void stopRemapping();
 
 	Keymapper *_keymapper;
 	Stack<Keymapper::MapRecord> *_activeKeymaps;
-	KeymapManager::Domain *_globalKeymaps;
-	KeymapManager::Domain *_gameKeymaps;
+	Keymap** _keymapTable;
 
-	List<Action*> *_currentActions;
-	List<Action*>::iterator _topAction;
-	uint _topRow;
+	Array<ActionInfo> _currentActions;
+	int _topAction;
 
 	Rect _keymapArea;
 
 	GUI::PopUpWidget *_kmPopUp;
-	Keymap** _keymapTable;
-
+	//GUI::ContainerWidget *_container;
 	GUI::ScrollBarWidget *_scrollBar;
 
-	uint _colWidth;
 	uint _colCount, _rowCount;
-	uint _spacing;
-	uint _buttonHeight;
 
-	Mapping *_activeRemap;
-	Array<Mapping> _keymapMappings;
+	Array<ActionWidgets> _keymapWidgets;
+	Action *_activeRemapAction;
 
 };
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/events.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/events.cpp	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/events.cpp	2008-08-13 11:46:08 UTC (rev 33821)
@@ -533,6 +533,7 @@
 	mapper->registerHardwareKeySet(keySet);
 
 	Keymap *global = new Keymap("global");
+	Keymap *specific = new Keymap("specific");
 	Action *act;
 	Event evt;
 
@@ -549,33 +550,28 @@
 	ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
 	global->addAction(act);
 
-	
-	act = new Action('QUIY', "Quit", kGenericActionCategory, kQuitAction);
-	ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
+	act = new Action('MENQ', "Menu", kGenericActionCategory, kMenuAction);
+	ADD_KEYDOWN_EVENT(KEYCODE_F5, ASCII_F5, 0)
 	global->addAction(act);
-
 	
-	act = new Action('QUIU', "Quit", kGenericActionCategory, kQuitAction);
+	act = new Action('QUIQ', "Quit", kGenericActionCategory, kQuitAction);
 	ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
 	global->addAction(act);
 
+	act = new Action('JUMP', "Jump");
+	ADD_KEYDOWN_EVENT(KEYCODE_j, 'j', 0);
+	specific->addAction(act);
 	
-	act = new Action('QUII', "Quit", kGenericActionCategory, kQuitAction);
-	ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
-	global->addAction(act);
-	
-	
-	act = new Action('QUIG', "Quit", kGenericActionCategory, kQuitAction);
-	ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
-	global->addAction(act);
-	
-	act = new Action('QUIH', "Quit", kGenericActionCategory, kQuitAction);
-	ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
-	global->addAction(act);
+	act = new Action('DUCK', "Duck");
+	ADD_KEYDOWN_EVENT(KEYCODE_d, 'd', 0);
+	specific->addAction(act);
 
 	#undef ADD_KEYDOWN_EVENT
 
 	mapper->addGlobalKeymap(global);
+	mapper->addGlobalKeymap(specific);
+
 	mapper->pushKeymap("global");
+	mapper->pushKeymap("specific", true);
 }
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/sdl.cpp	2008-08-13 11:41:42 UTC (rev 33820)
+++ scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/sdl.cpp	2008-08-13 11:46:08 UTC (rev 33821)
@@ -134,6 +134,11 @@
 		setupMixer();
 	}
 
+	// Setup the keymapper with backend's set of keys
+	// NOTE: must be done before creating TimerManager 
+	// to avoid race conditions in creating EventManager
+	setupKeymapper();
+
 	// Create and hook up the timer manager, if none exists yet (we check for
 	// this to allow subclasses to provide their own).
 	if (_timer == 0) {
@@ -148,9 +153,6 @@
 		_timerID = SDL_AddTimer(10, &timer_handler, _timer);
 	}
 
-	// Provide the keymapper with backend's set of keys
-	setupKeymapper();
-
 	// Invoke parent implementation of this method
 	OSystem::initBackend();
 


Property changes on: scummvm/branches/gsoc2008-vkeybd/dists/msvc8
___________________________________________________________________
Added: svn:ignore
   + scumm_Debug
scumm_Release
scummvm_Debug
scummvm_Release
sky_Debug
sky_Release
sword1_Debug
sword1_Release
sword2_Debug
sword2_Release
tinsel_Debug
touche_Debug
touche_Release
agi_Debug
agi_Release
agos_Debug
agos_Release
cine_Debug
cine_Release
cruise_Debug
cruise_Release
drascula_Debug
drascula_Release
gob_Debug
gob_Release
igor_Debug
igor_Release
kyra_Debug
kyra_Release
lure_Debug
lure_Release
m4_Debug
m4_Release
made_Debug
made_Release
parallaction_Debug
parallaction_Release
queen_Debug
queen_Release
saga_Debug
saga_Release
*.user



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