1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-03 00:46:55 +02:00

Implement Unicode support for ingame console

This commit is contained in:
AlexVinS
2014-07-02 19:16:05 +04:00
parent 195eae48ca
commit 9797372dbe
5 changed files with 82 additions and 28 deletions

View File

@ -1616,30 +1616,7 @@ void CTextInput::clickLeft( tribool down, bool previousState )
void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
{
auto trim = [](std::string & s){
if(s.empty())
return;
auto b = s.begin();
auto e = s.end();
size_t lastLen = 0;
size_t len = 0;
while (b != e) {
lastLen = len;
size_t n = Unicode::getCharacterSize(*b);
if(!Unicode::isValidCharacter(&(*b),e-b))
{
logGlobal->errorStream() << "Invalid UTF8 sequence";
break;//invalid sequence will be trimmed
}
len += n;
b += n;
}
s.resize(lastLen);
};
if(!focus || key.state != SDL_PRESSED)
return;
@ -1661,12 +1638,12 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
case SDLK_BACKSPACE:
if(!newText.empty())
{
trim(newText);
Unicode::trimRight(newText);
redrawNeeded = true;
}
else if(!text.empty())
{
trim(text);
Unicode::trimRight(text);
redrawNeeded = true;
}
break;