summaryrefslogtreecommitdiff
path: root/textscreen/txt_main.h
diff options
context:
space:
mode:
Diffstat (limited to 'textscreen/txt_main.h')
-rw-r--r--textscreen/txt_main.h30
1 files changed, 29 insertions, 1 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