}
-CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf, CtrlSliderCursor &rCursor,
+CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf,
const Bezier &rCurve, VarPercent &rVariable,
int thickness, GenericBitmap *pBackground,
int nbHoriz, int nbVert, int padHoriz, int padVert,
VarBool *pVisible, const UString &rHelp ):
- CtrlGeneric( pIntf, rHelp, pVisible ), m_rCursor( rCursor ),
+ CtrlGeneric( pIntf, rHelp, pVisible ),
m_rVariable( rVariable ), m_thickness( thickness ), m_rCurve( rCurve ),
m_width( rCurve.getWidth() ), m_height( rCurve.getHeight() ),
m_pImgSeq( NULL ), m_nbHoriz( nbHoriz ), m_nbVert( nbVert ),
// Forward the clic to the cursor
EvtMouse evt( getIntf(), x, y, EvtMouse::kLeft, EvtMouse::kDown );
TopWindow *pWin = getWindow();
- if( pWin )
+ if( pWin && m_pCursor )
{
EvtEnter evtEnter( getIntf() );
// XXX It was not supposed to be implemented like that !!
- pWin->forwardEvent( evtEnter, m_rCursor );
- pWin->forwardEvent( evt, m_rCursor );
+ pWin->forwardEvent( evtEnter, *m_pCursor );
+ pWin->forwardEvent( evt, *m_pCursor );
}
}
else if( rEvent.getAsString().find( "scroll" ) != string::npos )
}
+void CtrlSliderBg::associateCursor( CtrlSliderCursor &rCursor )
+{
+ m_pCursor = &rCursor;
+}
+
+
void CtrlSliderBg::onUpdate( Subject<VarPercent> &rVariable )
{
m_position = (int)( m_rVariable.get() * (m_nbHoriz * m_nbVert - 1) );
class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
{
public:
- CtrlSliderBg( intf_thread_t *pIntf, CtrlSliderCursor &rCursor,
+ CtrlSliderBg( intf_thread_t *pIntf,
const Bezier &rCurve, VarPercent &rVariable,
int thickness, GenericBitmap *pBackground, int nbHoriz,
int nbVert, int padHoriz, int padVert, VarBool *pVisible,
/// Get the type of control (custom RTTI)
virtual string getType() const { return "slider_bg"; }
+ /// Associate a cursor to this background
+ void associateCursor( CtrlSliderCursor &rCursor );
+
private:
/// Cursor of the slider
- CtrlSliderCursor &m_rCursor;
+ CtrlSliderCursor *m_pCursor;
/// Variable associated to the slider
VarPercent &m_rVariable;
/// Thickness of the curve
void Builder::addSlider( const BuilderData::Slider &rData )
{
- // Get the bitmaps of the slider
- GenericBitmap *pBmpUp = NULL;
- GET_BMP( pBmpUp, rData.m_upId );
-
- GenericBitmap *pBmpDown = pBmpUp;
- GET_BMP( pBmpDown, rData.m_downId );
-
- GenericBitmap *pBmpOver = pBmpUp;
- GET_BMP( pBmpOver, rData.m_overId );
+ // Add the background first, so that we will still have something almost
+ // functional if the cursor cannot be created properly (this happens for
+ // some winamp2 skins, where the images of the cursor are not always
+ // present)
+ // Get the bitmaps of the background
GenericBitmap *pBgImage = NULL;
if( rData.m_imageId != "none" )
{
return;
}
- // Create the cursor and background controls
- CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
- *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
- UString( getIntf(), rData.m_tooltip.c_str() ),
- UString( getIntf(), rData.m_help.c_str() ) );
-
- CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(), *pCursor,
+ // Create the background control
+ CtrlSliderBg *pBackground = new CtrlSliderBg( getIntf(),
*pCurve, *pVar, rData.m_thickness, pBgImage, rData.m_nbHoriz,
rData.m_nbVert, rData.m_padHoriz, rData.m_padVert,
pVisible, UString( getIntf(), rData.m_help.c_str() ) );
*pLayout );
pLayout->addControl( pBackground, pos, rData.m_layer );
+
+ m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
+
+ // Get the bitmaps of the cursor
+ GenericBitmap *pBmpUp = NULL;
+ GET_BMP( pBmpUp, rData.m_upId );
+
+ GenericBitmap *pBmpDown = pBmpUp;
+ GET_BMP( pBmpDown, rData.m_downId );
+
+ GenericBitmap *pBmpOver = pBmpUp;
+ GET_BMP( pBmpOver, rData.m_overId );
+
+ // Create the cursor control
+ CtrlSliderCursor *pCursor = new CtrlSliderCursor( getIntf(), *pBmpUp,
+ *pBmpOver, *pBmpDown, *pCurve, *pVar, pVisible,
+ UString( getIntf(), rData.m_tooltip.c_str() ),
+ UString( getIntf(), rData.m_help.c_str() ) );
+
pLayout->addControl( pCursor, pos, rData.m_layer );
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pCursor );
- m_pTheme->m_controls[rData.m_id + "_bg"] = CtrlGenericPtr( pBackground );
+
+ // Associate the cursor to the background
+ pBackground->associateCursor( *pCursor );
}