现在的位置: 首页 > 综合 > 正文

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

2018年06月07日 ⁄ 综合 ⁄ 共 2128字 ⁄ 字号 评论关闭

本文讲述了如何实现以下几个具体问题:

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里的相应按钮对象上去就可以了。

原文地址http://thatax.blog.163.com/blog/static/20892680200882711513145/

抱歉!评论已关闭.