(CEGUI)如何创建控件 ------下拉列表框,表格框,LISTBOX

 //窗口管理器

WindowManager& winMgr = WindowManager::getSingleton();

//取得首节点
 Window* root = winMgr.getWindow("root_wnd");

//创建下拉列表框   参数(窗体类型,窗口名称)

Combobox* cbbo = static_cast<Combobox*>(winMgr.createWindow("TaharezLook/Combobox", "Demo6/ControlPanel/SelModeBox"));

//设置属性位置和大小

cbbo->setPosition(UVector2(cegui_reldim(0.04f), cegui_reldim( 0.06f)));
cbbo->setSize(UVector2(cegui_reldim(0.66f), cegui_reldim( 0.33f)));

//获得元素背景纹理句柄

 const CEGUI::Image* sel_img = &ImagesetManager::getSingleton().get("TaharezLook").getImage("MultiListSelectionBrush");

//添加元素    参数(文本,ID)

ListboxTextItem* itm = = new ListboxTextItem("Full Row (Single)", 0);
itm->setSelectionBrushImage(sel_img);
cbbo->addItem(itm);
itm = new ListboxTextItem("Full Row (Multiple)", 1);
itm->setSelectionBrushImage(sel_img);
cbbo->addItem(itm);

//排序

cbbo->setSortingEnabled(true);

//添加处理事件消息

winMgr.getWindow("Demo6/ControlPanel/SelModeBox")->
        subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&Demo6Sample::handleSelectModeChanged, this));

 

 

//处理事件函数

 

bool handleSelectModeChanged(const CEGUI::EventArgs&)
{
    using namespace CEGUI;
    // 获得列表框句柄
    Combobox* combo = static_cast<Combobox*>(WindowManager::getSingleton().getWindow("Demo6/ControlPanel/SelModeBox"));

    // 获得选择的元素,  0是开始的位置
    ListboxItem* item = combo->findItemWithText(combo->getText(), 0);

    // 处理相应的ID事件
    if (item)
    {
        switch (item->getID())
        {
        case 0:                      

            break;

        case 1:
             break;

        case 2:
             break;

        case 3:
            break;

        case 4:
            
            break;

        case 5:
            break;

        case 6:                       

            break;

        case 7:
            break;

        case 8:
            break;

        case 9:            
            break;

        default:
            
            break;

        }
    }
    return true;
}

 

 

 

 ======================MultiColumnList  =========================

MultiColumnList* mclbox = static_cast<MultiColumnList*>(winMgr.getWindow("Demo7/Window2/MultiColumnList"));
 // 添加几个空行

    mclbox->addRow();
    mclbox->addRow();
    mclbox->addRow();
    mclbox->addRow();
    mclbox->addRow();

//添加双击事件

mclbox->subscribeEvent(MultiColumnList::EventMouseDoubleClick,Event::Subscriber(&Demo7Sample::handleClick,this));

 //填充 

 // 参数(ITEM* item,列,行)

    mclbox->setItem(new MyListItem("Laggers World"), 0, 0);
    mclbox->setItem(new MyListItem("yourgame.some-server.com"), 1, 0);
    mclbox->setItem(new MyListItem("[colour='FFFF0000']1000ms"), 2, 0);

 

    mclbox->setItem(new MyListItem("Super-Server"), 0, 1);
    mclbox->setItem(new MyListItem("whizzy.fakenames.net"), 1, 1);
    mclbox->setItem(new MyListItem("[colour='FF00FF00']8ms"), 2, 1);

 

    mclbox->setItem(new MyListItem("Cray-Z-Eds"), 0, 2);
    mclbox->setItem(new MyListItem("crayzeds.notarealserver.co.uk"), 1, 2);
    mclbox->setItem(new MyListItem("[colour='FF00FF00']43ms"), 2, 2);

 
    mclbox->setItem(new MyListItem("Fake IPs"), 0, 3);
    mclbox->setItem(new MyListItem("123.320.42.242"), 1, 3);
    mclbox->setItem(new MyListItem("[colour='FFFFFF00']63ms"), 2, 3);

 

    mclbox->setItem(new MyListItem("Yet Another Game Server"), 0, 4);
    mclbox->setItem(new MyListItem("abc.abcdefghijklmn.org"), 1, 4);
    mclbox->setItem(new MyListItem("[colour='FFFF6600']284ms"), 2, 4);

 

//响应事件

bool Demo7Sample::handleClick(const CEGUI::EventArgs &e)
{
 using namespace CEGUI;
 WindowManager& winMgr = WindowManager::getSingleton();
 MultiColumnList* mclbox = static_cast<MultiColumnList*>(winMgr.getWindow("Demo7/Window2/MultiColumnList"));
 //Listbox* mclbox = static_cast<Listbox*>(winMgr.getWindow("Demo7/Window2/Listbox"));
 
 ListboxItem* item = mclbox->getFirstSelectedItem();
 if (item)
 {
  String name = item->getText();
  MessageBox(NULL,name.c_str(),"",MB_OK);
 }
 
 
 return true;
}

=====================listbox  和以上类似==========================

 

 

你可能感兴趣的:(server,image,String,null)