X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fskins2%2Fcontrols%2Fctrl_video.cpp;h=cd346c03022b1bab0afe95c13e6a6f191b412c0f;hb=1bb2388c5dc158d4da460307f4ad4d71e9f35a18;hp=ccd7366dc7c40a0fd864e2c2d8766dacf9412f3f;hpb=e1670aca558b0fea3a9530c36d4753a022983ec9;p=vlc diff --git a/modules/gui/skins2/controls/ctrl_video.cpp b/modules/gui/skins2/controls/ctrl_video.cpp index ccd7366dc7..cd346c0302 100644 --- a/modules/gui/skins2/controls/ctrl_video.cpp +++ b/modules/gui/skins2/controls/ctrl_video.cpp @@ -26,6 +26,7 @@ #include "../src/vout_window.hpp" #include "../src/os_graphics.hpp" #include "../src/vlcproc.hpp" +#include "../src/vout_manager.hpp" #include "../src/window_manager.hpp" #include "../commands/async_queue.hpp" #include "../commands/cmd_resize.hpp" @@ -34,11 +35,12 @@ CtrlVideo::CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout, bool autoResize, const UString &rHelp, VarBool *pVisible ): - CtrlGeneric( pIntf, rHelp, pVisible ), m_pVout( NULL ), - m_rLayout( rLayout ), m_xShift( 0 ), m_yShift( 0 ) + CtrlGeneric( pIntf, rHelp, pVisible ), m_rLayout( rLayout ), + m_xShift( 0 ), m_yShift( 0 ), m_bAutoResize( autoResize ), + m_pVoutWindow( NULL ), m_bIsUseable( false ) { // Observe the vout size variable if the control is auto-resizable - if( autoResize ) + if( m_bAutoResize ) { VarBox &rVoutSize = VlcProc::instance( pIntf )->getVoutSizeVar(); rVoutSize.addObserver( this ); @@ -51,10 +53,7 @@ CtrlVideo::~CtrlVideo() VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar(); rVoutSize.delObserver( this ); - if( m_pVout ) - { - delete m_pVout; - } + //m_pLayout->getActiveVar().delObserver( this ); } @@ -72,10 +71,10 @@ bool CtrlVideo::mouseOver( int x, int y ) const void CtrlVideo::onResize() { const Position *pPos = getPosition(); - if( pPos && m_pVout ) + if( pPos && m_pVoutWindow ) { - m_pVout->move( pPos->getLeft(), pPos->getTop() ); - m_pVout->resize( pPos->getWidth(), pPos->getHeight() ); + m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() ); + m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() ); } } @@ -90,9 +89,8 @@ void CtrlVideo::onPositionChange() void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest ) { - GenericWindow *pParent = getWindow(); const Position *pPos = getPosition(); - if( pParent && pPos ) + if( pPos ) { // Draw a black rectangle under the video to avoid transparency rImage.fillRect( pPos->getLeft(), pPos->getTop(), pPos->getWidth(), @@ -101,46 +99,131 @@ void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest ) } +void CtrlVideo::setLayout( GenericLayout *pLayout, + const Position &rPosition ) +{ + CtrlGeneric::setLayout( pLayout, rPosition ); + m_pLayout->getActiveVar().addObserver( this ); + + m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get(); + + // register Video Control + VoutManager::instance( getIntf() )->registerCtrlVideo( this ); + + msg_Dbg( getIntf(),"New VideoControl detected(%p), useability=%s", + this, m_bIsUseable ? "true" : "false" ); +} + + +void CtrlVideo::resizeControl( int width, int height ) +{ + WindowManager &rWindowManager = + getIntf()->p_sys->p_theme->getWindowManager(); + + const Position *pPos = getPosition(); + + if( width != pPos->getWidth() || height != pPos->getHeight() ) + { + // new layout dimensions + int newWidth = width + m_xShift; + int newHeight = height + m_yShift; + + // Resize the layout + rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE ); + rWindowManager.resize( m_rLayout, newWidth, newHeight ); + rWindowManager.stopResize(); + + if( m_pVoutWindow ) + { + m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() ); + m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() ); + } + } +} + + void CtrlVideo::onUpdate( Subject &rVoutSize, void *arg ) { int newWidth = ((VarBox&)rVoutSize).getWidth() + m_xShift; int newHeight = ((VarBox&)rVoutSize).getHeight() + m_yShift; - // Create a resize command - // FIXME: this way of getting the window manager kind of sucks + resizeControl( newWidth, newHeight ); +} + + +void CtrlVideo::onUpdate( Subject &rVariable, void *arg ) +{ + // Visibility changed + if( &rVariable == m_pVisible ) + { + msg_Dbg( getIntf(), "VideoCtrl : Visibility changed (visible=%d)", + isVisible() ); + } + + // Active Layout changed + if( &rVariable == &m_pLayout->getActiveVar() ) + { + msg_Dbg( getIntf(), "VideoCtrl : Active Layout changed (isActive=%d)", + m_pLayout->getActiveVar().get() ); + } + + m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get(); + + if( m_bIsUseable && !isUsed() ) + { + VoutManager::instance( getIntf() )->requestVout( this ); + } + else if( !m_bIsUseable && isUsed() ) + { + VoutManager::instance( getIntf() )->discardVout( this ); + } +} + +void CtrlVideo::attachVoutWindow( VoutWindow* pVoutWindow, int width, int height ) +{ + width = ( width < 0 ) ? pVoutWindow->getOriginalWidth() : width; + height = ( height < 0 ) ? pVoutWindow->getOriginalHeight() : height; + 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 ) ); - - // FIXME: this should be a command too - rWindowManager.stopResize(); + TopWindow* pWin = getWindow(); + rWindowManager.show( *pWin ); + + if( m_bAutoResize && width && height ) + { + int newWidth = width + m_xShift; + int newHeight = height + m_yShift; + + rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE ); + rWindowManager.resize( m_rLayout, newWidth, newHeight ); + rWindowManager.stopResize(); + } + + pVoutWindow->setCtrlVideo( this ); + + m_pVoutWindow = pVoutWindow; +} + + +void CtrlVideo::detachVoutWindow( ) +{ + m_pVoutWindow->setCtrlVideo( NULL ); + m_pVoutWindow = NULL; } -void CtrlVideo::setVisible( bool visible ) +void CtrlVideo::resizeInnerVout( ) { - if( visible ) + if( m_pVoutWindow ) { - GenericWindow *pParent = getWindow(); + WindowManager &rWindowManager = + getIntf()->p_sys->p_theme->getWindowManager(); + TopWindow* pWin = getWindow(); + const Position *pPos = getPosition(); - // Create a child window for the vout if it doesn't exist yet - if( !m_pVout && pParent && pPos ) - { - m_pVout = new VoutWindow( getIntf(), pPos->getLeft(), - pPos->getTop(), false, false, *pParent ); - m_pVout->resize( pPos->getWidth(), pPos->getHeight() ); - m_pVout->show(); - } - } - else - { - delete m_pVout; - m_pVout = NULL; + + m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() ); + m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() ); } }