summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2014-10-19 16:52:36 -0400
committerSimon Howard2014-10-19 16:52:36 -0400
commit16c56ea0c4476f4d908a4f8073cab48cdfe43005 (patch)
treea90780cde55293238182625dcffdc4addfae1721
parenta8a5d2899a73f9830f69fe2c329d2a81e299def8 (diff)
downloadchocolate-doom-16c56ea0c4476f4d908a4f8073cab48cdfe43005.tar.gz
chocolate-doom-16c56ea0c4476f4d908a4f8073cab48cdfe43005.tar.bz2
chocolate-doom-16c56ea0c4476f4d908a4f8073cab48cdfe43005.zip
textscreen: Don't allow input of unprintable characters.
If a Unicode character is not part of the Extended ASCII set that we can display on screen, don't allow it to be typed (which would display a backwards question mark). Thanks Alexandre-Xavier for this suggestion on #229.
-rw-r--r--textscreen/txt_gui.c23
-rw-r--r--textscreen/txt_gui.h1
-rw-r--r--textscreen/txt_inputbox.c7
3 files changed, 28 insertions, 3 deletions
diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c
index 1a5275b6..74e3ec75 100644
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -322,6 +322,29 @@ static void PutUnicodeChar(unsigned int c)
TXT_PutChar('\xa8');
}
+int TXT_CanDrawCharacter(unsigned int c)
+{
+ unsigned int i;
+
+ // Standard ASCII range?
+ if (c < 128)
+ {
+ return 1;
+ }
+
+ // Extended ASCII range?
+ for (i = 0; i < 128; ++i)
+ {
+ if (cp437_unicode[i] == c)
+ {
+ return 1;
+ }
+ }
+
+ // Nope.
+ return 0;
+}
+
void TXT_DrawUTF8String(const char *s)
{
int x, y;
diff --git a/textscreen/txt_gui.h b/textscreen/txt_gui.h
index bb41b23d..f745ddd2 100644
--- a/textscreen/txt_gui.h
+++ b/textscreen/txt_gui.h
@@ -27,6 +27,7 @@ void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h);
void TXT_DrawSeparator(int x, int y, int w);
void TXT_DrawString(const char *s);
void TXT_DrawUTF8String(const char *s);
+int TXT_CanDrawCharacter(unsigned int c);
void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range);
void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range);
diff --git a/textscreen/txt_inputbox.c b/textscreen/txt_inputbox.c
index b2acaa8b..60512845 100644
--- a/textscreen/txt_inputbox.c
+++ b/textscreen/txt_inputbox.c
@@ -237,10 +237,11 @@ static int TXT_InputBoxKeyPress(TXT_UNCAST_ARG(inputbox), int key)
c = TXT_KEY_TO_UNICODE(key);
- if (c >= 128 || isprint(c))
+ // Add character to the buffer, but only if it's a printable character
+ // that we can represent on the screen.
+ if (isprint(c)
+ || (c >= 128 && TXT_CanDrawCharacter(c)))
{
- // Add character to the buffer
-
AddCharacter(inputbox, c);
}