]> git.sesse.net Git - vlc/commitdiff
Skins2: Mostly cosmetics, some C++ style casting, factor out a scroll() in anticipati...
authorJP Dinger <jpd@videolan.org>
Sun, 22 Nov 2009 15:34:36 +0000 (16:34 +0100)
committerJP Dinger <jpd@videolan.org>
Sat, 5 Dec 2009 21:25:42 +0000 (22:25 +0100)
modules/gui/skins2/controls/ctrl_image.cpp
modules/gui/skins2/controls/ctrl_radialslider.cpp
modules/gui/skins2/controls/ctrl_resize.cpp
modules/gui/skins2/controls/ctrl_slider.cpp
modules/gui/skins2/controls/ctrl_tree.cpp

index 854fab67bf55008404b5c2dfc85ed9e5f694f419..f705cbe789fbf13e889faaf82f9e041ed6191fc6 100644 (file)
@@ -37,10 +37,9 @@ CtrlImage::CtrlImage( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
     CtrlFlat( pIntf, rHelp, pVisible ), m_rBitmap( rBitmap ),
     m_rCommand( rCommand ), m_resizeMethod( resizeMethod )
 {
-    OSFactory *pOsFactory = OSFactory::instance( pIntf );
     // Create an initial unscaled image in the buffer
-    m_pImage = pOsFactory->createOSGraphics( rBitmap.getWidth(),
-                                             rBitmap.getHeight() );
+    m_pImage = OSFactory::instance( pIntf )->createOSGraphics(
+                                    rBitmap.getWidth(), rBitmap.getHeight() );
     m_pImage->drawBitmap( m_rBitmap );
 }
 
@@ -56,13 +55,11 @@ void CtrlImage::handleEvent( EvtGeneric &rEvent )
     // No FSM for this simple transition
     if( rEvent.getAsString() == "mouse:right:up:none" )
     {
-        CmdDlgShowPopupMenu cmd( getIntf() );
-        cmd.execute();
+        CmdDlgShowPopupMenu( getIntf() ).execute();
     }
     else if( rEvent.getAsString() == "mouse:left:up:none" )
     {
-        CmdDlgHidePopupMenu cmd( getIntf() );
-        cmd.execute();
+        CmdDlgHidePopupMenu( getIntf() ).execute();
     }
     else if( rEvent.getAsString() == "mouse:left:dblclick:none" )
     {
@@ -79,13 +76,10 @@ bool CtrlImage::mouseOver( int x, int y ) const
     {
         // In mosaic mode, convert the coordinates to make them fit to the
         // size of the original image
-        return m_pImage->hit( x % m_pImage->getWidth(),
-                              y % m_pImage->getHeight() );
-    }
-    else
-    {
-        return m_pImage->hit( x, y );
+        x %= m_pImage->getWidth();
+        y %= m_pImage->getHeight();
     }
+    return m_pImage->hit( x, y );
 }
 
 
index de0eeec823958de9d4d0921c260075c256c670a1..6aece647d9d86db9777c178fba071aa020185998 100644 (file)
@@ -44,9 +44,8 @@ CtrlRadialSlider::CtrlRadialSlider( intf_thread_t *pIntf,
     m_cmdMove( this )
 {
     // Build the images of the sequence
-    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
-    m_pImgSeq = pOsFactory->createOSGraphics( rBmpSeq.getWidth(),
-                                              rBmpSeq.getHeight() );
+    m_pImgSeq = OSFactory::instance( getIntf() )->createOSGraphics(
+                                     rBmpSeq.getWidth(), rBmpSeq.getHeight() );
     m_pImgSeq->drawBitmap( rBmpSeq, 0, 0 );
 
     m_width = rBmpSeq.getWidth();
@@ -125,7 +124,7 @@ void CtrlRadialSlider::CmdDownUp::execute()
 
 void CtrlRadialSlider::CmdMove::execute()
 {
-    EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
+    EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
 
     // Change the position of the cursor, in blocking mode
     m_pParent->setCursor( pEvtMouse->getXPos(), pEvtMouse->getYPos(), true );
index 7e5965563e603d08eebbf92f930d661068b99d44..5cd70702f80377a9ae3cb1285aa6a8b7ccc47d6a 100644 (file)
@@ -17,9 +17,9 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "ctrl_resize.hpp"
@@ -113,15 +113,16 @@ void CtrlResize::handleEvent( EvtGeneric &rEvent )
 
 void CtrlResize::changeCursor( WindowManager::Direction_t direction ) const
 {
-    OSFactory *pOsFactory = OSFactory::instance( getIntf() );
-    if( direction == WindowManager::kResizeSE )
-        pOsFactory->changeCursor( OSFactory::kResizeNWSE );
-    else if( direction == WindowManager::kResizeS )
-        pOsFactory->changeCursor( OSFactory::kResizeNS );
-    else if( direction == WindowManager::kResizeE )
-        pOsFactory->changeCursor( OSFactory::kResizeWE );
-    else if( direction == WindowManager::kNone )
-        pOsFactory->changeCursor( OSFactory::kDefaultArrow );
+    OSFactory::CursorType_t cursor;
+    switch( direction )
+    {
+    default:
+    case WindowManager::kNone:     cursor = OSFactory::kDefaultArrow; break;
+    case WindowManager::kResizeSE: cursor = OSFactory::kResizeNWSE;   break;
+    case WindowManager::kResizeS:  cursor = OSFactory::kResizeNS;     break;
+    case WindowManager::kResizeE:  cursor = OSFactory::kResizeWE;     break;
+    }
+    OSFactory::instance( getIntf() )->changeCursor( cursor );
 }
 
 
@@ -145,7 +146,7 @@ void CtrlResize::CmdStillStill::execute()
 
 void CtrlResize::CmdStillResize::execute()
 {
-    EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
+    EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
 
     // Set the cursor
     m_pParent->changeCursor( m_pParent->m_direction );
@@ -176,9 +177,8 @@ void CtrlResize::CmdResizeStill::execute()
 
 void CtrlResize::CmdResizeResize::execute()
 {
-    EvtMotion *pEvtMotion = (EvtMotion*)m_pParent->m_pEvt;
+    EvtMotion *pEvtMotion = static_cast<EvtMotion*>(m_pParent->m_pEvt);
 
-    // Set the cursor
     m_pParent->changeCursor( m_pParent->m_direction );
 
     int newWidth = m_pParent->m_width;
@@ -194,6 +194,5 @@ void CtrlResize::CmdResizeResize::execute()
                                       m_pParent->m_rLayout,
                                       newWidth, newHeight );
     // Push the command in the asynchronous command queue
-    AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
-    pQueue->push( CmdGenericPtr( pCmd ) );
+    AsyncQueue::instance( getIntf() )->push( CmdGenericPtr( pCmd ) );
 }
index 6b1883b91ce61998c6c7c43c60b4f216c960dc94..995cf7521ad7c4c490f14cd2364bcb58a1d7aca2 100644 (file)
@@ -17,9 +17,9 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "ctrl_slider.hpp"
 #define RANGE 40
 #define SCROLL_STEP 0.05f
 
+static inline float scroll( bool up, float pct )
+{
+    return pct + (up? SCROLL_STEP : -SCROLL_STEP);
+}
+
 
 CtrlSliderCursor::CtrlSliderCursor( intf_thread_t *pIntf,
                                     const GenericBitmap &rBmpUp,
@@ -170,7 +175,7 @@ void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable,
 
 void CtrlSliderCursor::CmdOverDown::execute()
 {
-    EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
+    EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
 
     // Compute the resize factors
     float factorX, factorY;
@@ -220,7 +225,7 @@ void CtrlSliderCursor::CmdOverUp::execute()
 
 void CtrlSliderCursor::CmdMove::execute()
 {
-    EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
+    EvtMouse *pEvtMouse = static_cast<EvtMouse*>(m_pParent->m_pEvt);
 
     // Get the position of the control
     const Position *pPos = m_pParent->getPosition();
@@ -251,21 +256,10 @@ void CtrlSliderCursor::CmdMove::execute()
 
 void CtrlSliderCursor::CmdScroll::execute()
 {
-    EvtScroll *pEvtScroll = (EvtScroll*)m_pParent->m_pEvt;
-
-    int direction = pEvtScroll->getDirection();
-
-    float percentage = m_pParent->m_rVariable.get();
-    if( direction == EvtScroll::kUp )
-    {
-        percentage += SCROLL_STEP;
-    }
-    else
-    {
-        percentage -= SCROLL_STEP;
-    }
-
-    m_pParent->m_rVariable.set( percentage );
+    // XXX Two of these in this file, figure out where it really belongs.
+    int dir = static_cast<EvtScroll*>(m_pParent->m_pEvt)->getDirection();
+    m_pParent->m_rVariable.set( scroll( EvtScroll::kUp == dir,
+                                        m_pParent->m_rVariable.get() ) );
 }
 
 
@@ -280,19 +274,17 @@ void CtrlSliderCursor::getResizeFactors( float &rFactorX,
 
     // Compute the resize factors
     if( m_width > 0 )
-    {
         rFactorX = (float)pPos->getWidth() / (float)m_width;
-    }
     if( m_height > 0 )
-    {
         rFactorY = (float)pPos->getHeight() / (float)m_height;
-    }
 }
 
 
 void CtrlSliderCursor::refreshLayout()
 {
-    if( m_pImg )
+    if( !m_pImg )
+        notifyLayout();
+    else
     {
         // Compute the resize factors
         float factorX, factorY;
@@ -303,8 +295,6 @@ void CtrlSliderCursor::refreshLayout()
                       - m_pImg->getWidth() / 2,
                       - m_pImg->getHeight() / 2 );
     }
-    else
-        notifyLayout();
 }
 
 
@@ -359,28 +349,25 @@ bool CtrlSliderBg::mouseOver( int x, int y ) const
 
 void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest )
 {
-    if( m_pImgSeq )
-    {
-        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) );
-        }
-    }
+    if( !m_pImgSeq || m_bgWidth <=0 || m_bgHeight <= 0 )
+        return;
+
+    // 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) );
 }
 
 
@@ -416,19 +403,9 @@ void CtrlSliderBg::handleEvent( EvtGeneric &rEvent )
     }
     else if( rEvent.getAsString().find( "scroll" ) != string::npos )
     {
-        int direction = ((EvtScroll&)rEvent).getDirection();
-
-        float percentage = m_rVariable.get();
-        if( direction == EvtScroll::kUp )
-        {
-            percentage += SCROLL_STEP;
-        }
-        else
-        {
-            percentage -= SCROLL_STEP;
-        }
-
-        m_rVariable.set( percentage );
+        // XXX Two of these in this file, figure out where it really belongs.
+        int dir = static_cast<EvtScroll*>(&rEvent)->getDirection();
+        m_rVariable.set( scroll( EvtScroll::kUp == dir, m_rVariable.get() ) );
     }
 }
 
@@ -474,12 +451,8 @@ void CtrlSliderBg::getResizeFactors( float &rFactorX, float &rFactorY ) const
 
     // Compute the resize factors
     if( m_width > 0 )
-    {
         rFactorX = (float)pPos->getWidth() / (float)m_width;
-    }
     if( m_height > 0 )
-    {
         rFactorY = (float)pPos->getHeight() / (float)m_height;
-    }
 }
 
index 4819646b29e2ba83fcaf5288f8bf210325e2bb1b..7450b48ee5ee497f23e85f0a9f48c8e35914b863 100644 (file)
@@ -574,7 +574,10 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
 
     else if( rEvent.getAsString().find( "scroll" ) != string::npos )
     {
-        int direction = ((EvtScroll&)rEvent).getDirection();
+        // XXX ctrl_slider.cpp has two more (but slightly different)
+        // XXX implementations of `scroll'. Figure out where it belongs.
+
+        int direction = static_cast<EvtScroll&>(rEvent).getDirection();
 
         double percentage = m_rTree.getPositionVar().get();
         double step = 2.0 / (double)( m_flat ? m_rTree.countLeafs()
@@ -622,17 +625,14 @@ void CtrlTree::handleEvent( EvtGeneric &rEvent )
 bool CtrlTree::mouseOver( int x, int y ) const
 {
     const Position *pPos = getPosition();
-    return ( pPos
-       ? x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight()
-       : false);
+    return !pPos ? false :
+        x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight();
 }
 
 void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest )
 {
     if( m_pImage )
-    {
         rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest );
-    }
 }
 
 bool CtrlTree::ensureVisible( VarTree::Iterator item )
@@ -776,7 +776,9 @@ void CtrlTree::makeImage()
         for( int yPos = 0; yPos < height; yPos += i_itemHeight )
         {
             int rectHeight = __MIN( i_itemHeight, height - yPos );
-            if( it != m_rTree.end() )
+            if( it == m_rTree.end() )
+                m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor );
+            else
             {
                 uint32_t color = ( it->m_selected ? m_selColor : bgColor );
                 m_pImage->fillRect( 0, yPos, width, rectHeight, color );
@@ -786,10 +788,6 @@ void CtrlTree::makeImage()
                                 : m_rTree.getNextVisibleItem( it );
                 } while( it != m_rTree.end() && it->m_deleted );
             }
-            else
-            {
-                m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor );
-            }
             bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 );
         }
     }