第二人生的源码分析(八十六)LLView类添加子窗口显示

前面已经介绍怎么样遍历子窗口显示,那么它的子窗口是怎么样添加到列表里的呢?下面就来仔细地分析这方面的代码,如下:
#001void 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里添加一个退出按钮:
#001LLProgressView::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
#014mCancelBtn = new LLButton(
#015 "Quit",
#016 r,
#017 "",
#018 LLProgressView::onCancelButtonClicked,
#019 NULL );
#020mCancelBtn->setFollows( FOLLOWS_RIGHT | FOLLOWS_BOTTOM );
#021addChild( mCancelBtn );
#022 mFadeTimer.stop();
#023 setVisible(FALSE);
#024
#025 sInstance = this;
#026}
这里就通过第 21行的代码来添加到这个窗口里,把按钮mCancelBtn当作类LLProgressView窗口的子窗口来显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值