]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/controls/ctrl_video.cpp
skins2(win): fix mouse wheel ineffective on Windows
[vlc] / modules / gui / skins2 / controls / ctrl_video.cpp
index ce62d721669baab938eda688f598c5f45b14b9dc..2ed026bdee14a3055fe3a546d56e209c02564d91 100644 (file)
@@ -36,41 +36,34 @@ CtrlVideo::CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout,
                       bool autoResize, const UString &rHelp,
                       VarBool *pVisible ):
     CtrlGeneric( pIntf, rHelp, pVisible ), m_rLayout( rLayout ),
-    m_xShift( 0 ), m_yShift( 0 ), m_bAutoResize( autoResize ),
-    m_pVoutWindow( NULL ), m_bIsUseable( false )
+    m_bAutoResize( autoResize), m_xShift( 0 ), m_yShift( 0 ),
+    m_bIsUseable( false), m_pVoutWindow( NULL )
 {
-    // Observe the vout size variable if the control is auto-resizable
-    if( m_bAutoResize )
-    {
-        VarBox &rVoutSize = VlcProc::instance( pIntf )->getVoutSizeVar();
-        rVoutSize.addObserver( this );
-    }
+    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
+    rFullscreen.addObserver( this );
 
-    // observe visibility variable
-    if( m_pVisible )
-        m_pVisible->addObserver( this );
+    // if global parameter set to no resize, override skins behavior
+    if( !var_InheritBool( pIntf, "qt-video-autoresize" ) )
+        m_bAutoResize = false;
 }
 
 
 CtrlVideo::~CtrlVideo()
 {
-    VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
-    rVoutSize.delObserver( this );
-
-    //m_pLayout->getActiveVar().delObserver( this );
-
-    if( m_pVisible )
-        m_pVisible->delObserver( this );
+    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
+    rFullscreen.delObserver( this );
 }
 
 
 void CtrlVideo::handleEvent( EvtGeneric &rEvent )
 {
+    (void)rEvent;
 }
 
 
 bool CtrlVideo::mouseOver( int x, int y ) const
 {
+    (void)x; (void)y;
     return false;
 }
 
@@ -94,15 +87,23 @@ void CtrlVideo::onPositionChange()
 }
 
 
-void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest )
+void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h)
 {
-    GenericWindow *pParent = getWindow();
     const Position *pPos = getPosition();
-    if( pParent && pPos )
+    rect region( pPos->getLeft(), pPos->getTop(),
+                 pPos->getWidth(), pPos->getHeight() );
+    rect clip( xDest, yDest, w, h );
+    rect inter;
+
+    if( rect::intersect( region, clip, &inter ) )
     {
         // Draw a black rectangle under the video to avoid transparency
-        rImage.fillRect( pPos->getLeft(), pPos->getTop(), pPos->getWidth(),
-                         pPos->getHeight(), 0 );
+        rImage.fillRect( inter.x, inter.y, inter.width, inter.height, 0 );
+    }
+
+    if( m_pVoutWindow )
+    {
+        m_pVoutWindow->show();
     }
 }
 
@@ -123,49 +124,53 @@ void CtrlVideo::setLayout( GenericLayout *pLayout,
 }
 
 
+void CtrlVideo::unsetLayout()
+{
+    m_pLayout->getActiveVar().delObserver( this );
+    CtrlGeneric::unsetLayout();
+}
+
+
 void CtrlVideo::resizeControl( int width, int height )
 {
-    int newWidth = width + m_xShift;
-    int newHeight = height + m_yShift;
+    if( !m_bAutoResize )
+        return;
 
-    // Create a resize command
-    // FIXME: this way of getting the window manager kind of sucks
     WindowManager &rWindowManager =
         getIntf()->p_sys->p_theme->getWindowManager();
-    rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
-    CmdGeneric *pCmd = new CmdResize( getIntf(), rWindowManager,
-                                      m_rLayout, newWidth, newHeight );
-    // Push the command in the asynchronous command queue
-    AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
-    pQueue->push( CmdGenericPtr( pCmd ), false );
-
-    // FIXME: this should be a command too
-    rWindowManager.stopResize();
 
-    pCmd = new CmdResizeInnerVout( getIntf(), this );
-    pQueue->push( CmdGenericPtr( pCmd ), false );
-
-    TopWindow* pWin = getWindow();
-    rWindowManager.show( *pWin );
-}
+    const Position *pPos = getPosition();
 
+    if( width != pPos->getWidth() || height != pPos->getHeight() )
+    {
+        // new layout dimensions
+        int newWidth = width + m_xShift;
+        int newHeight = height + m_yShift;
 
-void CtrlVideo::onUpdate( Subject<VarBox> &rVoutSize, void *arg )
-{
-    int newWidth = ((VarBox&)rVoutSize).getWidth() + m_xShift;
-    int newHeight = ((VarBox&)rVoutSize).getHeight() + m_yShift;
+        // Resize the layout
+        rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
+        rWindowManager.resize( m_rLayout, newWidth, newHeight );
+        rWindowManager.stopResize();
 
-    resizeControl( newWidth, newHeight );
+        if( m_pVoutWindow )
+        {
+            m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
+            m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
+        }
+    }
 }
 
 
 void CtrlVideo::onUpdate( Subject<VarBool> &rVariable, void *arg  )
 {
+    (void)arg;
+
     // Visibility changed
     if( &rVariable == m_pVisible )
     {
         msg_Dbg( getIntf(), "VideoCtrl : Visibility changed (visible=%d)",
                                   isVisible() );
+        notifyLayout();
     }
 
     // Active Layout changed
@@ -175,7 +180,16 @@ void CtrlVideo::onUpdate( Subject<VarBool> &rVariable, void *arg  )
                       m_pLayout->getActiveVar().get() );
     }
 
-    m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get();
+    VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
+    if( &rVariable == &rFullscreen )
+    {
+        msg_Dbg( getIntf(), "VideoCtrl : fullscreen toggled (fullscreen = %d)",
+                      rFullscreen.get() );
+    }
+
+    m_bIsUseable = isVisible() &&
+                   m_pLayout->getActiveVar().get() &&
+                   !rFullscreen.get();
 
     if( m_bIsUseable && !isUsed() )
     {
@@ -187,10 +201,10 @@ void CtrlVideo::onUpdate( Subject<VarBool> &rVariable, void *arg  )
     }
 }
 
-void CtrlVideo::attachVoutWindow( VoutWindow* pVoutWindow )
+void CtrlVideo::attachVoutWindow( VoutWindow* pVoutWindow, int width, int height )
 {
-    int width = pVoutWindow->getOriginalWidth();
-    int height = pVoutWindow->getOriginalHeight();
+    width = ( width < 0 ) ? pVoutWindow->getOriginalWidth() : width;
+    height = ( height < 0 ) ? pVoutWindow->getOriginalHeight() : height;
 
     WindowManager &rWindowManager =
         getIntf()->p_sys->p_theme->getWindowManager();
@@ -219,22 +233,3 @@ void CtrlVideo::detachVoutWindow( )
     m_pVoutWindow = NULL;
 }
 
-
-void CtrlVideo::resizeInnerVout( )
-{
-    if( m_pVoutWindow )
-    {
-        WindowManager &rWindowManager =
-             getIntf()->p_sys->p_theme->getWindowManager();
-        TopWindow* pWin = getWindow();
-
-        const Position *pPos = getPosition();
-
-        m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
-        m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
-
-        rWindowManager.show( *pWin );
-        m_pVoutWindow->show();
-    }
-}
-