cocos2dx 3.x 解决输入框(TextField,TextFieldTTF) 输入中文变乱码的问题
修改cocos2d-x-3.x\cocos\2d\platform\desktop\CCGLView.cpp GLView::onGLFWCharCallback方法
//原来的方法如下:
void GLView::onGLFWCharCallback(GLFWwindow *window, unsigned int character)
{
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*)&character, 1);
}
//修改后的方法如下:
void GLView::onGLFWCharCallback(GLFWwindow *window, unsigned int character)
{
if (character < 128)
IMEDispatcher::sharedDispatcher()->dispatchInsertText((const char*)&character, 1);
else
{
char szUtf8[8] = { 0 };
int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&character, 1, szUtf8, sizeof(szUtf8), NULL, NULL);
IMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen);
}
}