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

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等。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值