CEGUI显示汉字(转)

 

针对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.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值