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

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Tue Aug 12 01:08:24 CEST 2008


Revision: 33791
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33791&view=rev
Author:   kenny-d
Date:     2008-08-11 23:08:21 +0000 (Mon, 11 Aug 2008)

Log Message:
-----------
Remap dialog WIP

Modified Paths:
--------------
    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/vkeybd/virtual-keyboard-gui.cpp
    scummvm/branches/gsoc2008-vkeybd/gui/theme-config.cpp

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp	2008-08-11 23:01:32 UTC (rev 33790)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.cpp	2008-08-11 23:08:21 UTC (rev 33791)
@@ -1,3 +1,27 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ */
+
 #include "backends/keymapper/remap-dialog.h"
 #include "gui/eval.h"
 #include "gui/newgui.h"
@@ -2,2 +26,3 @@
 #include "gui/PopUpWidget.h"
+#include "gui/ScrollBarWidget.h"
 
@@ -10,7 +35,7 @@
 };
 
 RemapDialog::RemapDialog()
-	: Dialog("remap"), _activeRemap(0) {
+	: Dialog("remap"), _activeRemap(0), _currentActions(0), _topRow(0) {
 
 	const int screenW = g_system->getOverlayWidth();
 	const int screenH = g_system->getOverlayHeight();
@@ -37,7 +62,7 @@
 	_keymapTable = (Keymap**)malloc(sizeof(Keymap*) * keymapCount);
 
 	int labelWidth = g_gui.evaluator()->getVar("remap_popup_labelW");
-	_kmPopUp = new GUI::PopUpWidget(this, "remap_popup", "Keymap:", labelWidth);
+	_kmPopUp = new GUI::PopUpWidget(this, "remap_popup", "Keymap: ", labelWidth);
 
 	if (_activeKeymaps->size() > 0) {
 		_kmPopUp->appendEntry(_activeKeymaps->top().keymap->getName() + " (Active)");
@@ -60,21 +85,31 @@
 		}
 	}
 
-	_w = screenW - 2 * 20;
-	_h = screenH - 2 * 20;
-	// Center the dialog
-	_x = (screenW - _w) / 2;
-	_y = (screenH - _h) / 2;
-	
-	_colCount = 2;
-	_spacing = 10;
-	_colWidth = (_w - (_colCount - 1) * _spacing) / _colCount;
-	_widgetsY = g_gui.evaluator()->getVar("remap_widgetsY");
-	if (g_gui.getWidgetSize() == GUI::kBigWidgetSize)
+	int scrollbarWidth;
+	if (g_gui.getWidgetSize() == GUI::kBigWidgetSize) {
 		_buttonHeight = GUI::kBigButtonHeight;
-	else
+		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();
 }
 
 RemapDialog::~RemapDialog() {
@@ -85,14 +120,16 @@
 	Dialog::open();
 	
 	_kmPopUp->setSelected(0);
-	refreshKeymap();
+	loadKeymap();
 }
 
 void RemapDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
 	if (cmd >= kRemapCmd && cmd < kRemapCmd + _keymapMappings.size()) {
 		startRemapping(&_keymapMappings[cmd - kRemapCmd]);
 	} else if (cmd == GUI::kPopUpItemSelectedCmd) {
-		refreshKeymap();
+		loadKeymap();
+	} else if (cmd == GUI::kSetPositionCmd) {
+		if (data != _topRow) refreshKeymap();
 	} else {
 		GUI::Dialog::handleCommand(sender, cmd, data);
 	}
@@ -123,52 +160,96 @@
 
 }
 
-void RemapDialog::refreshKeymap() {
+void RemapDialog::loadKeymap() {
 	if (_activeKeymaps->size() > 0 && _kmPopUp->getSelected() == 0) {
 		// TODO: show active keymaps (with inherited mappings)
+	} 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 {
-		Keymap *km = _keymapTable[_kmPopUp->getSelectedTag()];
-		List<Action*>& actions = km->getActions();
-		setNumOfWidgets(actions.size());
-		uint idx = 0;
-		List<Action*>::iterator it;
-		for (it = actions.begin(); it != actions.end(); it++, idx++) {
-			Mapping& ma = _keymapMappings[idx];
-			ma.action = *it;
-			ma.actionText->setLabel(ma.action->description + ":");
-			ma.keyButton->setLabel(ma.action->getMappedKey()->description);
-		}
+		_currentActions = 0;
+		setupWidgets(0);
 	}
 
+	refreshKeymap();
+
 }
 
-void RemapDialog::setNumOfWidgets(uint newNum) {
+void RemapDialog::refreshKeymap() {
+	uint newTopRow = _scrollBar->_currentPos;
+	while (newTopRow < _topRow) {
+		for (uint i = 0; i < _colCount; i++)
+			_topAction--;
+		_topRow--;
+	}
+	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++;
+	}
+	draw();
+}
+
+void RemapDialog::setupWidgets(uint newNum) {
 	uint num = _keymapMappings.size();
-	if (num < newNum) {
-		uint textYOff = (_buttonHeight - kLineHeight) / 2;
-		while (num < newNum) {
-			uint x = (num % _colCount) * (_colWidth + _spacing);
-			uint y = _widgetsY + (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++;
-		}
-	} else {
-		while (num > newNum) {
-			Mapping ma = _keymapMappings.remove_at(num - 1);
-			removeWidget(ma.actionText);
-			delete ma.actionText;
-			removeWidget(ma.keyButton);
-			delete ma.keyButton;
-			num--;
-		}
+	if (num == newNum) return;
+
+	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++;
 	}
-
+	while (num > newNum) {
+		Mapping ma = _keymapMappings.remove_at(num - 1);
+		removeWidget(ma.actionText);
+		delete ma.actionText;
+		removeWidget(ma.keyButton);
+		delete ma.keyButton;
+		num--;
+	}
 }
 
 } // end of namespace Common

Modified: scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.h	2008-08-11 23:01:32 UTC (rev 33790)
+++ scummvm/branches/gsoc2008-vkeybd/backends/keymapper/remap-dialog.h	2008-08-11 23:08:21 UTC (rev 33791)
@@ -30,6 +30,7 @@
 
 namespace GUI {
 	class PopupWidget;
+	class ScrollBarWidget;
 }
 
 namespace Common {
@@ -49,8 +50,9 @@
 		GUI::ButtonWidget *keyButton;
 	};
 
+	void loadKeymap();
 	void refreshKeymap();
-	void setNumOfWidgets(uint num);
+	void setupWidgets(uint num);
 	void startRemapping(Mapping *remap);
 	void stopRemapping();
 
@@ -59,13 +61,20 @@
 	KeymapManager::Domain *_globalKeymaps;
 	KeymapManager::Domain *_gameKeymaps;
 
+	List<Action*> *_currentActions;
+	List<Action*>::iterator _topAction;
+	uint _topRow;
+
+	Rect _keymapArea;
+
 	GUI::PopUpWidget *_kmPopUp;
 	Keymap** _keymapTable;
 
+	GUI::ScrollBarWidget *_scrollBar;
+
 	uint _colWidth;
-	uint _colCount;
+	uint _colCount, _rowCount;
 	uint _spacing;
-	uint _widgetsY;
 	uint _buttonHeight;
 
 	Mapping *_activeRemap;

Modified: scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/events.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/events.cpp	2008-08-11 23:01:32 UTC (rev 33790)
+++ scummvm/branches/gsoc2008-vkeybd/backends/platform/sdl/events.cpp	2008-08-11 23:08:21 UTC (rev 33791)
@@ -549,6 +549,30 @@
 	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);
+	global->addAction(act);
+
+	
+	act = new Action('QUIU', "Quit", kGenericActionCategory, kQuitAction);
+	ADD_KEYDOWN_EVENT(KEYCODE_ESCAPE, ASCII_ESCAPE, 0);
+	global->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);
+
 	#undef ADD_KEYDOWN_EVENT
 
 	mapper->addGlobalKeymap(global);

Modified: scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.cpp	2008-08-11 23:01:32 UTC (rev 33790)
+++ scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.cpp	2008-08-11 23:08:21 UTC (rev 33791)
@@ -267,7 +267,7 @@
 	const OverlayColor *ove = (OverlayColor *) _overlayBackup.getBasePtr(_dirtyRect.left, _dirtyRect.top);
 	int16 h = surf.h;
 
-	while (h-- > 0) {
+	while (h--) {
 		memcpy(scr, ove, surf.w * sizeof(OverlayColor));
 		scr += surf.w;
 		ove += _overlayBackup.w;

Modified: scummvm/branches/gsoc2008-vkeybd/gui/theme-config.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/gui/theme-config.cpp	2008-08-11 23:01:32 UTC (rev 33790)
+++ scummvm/branches/gsoc2008-vkeybd/gui/theme-config.cpp	2008-08-11 23:08:21 UTC (rev 33791)
@@ -374,10 +374,12 @@
 "scummsaveload_extinfo.visible=true\n"
 "\n"
 "# Keymapper remap dialog\n"
-"remap=8 8 (w - 16) (h - 16)\n"
+"remap=8 8 (w - 16) (h / 5)\n"
+"remap_spacing=10\n"
+"remap_popup=remap_spacing remap_spacing (parent.w - remap_spacing * 2) (kLineHeight + 2)\n"
 "remap_popup_labelW=buttonWidth\n"
-"remap_popup=0 0 parent.w (kLineHeight + 2)\n"
-"remap_widgetsY=(remap_popup.h + 10)\n"
+"remap_col_count=3\n"
+"remap_keymap_area=remap_spacing (remap_popup.y + remap_popup.h + remap_spacing) (remap.w - remap_spacing * 2) (remap.h - self.y - remap_spacing)\n"
 "############################################\n"
 "[chooser]\n"
 "chooserW=(w - 2 * 8)\n"


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