标签:style blog color os 使用 ar for div 2014
近期开发cocos2dx 项目,做一个小游戏。(个人喜欢用最新版本号)
没系统学习就是问题多多,遇到了非常多问题,比方全部的opengl api都必须在主线程中调用,
这让我在多线程载入方面吃了不少亏,浪费了非常多时间。
这次遇到了输入框中输入中文出现乱码问题。搜索了非常多方法,都没找到。没办法。可是知道cocos2dx 2.x版本号没有这个问题,所以就仅仅有跟进代码了。
首先 找到2.x中找到WM_CHAR的派发消息:
在platform/win32/下的CCEGLView.cpp 中 LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)里面能够找到,
不说了,直接贴代码:
case WM_CHAR: { if (wParam < 0x20) { if (VK_BACK == wParam) { CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(); } else if (VK_RETURN == wParam) { CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); } else if (VK_TAB == wParam) { // tab input } else if (VK_ESCAPE == wParam) { // ESC input //CCDirector::sharedDirector()->end(); } } else if (wParam < 128) { // ascii char CCIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1); } else { char szUtf8[8] = {0}; int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL); CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } } break;
else if (wParam < 128) { // ascii char CCIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1); } else { char szUtf8[8] = {0}; int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL); CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); }
好了,进入我们3.2版本号里面:
首先看主注冊消息事件開始处:
在GLView::initWithRect中:
glfwSetMouseButtonCallback(_mainWindow,
GLFWEventHandler::onGLFWMouseCallBack);
glfwSetCursorPosCallback(_mainWindow, GLFWEventHandler::onGLFWMouseMoveCallBack);
glfwSetScrollCallback(_mainWindow, GLFWEventHandler::onGLFWMouseScrollCallback);
glfwSetCharCallback(_mainWindow, GLFWEventHandler::onGLFWCharCallback);
glfwSetKeyCallback(_mainWindow, GLFWEventHandler::onGLFWKeyCallback);
glfwSetWindowPosCallback(_mainWindow, GLFWEventHandler::onGLFWWindowPosCallback);
glfwSetFramebufferSizeCallback(_mainWindow, GLFWEventHandler::onGLFWframebuffersize);
glfwSetWindowSizeCallback(_mainWindow, GLFWEventHandler::onGLFWWindowSizeFunCallback);
上面红色就是我们想要的:
进入GLFWEventHandler::onGLFWCharCallback,在跟进: _view->onGLFWCharCallback(window, character);
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); } }
cocos2dx 3.2 解决输入框(TextField,TextFieldTTF) 中文乱码问题
标签:style blog color os 使用 ar for div 2014
原文地址:http://www.cnblogs.com/gcczhongduan/p/3988118.html