[Scummvm-cvs-logs] SF.net SVN: scummvm:[40439] scummvm/trunk

sev at users.sourceforge.net sev at users.sourceforge.net
Mon May 11 00:05:04 CEST 2009


Revision: 40439
          http://scummvm.svn.sourceforge.net/scummvm/?rev=40439&view=rev
Author:   sev
Date:     2009-05-10 22:05:04 +0000 (Sun, 10 May 2009)

Log Message:
-----------
Keymapper:
- Introduced new OSystem method getHardwareKeySet() with default implementation
- Moved global keymap creation to base/main.cpp
- Moved GUI keymap creation to gui/GuiManager.cpp
- Added various safeguard checks to various keymapper methods

Now it is really possible to add keymapper to all backends.

Modified Paths:
--------------
    scummvm/trunk/backends/keymapper/keymapper.cpp
    scummvm/trunk/backends/platform/sdl/events.cpp
    scummvm/trunk/backends/platform/sdl/sdl.cpp
    scummvm/trunk/backends/platform/sdl/sdl.h
    scummvm/trunk/base/main.cpp
    scummvm/trunk/common/system.h
    scummvm/trunk/gui/GuiManager.cpp
    scummvm/trunk/gui/GuiManager.h

Modified: scummvm/trunk/backends/keymapper/keymapper.cpp
===================================================================
--- scummvm/trunk/backends/keymapper/keymapper.cpp	2009-05-10 21:27:57 UTC (rev 40438)
+++ scummvm/trunk/backends/keymapper/keymapper.cpp	2009-05-10 22:05:04 UTC (rev 40439)
@@ -71,6 +71,11 @@
 	if (_hardwareKeys)
 		error("Hardware key set already registered!");
 
+	if (!keys) {
+		warning("No hardware keys are supplied");
+		return;
+	}
+
 	_hardwareKeys = keys;
 }
 
@@ -93,6 +98,11 @@
 }
 
 void Keymapper::initKeymap(Domain &domain, Keymap *map) {
+	if (!_hardwareKeys) {
+		warning("No hardware keys were registered yet (%s)", map->getName().c_str());
+		return;
+	}
+
 	map->setConfigDomain(domain.getConfigDomain());
 	map->loadMappings(_hardwareKeys);
 

Modified: scummvm/trunk/backends/platform/sdl/events.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/events.cpp	2009-05-10 21:27:57 UTC (rev 40438)
+++ scummvm/trunk/backends/platform/sdl/events.cpp	2009-05-10 22:05:04 UTC (rev 40439)
@@ -50,8 +50,7 @@
 
 
 
-static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode)
-{
+static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) {
 	if (key >= SDLK_F1 && key <= SDLK_F9) {
 		return key - SDLK_F1 + Common::ASCII_F1;
 	} else if (key >= SDLK_KP0 && key <= SDLK_KP9) {
@@ -522,10 +521,9 @@
 	return false;
 }
 
-void OSystem_SDL::setupKeymapper() {
+Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() {
 #ifdef ENABLE_KEYMAPPER
 	using namespace Common;
-	Keymapper *mapper = getEventManager()->getKeymapper();
 
 	HardwareKeySet *keySet = new HardwareKeySet();
 	keySet->addHardwareKey(new HardwareKey( "a", KeyState(KEYCODE_a), "a", kActionKeyType ));
@@ -536,49 +534,10 @@
 	keySet->addHardwareKey(new HardwareKey( "m", KeyState(KEYCODE_m), "m (remap)", kTriggerRightKeyType, kKeyRemapActionType ));
 	keySet->addHardwareKey(new HardwareKey( "[", KeyState(KEYCODE_LEFTBRACKET), "[ (select)", kSelectKeyType ));
 	keySet->addHardwareKey(new HardwareKey( "]", KeyState(KEYCODE_RIGHTBRACKET), "] (start)", kStartKeyType ));
-	mapper->registerHardwareKeySet(keySet);
 
-	Keymap *globalMap = new Keymap("global");
-	Action *act;
+	return keySet;
 
-	act = new Action(globalMap, "MENU", "Menu", kGenericActionType, kSelectKeyType);
-	act->addKeyEvent(KeyState(KEYCODE_F5, ASCII_F5, 0));
-	
-	act = new Action(globalMap, "SKCT", "Skip", kGenericActionType, kActionKeyType);
-	act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0));
-
-	act = new Action(globalMap, "PAUS", "Pause", kGenericActionType, kStartKeyType);
-	act->addKeyEvent(KeyState(KEYCODE_SPACE, ' ', 0));
-	
-	act = new Action(globalMap, "SKLI", "Skip line", kGenericActionType, kActionKeyType);
-	act->addKeyEvent(KeyState(KEYCODE_PERIOD, '.', 0));
-
-	act = new Action(globalMap, "VIRT", "Display keyboard", kVirtualKeyboardActionType);
-	act->addKeyEvent(KeyState(KEYCODE_F7, ASCII_F7, 0));
-
-	act = new Action(globalMap, "REMP", "Remap keys", kKeyRemapActionType);
-	act->addKeyEvent(KeyState(KEYCODE_F8, ASCII_F8, 0));
-
-	mapper->addGlobalKeymap(globalMap);
-
-
-	Keymap *guiMap = new Keymap("gui");
-
-	act = new Action(guiMap, "CLOS", "Close", kGenericActionType, kStartKeyType);
-	act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0));
-	
-	act = new Action(guiMap, "CLIK", "Mouse click");
-	act->addLeftClickEvent();
-
-	act = new Action(guiMap, "VIRT", "Display keyboard", kVirtualKeyboardActionType);
-	act->addKeyEvent(KeyState(KEYCODE_F7, ASCII_F7, 0));
-
-	act = new Action(guiMap, "REMP", "Remap keys", kKeyRemapActionType);
-	act->addKeyEvent(KeyState(KEYCODE_F8, ASCII_F8, 0));
-
-	mapper->addGlobalKeymap(guiMap);
-
-	mapper->pushKeymap("global");
+#else
+	return 0;
 #endif
 }
-

Modified: scummvm/trunk/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.cpp	2009-05-10 21:27:57 UTC (rev 40438)
+++ scummvm/trunk/backends/platform/sdl/sdl.cpp	2009-05-10 22:05:04 UTC (rev 40439)
@@ -170,11 +170,6 @@
 		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) {

Modified: scummvm/trunk/backends/platform/sdl/sdl.h
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.h	2009-05-10 21:27:57 UTC (rev 40438)
+++ scummvm/trunk/backends/platform/sdl/sdl.h	2009-05-10 22:05:04 UTC (rev 40439)
@@ -136,8 +136,7 @@
 	// Returns true if an event was retrieved.
 	virtual bool pollEvent(Common::Event &event); // overloaded by CE backend
 
-	// Sets up the keymapper with the backends hardware key set
-	virtual void setupKeymapper();
+	Common::HardwareKeySet *getHardwareKeySet();
 
 	// Set function that generates samples
 	virtual void setupMixer();

Modified: scummvm/trunk/base/main.cpp
===================================================================
--- scummvm/trunk/base/main.cpp	2009-05-10 21:27:57 UTC (rev 40438)
+++ scummvm/trunk/base/main.cpp	2009-05-10 22:05:04 UTC (rev 40439)
@@ -47,6 +47,8 @@
 #include "gui/GuiManager.h"
 #include "gui/message.h"
 
+#include "backends/keymapper/keymapper.h"
+
 #if defined(_WIN32_WCE)
 #include "backends/platform/wince/CELauncherDialog.h"
 #elif defined(__DC__)
@@ -234,7 +236,47 @@
 	system.fillScreen(0);
 }
 
+static void setupKeymapper(OSystem &system) {
 
+#ifdef ENABLE_KEYMAPPER
+	using namespace Common;
+
+	Keymapper *mapper = system.getEventManager()->getKeymapper();
+	Keymap *globalMap = new Keymap("global");
+	Action *act;
+	HardwareKeySet *keySet;
+
+	keySet = system.getHardwareKeySet();
+
+	// Query backend for hardware keys and register them
+	mapper->registerHardwareKeySet(keySet);
+
+	// Now create the global keymap
+	act = new Action(globalMap, "MENU", "Menu", kGenericActionType, kSelectKeyType);
+	act->addKeyEvent(KeyState(KEYCODE_F5, ASCII_F5, 0));
+	
+	act = new Action(globalMap, "SKCT", "Skip", kGenericActionType, kActionKeyType);
+	act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0));
+
+	act = new Action(globalMap, "PAUS", "Pause", kGenericActionType, kStartKeyType);
+	act->addKeyEvent(KeyState(KEYCODE_SPACE, ' ', 0));
+	
+	act = new Action(globalMap, "SKLI", "Skip line", kGenericActionType, kActionKeyType);
+	act->addKeyEvent(KeyState(KEYCODE_PERIOD, '.', 0));
+
+	act = new Action(globalMap, "VIRT", "Display keyboard", kVirtualKeyboardActionType);
+	act->addKeyEvent(KeyState(KEYCODE_F7, ASCII_F7, 0));
+
+	act = new Action(globalMap, "REMP", "Remap keys", kKeyRemapActionType);
+	act->addKeyEvent(KeyState(KEYCODE_F8, ASCII_F8, 0));
+
+	mapper->addGlobalKeymap(globalMap);
+
+	mapper->pushKeymap("global");
+#endif
+
+}
+
 extern "C" int scummvm_main(int argc, const char * const argv[]) {
 	Common::String specialDebug;
 	Common::String command;
@@ -295,6 +337,9 @@
 	// take place after the backend is initiated and the screen has been setup
 	system.getEventManager()->init();
 
+	// Now as the event manager is created, setup the keymapper
+	setupKeymapper(system);
+
 	// Unless a game was specified, show the launcher dialog
 	if (0 == ConfMan.getActiveDomain())
 		launcherDialog();

Modified: scummvm/trunk/common/system.h
===================================================================
--- scummvm/trunk/common/system.h	2009-05-10 21:27:57 UTC (rev 40438)
+++ scummvm/trunk/common/system.h	2009-05-10 22:05:04 UTC (rev 40439)
@@ -48,6 +48,7 @@
 	class TimerManager;
 	class SeekableReadStream;
 	class WriteStream;
+	class HardwareKeySet;
 }
 
 class FilesystemFactory;
@@ -744,6 +745,15 @@
 	 */
 	virtual Common::EventManager *getEventManager() = 0;
 
+	/**
+	 * Register hardware keys with keymapper
+	 *
+	 * @return HardwareKeySet with all keys and recommended mappings
+	 *
+	 * See keymapper documentation for further reference.
+	 */
+	virtual Common::HardwareKeySet *getHardwareKeySet() { return 0; }
+
 	//@}
 
 

Modified: scummvm/trunk/gui/GuiManager.cpp
===================================================================
--- scummvm/trunk/gui/GuiManager.cpp	2009-05-10 21:27:57 UTC (rev 40438)
+++ scummvm/trunk/gui/GuiManager.cpp	2009-05-10 22:05:04 UTC (rev 40439)
@@ -79,6 +79,36 @@
 	delete _theme;
 }
 
+#ifdef ENABLE_KEYMAPPER
+void GuiManager::initKeymap() {
+	using namespace Common;
+
+	bool tmp;
+	Keymapper *mapper = _system->getEventManager()->getKeymapper();
+
+	// Do not try to recreate same keymap over again
+	if (mapper->getKeymap("gui", tmp) != 0)
+		return;
+
+	Action *act;
+	Keymap *guiMap = new Keymap("gui");
+
+	act = new Action(guiMap, "CLOS", "Close", kGenericActionType, kStartKeyType);
+	act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0));
+	
+	act = new Action(guiMap, "CLIK", "Mouse click");
+	act->addLeftClickEvent();
+
+	act = new Action(guiMap, "VIRT", "Display keyboard", kVirtualKeyboardActionType);
+	act->addKeyEvent(KeyState(KEYCODE_F7, ASCII_F7, 0));
+
+	act = new Action(guiMap, "REMP", "Remap keys", kKeyRemapActionType);
+	act->addKeyEvent(KeyState(KEYCODE_F8, ASCII_F8, 0));
+
+	mapper->addGlobalKeymap(guiMap);
+}
+#endif
+
 bool GuiManager::loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx) {
 	// If we are asked to reload the currently active theme, just do nothing
 	// FIXME: Actually, why? It might be desirable at times to force a theme reload...
@@ -213,6 +243,12 @@
 	const uint32 waitTime = 1000 / 45;
 
 #ifdef ENABLE_KEYMAPPER
+	// Due to circular reference with event manager and GUI
+	// we cannot init keymap on the GUI creation. Thus, let's
+	// try to do it on every launch, checking whether the
+	// map is already existing
+	initKeymap();
+
 	eventMan->getKeymapper()->pushKeymap("gui");
 #endif
 

Modified: scummvm/trunk/gui/GuiManager.h
===================================================================
--- scummvm/trunk/gui/GuiManager.h	2009-05-10 21:27:57 UTC (rev 40438)
+++ scummvm/trunk/gui/GuiManager.h	2009-05-10 22:05:04 UTC (rev 40439)
@@ -124,6 +124,8 @@
 
 	bool _themeChange;
 
+	void initKeymap();
+
 	void saveState();
 	void restoreState();
 


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