您的位置:首页 > 编程语言

TVSKIN源代码阅读日记(二)------ ReadResourceData()

2009-02-17 05:36 232 查看
SkinProfile.h和skinProfile.cpp主要从事XML文件的解析

参见../EZDTV/EZPlayer/Skins/EasyDTV里面的Skin.xml有关于RESOURCE文件定义由那几个XML文件组成。

<resource file="default/resource.xml" />
<resource file="xml/res/ui.xml" />
<resource file="xml/res/frame.xml" />
<resource file="xml/res/radio.xml" />

../EZDTV/EZPlayer/Skins/EasyDTV/default/resource.xml文件组成

只出现了BITMAP和FONT两种资源

<bitmap id="null.add.favorite.nor" file="default/button/add_n.bmp" />
<bitmap id="null.add.favorite.hover" file="default/button/add_h.bmp" />
<bitmap id="null.add.favorite.down" file="default/button/add_p.bmp" />
<bitmap id="null.add.favorite.disable" file="default/button/add_d.bmp" />

<font id="null.font" pointsize="120" fontname="_System" />
<font id="null.font10" pointsize="100" fontname="_System" />
<font id="null.font8" pointsize="80" fontname="_System" />

../EZDTV/EZPlayer/Skins/EasyDTV/xml/res/ui.xml文件组成

也只出现FONT和BITMAP两种资源
<font id="main.font10" pointsize="100" fontname="_System" />
<font id="main.font12" pointsize="120" fontname="_System" />
<font id="main.font16" pointsize="160" fontname="_System" />

<bitmap id="main.play.nor" file="image/button/pannel_n.bmp" area="32, 54, 42, 42" />
<bitmap id="main.play.down" file="image/button/pannel_p.bmp" area="32, 54, 42, 42" />
<bitmap id="main.play.hover" file="image/button/pannel_h.bmp" area="32, 54, 42, 42" />
<bitmap id="main.play.disab" file="image/button/pannel_d.bmp" area="32, 54, 42, 42" />

../EZDTV/EZPlayer/Skins/EasyDTV/xml/res/radio.xml文件组成

只出现BITMAP资源

<!-- radio seek slider -->
<bitmap id="radio.seek.bar" file="image/radio/seek_bar_filled.bmp" />
<bitmap id="radio.seekthumb.hover" file="image/radio/thumb_hover.bmp" />
<bitmap id="radio.seekthumb.normal" file="image/radio/thumb_normal.bmp" />

../EZDTV/EZPlayer/Skins/EasyDTV/xml/res/frame.xml文件组成

只出现BITMAP资源
<!-- Frame -->
<bitmap id="frame.bottom.right" file="image/frame/m_rb.bmp" />
<bitmap id="frame.top.left" file="image/frame/m_lt.bmp" />
<bitmap id="frame.top.right" file="image/frame/m_rt.bmp" />
<bitmap id="frame.bottom.left" file="image/frame/m_lb.bmp" />
<bitmap id="frame.top.span" file="image/frame/m_ts.bmp" />
<bitmap id="frame.bottom.span" file="image/frame/m_bs.bmp" />
<bitmap id="frame.left.span" file="image/frame/m_ls.bmp" />
<bitmap id="frame.right.span" file="image/frame/m_rs.bmp" />

这些XML文件都以<resource></resource>为ROOT节点,这样就比较好区别是分析RESOURCE资源。

EXAMPLE:

BOOL ReadResourceData( MSXML::IXMLDOMNodePtr node )
{
if (NULL == node)
return S_FALSE;

try
{
MSXML::DOMNodeType nodeType;
node->get_nodeType(&nodeType); // node type
_bstr_t str = node->GetnodeName(); // node name

if( str == _bstr_t("bitmap") )
{
// read bitmap resource
CEZBitmap *tmp = new CEZBitmap;
int _x, _y, _w, _h;
_bstr_t filename, idName;
bool bArea = false;

MSXML::IXMLDOMNamedNodeMapPtr pAttrMap = node->Getattributes();
if (pAttrMap != NULL)
{
MSXML::IXMLDOMAttributePtr pAttribute;
while(pAttribute = pAttrMap->nextNode())
{
_bstr_t str = pAttribute->GetnodeName();
if( str == _bstr_t("id") )
{
idName = pAttribute->GetnodeValue();
}
else if(str == _bstr_t("file") )
{
filename = pAttribute->GetnodeValue();
}
else if(str == _bstr_t("area") )
{
bArea = true;
_bstr_t area = pAttribute->GetnodeValue();
sscanf( area, "%d, %d, %d, %d", &_x, &_y, &_w, &_h);
}
}
if( bArea )
{
tmp->LoadBitmap( _bstr_t(g_szSkinPath) + filename, idName, _x, _y, _w, _h );
}
else
{
tmp->LoadBitmap( _bstr_t(g_szSkinPath) + filename, idName );
}
g_pManager->AttachRes( tmp );
}

}
else if( str == _bstr_t("font") )
{
CEZFont *tmp = new CEZFont;
int pointsize = 0;
_bstr_t fontname, idName;

MSXML::IXMLDOMNamedNodeMapPtr pAttrMap = node->Getattributes();
if (pAttrMap != NULL)
{
MSXML::IXMLDOMAttributePtr pAttribute;
while(pAttribute = pAttrMap->nextNode())
{
_bstr_t str = pAttribute->GetnodeName();
if( str == _bstr_t("id") )
{
idName = pAttribute->GetnodeValue();
}
else if(str == _bstr_t("pointsize") )
{
_bstr_t strSize = pAttribute->GetnodeValue();
sscanf( strSize, "%d", &pointsize );
}
else if(str == _bstr_t("fontname") )
{
fontname = pAttribute->GetnodeValue();
}
}
tmp->CreatePointFont( pointsize, fontname);
tmp->SetID( idName );
g_pManager->AttachFont( tmp );
}
}
else if( str == _bstr_t("bmpfont") )
{
CEZFont *tmp = new CEZFont;
int _w = 0, _h = 0, space = 0, number = 0;
int _r = 0, _g = 0, _b = 0;
_bstr_t filename, idName, table;

MSXML::IXMLDOMNamedNodeMapPtr pAttrMap = node->Getattributes();
if (pAttrMap != NULL)
{
MSXML::IXMLDOMAttributePtr pAttribute;
while(pAttribute = pAttrMap->nextNode())
{
_bstr_t str = pAttribute->GetnodeName();
if( str == _bstr_t("id") )
{
idName = pAttribute->GetnodeValue();
}
else if(str == _bstr_t("filename") )
{
filename = pAttribute->GetnodeValue();
}
else if(str == _bstr_t("size") )
{
_bstr_t strSize = pAttribute->GetnodeValue();
sscanf( strSize, "%d, %d", &_w, &_h );
}
else if(str == _bstr_t("space") )
{
_bstr_t strSpace = pAttribute->GetnodeValue();
sscanf( strSpace, "%d", &space );
}
else if(str == _bstr_t("number") )
{
_bstr_t strNumber = pAttribute->GetnodeValue();
sscanf( strNumber, "%d", &number );
}
else if(str == _bstr_t("transparent") )
{
_bstr_t strColor = pAttribute->GetnodeValue();
sscanf( strColor, "%d, %d, %d", &_r, &_g, &_b );
}
else if( str == _bstr_t("table") )
{
table = pAttribute->GetnodeValue();
}

}
tmp->CreateBitmapFont( _bstr_t(g_szSkinPath) + filename, _w, _h, space, number, RGB(_r, _g, _b), table );
tmp->SetID( idName );
g_pManager->AttachFont( tmp );
}
}
else if ( str == _bstr_t("color") )
{
// read color resource
}

MSXML::IXMLDOMNodeListPtr pNodeList = node->GetchildNodes();
if (pNodeList != NULL)
{
MSXML::IXMLDOMNodePtr pChild;
while(pChild = pNodeList->nextNode())
{
ReadResourceData(pChild);
}
}
}
catch(_com_error e)
{
ATLASSERT("Caught Exception: ReadElement");
}
catch(...)
{
ATLASSERT("Caught Exception: ReadElement");
}

return S_OK;
}

Resource文件中的解析NODE NAME 和Resource xml文件中的类型相对应起来。bitmap,front,color,bmpfont等。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐