mirror of
https://github.com/UberGames/lilium-voyager.git
synced 2024-12-13 21:51:09 +00:00
Convert SDL text input to UTF-32
This commit is contained in:
parent
3105d62027
commit
aaea838d39
1 changed files with 34 additions and 8 deletions
|
@ -729,15 +729,41 @@ static void IN_ProcessEvents( void )
|
||||||
|
|
||||||
case SDL_TEXTINPUT:
|
case SDL_TEXTINPUT:
|
||||||
{
|
{
|
||||||
int i;
|
char *c = e.text.text;
|
||||||
int numChars = strlen( e.text.text );
|
|
||||||
|
|
||||||
for( i = 0; i < numChars; i++ )
|
// Quick and dirty UTF-8 to UTF-32 conversion
|
||||||
|
while( *c )
|
||||||
{
|
{
|
||||||
char c = e.text.text[ i ];
|
int utf32 = 0;
|
||||||
|
|
||||||
if( !IN_IsConsoleKey( 0, c ) )
|
if( ( *c & 0x80 ) == 0 )
|
||||||
Com_QueueEvent( 0, SE_CHAR, c, 0, 0, NULL );
|
utf32 = *c++;
|
||||||
|
else if( ( *c & 0xE0 ) == 0xC0 ) // 110x xxxx
|
||||||
|
{
|
||||||
|
utf32 |= ( *c++ & 0x1F ) << 6;
|
||||||
|
utf32 |= ( *c++ & 0x3F );
|
||||||
|
}
|
||||||
|
else if( ( *c & 0xF0 ) == 0xE0 ) // 1110 xxxx
|
||||||
|
{
|
||||||
|
utf32 |= ( *c++ & 0x0F ) << 12;
|
||||||
|
utf32 |= ( *c++ & 0x3F ) << 6;
|
||||||
|
utf32 |= ( *c++ & 0x3F );
|
||||||
|
}
|
||||||
|
else if( ( *c & 0xF8 ) == 0xF0 ) // 1111 0xxx
|
||||||
|
{
|
||||||
|
utf32 |= ( *c++ & 0x07 ) << 18;
|
||||||
|
utf32 |= ( *c++ & 0x3F ) << 6;
|
||||||
|
utf32 |= ( *c++ & 0x3F ) << 6;
|
||||||
|
utf32 |= ( *c++ & 0x3F );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Com_DPrintf( "Unrecognised UTF-8 lead byte: 0x%x\n", (unsigned int)*c );
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( utf32 != 0 )
|
||||||
|
Com_QueueEvent( 0, SE_CHAR, utf32, 0, 0, NULL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue