]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/controls/ctrl_list.cpp
That's safe to delete NULL.
[vlc] / modules / gui / skins2 / controls / ctrl_list.cpp
index 50fee9217ee8f94a71241cb25382074fc52dbf87..c0dc427ef23df4080a1b56fcf5d4a9e54f68a19a 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * ctrl_list.cpp
  *****************************************************************************
- * Copyright (C) 2003 VideoLAN
+ * Copyright (C) 2003 the VideoLAN team
  * $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 <math.h>
@@ -28,6 +28,7 @@
 #include "../src/os_graphics.hpp"
 #include "../src/generic_bitmap.hpp"
 #include "../src/generic_font.hpp"
+#include "../src/scaled_bitmap.hpp"
 #include "../utils/position.hpp"
 #include "../utils/ustring.hpp"
 #include "../events/evt_key.hpp"
 #   include "solaris_specific.h" // for lrint
 #endif
 
-#define SCROLL_STEP 0.05
+#define SCROLL_STEP 0.05f
 #define LINE_INTERVAL 1  // Number of pixels inserted between 2 lines
 
 
-CtrlList::CtrlList( intf_thread_t *pIntf, VarList &rList, GenericFont &rFont,
+CtrlList::CtrlList( intf_thread_t *pIntf, VarList &rList,
+                    const GenericFont &rFont, const GenericBitmap *pBitmap,
                     uint32_t fgColor, uint32_t playColor, uint32_t bgColor1,
                     uint32_t bgColor2, uint32_t selColor,
                     const UString &rHelp, VarBool *pVisible ):
     CtrlGeneric( pIntf, rHelp, pVisible ), m_rList( rList ), m_rFont( rFont ),
-    m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ),
-    m_bgColor2( bgColor2 ), m_selColor( selColor ), m_pLastSelected( NULL ),
-    m_pImage( NULL ), m_lastPos( 0 )
+    m_pBitmap( pBitmap ), m_fgColor( fgColor ), m_playColor( playColor ),
+    m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ),
+    m_pLastSelected( NULL ), m_pImage( NULL ), m_lastPos( 0 )
 {
     // Observe the list and position variables
     m_rList.addObserver( this );
@@ -63,21 +65,18 @@ CtrlList::~CtrlList()
 {
     m_rList.getPositionVar().delObserver( this );
     m_rList.delObserver( this );
-    if( m_pImage )
-    {
-        delete m_pImage;
-    }
+    delete m_pImage;
 }
 
 
-void CtrlList::onUpdate( Subject<VarList> &rList )
+void CtrlList::onUpdate( Subject<VarList> &rList, void *arg  )
 {
     autoScroll();
     m_pLastSelected = NULL;
 }
 
 
-void CtrlList::onUpdate( Subject<VarPercent> &rPercent )
+void CtrlList::onUpdate( Subject<VarPercent> &rPercent, void *arg  )
 {
     // Get the size of the control
     const Position *pPos = getPosition();
@@ -330,13 +329,14 @@ void CtrlList::handleEvent( EvtGeneric &rEvent )
         int direction = ((EvtScroll&)rEvent).getDirection();
 
         double percentage = m_rList.getPositionVar().get();
+        double step = 2.0 / (double)m_rList.size();
         if( direction == EvtScroll::kUp )
         {
-            percentage += SCROLL_STEP;
+            percentage += step;
         }
         else
         {
-            percentage -= SCROLL_STEP;
+            percentage -= step;
         }
         m_rList.getPositionVar().set( percentage );
     }
@@ -408,10 +408,7 @@ void CtrlList::autoScroll()
 
 void CtrlList::makeImage()
 {
-    if( m_pImage )
-    {
-        delete m_pImage;
-    }
+    delete m_pImage;
 
     // Get the size of the control
     const Position *pPos = getPosition();
@@ -427,34 +424,60 @@ void CtrlList::makeImage()
     OSFactory *pOsFactory = OSFactory::instance( getIntf() );
     m_pImage = pOsFactory->createOSGraphics( width, height );
 
-    // Current background color
-    uint32_t bgColor = m_bgColor1;
+    VarList::ConstIterator it = m_rList[m_lastPos];
 
     // Draw the background
-    VarList::ConstIterator it = m_rList[m_lastPos];
-    for( int yPos = 0; yPos < height; yPos += itemHeight )
+    if( m_pBitmap )
     {
-        int rectHeight = __MIN( itemHeight, height - yPos );
-        if( it != m_rList.end() )
+        // A background bitmap is given, so we scale it, ignoring the
+        // background colors
+        ScaledBitmap bmp( getIntf(), *m_pBitmap, width, height );
+        m_pImage->drawBitmap( bmp, 0, 0 );
+
+        // Take care of the selection color
+        for( int yPos = 0; yPos < height; yPos += itemHeight )
         {
-            uint32_t color = ( (*it).m_selected ? m_selColor : bgColor );
-            m_pImage->fillRect( 0, yPos, width, rectHeight, color );
-            it++;
+            int rectHeight = __MIN( itemHeight, height - yPos );
+            if( it != m_rList.end() )
+            {
+                if( (*it).m_selected )
+                {
+                    m_pImage->fillRect( 0, yPos, width, rectHeight,
+                                        m_selColor );
+                }
+                it++;
+            }
         }
-        else
+    }
+    else
+    {
+        // No background bitmap, so use the 2 background colors
+        // Current background color
+        uint32_t bgColor = m_bgColor1;
+        for( int yPos = 0; yPos < height; yPos += itemHeight )
         {
-            m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor );
+            int rectHeight = __MIN( itemHeight, height - yPos );
+            if( it != m_rList.end() )
+            {
+                uint32_t color = ( (*it).m_selected ? m_selColor : bgColor );
+                m_pImage->fillRect( 0, yPos, width, rectHeight, color );
+                it++;
+            }
+            else
+            {
+                m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor );
+            }
+            // Flip the background color
+            bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 );
         }
-        // Flip the background color
-        bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 );
     }
 
     // Draw the items
     int yPos = 0;
     for( it = m_rList[m_lastPos]; it != m_rList.end() && yPos < height; it++ )
     {
-        UString *pStr = (UString*)((*it).m_cString.get());
-        uint32_t color = ( (*it).m_playing ? m_playColor : m_fgColor );
+        UString *pStr = (UString*)(it->m_cString.get());
+        uint32_t color = ( it->m_playing ? m_playColor : m_fgColor );
 
         // Draw the text
         GenericBitmap *pText = m_rFont.drawString( *pStr, color, width );