summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
}