shithub: choc

Download patch

ref: 4e3ab57537d4d6ec11af3787ff963b9d000b90a6
parent: afe0c972341d0e3a722b721b2a7628d216998253
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Dec 17 20:13:36 EST 2016

textscreen: Decode UTF8 of character from event.

It's not enough to simply return the first byte from the buffer, since
it may be a non-ASCII character. Decode the whole first character using
the UTF8 library.

--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -26,6 +26,7 @@
 
 #include "txt_main.h"
 #include "txt_sdl.h"
+#include "txt_utf8.h"
 
 #if defined(_MSC_VER) && !defined(__cplusplus)
 #define inline __inline
@@ -668,8 +669,9 @@
             case SDL_TEXTINPUT:
                 if (input_mode == TXT_INPUT_TEXT)
                 {
-                    // TODO: Support input of more than just the first char.
-                    return ev.text.text[0];
+                    // TODO: Support input of more than just the first char?
+                    const char *p = ev.text.text;
+                    return TXT_DecodeUTF8(&p);
                 }
                 break;