From 988cbc9fd1c61208f38d29dbbbcab9a4ff2b0c6d Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 19 Sep 2021 16:17:14 +0200 Subject: [PATCH] Support space and digits in alphanumeric input mode --- cgdoom/i_system.c | 3 ++- src-cg/keyboard.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cgdoom/i_system.c b/cgdoom/i_system.c index 670fae6..d6a04b1 100644 --- a/cgdoom/i_system.c +++ b/cgdoom/i_system.c @@ -363,6 +363,7 @@ void I_StartTic (void) static const int input_keys[] = { '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', + -'0', -'1', -'2', -'3', -'4', -'5', -'6', -'7', -'8', -'9', -' ', KEY_BACKSPACE, KEY_ESCAPE, KEY_ENTER, 0 }; @@ -381,7 +382,7 @@ void I_StartTic (void) e.type = ev_keyup; else continue; - e.data1 = keys[i]; + e.data1 = (keys[i] < 0) ? -keys[i] : keys[i]; D_PostEvent(&e); } } diff --git a/src-cg/keyboard.c b/src-cg/keyboard.c index 18d4593..b84be29 100644 --- a/src-cg/keyboard.c +++ b/src-cg/keyboard.c @@ -147,21 +147,45 @@ static int DoomKeyToKeycode(int key) case 'X': return KEYCODE_PLUS; case 'Y': return KEYCODE_MINUS; case 'Z': return KEYCODE_0; + case -' ': return KEYCODE_DOT; case KEY_BACKSPACE: return KEYCODE_DEL; + /* Numeric keys (handled differently, require a modifier) */ + case -'0': return KEYCODE_0; + case -'1': return KEYCODE_1; + case -'2': return KEYCODE_2; + case -'3': return KEYCODE_3; + case -'4': return KEYCODE_4; + case -'5': return KEYCODE_5; + case -'6': return KEYCODE_6; + case -'7': return KEYCODE_7; + case -'8': return KEYCODE_8; + case -'9': return KEYCODE_9; + default: return -1; } } -static int KeyDown(KeyboardState state, int key) +static int KeycodeDown(KeyboardState state, int code) { - int code = DoomKeyToKeycode(key); if(code < 0) return 0; int row = (code >> 4) ^ 1; int col = 0x80 >> (code & 0x7); return (state[row] & col) != 0; } +static int KeyDown(KeyboardState state, int key) +{ + int code = DoomKeyToKeycode(key); + + if(key >= -'9' && key <= -'0') + return KeycodeDown(state, code) && KeycodeDown(state, KEYCODE_ALPHA); + else if(code == KEYCODE_ALPHA) + return KeycodeDown(state, code); + else + return KeycodeDown(state, code) && !KeycodeDown(state, KEYCODE_ALPHA); +} + void UpdateKeyboardState(void) { memcpy(st_prev, st_now, sizeof st_now);