From: Cyril Deguet Date: Tue, 8 Nov 2005 20:26:13 +0000 (+0000) Subject: * all: the skin sliders can now have a background image, which X-Git-Tag: 0.9.0-test0~13365 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=e0352f9138f8da06abf7cb621011bbfafda9c803;p=vlc * all: the skin sliders can now have a background image, which depends on the position of the slider. The "Slider" elements now have optional attributes "background", which the Id of a bitmap, and "nbimages" which is the number of images in the bitmap (it is similar to the radialslider). At the moment there is a hack to support winamp slider bars: the different images must be separated by 3 rows of unused pixels (well, maybe they are useful; if someone knows how... ;) * theme_loader.cpp: convert the file names from zip archives to lower case, to avoid mixed case issues in some winamp skins --- diff --git a/modules/gui/skins2/controls/ctrl_slider.cpp b/modules/gui/skins2/controls/ctrl_slider.cpp index d9bb33ba9c..73edd8cb2e 100644 --- a/modules/gui/skins2/controls/ctrl_slider.cpp +++ b/modules/gui/skins2/controls/ctrl_slider.cpp @@ -335,12 +335,39 @@ void CtrlSliderCursor::getResizeFactors( float &rFactorX, CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf, CtrlSliderCursor &rCursor, const Bezier &rCurve, VarPercent &rVariable, - int thickness, VarBool *pVisible, + int thickness, GenericBitmap *pBackground, + int nbImages, VarBool *pVisible, const UString &rHelp ): CtrlGeneric( pIntf, rHelp, pVisible ), m_rCursor( rCursor ), m_rVariable( rVariable ), m_thickness( thickness ), m_rCurve( rCurve ), - m_width( rCurve.getWidth() ), m_height( rCurve.getHeight() ) + m_width( rCurve.getWidth() ), m_height( rCurve.getHeight() ), + m_pImgSeq( NULL ), m_nbImages( nbImages ), m_bgWidth( 0 ), + m_bgHeight( 0 ), m_position( 0 ) { + if( pBackground ) + { + // Build the background image sequence + OSFactory *pOsFactory = OSFactory::instance( getIntf() ); + m_pImgSeq = pOsFactory->createOSGraphics( pBackground->getWidth(), + pBackground->getHeight() ); + m_pImgSeq->drawBitmap( *pBackground, 0, 0 ); + + m_bgWidth = pBackground->getWidth(); + m_bgHeight = pBackground->getHeight() / nbImages; + + // Observe the position variable + m_rVariable.addObserver( this ); + + // Initial position + m_position = (int)( m_rVariable.get() * (m_nbImages - 1) ); + } +} + + +CtrlSliderBg::~CtrlSliderBg() +{ + m_rVariable.delObserver( this ); + delete m_pImgSeq; } @@ -355,6 +382,18 @@ bool CtrlSliderBg::mouseOver( int x, int y ) const } +void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest ) +{ + if( m_pImgSeq ) + { + // Draw the background image + // XXX the "-3" is a hack for winamp skins... + rImage.drawGraphics( *m_pImgSeq, 0, m_position * m_bgHeight, + xDest, yDest, m_bgWidth, m_bgHeight - 3); + } +} + + void CtrlSliderBg::handleEvent( EvtGeneric &rEvent ) { if( rEvent.getAsString().find( "mouse:left:down" ) != string::npos ) @@ -404,6 +443,13 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent ) } +void CtrlSliderBg::onUpdate( Subject &rVariable ) +{ + m_position = (int)( m_rVariable.get() * (m_nbImages - 1) ); + notifyLayout( m_bgWidth, m_bgHeight ); +} + + void CtrlSliderBg::getResizeFactors( float &rFactorX, float &rFactorY ) const { // Get the position of the control diff --git a/modules/gui/skins2/controls/ctrl_slider.hpp b/modules/gui/skins2/controls/ctrl_slider.hpp index 5b082eef28..3188d51aec 100644 --- a/modules/gui/skins2/controls/ctrl_slider.hpp +++ b/modules/gui/skins2/controls/ctrl_slider.hpp @@ -106,17 +106,21 @@ class CtrlSliderCursor: public CtrlGeneric, public Observer /// Slider background -class CtrlSliderBg: public CtrlGeneric +class CtrlSliderBg: public CtrlGeneric, public Observer { public: CtrlSliderBg( intf_thread_t *pIntf, CtrlSliderCursor &rCursor, const Bezier &rCurve, VarPercent &rVariable, - int thickness, VarBool *pVisible, const UString &rHelp ); - virtual ~CtrlSliderBg() {} + int thickness, GenericBitmap *pBackground, int nbImages, + VarBool *pVisible, const UString &rHelp ); + virtual ~CtrlSliderBg(); /// Tell whether the mouse is over the control virtual bool mouseOver( int x, int y ) const; + /// Draw the control on the given graphics + virtual void draw( OSGraphics &rImage, int xDest, int yDest ); + /// Handle an event virtual void handleEvent( EvtGeneric &rEvent ); @@ -134,6 +138,17 @@ class CtrlSliderBg: public CtrlGeneric const Bezier &m_rCurve; /// Initial size of the control int m_width, m_height; + /// Background image sequence (optional) + OSGraphics *m_pImgSeq; + /// Number of images in the background bitmap + int m_nbImages; + /// Size of a background image + int m_bgWidth, m_bgHeight; + /// Index of the current background image + int m_position; + + /// Method called when the observed variable is modified + virtual void onUpdate( Subject &rVariable ); /// Methode to compute the resize factors void getResizeFactors( float &rFactorX, float &rFactorY ) const; diff --git a/modules/gui/skins2/parser/builder.cpp b/modules/gui/skins2/parser/builder.cpp index 22ef1deb13..22933ee2a3 100644 --- a/modules/gui/skins2/parser/builder.cpp +++ b/modules/gui/skins2/parser/builder.cpp @@ -161,11 +161,6 @@ 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 = @@ -563,6 +558,12 @@ void Builder::addSlider( const BuilderData::Slider &rData ) GenericBitmap *pBmpOver = pBmpUp; GET_BMP( pBmpOver, rData.m_overId ); + GenericBitmap *pBgImage = NULL; + if( rData.m_background != "none" ) + { + GET_BMP( pBgImage, rData.m_background ); + } + GenericLayout *pLayout = m_pTheme->getLayoutById(rData.m_layoutId); if( pLayout == NULL ) { @@ -599,8 +600,8 @@ void Builder::addSlider( const BuilderData::Slider &rData ) UString( getIntf(), rData.m_help.c_str() ) ); CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(), *pCursor, - *pCurve, *pVar, rData.m_thickness, pVisible, - UString( getIntf(), rData.m_help.c_str() ) ); + *pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbImages, + pVisible, UString( getIntf(), rData.m_help.c_str() ) ); // Compute the position of the control const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, diff --git a/modules/gui/skins2/parser/builder_data.def b/modules/gui/skins2/parser/builder_data.def index 0c7a7d0cbf..5e884b012f 100644 --- a/modules/gui/skins2/parser/builder_data.def +++ b/modules/gui/skins2/parser/builder_data.def @@ -11,7 +11,7 @@ Checkbox id:string xPos:int yPos:int leftTop:string rightBottom:string visible:s Image id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string bmpId:string actionId:string resize:string help:string layer:int windowId:string layoutId:string Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string color:uint32_t help:string layer:int windowId:string layoutId:string RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string sequence:string nbImages:int minAngle:float maxAngle:float value:string tooltip:string help:string layer:int windowId:string layoutId:string -Slider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string upId:string downId:string overId:string points:string thickness:int value:string tooltip:string help:string layer:int windowId:string layoutId:string +Slider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string upId:string downId:string overId:string points:string thickness:int value:string background:string nbImages:int tooltip:string help:string layer:int windowId:string layoutId:string List id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string fgColor:uint32_t playColor:uint32_t bgColor1:uint32_t bgColor2:uint32_t selColor:uint32_t help:string layer:int windowId:string layoutId:string Tree id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string itemImageId:string openImageId:string closedImageId:string fgColor:uint32_t playColor:uint32_t bgColor1:uint32_t bgColor2:uint32_t selColor:uint32_t help:string layer:int windowId:string layoutId:string Video id:string xPos:int yPos:int width:int height:int leftTop:string rightBottom:string visible:string autoResize:bool help:string layer:int windowId:string layoutId:string diff --git a/modules/gui/skins2/parser/builder_data.hpp b/modules/gui/skins2/parser/builder_data.hpp index 04e5bc27c0..3562660af1 100644 --- a/modules/gui/skins2/parser/builder_data.hpp +++ b/modules/gui/skins2/parser/builder_data.hpp @@ -290,8 +290,8 @@ m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( lef /// Type definition struct Slider { - Slider( const string & id, const string & visible, int xPos, int yPos, const string & leftTop, const string & rightBottom, const string & upId, const string & downId, const string & overId, const string & points, int thickness, const string & value, const string & tooltip, const string & help, int layer, const string & windowId, const string & layoutId ): -m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_upId( upId ), m_downId( downId ), m_overId( overId ), m_points( points ), m_thickness( thickness ), m_value( value ), m_tooltip( tooltip ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {} + Slider( const string & id, const string & visible, int xPos, int yPos, const string & leftTop, const string & rightBottom, const string & upId, const string & downId, const string & overId, const string & points, int thickness, const string & value, const string & background, int nbImages, const string & tooltip, const string & help, int layer, const string & windowId, const string & layoutId ): +m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_upId( upId ), m_downId( downId ), m_overId( overId ), m_points( points ), m_thickness( thickness ), m_value( value ), m_background( background ), m_nbImages( nbImages ), m_tooltip( tooltip ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {} const string m_id; const string m_visible; @@ -305,6 +305,8 @@ m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( lef const string m_points; int m_thickness; const string m_value; + const string m_background; + int m_nbImages; const string m_tooltip; const string m_help; int m_layer; diff --git a/modules/gui/skins2/parser/skin_parser.cpp b/modules/gui/skins2/parser/skin_parser.cpp index 8796238ecd..0b56b860eb 100644 --- a/modules/gui/skins2/parser/skin_parser.cpp +++ b/modules/gui/skins2/parser/skin_parser.cpp @@ -339,6 +339,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) CheckDefault( "over", "none" ); CheckDefault( "thickness", "10" ); CheckDefault( "value", "none" ); + CheckDefault( "background", "none" ); + CheckDefault( "nbimages", "1" ); CheckDefault( "tooltiptext", "" ); CheckDefault( "help", "" ); @@ -358,7 +360,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["lefttop"], attr["rightbottom"], attr["up"], attr["down"], attr["over"], attr["points"], atoi( attr["thickness"] ), - newValue, attr["tooltiptext"], attr["help"], m_curLayer, + newValue, attr["background"], atoi( attr["nbimages"] ), + attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId, m_curLayoutId ); m_curLayer++; m_data.m_listSlider.push_back( slider ); diff --git a/modules/gui/skins2/src/theme_loader.cpp b/modules/gui/skins2/src/theme_loader.cpp index e809c35771..69f993d4c2 100644 --- a/modules/gui/skins2/src/theme_loader.cpp +++ b/modules/gui/skins2/src/theme_loader.cpp @@ -195,6 +195,13 @@ bool ThemeLoader::extractFileInZip( unzFile file, const string &rootDir ) return false; } + // Convert the file name to lower case, because some winamp skins + // use the wrong case... + for( int i=0; i< strlen( filenameInZip ); i++) + { + filenameInZip[i] = tolower( filenameInZip[i] ); + } + // Allocate the buffer void *pBuffer = malloc( ZIP_BUFFER_SIZE ); if( !pBuffer ) diff --git a/share/skins2/skin.dtd b/share/skins2/skin.dtd index bed5dbf624..80b970b84e 100644 --- a/share/skins2/skin.dtd +++ b/share/skins2/skin.dtd @@ -132,7 +132,7 @@ tooltiptext2 CDATA "" help CDATA "" > - + diff --git a/share/skins2/winamp2.xml b/share/skins2/winamp2.xml index 707a7a9463..9772a4088e 100644 --- a/share/skins2/winamp2.xml +++ b/share/skins2/winamp2.xml @@ -1,7 +1,7 @@ - + @@ -38,7 +38,7 @@ - + @@ -52,8 +52,7 @@ - - +