|
@@ -49,7 +49,7 @@ void TextInput::onKeyEvent(int key, int scancode, int action, int mods) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void TextInput::onCharEvent(unsigned int codepoint) {
|
|
|
+void TextInput::onCharEvent(uint32 codepoint) {
|
|
|
if(!active || input.getLength() >= limit) {
|
|
|
return;
|
|
|
}
|
|
@@ -60,6 +60,40 @@ void TextInput::onCharEvent(unsigned int codepoint) {
|
|
|
cursor++;
|
|
|
}
|
|
|
|
|
|
+static uint32 read(int& index, const char* s) {
|
|
|
+ if(s[index] == '\0') {
|
|
|
+ return '\0';
|
|
|
+ }
|
|
|
+ return s[index++];
|
|
|
+}
|
|
|
+
|
|
|
+static uint32 readUnicode(int& index, const char* s) {
|
|
|
+ uint32 c = read(index, s);
|
|
|
+ if((c & 0xE0) == 0xC0) {
|
|
|
+ c = ((c & 0x1F) << 6) | (read(index, s) & 0x3F);
|
|
|
+ } else if((c & 0xF0) == 0xE0) {
|
|
|
+ c = ((c & 0xF) << 12) | ((read(index, s) & 0x3F) << 6);
|
|
|
+ c |= read(index, s) & 0x3F;
|
|
|
+ } else if((c & 0xF8) == 0xF0) {
|
|
|
+ c = ((c & 0x7) << 18) | ((read(index, s) & 0x3F) << 12);
|
|
|
+ c |= (read(index, s) & 0x3F) << 6;
|
|
|
+ c |= read(index, s) & 0x3F;
|
|
|
+ }
|
|
|
+ return c;
|
|
|
+}
|
|
|
+
|
|
|
+void TextInput::fill(const char* s) {
|
|
|
+ int index = 0;
|
|
|
+ reset();
|
|
|
+ while(true) {
|
|
|
+ uint32 c = readUnicode(index, s);
|
|
|
+ if(c == '\0') {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ onCharEvent(c);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
int TextInput::getCursor() const {
|
|
|
return cursor;
|
|
|
}
|