您的位置:首页 > 产品设计 > UI/UE

第二人生的源码分析(八十二)创建UI的浮动窗口(floater)

2008-06-06 21:00 447 查看
上一次介绍了显示板的创建,这里来介绍创建浮动窗口。浮动的窗口可以显示在显示板之上,并且可以放在显示窗口不同的位置,也就是方便用户布局这个窗口在那里显示,比如聊天窗口,就可以放大,并且调整到合适的位置。下面就来分析创建浮动窗口的代码,如下:
#001 void LLUICtrlFactory::buildFloater(LLFloater* floaterp, const LLString &filename,
#002 const LLCallbackMap::map_t*
#003 factory_map, BOOL open) /* Flawfinder: ignore */
#004 {
#005 LLXMLNodePtr root;
#006

分析给出名称的XML文件,生成所有节点数据保存到root里面。
#007 if (!LLUICtrlFactory::getLayeredXMLNode(filename, root))
#008 {
#009 return;
#010 }
#011

检测这个XML文件是否是浮动窗口的文件。
#012 // root must be called floater
#013 if( !(root->hasName("floater") || root->hasName("multi_floater") ) )
#014 {
#015 llwarns << "Root node should be named floater in: " << filename << llendl;
#016 return;
#017 }
#018

保存map工厂。
#019 if (factory_map)
#020 {
#021 mFactoryStack.push_front(factory_map);
#022 }
#023

调用LLFloater类来创建浮动窗口。
#024 floaterp->initFloaterXML(root, NULL, this, open); /* Flawfinder: ignore */
#025

设置窗口的提示信息来XML文件名称。
#026 if (LLUI::sShowXUINames)
#027 {
#028 floaterp->setToolTip(filename);
#029 }
#030
#031 if (factory_map)
#032 {
#033 mFactoryStack.pop_front();
#034 }
#035

获取窗口的句柄。
#036 LLHandle<LLFloater> handle = floaterp->getHandle();

设置窗口的句柄与XML文件关联到一起。
#037 mBuiltFloaters[handle] = filename;
#038 }
#039

通过上面的函数就把浮动的窗口创建了,下面来看看一个浮动窗口的XML是怎么样的,如下:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<multi_floater bottom="-690" can_close="true" can_drag_on_left="false" can_minimize="true"
can_resize="true" enabled="true" follows="left|bottom" height="422"
left="294" min_height="130" min_width="350" mouse_opaque="true"
name="im_floater" rect_control="FloaterIMRect" title="Instant Message"
width="419">
<tab_container border="false" bottom="-422" enabled="true" follows="left|top|right|bottom"
height="406" left="1" mouse_opaque="false" name="Preview Tabs"
tab_position="bottom" width="417" />
<string name="only_user_message">
You are the only user in this session.
</string>
<string name="offline_message">
[FIRST] [LAST] is offline.
</string>
<string name="invite_message">
Click the [BUTTON NAME] button to accept/connect to this voice chat.
</string>
<string name="generic_request_error">
Error making request, please try again later.
</string>
<string name="insufficient_perms_error">
You do not have sufficient permissions.
</string>
<string name="session_does_not_exist_error">
The session no longer exists
</string>
<string name="no_ability_error">
You do not have that ability.
</string>
<string name="not_a_mod_error">
You are not a session moderator.
</string>
<string name="muted_error">
You have been muted.
</string>
<string name="add_session_event">
adding agents to chat session with
</string>
<string name="message_session_event">
messaging chat session with
</string>
<string name="mute_agent_event">
muting agent in
</string>
<string name="removed_from_group">
You have been removed from the group.
</string>
<string name="close_on_no_ability">
You no longer have the ability to be in the chat session
</string>
</multi_floater>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: