aboutsummaryrefslogtreecommitdiff
path: root/backends/events
diff options
context:
space:
mode:
authorLMerckx2018-04-04 20:40:16 +0200
committerBastien Bouclet2018-04-04 20:40:16 +0200
commitf0dfc19f29dab5961598f625a24a922172d06912 (patch)
treed91c6b6ee015abbf887c78c4ad71d9203c990414 /backends/events
parent73d72f4fc84d3c047415f0de2d2f2f0fb5cb7879 (diff)
downloadscummvm-rg350-f0dfc19f29dab5961598f625a24a922172d06912.tar.gz
scummvm-rg350-f0dfc19f29dab5961598f625a24a922172d06912.tar.bz2
scummvm-rg350-f0dfc19f29dab5961598f625a24a922172d06912.zip
SDL: Allow to load a custom game controller mapping file
And add a specific joystick button to open virtual keyboard
Diffstat (limited to 'backends/events')
-rw-r--r--backends/events/sdl/sdl-events.cpp44
-rw-r--r--backends/events/sdl/sdl-events.h5
2 files changed, 49 insertions, 0 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index 1ea97a6350..6c4774554c 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 2899b584af..b26d4cc6bd 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.