CEGUI学习笔记六-- 使用CEGUI解决具体问题

本文讲述了如何实现以下几个具体问题:
1、设置控件的背景为透明。
2、以D3D9为渲染层的时候,Tooltip工作不正常(一闪而过)。
3、模拟MessageBox。


--------------------------------------------------------------------------------

1、设置控件的背景为透明
有3种方法来解决这个问题:

1、修改Imageset文件,提供相关的透明位图;
修改Looknfeel文件,使用透明位图进行绘制;
修改Scheme文件,使用新的外观配置。

2、在程序里写如下代码:

d_framewindow->setProperty("FrameEnabled","false");
d_framewindow->setProperty("BackgroundEnabled","false");

3、在LayoutEdit 中配置对象的FrameEnabled,和BackgroundEnabled属性都为false。


--------------------------------------------------------------------------------

2、以D3D9为渲染层的时候,Tooltip工作不正常(一闪而过)。
该问题是BUG引起的,但不是CEGUI本身的问题。

出问题的语句在CEGuiD3D9BaseApplication.cpp中的这句:


guiSystem.injectTimePulse(GetTickCount() - d_lastTime);

明显是个有问题的语句。。。。这句话导致CEGUI内部的时间流逝记数完全是个乱的....并且比现实至少快1000倍。Tooltip默认显示7.5秒,7.5S * 000.1 = 7.5ns,所以显示的时候一闪而过。

改为

unsigned int time_diff = GetTickCount() - d_lastTime;
d_lastTime = GetTickCount();
guiSystem.injectTimePulse( time_diff * 0.001f)
而以OpenGL或者OGRE的渲染层则不会出现这个问题。


--------------------------------------------------------------------------------

3、模拟MessageBox
 1、使用LayoutEdit 搭建一个MessageBox,然后在程序的适当位置加入如下代码:

bool handleMessageBoxBtnOKClicked( const CEGUI::EventArgs& args);
void CEGUI_MessageBox();


bool handleMessageBoxBtnOKClicked( const CEGUI::EventArgs& args)
...{
    using namespace CEGUI;
    const WindowEvetArgs& WindowArgs = static_cast<const WindowEventArgs&>(args);
    WindowArgs.window->getParent()->setModalState(false);
    WindowArgs.window->getParent()->setVisible(false);
    WindowArgs.window->getParent()->destroy();  
}

void CEGUI_MessageBox(const CEGUI::String& layoutfileName)
...{
    using namespace CEGUI;
    // 读取MessageBox的布局文件
    Window* msgbox = CEGUI::WindowManager::getSingleton().loadWindowLayout( layoutfileName );
    // 注册MessageBox的按钮事件
    msgbox->getChild("Frame/OK")->subscribeEvent( Window::EventMouseClick, Event::Subscriber( &handleMessageBoxBtnOKClicked) );
    // 将MessageBox的属性设置为模态窗口
  msgbox->setModalState(true);
    // 显示MessageBox
    CEGUI::System::getSingleton().getGUISheet()->addChildWindow(msgbox);
}

不要担心关于删除的问题,CEGUI采用延后一贞删除的策略,任何Destory操作都延后了。可以查看CEGUISystem的代码。

在MS里我们一般这样写关于MBox的代码:
int ret = MessageBox("123","123",NULL,MB_OKCANCEL);
if( ret == 6 )
{}
else
{}

别想实现象MS里的MessageBox,否则将面临相当复杂的“重入”问题。

而且因为我们事先已经知道如果MessageBox的某按钮被按下时需要做什么事,所以只需要把这部分的逻辑事先写好,然后注册到MessageBox里的相应按钮对象上去就可以了。

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kun1234567/archive/2008/04/17/2301036.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值