Commit e0352f91 authored by Cyril Deguet's avatar Cyril Deguet

* 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
parent cfe22e54
......@@ -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<VarPercent> &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
......
......@@ -106,17 +106,21 @@ class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
/// Slider background
class CtrlSliderBg: public CtrlGeneric
class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
{
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<VarPercent> &rVariable );
/// Methode to compute the resize factors
void getResizeFactors( float &rFactorX, float &rFactorY ) const;
......
......@@ -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,
......
......@@ -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
......@@ -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;
......
......@@ -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 );
......
......@@ -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 )
......
......@@ -132,7 +132,7 @@
tooltiptext2 CDATA ""
help CDATA ""
>
<!ELEMENT Slider EMPTY>
<!ELEMENT Slider (SliderBackground)?>
<!ATTLIST Slider
id CDATA "none"
visible CDATA "true"
......@@ -146,6 +146,8 @@
points CDATA #REQUIRED
thickness CDATA "10"
value CDATA "none"
background CDATA "none"
nbimages CDATA "1"
tooltiptext CDATA ""
help CDATA ""
>
......
<!DOCTYPE Theme PUBLIC "-//VideoLAN//DTD VLC Skins V2.0//EN" "skins.dtd">
<Theme version="2.0" magnet="9" alpha="255">
<ThemeInfo name="Winamp2" author="Cyril Deguet"/>
<ThemeInfo name="Winamp2" author="See README.txt in the skin file"/>
<Bitmap id="main" file="main.bmp" alphacolor="#FF0000" />
<Bitmap id="cbuttons" file="cbuttons.bmp" alphacolor="#FF0000">
......@@ -38,7 +38,7 @@
<SubBitmap id="shuffle_down" x="28" y="45" width="47" height="15" />
</Bitmap>
<Bitmap id="volume" file="volume.bmp" alphacolor="#FF0000">
<SubBitmap id="volume_bg" x="0" y="405" width="68" height="13" />
<SubBitmap id="volume_bg" x="0" y="0" width="68" height="420" />
<SubBitmap id="volume_up" x="15" y="422" width="14" height="11" />
<SubBitmap id="volume_down" x="0" y="422" width="14" height="11" />
</Bitmap>
......@@ -52,8 +52,7 @@
<Image x="0" y="0" image="main" action="move" />
<Text font="digits_font" x="30" y="26" width="75" text="$T"/>
<Text font="text_font" x="111" y="27" width="155" text="$N"/>
<Image x="107" y="57" image="volume_bg"/>
<Slider value="volume" up="volume_up" down="volume_down" points="(114,63),(165,63)" tooltiptext="Volume: $V%" />
<Slider value="volume" x="107" y="57" up="volume_up" down="volume_down" points="(7,6),(58,6)" background="volume_bg" nbimages="28" tooltiptext="Volume: $V%" />
<Image x="15" y="72" image="time_bg"/>
<Slider value="time" up="time_up" down="time_down" points="(30,78),(250,78)" thickness="5" tooltiptext="Time: $T"/>
<Button x="263" y="3" up="quit_up" down="quit_down" over="quit_up" action="vlc.quit()" tooltiptext="Quit" />
......
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