第二人生的源码分析(八十一)创建UI的显示板(Panel)

在第二人生里,UI部分主要有三种大组件组成:显示板、浮动窗口、菜单。显示板是固定在窗口里面,上面可以放浮动的窗口。像登录的界面,就是一个显示板组成,那么它是怎么样实现的呢?现在就分析下面这段代码,如下:
#001BOOL LLUICtrlFactory::buildPanel(LLPanel* panelp, const LLString &filename,
#002 const LLCallbackMap::map_t*
#003factory_map)
#004{
#005 BOOL didPost = FALSE;
#006 LLXMLNodePtr root;
#007
下面读取XML描述文件,然后通过前面介绍的XML类来分析XML文件,生成所有节点数据返回。
#008 if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
#009 {
#010 return didPost;
#011 }
#012
判断这个XML文件里是否有panel定义,也就是判断它是否用来构造显示板的。
#013 // root must be called panel
#014 if( !root->hasName("panel" ) )
#015 {
#016 llwarns << "Root node should be named panel in : " << filename << llendl;
#017 return didPost;
#018 }
#019
保存这个工厂图到工厂栈里。
#020 if (factory_map)
#021 {
#022 mFactoryStack.push_front(factory_map);
#023 }
#024
根据XML里的数据节点来生成显示板。
#025 didPost = panelp->initPanelXML(root, NULL, this);
#026
设置显示板的提示文件名称。
#027 if (LLUI::sShowXUINames)
#028 {
#029 panelp->setToolTip(filename);
#030 }
#031
获取显示板的句柄。
#032 LLHandle<LLPanel> handle = panelp->getHandle();
把构造的显示板和XML文件关联起来。
#033 mBuiltPanels[handle] = filename;
#034
弹出factory_map对象。
#035 if (factory_map)
#036 {
#037 mFactoryStack.pop_front();
#038 }
#039
#040 return didPost;
#041}
在这个函数里,主要通过XML文件生成XML的节点数据,然后调用函数initPanelXML从XML的节点数据里生成显示板的组件。
下面再来仔细地看一下显示板的XML数据是怎么样的,如下:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<panel bottom="0" follows="left|top|right|bottom" height="600" left="0"
mouse_opaque="true" name="panel_login" width="800">
<web_browser border_visible="false" bottom="0" follows="top|left|bottom|right" left="0"
name="login_html" right="-1"
start_url="data:text/html,%3Chtml%3E%3Chead%3E%3C/head%3E%3Cbody bgcolor=%22#000000%22 text=%22ffffff%22%3E%3Ch1%3E%3Ctt%3Eloading...%3C/tt%3E%3C/h1%3E %3C/body%3E %3C/html%3E"
top="-1" />
<string name="real_url">
http://secondlife.com/app/login/
</string>
<string name="forgot_password_url">
http://secondlife.com/account/request.php
</string>
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="54" drop_shadow_visible="true" follows="left|bottom"
font="SansSerif" h_pad="0" halign="left" height="16" hidden="false"
left="32" mouse_opaque="true" name="first_name_text" v_pad="0" width="120">
First Name:
</text>
<line_editor bevel_style="in" border_style="line" border_thickness="1" bottom_delta="-24"
follows="left|bottom" font="SansSerif" handle_edit_keys_directly="true"
height="20" hidden="false" left="32" max_length="31" mouse_opaque="true"
name="first_name_edit" select_all_on_focus_received="true" width="120" />
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="54" drop_shadow_visible="true" follows="left|bottom"
font="SansSerif" h_pad="0" halign="left" height="16" hidden="false"
left="164" mouse_opaque="true" name="last_name_text" v_pad="0" width="120">
Last Name:
</text>
<line_editor bevel_style="in" border_style="line" border_thickness="1" bottom_delta="-24"
follows="left|bottom" font="SansSerif" handle_edit_keys_directly="true"
height="20" hidden="false" left="164" max_length="31" mouse_opaque="true"
name="last_name_edit" select_all_on_focus_received="true" width="120" />
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="54" drop_shadow_visible="true" follows="left|bottom"
font="SansSerif" h_pad="0" halign="left" height="16" hidden="false"
left="296" mouse_opaque="true" name="password_text" v_pad="0" width="120">
Password:
</text>
<line_editor bevel_style="in" border_style="line" border_thickness="1" bottom_delta="-24"
follows="left|bottom" font="SansSerif" handle_edit_keys_directly="true"
height="20" hidden="false" left="296" max_length="16" mouse_opaque="true"
name="password_edit" select_all_on_focus_received="true" width="120" />
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="10" drop_shadow_visible="true" follows="left|bottom"
font="SansSerif" h_pad="0" halign="left" height="16" hidden="false"
left="32" mouse_opaque="true" name="start_location_text" v_pad="0"
width="95">
Start Location:
</text>
<combo_box allow_text_entry="true" bottom="8" follows="left|bottom" height="18"
hidden="false" left_delta="97" max_chars="128" mouse_opaque="true"
name="start_location_combo" width="155">
<combo_item name="MyHome" value="My Home">
My Home
</combo_item>
<combo_item name="MyLastLocation" value="My Last Location">
My Last Location
</combo_item>
<combo_item name="Typeregionname" value="&lt;Type region name&gt;">
&lt;Type region name&gt;
</combo_item>
</combo_box>
<check_box bottom="10" follows="left|bottom" font="SansSerifSmall" height="16"
hidden="false" initial_value="false" label="Remember password"
left_delta="165" mouse_opaque="true" name="remember_check" width="138" />
<button bottom="28" follows="left|bottom" font="SansSerif" halign="center" height="24"
hidden="false" label="Connect" label_selected="Connect" left="440"
mouse_opaque="true" name="connect_btn" scale_image="TRUE" width="120" />
<button bottom="28" follows="left|bottom" font="SansSerif" halign="center" height="24"
hidden="false" label="Quit" label_selected="Quit" left="572"
mouse_opaque="true" name="quit_btn" scale_image="TRUE" width="120" />
<combo_box allow_text_entry="true" bottom="32" follows="left|bottom" height="18"
hidden="false" left_delta="135" max_chars="20" mouse_opaque="true"
name="server_combo" width="120" />
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="30" drop_shadow_visible="true" follows="right|bottom"
font="SansSerifSmall" h_pad="0" halign="right" height="12" hidden="false"
hover="true" left="-202" mouse_opaque="true" name="channel_text" v_pad="0"
width="200">
[Viewer Channel Name]
</text>
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="18" drop_shadow_visible="true" follows="right|bottom"
font="SansSerifSmall" h_pad="0" halign="right" height="12" hidden="false"
hover="true" left="-102" mouse_opaque="true" name="version_text" v_pad="0"
width="100">
1.23.4 (5)
</text>
<text bg_visible="false" border_drop_shadow_visible="false" border_visible="false"
bottom="2" drop_shadow_visible="true" follows="right|bottom"
font="SansSerifSmall" h_pad="0" halign="right" height="12" hidden="false"
hover="true" left="-172" mouse_opaque="true" name="forgot_password_text"
v_pad="0" width="170">
Forgot your password?
</text>
</panel>
阅读更多

没有更多推荐了,返回首页