//自己定义一个窗口
Window* MyWindow = winMgr.createWindow("TaharezLook/FrameWindow","MyWindow");
MyWindow->setText("Demo7 -- MyWindow");
MyWindow->setProperty("CloseButtonEnabled","False");
MyWindow->setPosition(UVector2(cegui_reldim(0.0f),cegui_reldim(0.3)));
MyWindow->setSize(UVector2(cegui_reldim(0.3f),cegui_reldim(0.3f)));
Window* root = winMgr.getWindow("root");
root->addChildWindow(MyWindow);
//创建单选按钮
RadioButton* op1 = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton","option1"));
//设置TEXT
op1->setText("Option 1");
//设置ID
op1->setID(1);
//设置大小和位置
op1->setPosition(UVector2(cegui_reldim(0.1f),cegui_reldim(0.1f)));
op1->setSize(UVector2(cegui_reldim(0.4f),cegui_reldim(0.1f)));
MyWindow->addChildWindow(op1);
RadioButton* op2 = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton","option2"));
op2->setText("Option 2");
op2->setID(2);
op2->setPosition(UVector2(cegui_reldim(0.1f),cegui_reldim(0.2f)));
op2->setSize(UVector2(cegui_reldim(0.4f),cegui_reldim(0.1f)));
MyWindow->addChildWindow(op2);
RadioButton* op3 = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton","option3"));
op3->setText("Option 3");
op3->setID(3);
op3->setGroupID(1);
op3->setPosition(UVector2(cegui_reldim(0.1f),cegui_reldim(0.4f)));
op3->setSize(UVector2(cegui_reldim(0.4f),cegui_reldim(0.1f)));
MyWindow->addChildWindow(op3);
RadioButton* op4 = static_cast<RadioButton*>(winMgr.createWindow("TaharezLook/RadioButton","option4"));
op4->setText("Option 4");
op4->setID(4);
//设置GroupID,如果不设置就是默认为0
op4->setGroupID(1);
op4->setPosition(UVector2(cegui_reldim(0.1f),cegui_reldim(0.5f)));
op4->setSize(UVector2(cegui_reldim(0.4f),cegui_reldim(0.1f)));
//op4->
MyWindow->addChildWindow(op4);
//设置回调函数
WindowManager::getSingleton().getWindow("option1")->subscribeEvent(RadioButton::EventSelectStateChanged,Event::Subscriber(&Demo7Sample::handleOption,this));
WindowManager::getSingleton().getWindow("option2")->subscribeEvent(RadioButton::EventSelectStateChanged,Event::Subscriber(&Demo7Sample::handleOption,this));
WindowManager::getSingleton().getWindow("option3")->subscribeEvent(RadioButton::EventSelectStateChanged,Event::Subscriber(&Demo7Sample::handleOption,this));
WindowManager::getSingleton().getWindow("option3")->subscribeEvent(RadioButton::EventSelectStateChanged,Event::Subscriber(&Demo7Sample::handleOption,this));
//回调函数
bool Demo7Sample::handleOption(const CEGUI::EventArgs& e)
{
using namespace CEGUI;
*getSelectedButtonInGroup():获得同个组的那个选中的按钮
uint optionid = static_cast<RadioButton*>(static_cast<const WindowEventArgs&>(e).window)->getSelectedButtonInGroup()->getID();
switch(optionid)
{
case 1:
MessageBox(NULL,"1","",MB_OK);
break;
case 2:
MessageBox(NULL,"2","",MB_OK);
break;
case 3:
MessageBox(NULL,"3","",MB_OK);
break;
case 4:
MessageBox(NULL,"4","",MB_OK);
break;
}
return true;
}