[vlc-commits] skins2: fix background slider focus problems

Erwan Tulou git at videolan.org
Mon Apr 8 20:13:27 CEST 2013


vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Mon Apr  8 19:43:52 2013 +0200| [c9224228f6cd18022fa7698031e8c4f37e9bf06f] | committer: Erwan Tulou

skins2: fix background slider focus problems

This fixes several skins where focus was hard to obtain, because
the slider area was not properly clipped. For instance, it fixes
the 'Modern' skin with the tiny blue equaliser in the main window.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c9224228f6cd18022fa7698031e8c4f37e9bf06f
---

 modules/gui/skins2/controls/ctrl_slider.cpp |   53 +++++++++++++++++----------
 1 file changed, 33 insertions(+), 20 deletions(-)

diff --git a/modules/gui/skins2/controls/ctrl_slider.cpp b/modules/gui/skins2/controls/ctrl_slider.cpp
index 92656d7..be61ea9 100644
--- a/modules/gui/skins2/controls/ctrl_slider.cpp
+++ b/modules/gui/skins2/controls/ctrl_slider.cpp
@@ -6,6 +6,7 @@
  *
  * Authors: Cyril Deguet     <asmax at via.ecp.fr>
  *          Olivier Teulière <ipkiss at via.ecp.fr>
+ *          Erwan Tulou      <erwan10 At videolan doT org>
  *
  * 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
@@ -334,6 +335,11 @@ CtrlSliderBg::CtrlSliderBg( intf_thread_t *pIntf,
 
         // Initial position
         m_position = (int)( m_rVariable.get() * (m_nbHoriz * m_nbVert - 1) );
+
+        // Initialize the scaled image for the control
+        int width = m_bgWidth * m_nbHoriz - m_padHoriz;
+        int height = m_bgHeight * m_nbVert - m_padVert;
+        m_pScaledBmp = new ScaledBitmap( getIntf(), *m_pImgSeq, width, height );
     }
 }
 
@@ -353,32 +359,30 @@ bool CtrlSliderBg::mouseOver( int x, int y ) const
     float factorX, factorY;
     getResizeFactors( factorX, factorY );
 
-    return (m_rCurve.getMinDist( (int)(x / factorX), (int)(y / factorY),
-                                 factorX, factorY ) < m_thickness );
+    bool b_isWithinCurve =
+        m_rCurve.getMinDist( (int)(x / factorX), (int)(y / factorY),
+                                      factorX, factorY ) < m_thickness;
+    bool b_isWithinBitmap =
+        m_pScaledBmp &&
+        x >= 0 && x < m_pScaledBmp->getWidth() &&
+        y >= 0 && y < m_pScaledBmp->getHeight();
+
+    return
+        m_pScaledBmp ?
+        b_isWithinCurve && b_isWithinBitmap :
+        b_isWithinCurve;
 }
 
 
 void CtrlSliderBg::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h )
 {
-    if( !m_pImgSeq || m_bgWidth <= 0 || m_bgHeight <= 0 )
+    if( !m_pScaledBmp || m_bgWidth <= 0 || m_bgHeight <= 0 )
         return;
 
     // Compute the resize factors
     float factorX, factorY;
     getResizeFactors( factorX, factorY );
 
-    int width = m_bgWidth * m_nbHoriz - (int)(m_padHoriz * factorX);
-    int height = m_bgHeight * m_nbVert - (int)(m_padVert * factorY);
-
-    // Rescale the image with the actual size of the control if needed
-    if( !m_pScaledBmp ||
-        m_pScaledBmp->getWidth() != width ||
-        m_pScaledBmp->getHeight() != height )
-    {
-        delete m_pScaledBmp;
-        m_pScaledBmp = new ScaledBitmap( getIntf(), *m_pImgSeq, width, height );
-    }
-
     // Locate the right image in the background bitmap
     int x = m_bgWidth * ( m_position % m_nbHoriz );
     int y = m_bgHeight * ( m_position / m_nbHoriz );
@@ -442,16 +446,25 @@ 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);
+        m_bgWidth =
+           (int)((m_pImgSeq->getWidth() + m_padHoriz) * factorX / m_nbHoriz);
+        m_bgHeight =
+            (int)((m_pImgSeq->getHeight() + m_padVert) * factorY / m_nbVert);
+
+        // Rescale the image with the actual size of the control if needed
+        int width = m_bgWidth * m_nbHoriz - (int)(m_padHoriz * factorX);
+        int height = m_bgHeight * m_nbVert - (int)(m_padVert * factorY);
+        if( m_pScaledBmp->getWidth() != width ||
+            m_pScaledBmp->getHeight() != height )
+        {
+            delete m_pScaledBmp;
+            m_pScaledBmp = new ScaledBitmap( getIntf(), *m_pImgSeq, width, height );
+        }
     }
 }
 



More information about the vlc-commits mailing list