第二人生的源码分析(九十三)LLComboBox类实现组合框
来源:互联网 发布:mac强制恢复出厂设置 编辑:程序博客网 时间:2024/06/10 03:34
在第二人生里,从登录的界面可以看到一个组合框,就是选择不同服务器的组件,它就使用到组合框了。其实组合框是由按钮、滚动列表框和编辑框组成的。它的继承关系如下:
class LLComboBox
: public LLUICtrl, public LLCtrlListInterface
同样它也是一个控件类,继承了基类LLUICtrl。从LLComboBox类的声明里,可以看到下面这段代码:
#001 protected:
组合框里的按钮。
#002 LLButton* mButton;
组合框里的滚动列表。
#003 LLScrollListCtrl* mList;
#004 LLViewBorder* mBorder;
#005 EPreferredPosition mListPosition;
#006 LLPointer<LLImageGL> mArrowImage;
#007
#008 private:
#009 S32 mButtonPadding;
组合框里的编辑框。
#010 LLLineEditor* mTextEntry;
#011 BOOL mAllowTextEntry;
#012 S32 mMaxChars;
#013 BOOL mTextEntryTentative;
由于组合框都是有现成的控件组成,所以它的显示代码是非常简单的,如下:
#001 void LLComboBox::draw()
#002 {
判断是否可以可见。
#003 if( getVisible() )
#004 {
设置边框。
#005 mBorder->setKeyboardFocusHighlight(hasFocus());
#006
设置按钮是否起作用。
#007 mButton->setEnabled(getEnabled() /*&& !mList->isEmpty()*/);
#008
显示所有子窗口组件。
#009 // Draw children normally
#010 LLUICtrl::draw();
#011 }
#012 }
上面子窗口显示的代码是显示那些组件的呢?下面从构造函数里看到它是下面的组件构成,如下:
#001 LLComboBox::LLComboBox( const LLString& name, const LLRect &rect, const LLString& label,
#002 void (*commit_callback)(LLUICtrl*,void*),
#003 void *callback_userdata
#004 )
#005 : LLUICtrl(name, rect, TRUE, commit_callback, callback_userdata,
#006 FOLLOWS_LEFT | FOLLOWS_TOP),
#007 mTextEntry(NULL),
#008 mArrowImage(NULL),
#009 mAllowTextEntry(FALSE),
#010 mMaxChars(20),
#011 mTextEntryTentative(TRUE),
#012 mListPosition(BELOW),
#013 mPrearrangeCallback( NULL ),
#014 mTextEntryCallback( NULL )
#015 {
创建按钮类。
#016 // Always use text box
#017 // Text label button
#018 mButton = new LLButton("comboxbox button",
#019 LLRect(), label, NULL, LLString::null,
#020 NULL, this);
#021 mButton->setImageUnselected("square_btn_32x128.tga");
#022 mButton->setImageSelected("square_btn_selected_32x128.tga");
#023 mButton->setImageDisabled("square_btn_32x128.tga");
#024 mButton->setImageDisabledSelected("square_btn_selected_32x128.tga");
#025 mButton->setScaleImage(TRUE);
#026
#027 mButton->setMouseDownCallback(onButtonDown);
#028 mButton->setFont(LLFontGL::sSansSerifSmall);
#029 mButton->setFollows(FOLLOWS_LEFT | FOLLOWS_BOTTOM | FOLLOWS_RIGHT);
#030 mButton->setHAlign( LLFontGL::LEFT );
#031 mButton->setRightHPad(2);
添加到子窗口列表。
#032 addChild(mButton);
#033
创建滚动列表框。
#034 // disallow multiple selection
#035 mList = new LLScrollListCtrl(
#036 "ComboBox", LLRect(),
#037 &LLComboBox::onItemSelected, this, FALSE);
#038 mList->setVisible(FALSE);
#039 mList->setBgWriteableColor( LLColor4(1,1,1,1) );
#040 mList->setCommitOnKeyboardMovement(FALSE);
添加到子窗口列表。
#041 addChild(mList);
#042
#043 LLRect border_rect(0, getRect().getHeight(), getRect().getWidth(), 0);
创建边框。
#044 mBorder = new LLViewBorder( "combo border", border_rect );
#045 addChild( mBorder );
#046 mBorder->setFollowsAll();
#047
#048 LLUUID arrow_image_id( LLUI::sAssetsGroup->getString("combobox_arrow.tga") );
#049 mArrowImage = LLUI::sImageProvider->getImageByID(arrow_image_id);
#050 mButton->setImageOverlay("combobox_arrow.tga", LLFontGL::RIGHT);
#051
在这个函数里添加编辑框到子窗口列表里。
#052 updateLayout();
#053 }
通过上面的代码分析,看到一个组合框是怎么样构成,并且怎么样显示出来。
- 第二人生的源码分析(九十三)LLComboBox类实现组合框
- 第二人生的源码分析(十九)人物组合显示
- 第二人生的源码分析(5)类Log的实现
- 第二人生的源码分析(6)类CallSite的实现
- 第二人生的源码分析(5)类Log的实现
- 第二人生的源码分析(6)类CallSite的实现
- 第二人生的源码分析(九十二)LLLineEditor实现编辑框
- 第二人生的源码分析(11)地面显示的实现
- 第二人生的源码分析(12)天空显示的实现
- 第二人生的源码分析(13)树显示的实现
- 第二人生的源码分析(十四)人物角色的实现
- 第二人生的源码分析(九十九)雷达地图的实现
- 第二人生的源码分析(七十一)实现闪屏窗口
- 第二人生的源码分析(九十)LLScrollListCtrl实现列表显示
- 第二人生的源码分析(2)第二人生的基本功能
- 第二人生的源码分析(2)第二人生的基本功能
- 蔡军生先生第二人生的源码分析(十九)人物组合显示
- 第二人生的源码分析(四十二)实现消息处理的线程类
- eBay改变开发计划 对第三方免费开放API
- Google的API介绍
- (FBA) Flashback Best Analisator 1.6beta
- 赢在起跑线上
- Google应用指南:高级搜索语法
- 第二人生的源码分析(九十三)LLComboBox类实现组合框
- dat文件和.mpg文件有什么区别?
- H.323与SIP在VoIP和多媒体应用中的比较
- dat文件和.mpg文件有什么区别?
- Cisco.Press.Implementing.Cisco.Unified.Communications.Manager.Part.1.CIPT1.Jun.2008.eBook-BBL
- Java程序员必须了解的开源协议
- 7个Linux手机平台比较 (3):“保存手机设置”的异同
- SQL SERVER 与ACCESS、EXCEL的数据转换
- MSCML协议:下一代多媒体SIP业务的关键