cegui中文输入。。。。

老生常谈。。。好多教程了。。。对字符不了解~加上基础知识不扎实~一直看不懂~其实现在还是不懂~都是瞎猜的~

demo阶段,老大和我一起网上找了找中文字的处理~然后老大加上的,我就做旁边看~

原文http://blog.csdn.net/ShowLong/archive/2007/02/13/1509217.aspx

差不多都是这种~代码如下~

namespace CEGUI{
bool DbcsSupport::injectChar(utf32 code_point )
 {
#ifndef UNICODE
  static char     s_tempChar[3]  = "";
  static wchar_t  s_tempWchar[2] = L"";
  static bool s_flag = false;
  unsigned char  uch  = (unsigned char)code_point;
  if( uch >= 0xA1 )
  {
   if( !s_flag )
   {
    s_tempChar[0] = (char)uch; //第一个字节
    s_flag = true;
    return true;
   }
   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';
    utf32 code = (utf32)s_tempWchar[0];
    //Font* fnt = System::getSingleton().getDefaultFont();
    return CEGUI::System::getSingleton().injectChar( code );
   }
   else
   {
    return CEGUI::System::getSingleton().injectChar(code_point);
   }
  }
  else
  {
   s_flag = false;
   return CEGUI::System::getSingleton().injectChar(code_point);
  }
#else
  return CEGUI::System::getSingleton().injectChar(code_point );
#endif
 }
}

然后老大扫了下~就用上了~最后果然可以,但是没有去测试下~普通的字可以用就可以了~也就没深究~

代码如下~

//     static char sCharBuf[3] = "";
//     static wchar_t sWCharBuf[2] = L"";
//     static bool sIsChs = false;
//     uchar uch = (uchar)codePoint;
//     if ( uch >= 0xA1 )
//     {
//         if ( !sIsChs )
//         {
//             sCharBuf[0] = (char)uch; // 第一个字节
//             sIsChs = true;
//             return true;
//         }
//         else if( uch >= 0xA1 )
//         {
//             sCharBuf[1] = (char)uch; //第二个字节
//             sIsChs = false;
//             MultiByteToWideChar( 0, 0, sCharBuf, 2, sWCharBuf, 1); // 转成宽字节
//             sWCharBuf[1] = L'/0';
//             CEGUI::utf32 code = (CEGUI::utf32)sWCharBuf[0];
//             return CEGUI::System::getSingletonPtr()->injectChar( code );
//         }
//         else
//         {
//             return CEGUI::System::getSingletonPtr()->injectChar( codePoint );
//         }
//     }
//     else
//     {
//         sIsChs = false;
//         return CEGUI::System::getSingletonPtr()->injectChar( codePoint );
//     }

没啥改动~差不多~会出现复杂字敲不进去~还有时会影响下一次的输入。。。

最近看逻辑和网络通信看的要吐了。。百子哥那边也在忙~也没法测试刚写好的代码~然后就看了下~中文输入,这个一直没看懂的东西~又闲的蛋疼的一天。。。而且亮亮让我输入“喆”字看看。。靠~果然显示不了。。。哭了~虽然还没看懂~不管了~直接敲。。代码如下

bool InputSystem::injectCharChs( unsigned short codePoint )
{
 static char sCharBuf[3] = "";
 static wchar_t sWCharBuf[2] = L"";
 static bool sThisIsChsSecondChar = false;
 uchar uch = (uchar)codePoint;
 bool chsFirstChar = uch >= 0x80;
 bool dealAsChs = sThisIsChsSecondChar || chsFirstChar;
 if ( dealAsChs )
 {
  if ( sThisIsChsSecondChar )
  {
   sCharBuf[1] = (char)uch; //第二个字节
   sThisIsChsSecondChar = false;
   MultiByteToWideChar( 0, 0, sCharBuf, 2, sWCharBuf, 1); // 转成宽字节
   sWCharBuf[1] = L'/0';
   unsigned short code = (unsigned short)sWCharBuf[0];
   return GuiSystem::getSingletonPtr()->injectChar( code );
  }
  else if(chsFirstChar)//最后一种情况
  {
   sCharBuf[0] = (char)uch; // 第一个字节
   sThisIsChsSecondChar = true;
   return true;
  }
  else//不可能的情况([不知道有没有]两个字节以上的中文字),清楚已记录的中文数据,防止影响下一次的输入
  {
   sThisIsChsSecondChar = false;
   memset(sCharBuf, 0, 3);
   memset(sWCharBuf, 0, 2);
  }
 }
 else//deal as english
 {
  sThisIsChsSecondChar = false;
  return GuiSystem::getSingletonPtr()->injectChar( codePoint );
 }

}

其实是看了下基础教程,然后无意中发现,中文字,Windows会传两次消息,才明白static的用意~才知道两个字符的意思。。。测试了下一些复杂的字都可以显示了。。不过“囖”输不进去。。。跟了下~是两个字节~可是就显示不了。。unicode是22230,新华字典下。。没错。。也许是字库里没有这个字吧。。希望是对的了。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值