Add UTF8 support in the TextEntry object

This commit is contained in:
Victor Levasseur
2015-04-29 11:28:56 +02:00
parent a63638dfbd
commit 7dd5be4c19
+12 -3
View File
@@ -14,6 +14,8 @@ This project is released under the MIT License.
#include "GDCpp/Position.h"
#include "GDCpp/Project.h"
#include "GDCpp/RuntimeScene.h"
#include "GDCpp/Utf8Tools.h"
#include "GDCore/Utf8/utf8.h"
#include "TextEntryObject.h"
#if defined(GD_IDE_ONLY)
#include <wx/bitmap.h>
@@ -36,6 +38,7 @@ TextEntryObject::TextEntryObject(std::string name_) :
RuntimeTextEntryObject::RuntimeTextEntryObject(RuntimeScene & scene_, const gd::Object & object) :
RuntimeObject(scene_, object),
text(),
scene(&scene_),
activated(true)
{
@@ -54,11 +57,17 @@ void RuntimeTextEntryObject::UpdateTime(float)
{
//Skip some non displayable characters
if (characters[i] > 30 && (characters[i] < 127 || characters[i] > 159))
text += characters[i];
text += gd::utf8::FromSfString(sf::String(characters[i]));
else if (characters[i] == 8)
{
//Backspace
if (!text.empty()) text.erase(text.end()-1);
//Backspace : find the previous codepoint and remove it
if(text.empty())
continue;
std::string::iterator it = text.end();
utf8::prior(it, text.begin());
text.erase(it, text.end());
}
}
}