]> git.sesse.net Git - vlc/commitdiff
* all: added a new xml element: "SubBitmap". It allows to define
authorCyril Deguet <asmax@videolan.org>
Sun, 6 Nov 2005 14:23:16 +0000 (14:23 +0000)
committerCyril Deguet <asmax@videolan.org>
Sun, 6 Nov 2005 14:23:16 +0000 (14:23 +0000)
  several bitmaps in a skin from regions of the same image file.
  Usage is:
  <Bitmap id="body" file="main.bmp" alphacolor="#FF0000">
    <SubBitmap id="sub1" x="0" y="10" width="100" height="100" />
    <SubBitmap id="sub2" x="100" y="10" width="100" height="100" />
  </Bitmap>

modules/gui/skins2/parser/builder.cpp
modules/gui/skins2/parser/builder.hpp
modules/gui/skins2/parser/builder_data.def
modules/gui/skins2/parser/builder_data.hpp
modules/gui/skins2/parser/skin_parser.cpp
modules/gui/skins2/parser/skin_parser.hpp
share/skins2/skin.dtd

index d2cf34c67dd3910823cc2a93602b5711fae4d7d0..5099e8a64047901c709ec1f9101a86f7f76735e4 100644 (file)
@@ -90,6 +90,7 @@ Theme *Builder::build()
     // Create everything from the data in the XML
     ADD_OBJECTS( Theme );
     ADD_OBJECTS( Bitmap );
+    ADD_OBJECTS( SubBitmap );
     ADD_OBJECTS( BitmapFont );
     ADD_OBJECTS( Font );
     ADD_OBJECTS( Window );
@@ -149,6 +150,27 @@ void Builder::addBitmap( const BuilderData::Bitmap &rData )
 }
 
 
+void Builder::addSubBitmap( const BuilderData::SubBitmap &rData )
+{
+    // Get the parent bitmap
+    GenericBitmap *pParentBmp = NULL;
+    GET_BMP( pParentBmp, rData.m_parent );
+    if( !pParentBmp )
+    {
+        msg_Err( getIntf(), "unknown bitmap id: %s", rData.m_parent.c_str() );
+        return;
+    }
+
+    // Copy a region of the parent bitmap to the new one
+    BitmapImpl *pBmp =
+        new BitmapImpl( getIntf(), rData.m_width, rData.m_height );
+    pBmp->drawBitmap( *pParentBmp, rData.m_x, rData.m_y, 0, 0, rData.m_width,
+                      rData.m_height );
+
+    m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
+}
+
+
 void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
 {
     GenericBitmap *pBmp =
index 84023fbe798b31bede766063c6895b949b50123e..f041d56ee4b2d5a8f49b32df52828afb21f45eff 100644 (file)
@@ -65,6 +65,7 @@ class Builder: public SkinObject
 
         void addTheme( const BuilderData::Theme &rData );
         void addBitmap( const BuilderData::Bitmap &rData );
+        void addSubBitmap( const BuilderData::SubBitmap &rData );
         void addBitmapFont( const BuilderData::BitmapFont &rData );
         void addFont( const BuilderData::Font &rData );
         void addWindow( const BuilderData::Window &rData );
index 0bc358e23339ce6f50d4e2e506c3ba98f809db8f..0c7a7d0cbf6b6fbdb76b919e111cc66183124dd0 100644 (file)
@@ -1,5 +1,6 @@
 Theme tooltipfont:string magnet:int alpha:uint32_t moveAlpha:uint32_t
 Bitmap id:string fileName:string alphaColor:uint32_t
+SubBitmap id:string parent:string x:int y:int width:int height:int
 BitmapFont id:string file:string type:string
 Font id:string fontFile:string size:int
 Window id:string xPos:int yPos:int visible:bool dragDrop:bool playOnDrop:bool
index 33b22c863a80e9f1f95002fd9c93e6bbeb9d510d..04e5bc27c0c5ec96e13cee112e8de9a411202b49 100644 (file)
@@ -66,6 +66,22 @@ m_id( id ), m_fileName( fileName ), m_alphaColor( alphaColor ) {}
     /// List
     list<Bitmap> m_listBitmap;
 
+    /// Type definition
+    struct SubBitmap
+    {
+        SubBitmap( const string & id, const string & parent, int x, int y, int width, int height ):
+m_id( id ), m_parent( parent ), m_x( x ), m_y( y ), m_width( width ), m_height( height ) {}
+
+        const string m_id;
+        const string m_parent;
+        int m_x;
+        int m_y;
+        int m_width;
+        int m_height;
+    };
+    /// List
+    list<SubBitmap> m_listSubBitmap;
+
     /// Type definition
     struct BitmapFont
     {
index 4b510c985af3b74af30864d2ab233b26ab7073c7..351d77f5af928a3b5b8c28a5a6b64f78dd1b2cfd 100644 (file)
@@ -64,12 +64,27 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         RequireDefault( "file" );
         RequireDefault( "alphacolor" );
 
-        const BuilderData::Bitmap bitmap( uniqueId( attr["id"] ),
+        m_curBitmapId = uniqueId( attr["id"] );
+        const BuilderData::Bitmap bitmap( m_curBitmapId,
                 convertFileName( attr["file"] ),
                 convertColor( attr["alphacolor"] ) );
         m_data.m_listBitmap.push_back( bitmap );
     }
 
+    else if( rName == "SubBitmap" )
+    {
+        RequireDefault( "id" );
+        RequireDefault( "x" );
+        RequireDefault( "y" );
+        RequireDefault( "width" );
+        RequireDefault( "height" );
+
+        const BuilderData::SubBitmap bitmap( uniqueId( attr["id"] ),
+                m_curBitmapId, atoi( attr["x"] ), atoi( attr["y"] ),
+                atoi( attr["width"] ), atoi( attr["height"] ) );
+        m_data.m_listSubBitmap.push_back( bitmap );
+    }
+
     else if( rName == "BitmapFont" )
     {
         RequireDefault( "id" );
index 957df56b4fdcdc5b96c288373f1e08dce52fe5c8..92952c8e35390feaba58b188f7997fd919ad4dc9 100644 (file)
@@ -43,6 +43,7 @@ class SkinParser: public XMLParser
         /// Container for mapping data from the XML
         BuilderData m_data;
         /// Current IDs
+        string m_curBitmapId;
         string m_curWindowId;
         string m_curLayoutId;
         string m_curListId;
index ed09bc4dc255beb5355f6e45f3cee53a282b9c5a..bed5dbf6248eb3e96bca51110e76dae4bafc0c06 100644 (file)
     >
 
 <!-- main elements -->
-<!ELEMENT Bitmap EMPTY>
+<!ELEMENT Bitmap (SubBitmap)*>
     <!ATTLIST Bitmap
         id          CDATA   #REQUIRED
         file        CDATA   #REQUIRED
         alphacolor  CDATA   #REQUIRED
     >
+<!ELEMENT SubBitmap EMPTY>
+    <!ATTLIST SubBitmap
+        id          CDATA   #REQUIRED
+        x           CDATA   #REQUIRED
+        y           CDATA   #REQUIRED
+        width       CDATA   #REQUIRED
+        height      CDATA   #REQUIRED
+    >
 <!ELEMENT Font EMPTY>
     <!ATTLIST Font
         id          CDATA   #REQUIRED