Commit 43a4fcef authored by Erwan Tulou's avatar Erwan Tulou

skins2: fix nested panels wrongly positioned if not the first child

plus factorise some code.

This fixes a bug reported on the forum at
http://forum.videolan.org/viewtopic.php?f=26&t=111572
parent 212048ac
...@@ -99,8 +99,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -99,8 +99,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "points", "(0,0)" ); DefaultAttr( attr, "points", "(0,0)" );
DefaultAttr( attr, "range", "10" ); DefaultAttr( attr, "range", "10" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
const BuilderData::Anchor anchor( x + m_xOffset, const BuilderData::Anchor anchor( x + m_xOffset,
...@@ -204,8 +204,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -204,8 +204,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "tooltiptext", "" ); DefaultAttr( attr, "tooltiptext", "" );
DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
const BuilderData::Button button( uniqueId( attr["id"] ), const BuilderData::Button button( uniqueId( attr["id"] ),
...@@ -243,8 +243,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -243,8 +243,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "tooltiptext2", "" ); DefaultAttr( attr, "tooltiptext2", "" );
DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ), const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ),
...@@ -302,8 +302,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -302,8 +302,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "help", "" );
DefaultAttr( attr, "art", "false" ); DefaultAttr( attr, "art", "false" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth ); int width = getDimension( attr["width"], refWidth );
...@@ -331,8 +331,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -331,8 +331,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "minheight", "-1" ); DefaultAttr( attr, "minheight", "-1" );
DefaultAttr( attr, "maxheight", "-1" ); DefaultAttr( attr, "maxheight", "-1" );
int refWidth = getRefWidth( true ); int refWidth, refHeight;
int refHeight = getRefHeight( true ); getRefDimensions( refWidth, refHeight, true );
int width = getDimension( attr["width"], refWidth ); int width = getDimension( attr["width"], refWidth );
int height = getDimension( attr["height"], refHeight ); int height = getDimension( attr["height"], refHeight );
...@@ -366,9 +366,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -366,9 +366,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "xmargin", "0" ); DefaultAttr( attr, "xmargin", "0" );
DefaultAttr( attr, "ymargin", "0" ); DefaultAttr( attr, "ymargin", "0" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth ); int width = getDimension( attr["width"], refWidth );
...@@ -422,9 +421,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -422,9 +421,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "selcolor", "#0000FF" ); DefaultAttr( attr, "selcolor", "#0000FF" );
DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth ); int width = getDimension( attr["width"], refWidth );
...@@ -484,9 +482,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -484,9 +482,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "selcolor", "#0000FF" ); DefaultAttr( attr, "selcolor", "#0000FF" );
DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth ); int width = getDimension( attr["width"], refWidth );
...@@ -533,8 +530,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -533,8 +530,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "tooltiptext", "" ); DefaultAttr( attr, "tooltiptext", "" );
DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
const BuilderData::RadialSlider radial( uniqueId( attr["id"] ), const BuilderData::RadialSlider radial( uniqueId( attr["id"] ),
...@@ -577,8 +574,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -577,8 +574,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
newValue = "playtree.slider"; newValue = "playtree.slider";
} }
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
const BuilderData::Slider slider( uniqueId( attr["id"] ), const BuilderData::Slider slider( uniqueId( attr["id"] ),
...@@ -631,9 +628,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -631,9 +628,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" );
DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth ); int width = getDimension( attr["width"], refWidth );
...@@ -708,9 +704,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -708,9 +704,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
DefaultAttr( attr, "autoresize", "false" ); DefaultAttr( attr, "autoresize", "false" );
DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "help", "" );
int refWidth = getRefWidth( false ); int refWidth, refHeight;
int refHeight = getRefHeight( false ); getRefDimensions( refWidth, refHeight, false );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
int width = getDimension( attr["width"], refWidth ); int width = getDimension( attr["width"], refWidth );
...@@ -748,8 +743,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -748,8 +743,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
m_curWindowId = uniqueId( attr["id"] ); m_curWindowId = uniqueId( attr["id"] );
int refWidth = getRefWidth( true ); int refWidth, refHeight;
int refHeight = getRefHeight( true ); getRefDimensions( refWidth, refHeight, true );
int x = getDimension( attr["x"], refWidth ); int x = getDimension( attr["x"], refWidth );
int y = getDimension( attr["y"], refHeight ); int y = getDimension( attr["y"], refHeight );
const BuilderData::Window window( m_curWindowId, const BuilderData::Window window( m_curWindowId,
...@@ -871,46 +866,39 @@ const string SkinParser::uniqueId( const string &id ) ...@@ -871,46 +866,39 @@ const string SkinParser::uniqueId( const string &id )
return newId; return newId;
} }
int SkinParser::getRefWidth( bool toScreen ) void SkinParser::getRefDimensions( int &rWidth, int &rHeight, bool toScreen )
{ {
if( toScreen ) if( toScreen )
{ {
OSFactory *pOsFactory = OSFactory::instance( getIntf() ); OSFactory *pOsFactory = OSFactory::instance( getIntf() );
return pOsFactory->getScreenWidth(); rWidth = pOsFactory->getScreenWidth();
rHeight = pOsFactory->getScreenHeight();
return;
} }
string panelId = m_panelStack.back(); string panelId = m_panelStack.back();
if( panelId != "none" ) if( panelId != "none" )
{ {
const BuilderData::Panel panel = m_pData->m_listPanel.back(); list<BuilderData::Panel>::const_iterator it;
return panel.m_width; for( it = m_pData->m_listPanel.begin();
} it != m_pData->m_listPanel.end(); ++it )
else
{ {
const BuilderData::Layout layout = m_pData->m_listLayout.back(); if( it->m_id == panelId )
return layout.m_width;
}
}
int SkinParser::getRefHeight( bool toScreen )
{
if( toScreen )
{ {
OSFactory *pOsFactory = OSFactory::instance( getIntf() ); rWidth = it->m_width;
return pOsFactory->getScreenHeight(); rHeight = it->m_height;
return;
}
} }
string panelId = m_panelStack.back();
if( panelId != "none" )
{
const BuilderData::Panel panel = m_pData->m_listPanel.back();
return panel.m_height;
} }
else else
{ {
const BuilderData::Layout layout = m_pData->m_listLayout.back(); 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 ) ...@@ -1006,8 +994,8 @@ void SkinParser::updateWindowPos( int width, int height )
BuilderData::Window win = m_pData->m_listWindow.back(); BuilderData::Window win = m_pData->m_listWindow.back();
m_pData->m_listWindow.pop_back(); m_pData->m_listWindow.pop_back();
int refWidth = getRefWidth( true ); int refWidth, refHeight;
int refHeight = getRefHeight( true ); getRefDimensions( refWidth, refHeight, true );
convertPosition( win.m_position, convertPosition( win.m_position,
win.m_xOffset, win.m_yOffset, win.m_xOffset, win.m_yOffset,
win.m_xMargin, win.m_yMargin, win.m_xMargin, win.m_yMargin,
......
...@@ -98,8 +98,7 @@ private: ...@@ -98,8 +98,7 @@ private:
const string uniqueId( const string &id ); const string uniqueId( const string &id );
/// Management of relative positions /// Management of relative positions
int getRefWidth( bool toScreen ); void getRefDimensions( int &rWidth, int &rHeight, bool toScreen );
int getRefHeight( bool toScreen );
int getDimension( string value, int refDimension ); int getDimension( string value, int refDimension );
int getPosition( string value ); int getPosition( string value );
void updateWindowPos( int width, int height ); void updateWindowPos( int width, int height );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment