]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/parser/skin_parser.cpp
skins2: fix nested panels wrongly positioned if not the first child
[vlc] / modules / gui / skins2 / parser / skin_parser.cpp
index 30ed199f6ff5738bec19066fe262b02baad70c27..f0937e4d9d5cd7a70eea17781020b613471928bc 100644 (file)
@@ -99,8 +99,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "points", "(0,0)" );
         DefaultAttr( attr, "range", "10" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         const BuilderData::Anchor anchor( x + m_xOffset,
@@ -204,8 +204,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "tooltiptext", "" );
         DefaultAttr( attr, "help", "" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         const BuilderData::Button button( uniqueId( attr["id"] ),
@@ -243,8 +243,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "tooltiptext2", "" );
         DefaultAttr( attr, "help", "" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ),
@@ -302,8 +302,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "help", "" );
         DefaultAttr( attr, "art", "false" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         int width = getDimension( attr["width"], refWidth );
@@ -331,8 +331,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "minheight", "-1" );
         DefaultAttr( attr, "maxheight", "-1" );
 
-        int refWidth = getRefWidth( true );
-        int refHeight = getRefHeight( true );
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, true );
         int width = getDimension( attr["width"], refWidth );
         int height = getDimension( attr["height"], refHeight );
 
@@ -366,9 +366,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "xmargin", "0" );
         DefaultAttr( attr, "ymargin", "0" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
-
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         int width = getDimension( attr["width"], refWidth );
@@ -422,9 +421,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "selcolor", "#0000FF" );
         DefaultAttr( attr, "help", "" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
-
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         int width = getDimension( attr["width"], refWidth );
@@ -484,9 +482,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "selcolor", "#0000FF" );
         DefaultAttr( attr, "help", "" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
-
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         int width = getDimension( attr["width"], refWidth );
@@ -533,8 +530,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "tooltiptext", "" );
         DefaultAttr( attr, "help", "" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
@@ -577,8 +574,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
             newValue = "playtree.slider";
         }
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         const BuilderData::Slider slider( uniqueId( attr["id"] ),
@@ -631,9 +628,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "ykeepratio", "false" );
         DefaultAttr( attr, "help", "" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
-
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         int width = getDimension( attr["width"], refWidth );
@@ -708,9 +704,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         DefaultAttr( attr, "autoresize", "false" );
         DefaultAttr( attr, "help", "" );
 
-        int refWidth = getRefWidth( false );
-        int refHeight = getRefHeight( false );
-
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, false );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         int width = getDimension( attr["width"], refWidth );
@@ -748,8 +743,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
 
         m_curWindowId = uniqueId( attr["id"] );
 
-        int refWidth = getRefWidth( true );
-        int refHeight = getRefHeight( true );
+        int refWidth, refHeight;
+        getRefDimensions( refWidth, refHeight, true );
         int x = getDimension( attr["x"], refWidth );
         int y = getDimension( attr["y"], refHeight );
         const BuilderData::Window window( m_curWindowId,
@@ -871,46 +866,39 @@ const string SkinParser::uniqueId( const string &id )
     return newId;
 }
 
-int SkinParser::getRefWidth( bool toScreen )
+void SkinParser::getRefDimensions( int &rWidth, int &rHeight, bool toScreen )
 {
     if( toScreen )
     {
         OSFactory *pOsFactory = OSFactory::instance( getIntf() );
-        return pOsFactory->getScreenWidth();
-    }
-
-    string panelId = m_panelStack.back();
-    if( panelId != "none" )
-    {
-        const BuilderData::Panel panel = m_pData->m_listPanel.back();
-        return panel.m_width;
-    }
-    else
-    {
-        const BuilderData::Layout layout = m_pData->m_listLayout.back();
-        return layout.m_width;
-    }
-}
-
-int SkinParser::getRefHeight( bool toScreen )
-{
-    if( toScreen )
-    {
-        OSFactory *pOsFactory = OSFactory::instance( getIntf() );
-        return pOsFactory->getScreenHeight();
+        rWidth = pOsFactory->getScreenWidth();
+        rHeight = pOsFactory->getScreenHeight();
+        return;
     }
 
     string panelId = m_panelStack.back();
     if( panelId != "none" )
     {
-        const BuilderData::Panel panel = m_pData->m_listPanel.back();
-        return panel.m_height;
+        list<BuilderData::Panel>::const_iterator it;
+        for( it = m_pData->m_listPanel.begin();
+             it != m_pData->m_listPanel.end(); ++it )
+        {
+            if( it->m_id == panelId )
+            {
+                rWidth = it->m_width;
+                rHeight = it->m_height;
+                return;
+            }
+        }
     }
     else
     {
         const BuilderData::Layout layout = m_pData->m_listLayout.back();
-        return layout.m_height;
+        rWidth = layout.m_width;
+        rHeight = layout.m_height;
+        return;
     }
+    msg_Err( getIntf(), "failure to retrieve parent panel or layout" );
 }
 
 
@@ -1006,8 +994,8 @@ void SkinParser::updateWindowPos( int width, int height )
     BuilderData::Window win = m_pData->m_listWindow.back();
     m_pData->m_listWindow.pop_back();
 
-    int refWidth = getRefWidth( true );
-    int refHeight = getRefHeight( true );
+    int refWidth, refHeight;
+    getRefDimensions( refWidth, refHeight, true );
     convertPosition( win.m_position,
                      win.m_xOffset, win.m_yOffset,
                      win.m_xMargin, win.m_yMargin,