From 43a4fcef9252973828d5b465c20031095a52974b Mon Sep 17 00:00:00 2001 From: Erwan Tulou Date: Sat, 22 Jun 2013 11:27:22 +0200 Subject: [PATCH] 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 --- modules/gui/skins2/parser/skin_parser.cpp | 106 ++++++++++------------ modules/gui/skins2/parser/skin_parser.hpp | 3 +- 2 files changed, 48 insertions(+), 61 deletions(-) diff --git a/modules/gui/skins2/parser/skin_parser.cpp b/modules/gui/skins2/parser/skin_parser.cpp index 30ed199f6f..f0937e4d9d 100644 --- a/modules/gui/skins2/parser/skin_parser.cpp +++ b/modules/gui/skins2/parser/skin_parser.cpp @@ -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::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, diff --git a/modules/gui/skins2/parser/skin_parser.hpp b/modules/gui/skins2/parser/skin_parser.hpp index f9d9550979..fb85adaee9 100644 --- a/modules/gui/skins2/parser/skin_parser.hpp +++ b/modules/gui/skins2/parser/skin_parser.hpp @@ -98,8 +98,7 @@ private: const string uniqueId( const string &id ); /// Management of relative positions - int getRefWidth( bool toScreen ); - int getRefHeight( bool toScreen ); + void getRefDimensions( int &rWidth, int &rHeight, bool toScreen ); int getDimension( string value, int refDimension ); int getPosition( string value ); void updateWindowPos( int width, int height ); -- 2.39.2