]> git.sesse.net Git - vlc/commitdiff
* skins2/parser/builder.cpp: create the background part of the slider, even if
authorOlivier Teulière <ipkiss@videolan.org>
Sat, 12 Nov 2005 18:11:12 +0000 (18:11 +0000)
committerOlivier Teulière <ipkiss@videolan.org>
Sat, 12 Nov 2005 18:11:12 +0000 (18:11 +0000)
   the cursor cannot be created. This allows using the slider in some winamp
   skins which do not use cursors.

modules/gui/skins2/controls/ctrl_slider.cpp
modules/gui/skins2/controls/ctrl_slider.hpp
modules/gui/skins2/parser/builder.cpp

index 57d9c062e79a4bf685bc86b17d5e7cf9490917fa..251c4a264f78a461f1499ec6320f0cf8ee7cf505 100644 (file)
@@ -332,12 +332,12 @@ void CtrlSliderCursor::getResizeFactors( float &rFactorX,
 }
 
 
-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 ),
@@ -418,12 +418,12 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
         // 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 )
@@ -445,6 +445,12 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
 }
 
 
+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) );
index c97252ee2b7a4be29d59c9538b776eb68578ae00..d0d5e6a9d6eb0a34dd25d92108ec6aa8345f4f9b 100644 (file)
@@ -109,7 +109,7 @@ class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
 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,
@@ -128,9 +128,12 @@ class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
         /// 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
index 40ed59d75ca3d70b2c6e645521ca79f74d9714ae..8e1cce8820e46ce7e748574aec2a9ac2e1d03eb0 100644 (file)
@@ -580,16 +580,12 @@ void Builder::addRadialSlider( const BuilderData::RadialSlider &rData )
 
 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" )
     {
@@ -625,13 +621,8 @@ void Builder::addSlider( const BuilderData::Slider &rData )
         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() ) );
@@ -643,10 +634,31 @@ void Builder::addSlider( const BuilderData::Slider &rData )
                                        *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 );
 }