summaryrefslogtreecommitdiff
path: root/textscreen/txt_sdl.c
diff options
context:
space:
mode:
authorSimon Howard2011-04-11 19:49:45 +0000
committerSimon Howard2011-04-11 19:49:45 +0000
commiteb86fcdf3099404ed8cc0feaf96dd94654d2b8dd (patch)
tree26acfbe82ee8ce3281e8f254467e6f66af095159 /textscreen/txt_sdl.c
parentd4ef7c37721ee261ac23305fd52239a91e58250a (diff)
downloadchocolate-doom-eb86fcdf3099404ed8cc0feaf96dd94654d2b8dd.tar.gz
chocolate-doom-eb86fcdf3099404ed8cc0feaf96dd94654d2b8dd.tar.bz2
chocolate-doom-eb86fcdf3099404ed8cc0feaf96dd94654d2b8dd.zip
Allow the shift key to be held down when changing key/mouse/joystick
bindings to prevent bindings to the same key from being cleared (thanks myk). Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2325
Diffstat (limited to 'textscreen/txt_sdl.c')
-rw-r--r--textscreen/txt_sdl.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c
index 5ae151e9..767c9b3e 100644
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -63,6 +63,8 @@ static int key_mapping = 1;
static TxtSDLEventCallbackFunc event_callback;
static void *event_callback_data;
+static int modifier_state[TXT_NUM_MODIFIERS];
+
// Font we are using:
static txt_font_t *font;
@@ -493,6 +495,48 @@ static int MouseHasMoved(void)
}
}
+// Examine a key press/release and update the modifier key state
+// if necessary.
+
+static void UpdateModifierState(SDL_keysym *sym, int pressed)
+{
+ txt_modifier_t mod;
+
+ switch (sym->sym)
+ {
+ case SDLK_LSHIFT:
+ case SDLK_RSHIFT:
+ mod = TXT_MOD_SHIFT;
+ break;
+
+ case SDLK_LCTRL:
+ case SDLK_RCTRL:
+ mod = TXT_MOD_CTRL;
+ break;
+
+ case SDLK_LALT:
+ case SDLK_RALT:
+#if !SDL_VERSION_ATLEAST(1, 3, 0)
+ case SDLK_LMETA:
+ case SDLK_RMETA:
+#endif
+ mod = TXT_MOD_ALT;
+ break;
+
+ default:
+ return;
+ }
+
+ if (pressed)
+ {
+ ++modifier_state[mod];
+ }
+ else
+ {
+ --modifier_state[mod];
+ }
+}
+
signed int TXT_GetChar(void)
{
SDL_Event ev;
@@ -522,8 +566,14 @@ signed int TXT_GetChar(void)
break;
case SDL_KEYDOWN:
+ UpdateModifierState(&ev.key.keysym, 1);
+
return TranslateKey(&ev.key.keysym);
+ case SDL_KEYUP:
+ UpdateModifierState(&ev.key.keysym, 0);
+ break;
+
case SDL_QUIT:
// Quit = escape
return 27;
@@ -542,6 +592,16 @@ signed int TXT_GetChar(void)
return -1;
}
+int TXT_GetModifierState(txt_modifier_t mod)
+{
+ if (mod < TXT_NUM_MODIFIERS)
+ {
+ return modifier_state[mod] > 0;
+ }
+
+ return 0;
+}
+
static const char *SpecialKeyName(int key)
{
switch (key)