[Scummvm-git-logs] scummvm master -> f0dfc19f29dab5961598f625a24a922172d06912

bgK bastien.bouclet at gmail.com
Wed Apr 4 20:40:19 CEST 2018


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f0dfc19f29 SDL: Allow to load a custom game controller mapping file


Commit: f0dfc19f29dab5961598f625a24a922172d06912
    https://github.com/scummvm/scummvm/commit/f0dfc19f29dab5961598f625a24a922172d06912
Author: LMerckx (laurent-merckx at skynet.be)
Date: 2018-04-04T20:40:16+02:00

Commit Message:
SDL: Allow to load a custom game controller mapping file

And add a specific joystick button to open virtual keyboard

Changed paths:
    README
    backends/events/sdl/sdl-events.cpp
    backends/events/sdl/sdl-events.h


diff --git a/README b/README
index c777c64..3fcde4c 100644
--- a/README
+++ b/README
@@ -2630,6 +2630,10 @@ The following keywords are recognized:
     cdrom              number   Number of CD-ROM unit to use for audio. If
                                 negative, don't even try to access the CD-ROM.
     joystick_num       number   Number of joystick device to use for input
+    controller_map_db  string   A custom controller mapping file to load to 
+                                complete default database (SDL backend only).
+                                Otherwise, file gamecontrollerdb.txt will be
+                                loaded from extrapath.
     music_driver       string   The music engine to use.
     opl_driver         string   The AdLib (OPL) emulator to use.
     output_rate        number   The output sample rate to use, in Hz. Sensible
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 1ea97a6..6c47745 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -29,6 +29,7 @@
 #include "backends/graphics/graphics.h"
 #include "common/config-manager.h"
 #include "common/textconsole.h"
+#include "common/fs.h"
 
 // FIXME move joystick defines out and replace with confile file options
 // we should really allow users to map any key to a joystick button
@@ -43,8 +44,14 @@
 #define JOY_BUT_PERIOD 1
 #define JOY_BUT_SPACE 4
 #define JOY_BUT_F5 5
+#ifdef ENABLE_VKEYBD
+#define JOY_BUT_VKEYBOARD 7
+#endif
+
 
 #if SDL_VERSION_ATLEAST(2, 0, 0)
+#define GAMECONTROLLERDB_FILE "gamecontrollerdb.txt"
+
 static uint32 convUTF8ToUTF32(const char *src) {
 	uint32 utf32 = 0;
 
@@ -63,6 +70,32 @@ static uint32 convUTF8ToUTF32(const char *src) {
 
 	return utf32;
 }
+
+void SdlEventSource::loadGameControllerMappingFile() {
+	bool loaded = false;
+	if (ConfMan.hasKey("controller_map_db")) {
+		Common::FSNode file = Common::FSNode(ConfMan.get("controller_map_db"));
+		if (file.exists()) {
+			if (SDL_GameControllerAddMappingsFromFile(file.getPath().c_str()) < 0)
+				error("File %s not valid: %s", file.getPath().c_str(), SDL_GetError());	
+			else {
+				loaded = true;
+				debug("Game controller DB file loaded: %s", file.getPath().c_str());
+			}
+		} else
+			warning("Game controller DB file not found: %s", file.getPath().c_str());
+	}
+	if (!loaded && ConfMan.hasKey("extrapath")) {
+		Common::FSNode dir = Common::FSNode(ConfMan.get("extrapath"));
+		Common::FSNode file = dir.getChild(GAMECONTROLLERDB_FILE);
+		if (file.exists()) {
+			if (SDL_GameControllerAddMappingsFromFile(file.getPath().c_str()) < 0)
+				error("File %s not valid: %s", file.getPath().c_str(), SDL_GetError());	
+			else
+				debug("Game controller DB file loaded: %s", file.getPath().c_str());
+		}
+	}
+}
 #endif
 
 SdlEventSource::SdlEventSource()
@@ -85,6 +118,7 @@ SdlEventSource::SdlEventSource()
 		if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1) {
 			error("Could not initialize SDL: %s", SDL_GetError());
 		}
+		loadGameControllerMappingFile();
 #endif
 
 		openJoystick(joystick_num);
@@ -876,6 +910,11 @@ bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
 			event.kbd.keycode = Common::KEYCODE_F5;
 			event.kbd.ascii = mapKey(SDLK_F5, (SDLMod)ev.key.keysym.mod, 0);
 			break;
+#ifdef ENABLE_VKEYBD
+		case JOY_BUT_VKEYBOARD: // Toggles virtual keyboard
+			event.type = Common::EVENT_VIRTUAL_KEYBOARD;
+			break;
+#endif
 		}
 		return true;
 	}
@@ -907,6 +946,11 @@ bool SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
 			event.kbd.keycode = Common::KEYCODE_F5;
 			event.kbd.ascii = mapKey(SDLK_F5, (SDLMod)ev.key.keysym.mod, 0);
 			break;
+#ifdef ENABLE_VKEYBD
+		case JOY_BUT_VKEYBOARD: // Toggles virtual keyboard
+			// Handled in key down
+			break;
+#endif
 		}
 		return true;
 	}
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index 2899b58..b26d4cc 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -94,6 +94,11 @@ protected:
 	SdlGraphicsManager *_graphicsManager;
 
 	/**
+	 * Search for a game controller db file and load it.
+	 */
+	void loadGameControllerMappingFile();
+
+	/**
 	 * Open the SDL joystick with the specified index
 	 *
 	 * After this function completes successfully, SDL sends events for the device.





More information about the Scummvm-git-logs mailing list