aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl
diff options
context:
space:
mode:
authorTarek Soliman2012-02-09 01:26:11 -0600
committerTarek Soliman2012-02-12 13:28:13 -0600
commit52da780fbc10200b91d92e7cd04932b101c7539b (patch)
tree6f7ace246c4a711ec760c35d102492e0c3da75d3 /backends/platform/sdl
parent0ba3335674dcd88d34d1d2ab8453658191d31c38 (diff)
downloadscummvm-rg350-52da780fbc10200b91d92e7cd04932b101c7539b.tar.gz
scummvm-rg350-52da780fbc10200b91d92e7cd04932b101c7539b.tar.bz2
scummvm-rg350-52da780fbc10200b91d92e7cd04932b101c7539b.zip
KEYMAPPER: Refactor HardwareKeySet generation
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r--backends/platform/sdl/hardwarekeys.cpp50
-rw-r--r--backends/platform/sdl/sdl.h5
2 files changed, 8 insertions, 47 deletions
diff --git a/backends/platform/sdl/hardwarekeys.cpp b/backends/platform/sdl/hardwarekeys.cpp
index 9a33e357da..3e9378602e 100644
--- a/backends/platform/sdl/hardwarekeys.cpp
+++ b/backends/platform/sdl/hardwarekeys.cpp
@@ -28,16 +28,7 @@
using namespace Common;
-struct Key {
- const char *hwId;
- KeyCode keycode;
- uint16 ascii;
- const char *desc;
- KeyType preferredAction;
- bool shiftable;
-};
-
-static const Key keys[] = {
+static const KeyTableEntry sdlKeys[] = {
{"BACKSPACE", KEYCODE_BACKSPACE, ASCII_BACKSPACE, "Backspace", kActionKeyType, false},
{"TAB", KEYCODE_TAB, ASCII_TAB, "Tab", kActionKeyType, false},
{"CLEAR", KEYCODE_CLEAR, 0, "Clear", kActionKeyType, false},
@@ -173,14 +164,7 @@ static const Key keys[] = {
{0, KEYCODE_INVALID, 0, 0, kGenericKeyType, false}
};
-struct Mod {
- byte flag;
- const char *id;
- const char *desc;
- bool shiftable;
-};
-
-static const Mod modifiers[] = {
+static const ModifierTableEntry sdlModifiers[] = {
{ 0, "", "", false },
{ KBD_CTRL, "C+", "Ctrl+", false },
{ KBD_ALT, "A+", "Alt+", false },
@@ -195,35 +179,7 @@ static const Mod modifiers[] = {
Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() {
#ifdef ENABLE_KEYMAPPER
- HardwareKeySet *keySet = new HardwareKeySet();
- const Key *key;
- const Mod *mod;
- char fullKeyId[50];
- char fullKeyDesc[100];
- uint16 ascii;
-
- for (mod = modifiers; mod->id; mod++) {
- for (key = keys; key->hwId; key++) {
- ascii = key->ascii;
-
- if (mod->shiftable && key->shiftable) {
- snprintf(fullKeyId, 50, "%s%c", mod->id, toupper(key->hwId[0]));
- snprintf(fullKeyDesc, 100, "%s%c", mod->desc, toupper(key->desc[0]));
- ascii = toupper(key->ascii);
- } else if (mod->shiftable) {
- snprintf(fullKeyId, 50, "S+%s%s", mod->id, key->hwId);
- snprintf(fullKeyDesc, 100, "Shift+%s%s", mod->desc, key->desc);
- } else {
- snprintf(fullKeyId, 50, "%s%s", mod->id, key->hwId);
- snprintf(fullKeyDesc, 100, "%s%s", mod->desc, key->desc);
- }
-
- keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, mod->flag), fullKeyDesc, key->preferredAction ));
- }
- }
-
- return keySet;
-
+ return new HardwareKeySet(sdlKeys, sdlModifiers);
#else
return 0;
#endif
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 22d79dbfe7..6c84c5c26a 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -30,6 +30,11 @@
#include "backends/events/sdl/sdl-events.h"
#include "backends/log/log.h"
+namespace Common {
+struct KeyTableEntry;
+struct ModifierTableEntry;
+}
+
/**
* Base OSystem class for all SDL ports.
*/