summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2007-03-09 12:35:18 +0000
committerSimon Howard2007-03-09 12:35:18 +0000
commitc5a4f04bc21825a0bdd59bef804229389a7a4ce1 (patch)
treebbdf0d16c1aa5e468698f0b202175bf7b32ccb83
parentcebecf16cc349650bf2a9b20f24b2eac6372e07b (diff)
downloadchocolate-doom-c5a4f04bc21825a0bdd59bef804229389a7a4ce1.tar.gz
chocolate-doom-c5a4f04bc21825a0bdd59bef804229389a7a4ce1.tar.bz2
chocolate-doom-c5a4f04bc21825a0bdd59bef804229389a7a4ce1.zip
Fix discrepancy between Doom and setup program when prompting for keys.
Add the ability to enable/disable key mappings so that the raw key can be read in setup, exactly the same way that it is in Doom. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 846
-rw-r--r--setup/txt_keyinput.c9
-rw-r--r--textscreen/txt_main.c153
-rw-r--r--textscreen/txt_main.h5
3 files changed, 101 insertions, 66 deletions
diff --git a/setup/txt_keyinput.c b/setup/txt_keyinput.c
index bdf2f926..b7e68f44 100644
--- a/setup/txt_keyinput.c
+++ b/setup/txt_keyinput.c
@@ -44,6 +44,11 @@ static int KeyPressCallback(txt_window_t *window, int key,
*key_input->variable = key;
TXT_EmitSignal(key_input, "set");
TXT_CloseWindow(window);
+
+ // Re-enable key mappings now that we have the key
+
+ TXT_EnableKeyMapping(1);
+
return 1;
}
else
@@ -69,6 +74,10 @@ static void OpenPromptWindow(txt_key_input_t *key_input)
TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER);
TXT_SetKeyListener(window, KeyPressCallback, key_input);
+
+ // Disable key mappings while we prompt for the key press
+
+ TXT_EnableKeyMapping(0);
}
static void TXT_KeyInputSizeCalc(TXT_UNCAST_ARG(key_input))
diff --git a/textscreen/txt_main.c b/textscreen/txt_main.c
index d4b320a6..ee8b7a2d 100644
--- a/textscreen/txt_main.c
+++ b/textscreen/txt_main.c
@@ -44,6 +44,7 @@
static SDL_Surface *screen;
static unsigned char *screendata;
+static int key_mapping = 1;
//#define TANGO
@@ -229,72 +230,87 @@ static int TranslateKey(SDL_keysym *sym)
{
switch(sym->sym)
{
- case SDLK_LEFT: return KEY_LEFTARROW;
- case SDLK_RIGHT: return KEY_RIGHTARROW;
- case SDLK_DOWN: return KEY_DOWNARROW;
- case SDLK_UP: return KEY_UPARROW;
- case SDLK_ESCAPE: return KEY_ESCAPE;
- case SDLK_RETURN: return KEY_ENTER;
- case SDLK_TAB: return KEY_TAB;
- case SDLK_F1: return KEY_F1;
- case SDLK_F2: return KEY_F2;
- case SDLK_F3: return KEY_F3;
- case SDLK_F4: return KEY_F4;
- case SDLK_F5: return KEY_F5;
- case SDLK_F6: return KEY_F6;
- case SDLK_F7: return KEY_F7;
- case SDLK_F8: return KEY_F8;
- case SDLK_F9: return KEY_F9;
- case SDLK_F10: return KEY_F10;
- case SDLK_F11: return KEY_F11;
- case SDLK_F12: return KEY_F12;
-
- case SDLK_BACKSPACE: return KEY_BACKSPACE;
- case SDLK_DELETE: return KEY_DEL;
-
- case SDLK_PAUSE: return KEY_PAUSE;
-
- case SDLK_KP_EQUALS: return KEY_EQUALS;
-
- case SDLK_LSHIFT:
- case SDLK_RSHIFT:
- return KEY_RSHIFT;
-
- case SDLK_LCTRL:
- case SDLK_RCTRL:
- return KEY_RCTRL;
-
- case SDLK_LALT:
- case SDLK_LMETA:
- case SDLK_RALT:
- case SDLK_RMETA:
- return KEY_RALT;
-
- case SDLK_CAPSLOCK: return KEY_CAPSLOCK;
- case SDLK_SCROLLOCK: return KEY_SCRLCK;
-
- case SDLK_KP0: return KEYP_0;
- case SDLK_KP1: return KEYP_1;
- case SDLK_KP2: return KEYP_2;
- case SDLK_KP3: return KEYP_3;
- case SDLK_KP4: return KEYP_4;
- case SDLK_KP5: return KEYP_5;
- case SDLK_KP6: return KEYP_6;
- case SDLK_KP7: return KEYP_7;
- case SDLK_KP8: return KEYP_8;
- case SDLK_KP9: return KEYP_9;
-
- case SDLK_HOME: return KEY_HOME;
- case SDLK_INSERT: return KEY_INS;
- case SDLK_END: return KEY_END;
- case SDLK_PAGEUP: return KEY_PGUP;
- case SDLK_PAGEDOWN: return KEY_PGDN;
- case SDLK_KP_MULTIPLY: return KEYP_MULTIPLY;
- case SDLK_KP_PLUS: return KEYP_PLUS;
- case SDLK_KP_MINUS: return KEYP_MINUS;
- case SDLK_KP_DIVIDE: return KEYP_DIVIDE;
-
- default: return sym->unicode;
+ case SDLK_LEFT: return KEY_LEFTARROW;
+ case SDLK_RIGHT: return KEY_RIGHTARROW;
+ case SDLK_DOWN: return KEY_DOWNARROW;
+ case SDLK_UP: return KEY_UPARROW;
+ case SDLK_ESCAPE: return KEY_ESCAPE;
+ case SDLK_RETURN: return KEY_ENTER;
+ case SDLK_TAB: return KEY_TAB;
+ case SDLK_F1: return KEY_F1;
+ case SDLK_F2: return KEY_F2;
+ case SDLK_F3: return KEY_F3;
+ case SDLK_F4: return KEY_F4;
+ case SDLK_F5: return KEY_F5;
+ case SDLK_F6: return KEY_F6;
+ case SDLK_F7: return KEY_F7;
+ case SDLK_F8: return KEY_F8;
+ case SDLK_F9: return KEY_F9;
+ case SDLK_F10: return KEY_F10;
+ case SDLK_F11: return KEY_F11;
+ case SDLK_F12: return KEY_F12;
+
+ case SDLK_BACKSPACE: return KEY_BACKSPACE;
+ case SDLK_DELETE: return KEY_DEL;
+
+ case SDLK_PAUSE: return KEY_PAUSE;
+
+ case SDLK_KP_EQUALS: return KEY_EQUALS;
+
+ case SDLK_LSHIFT:
+ case SDLK_RSHIFT:
+ return KEY_RSHIFT;
+
+ case SDLK_LCTRL:
+ case SDLK_RCTRL:
+ return KEY_RCTRL;
+
+ case SDLK_LALT:
+ case SDLK_LMETA:
+ case SDLK_RALT:
+ case SDLK_RMETA:
+ return KEY_RALT;
+
+ case SDLK_CAPSLOCK: return KEY_CAPSLOCK;
+ case SDLK_SCROLLOCK: return KEY_SCRLCK;
+
+ case SDLK_KP0: return KEYP_0;
+ case SDLK_KP1: return KEYP_1;
+ case SDLK_KP2: return KEYP_2;
+ case SDLK_KP3: return KEYP_3;
+ case SDLK_KP4: return KEYP_4;
+ case SDLK_KP5: return KEYP_5;
+ case SDLK_KP6: return KEYP_6;
+ case SDLK_KP7: return KEYP_7;
+ case SDLK_KP8: return KEYP_8;
+ case SDLK_KP9: return KEYP_9;
+
+ case SDLK_HOME: return KEY_HOME;
+ case SDLK_INSERT: return KEY_INS;
+ case SDLK_END: return KEY_END;
+ case SDLK_PAGEUP: return KEY_PGUP;
+ case SDLK_PAGEDOWN: return KEY_PGDN;
+ case SDLK_KP_MULTIPLY: return KEYP_MULTIPLY;
+ case SDLK_KP_PLUS: return KEYP_PLUS;
+ case SDLK_KP_MINUS: return KEYP_MINUS;
+ case SDLK_KP_DIVIDE: return KEYP_DIVIDE;
+
+ default: break;
+ }
+
+ // Returned value is different, depending on whether key mapping is
+ // enabled. Key mapping is preferable most of the time, for typing
+ // in text, etc. However, when we want to read raw keyboard codes
+ // for the setup keyboard configuration dialog, we want the raw
+ // key code.
+
+ if (key_mapping)
+ {
+ return sym->unicode;
+ }
+ else
+ {
+ return tolower(sym->sym);
}
}
@@ -497,3 +513,8 @@ void TXT_Sleep(int timeout)
}
}
+void TXT_EnableKeyMapping(int enable)
+{
+ key_mapping = enable;
+}
+
diff --git a/textscreen/txt_main.h b/textscreen/txt_main.h
index 49986faf..b693bce0 100644
--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -104,5 +104,10 @@ void TXT_GetMousePosition(int *x, int *y);
void TXT_Sleep(int timeout);
+// Controls whether keys are returned from TXT_GetChar based on keyboard
+// mapping, or raw key code.
+
+void TXT_EnableKeyMapping(int enable);
+
#endif /* #ifndef TXT_MAIN_H */