From 510bd2ea5739c5b58c7e5895724ce7758bf2b37c Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Wed, 1 Jul 2020 23:29:21 +0200 Subject: [PATCH] Fix for text input --- code/redalert/edit.cpp | 28 +++++++++++++++------------- code/redalert/io/userinput.cpp | 5 +---- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/code/redalert/edit.cpp b/code/redalert/edit.cpp index 1684c36..d1f3a31 100644 --- a/code/redalert/edit.cpp +++ b/code/redalert/edit.cpp @@ -345,10 +345,9 @@ void EditClass::Draw_Text(char const * text) *=============================================================================================*/ bool EditClass::Handle_Key(KeyNumType key, unsigned flags) { - unsigned char testAscii = UserInput.KeyB.ASCII; - //if (key & KN_SHIFT_BIT || key & KN_CAPSLOCK_BIT) testAscii = toupper(testAscii); + unsigned rawKey = key & 0xff; - switch (key & 0xff) { + switch (rawKey) { /* ** Handle the special case of a non-keyboard event. It is possible that this ** key code might be passed to this routine if this routine has been overridden @@ -357,6 +356,7 @@ bool EditClass::Handle_Key(KeyNumType key, unsigned flags) case 0: break; + /* ** If the return key is pressed, then remove the focus from this edit ** gadget but otherwise let the normal gadget processing proceed. This @@ -384,11 +384,13 @@ bool EditClass::Handle_Key(KeyNumType key, unsigned flags) ** if it can legally be added to the edit string and do so if possible. */ default: + unsigned char keyAscii = UserInput.KeyB.ASCII; + if (key & KN_SHIFT_BIT || key & KN_CAPSLOCK_BIT) keyAscii = toupper(keyAscii); /* ** Don't add a character if the length is greater than edit width. */ - if (((int)String_Pixel_Width(String) + (int)Char_Pixel_Width(testAscii) ) >= (Width-2)) { + if (((int)String_Pixel_Width(String) + (int)Char_Pixel_Width(keyAscii) ) >= (Width-2)) { break; } @@ -401,21 +403,21 @@ bool EditClass::Handle_Key(KeyNumType key, unsigned flags) ** Invisible characters are never added to the string. This is ** especially true for spaces at the beginning of the string. */ - if (!isgraph(testAscii) && testAscii != ' ') break; - if (testAscii == ' ' && Length == 0) break; + if (!isgraph(keyAscii) && keyAscii != ' ') break; + if (keyAscii == ' ' && Length == 0) break; /* ** If this is an upper case only edit gadget, then force the alphabetic ** character to upper case. */ - if ((EditFlags & UPPERCASE) && isalpha(testAscii)) { - testAscii = (KeyASCIIType)toupper(testAscii); + if ((EditFlags & UPPERCASE) && isalpha(keyAscii)) { + rawKey = (KeyASCIIType)toupper(keyAscii); } - if ((!(EditFlags & NUMERIC) || !isdigit(testAscii)) && - (!(EditFlags & ALPHA) || !isalpha(testAscii)) && - (!(EditFlags & MISC) || isalnum(testAscii)) && - testAscii != ' ') { + if ((!(EditFlags & NUMERIC) || !isdigit(keyAscii)) && + (!(EditFlags & ALPHA) || !isalpha(keyAscii)) && + (!(EditFlags & MISC) || isalnum(keyAscii)) && + rawKey != ' ') { break; } @@ -425,7 +427,7 @@ bool EditClass::Handle_Key(KeyNumType key, unsigned flags) ** because the event flag has been cleared. This prevents the gadget's ID ** number from being returned just because the gadget has been edited. */ - String[Length++] = testAscii; + String[Length++] = keyAscii; String[Length] = '\0'; Flag_To_Redraw(); diff --git a/code/redalert/io/userinput.cpp b/code/redalert/io/userinput.cpp index 6c05848..1d3ce53 100644 --- a/code/redalert/io/userinput.cpp +++ b/code/redalert/io/userinput.cpp @@ -204,10 +204,7 @@ void UserInputClass::Process_Input(KeyNumType& key, int& flags) Keyboard->Put_Element(element->second | keyFlags); KeyB.LastKey = element->first; - if (event.text.text[0] == (event.text.text[0] & 0xFF)) - { - KeyB.ASCII = element->second; - } + KeyB.ASCII = 0x0; } break;