您的位置:首页 > 产品设计 > UI/UE

实现CEGUI的中文显示和输入

2010-08-10 17:23 507 查看
针对CEGUI SDK6.0下的Sample文件夹中的例子修改,

中文显示:
1.拷贝C:/WINDOWS/Fonts/SimHei.tif到CEGUI的./datafiles/fonts目录。
2.新建一个文本文件simhei-12.font,内容如下:
<?xml version="1.0" ?>
<Font Name="SimHei-12" Filename="simhei.ttf" Type="FreeType" Size="12" NativeHorzRes="800" NativeVertRes="600" AutoScaled="true"/>
3.修改CEGUI的./datafiles/schemes/TaharezLook.scheme,
删除:
<Font Name="Commonwealth-10" Filename="Commonwealth-10.font" />
添加:
<Font Name="SimHei-12" Filename="simhei-12.font" />
4.另存所使用的*.layout文件,编码选择utf-8。
5.修改代码,在继承自CEGUISample的类的initialiseSample()中修改
CFont* d_font;
// load the default font
if(FontManager::getSingleton().isFontPresent("SimHei-12"))
d_font = FontManager::getSingleton().getFont("SimHei-12");
else
d_font = FontManager::getSingleton().createFont("SimHei-12.font");

中文输入:
参考了网上的一些介绍,稍做了一些修改。
重写
void CEGuiOpenGLBaseApplication::keyChar(unsigned char key, int x, int y)
在default处理地方:
删除:
CEGUI::System::getSingleton().injectChar(static_cast<CEGUI::utf32>(key));
添加:
if (ImmIsIME(GetKeyboardLayout(0)))
{
#ifndef UNICODE
static char s_tempChar[3] = "";
static wchar_t s_tempWchar[2] = L"";
static bool s_flag = false;
unsigned char uch = (unsigned char)key;
if( uch >= 0xA1 )
{
if( !s_flag )
{
s_tempChar[0] = (char)uch; //第一个字节
s_flag = true;
return;
}
else if( uch >= 0xA1 )
{
s_tempChar[1] = (char)uch; //第二个字节
s_flag = false;
MultiByteToWideChar( 0, 0, s_tempChar, 2, s_tempWchar, 1); //转成宽字节
s_tempWchar[1] = L'/0';
CEGUI::utf32 code = (CEGUI::utf32)s_tempWchar[0];
//Font* fnt = System::getSingleton().getDefaultFont();
CEGUI::System::getSingleton().injectChar( code );
return;
}
else
{
CEGUI::System::getSingleton().injectChar(key);
return;
}
}
else
{
s_flag = false;
CEGUI::System::getSingleton().injectChar(key);
return;
}
#else
{
CEGUI::System::getSingleton().injectChar(code_point );
return;
}
#endif
}
else
{
CEGUI::System::getSingleton().injectChar((CEGUI::utf32)key);
}

最后还需要添加链接库Imm32.lib,或许有些工程还需要对应的Header: Declared in Imm.h; include Windows.h.

下载 (32.59 KB)

2008-7-12 08:44
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: