diff options
author | Simon Howard | 2012-02-03 21:09:57 +0000 |
---|---|---|
committer | Simon Howard | 2012-02-03 21:09:57 +0000 |
commit | d745a6409c84a9ffb85e5d2029132642435c5879 (patch) | |
tree | 5bc0098164360cf8704c753a8c2945544ca107a5 | |
parent | c818fb021632cbb68229ba265f01b060e6b6d0f4 (diff) | |
download | chocolate-doom-d745a6409c84a9ffb85e5d2029132642435c5879.tar.gz chocolate-doom-d745a6409c84a9ffb85e5d2029132642435c5879.tar.bz2 chocolate-doom-d745a6409c84a9ffb85e5d2029132642435c5879.zip |
Support Unicode input by mapping typed Unicode characters >= 128 up into
a higher range to avoid conflicts with Doom's key constants.
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2490
-rw-r--r-- | textscreen/txt_main.h | 30 | ||||
-rw-r--r-- | textscreen/txt_sdl.c | 12 |
2 files changed, 40 insertions, 2 deletions
diff --git a/textscreen/txt_main.h b/textscreen/txt_main.h index a415ee1b..a6dcc954 100644 --- a/textscreen/txt_main.h +++ b/textscreen/txt_main.h @@ -32,9 +32,21 @@ #include "txt_sdl.h" +// textscreen key values: +// Key values are difficult because we have to support multiple conflicting +// address spaces. +// First, Doom's key constants use 0-127 as ASCII and extra values from +// 128-255 to represent special keys. Second, mouse buttons are represented +// as buttons. Finally, we want to be able to support Unicode. +// +// So we define different ranges: +// 0-255: Doom key constants, including ASCII. +// 256-511: Mouse buttons and other reserved. +// >=512: Unicode values greater than 127 are offset up into this range. + // Special keypress values that correspond to mouse button clicks -#define TXT_MOUSE_BASE 0x10000 +#define TXT_MOUSE_BASE 256 #define TXT_MOUSE_LEFT (TXT_MOUSE_BASE + 0) #define TXT_MOUSE_RIGHT (TXT_MOUSE_BASE + 1) #define TXT_MOUSE_MIDDLE (TXT_MOUSE_BASE + 2) @@ -42,6 +54,22 @@ #define TXT_MOUSE_SCROLLDOWN (TXT_MOUSE_BASE + 4) #define TXT_MAX_MOUSE_BUTTONS 16 +#define TXT_KEY_TO_MOUSE_BUTTON(x) \ + ( (x) >= TXT_MOUSE_BASE \ + && (x) < TXT_MOUSE_BASE + TXT_MAX_MOUSE_BUTTONS ? \ + (x) - TXT_MOUSE_BASE : -1 ) + +// Unicode offset. Unicode values from 128 onwards are offset up into +// this range, so TXT_UNICODE_BASE = Unicode character #128, and so on. + +#define TXT_UNICODE_BASE 512 + +// Convert a key value to a Unicode character: + +#define TXT_KEY_TO_UNICODE(x) \ + ( (x) < 128 ? (x) : \ + (x) >= TXT_UNICODE_BASE ? ((x) - TXT_UNICODE_BASE + 128) : 0 ) + // Screen size #define TXT_SCREEN_W 80 diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index a2781ac1..eeb3732f 100644 --- a/textscreen/txt_sdl.c +++ b/textscreen/txt_sdl.c @@ -431,7 +431,17 @@ static int TranslateKey(SDL_keysym *sym) if (key_mapping) { - return sym->unicode; + // Unicode characters beyond the ASCII range need to be + // mapped up into textscreen's Unicode range. + + if (sym->unicode < 128) + { + return sym->unicode; + } + else + { + return sym->unicode - 128 + TXT_UNICODE_BASE; + } } else { |