summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2008-10-10 23:44:34 +0000
committerSimon Howard2008-10-10 23:44:34 +0000
commit32565063e7dd9a0e18e496a31bc46ddfe65eee4d (patch)
treefca9b565d2e22d7b488c521349bac793f43486fb /src
parentea4e1fcf59d9478e20a4cec471ef6d34bb37eadb (diff)
downloadchocolate-doom-32565063e7dd9a0e18e496a31bc46ddfe65eee4d.tar.gz
chocolate-doom-32565063e7dd9a0e18e496a31bc46ddfe65eee4d.tar.bz2
chocolate-doom-32565063e7dd9a0e18e496a31bc46ddfe65eee4d.zip
Move shiftxform table to i_video.c; make 'data2' for key events
consistently be the properly translated version of the key pressed. Subversion-branch: /branches/raven-branch Subversion-revision: 1352
Diffstat (limited to 'src')
-rw-r--r--src/doom/hu_stuff.c51
-rw-r--r--src/i_video.c139
2 files changed, 120 insertions, 70 deletions
diff --git a/src/doom/hu_stuff.c b/src/doom/hu_stuff.c
index d31b8ce8..7cd06bd5 100644
--- a/src/doom/hu_stuff.c
+++ b/src/doom/hu_stuff.c
@@ -287,49 +287,6 @@ char *mapnamest[] = // TNT WAD map names.
THUSTR_32
};
-static const char shiftxform[] =
-{
-
- 0,
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
- 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
- 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
- 31,
- ' ', '!', '"', '#', '$', '%', '&',
- '"', // shift-'
- '(', ')', '*', '+',
- '<', // shift-,
- '_', // shift--
- '>', // shift-.
- '?', // shift-/
- ')', // shift-0
- '!', // shift-1
- '@', // shift-2
- '#', // shift-3
- '$', // shift-4
- '%', // shift-5
- '^', // shift-6
- '&', // shift-7
- '*', // shift-8
- '(', // shift-9
- ':',
- ':', // shift-;
- '<',
- '+', // shift-=
- '>', '?', '@',
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- '[', // shift-[
- '!', // shift-backslash - OH MY GOD DOES WATCOM SUCK
- ']', // shift-]
- '"', '_',
- '\'', // shift-`
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- '{', '|', '}', '~', 127
-};
-
-
void HU_Init(void)
{
@@ -669,14 +626,6 @@ boolean HU_Responder(event_t *ev)
}
else
{
- if (vanilla_keyboard_mapping)
- {
- if (shiftdown || (c >= 'a' && c <= 'z'))
- {
- c = shiftxform[c];
- }
- }
-
eatkey = HUlib_keyInIText(&w_chat, c);
if (eatkey)
{
diff --git a/src/i_video.c b/src/i_video.c
index f72e70ae..a9c53b34 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -48,6 +48,49 @@
#include "w_wad.h"
#include "z_zone.h"
+// Lookup table for mapping ASCII characters to their equivalent when
+// shift is pressed on an American layout keyboard:
+
+static const char shiftxform[] =
+{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+ 31, ' ', '!', '"', '#', '$', '%', '&',
+ '"', // shift-'
+ '(', ')', '*', '+',
+ '<', // shift-,
+ '_', // shift--
+ '>', // shift-.
+ '?', // shift-/
+ ')', // shift-0
+ '!', // shift-1
+ '@', // shift-2
+ '#', // shift-3
+ '$', // shift-4
+ '%', // shift-5
+ '^', // shift-6
+ '&', // shift-7
+ '*', // shift-8
+ '(', // shift-9
+ ':',
+ ':', // shift-;
+ '<',
+ '+', // shift-=
+ '>', '?', '@',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
+ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ '[', // shift-[
+ '!', // shift-backslash - OH MY GOD DOES WATCOM SUCK
+ ']', // shift-]
+ '"', '_',
+ '\'', // shift-`
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
+ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ '{', '|', '}', '~', 127
+};
+
+
// Non aspect ratio-corrected modes (direct multiples of 320x200)
static screen_mode_t *screen_modes[] = {
@@ -188,6 +231,10 @@ static screen_mode_t *screen_mode;
int vanilla_keyboard_mapping = true;
+// Is the shift key currently down?
+
+static int shiftdown = 0;
+
// Mouse acceleration
//
// This emulates some of the behavior of DOS mouse drivers by increasing
@@ -476,6 +523,74 @@ static int AccelerateMouse(int val)
}
}
+// Get the equivalent ASCII (Unicode?) character for a keypress.
+
+static int GetTypedChar(SDL_Event *event)
+{
+ int key;
+
+ // If Vanilla keyboard mapping enabled, the keyboard
+ // scan code is used to give the character typed.
+ // This does not change depending on keyboard layout.
+ // If you have a German keyboard, pressing 'z' will
+ // give 'y', for example. It is desirable to be able
+ // to fix this so that people with non-standard
+ // keyboard mappings can type properly. If vanilla
+ // mode is disabled, use the properly translated
+ // version.
+
+ if (vanilla_keyboard_mapping)
+ {
+ key = TranslateKey(&event->key.keysym);
+
+ // Is shift held down? If so, perform a translation.
+
+ if (shiftdown > 0)
+ {
+ if (key >= 0 && key < arrlen(shiftxform))
+ {
+ key = shiftxform[key];
+ }
+ else
+ {
+ key = 0;
+ }
+ }
+
+ return key;
+ }
+ else
+ {
+ // Unicode value, from key layout.
+
+ return event->key.keysym.unicode;
+ }
+}
+
+static void UpdateShiftStatus(SDL_Event *event)
+{
+ int change;
+
+ if (event->type == SDL_KEYDOWN)
+ {
+ change = 1;
+ }
+ else if (event->type == SDL_KEYUP)
+ {
+ change = -1;
+ }
+ else
+ {
+ return;
+ }
+
+ if (event->key.keysym.sym == SDLK_LSHIFT
+ || event->key.keysym.sym == SDLK_RSHIFT)
+ {
+ shiftdown += change;
+ }
+}
+
void I_GetEvent(void)
{
SDL_Event sdlevent;
@@ -504,32 +619,18 @@ void I_GetEvent(void)
I_Quit();
}
+ UpdateShiftStatus(&sdlevent);
+
// process event
switch (sdlevent.type)
{
case SDL_KEYDOWN:
+ // data1 has the key pressed, data2 has the character
+ // (shift-translated, etc)
event.type = ev_keydown;
event.data1 = TranslateKey(&sdlevent.key.keysym);
-
- // If Vanilla keyboard mapping enabled, the keyboard
- // scan code is used to give the character typed.
- // This does not change depending on keyboard layout.
- // If you have a German keyboard, pressing 'z' will
- // give 'y', for example. It is desirable to be able
- // to fix this so that people with non-standard
- // keyboard mappings can type properly. If vanilla
- // mode is disabled, use the properly translated
- // version.
-
- if (vanilla_keyboard_mapping)
- {
- event.data2 = event.data1;
- }
- else
- {
- event.data2 = sdlevent.key.keysym.unicode;
- }
+ event.data2 = GetTypedChar(&sdlevent);
D_PostEvent(&event);
break;