]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/controls/ctrl_slider.cpp
Qt4 - Typo correction.
[vlc] / modules / gui / skins2 / controls / ctrl_slider.cpp
index 1973d5f2abccca131ac57102e166e3cde2b29609..b7c982926e454b61db8b8c819fa185da7bbe3946 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "ctrl_slider.hpp"
@@ -27,6 +27,7 @@
 #include "../events/evt_mouse.hpp"
 #include "../events/evt_scroll.hpp"
 #include "../src/generic_bitmap.hpp"
+#include "../src/scaled_bitmap.hpp"
 #include "../src/top_window.hpp"
 #include "../src/os_factory.hpp"
 #include "../src/os_graphics.hpp"
@@ -159,7 +160,8 @@ void CtrlSliderCursor::draw( OSGraphics &rImage, int xDest, int yDest )
 }
 
 
-void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable )
+void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable,
+                                 void *arg  )
 {
     // The position has changed
     refreshLayout();
@@ -314,18 +316,18 @@ CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf,
     CtrlGeneric( pIntf, rHelp, pVisible ), m_pCursor( NULL ),
     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 ),
+    m_pImgSeq( pBackground ), m_nbHoriz( nbHoriz ), m_nbVert( nbVert ),
     m_padHoriz( padHoriz ), m_padVert( padVert ), 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 );
-
+        // Note: we suppose that the last padding is not included in the
+        // given image
+        // TODO: we should probably change this assumption, as it would make
+        // the code a bit simpler and it would be more natural for the skins
+        // designers
         m_bgWidth = (pBackground->getWidth() + m_padHoriz) / nbHoriz;
         m_bgHeight = (pBackground->getHeight() + m_padVert) / nbVert;
 
@@ -341,7 +343,6 @@ CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf,
 CtrlSliderBg::~CtrlSliderBg()
 {
     m_rVariable.delObserver( this );
-    delete m_pImgSeq;
 }
 
 
@@ -360,12 +361,25 @@ void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest )
 {
     if( m_pImgSeq )
     {
-        // Locate the right image in the background bitmap
-        int x = m_bgWidth * ( m_position % m_nbHoriz );
-        int y = m_bgHeight * ( m_position / m_nbHoriz );
-        // Draw the background image
-        rImage.drawGraphics( *m_pImgSeq, x, y, xDest, yDest,
-                             m_bgWidth - m_padHoriz, m_bgHeight - m_padVert );
+        if( m_bgWidth > 0 && m_bgHeight > 0 )
+        {
+            // Compute the resize factors
+            float factorX, factorY;
+            getResizeFactors( factorX, factorY );
+
+            // Rescale the image with the actual size of the control
+            ScaledBitmap bmp( getIntf(), *m_pImgSeq,
+                 m_bgWidth * m_nbHoriz - (int)(m_padHoriz * factorX),
+                 m_bgHeight * m_nbVert - (int)(m_padVert * factorY) );
+
+            // Locate the right image in the background bitmap
+            int x = m_bgWidth * ( m_position % m_nbHoriz );
+            int y = m_bgHeight * ( m_position / m_nbHoriz );
+            // Draw the background image
+            rImage.drawBitmap( bmp, x, y, xDest, yDest,
+                               m_bgWidth - (int)(m_padHoriz * factorX),
+                               m_bgHeight - (int)(m_padVert * factorY) );
+        }
     }
 }
 
@@ -419,13 +433,31 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
 }
 
 
+void CtrlSliderBg::onResize()
+{
+    if( m_pImgSeq )
+    {
+        // Compute only the new size of an elementary image.
+        // The actual resizing is done in the draw() method for now...
+
+        // Compute the resize factors
+        float factorX, factorY;
+        getResizeFactors( factorX, factorY );
+
+        // Size of one elementary background image (padding included)
+        m_bgWidth = (int)((m_pImgSeq->getWidth() + m_padHoriz) * factorX / m_nbHoriz);
+        m_bgHeight = (int)((m_pImgSeq->getHeight() + m_padVert) * factorY / m_nbVert);
+    }
+}
+
+
 void CtrlSliderBg::associateCursor( CtrlSliderCursor &rCursor )
 {
     m_pCursor = &rCursor;
 }
 
 
-void CtrlSliderBg::onUpdate( Subject<VarPercent> &rVariable )
+void CtrlSliderBg::onUpdate( Subject<VarPercent> &rVariable, void*arg )
 {
     m_position = (int)( m_rVariable.get() * (m_nbHoriz * m_nbVert - 1) );
     notifyLayout( m_bgWidth, m_bgHeight );