前面已經介紹怎么樣遍歷子窗口顯示,那么它的子窗口是怎么樣添加到列表里的呢?下面就來仔細地分析這方面的代碼,如下:
#001?void LLView::addChild(LLView* child, S32 tab_group)
#002?{
?
如果添加自己到子窗口里提示出錯。
#003?
?? if (mParentView == child)
#004?
?? {
#005?
?????? llerrs << "Adding view " << child->getName() << " as child of itself" << llendl;
#006?
?? }
?
如果這個子窗口已經有父窗口,就先刪除它。
#007?
?? // remove from current parent
#008?
?? if (child->mParentView)
#009?
?? {
#010?
?????? child->mParentView->removeChild(child);
#011?
?? }
#012?
?
添加子窗口到保存列表里。
#013?
?? // add to front of child list, as normal
#014?
?? mChildList.push_front(child);
#015?
?
如果這個子窗口是控制窗口就添加到控制隊列。
#016?
?? // add to ctrl list if is LLUICtrl
#017?
?? if (child->isCtrl())
#018?
?? {
#019?
?????? // controls are stored in reverse order from render order
#020?
?????? addCtrlAtEnd((LLUICtrl*) child, tab_group);
#021?
?? }
#022?
?
指明這個子窗口的父窗口。
#023?
?? child->mParentView = this;
#024?
?? updateBoundingRect();
#025?}
?
通過上面的函數,就可以把一個界面顯示的子窗口全部添加到隊列里,然后再遍歷子窗口隊列,就可以顯示這個窗口相關的內容了。比如下面的例子:
在類
LLProgressView里添加一個退出按鈕:
#001?LLProgressView::LLProgressView(const std::string& name, const LLRect &rect)
#002?: LLPanel(name, rect, FALSE)
#003?{
#004?
?? mPercentDone = 0.f;
#005?
?? mDrawBackground = TRUE;
#006?
#007?
?? const S32 CANCEL_BTN_WIDTH = 70;
#008?
?? const S32 CANCEL_BTN_OFFSET = 16;
#009?
?? LLRect r;
#010?
?? r.setOriginAndSize(
#011?
?????? getRect().getWidth() - CANCEL_BTN_OFFSET - CANCEL_BTN_WIDTH, CANCEL_BTN_OFFSET,
#012?
?????? CANCEL_BTN_WIDTH, BTN_HEIGHT );
#013?
??
#014??mCancelBtn = new LLButton(
#015?
????? "Quit",
#016?
????? r,
#017?
????? "",
#018?
????? LLProgressView::onCancelButtonClicked,
#019?
????? NULL );
#020??mCancelBtn->setFollows( FOLLOWS_RIGHT | FOLLOWS_BOTTOM );
#021??addChild( mCancelBtn );
#022?
?? mFadeTimer.stop();
#023?
?? setVisible(FALSE);
#024?
#025?
?? sInstance = this;
#026?}
?
這里就通過第
21行的代碼來添加到這個窗口里,把按鈕
mCancelBtn
當作類LLProgressView窗口的子窗口來顯示。
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
