From d745a6409c84a9ffb85e5d2029132642435c5879 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 3 Feb 2012 21:09:57 +0000 Subject: 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 --- textscreen/txt_main.h | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'textscreen/txt_main.h') 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 -- cgit v1.2.3