1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "ctrl_video.hpp"
25 #include "../src/theme.hpp"
26 #include "../src/vout_window.hpp"
27 #include "../src/os_graphics.hpp"
28 #include "../src/vlcproc.hpp"
29 #include "../src/vout_manager.hpp"
30 #include "../src/window_manager.hpp"
31 #include "../commands/async_queue.hpp"
32 #include "../commands/cmd_resize.hpp"
35 CtrlVideo::CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout,
36 bool autoResize, const UString &rHelp,
38 CtrlGeneric( pIntf, rHelp, pVisible ), m_rLayout( rLayout ),
39 m_bAutoResize( autoResize), m_xShift( 0 ), m_yShift( 0 ),
40 m_bIsUseable( false), m_pVoutWindow( NULL )
42 VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
43 rFullscreen.addObserver( this );
45 // if global parameter set to no resize, override skins behavior
46 if( !var_InheritBool( pIntf, "qt-video-autoresize" ) )
47 m_bAutoResize = false;
51 CtrlVideo::~CtrlVideo()
53 VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
54 rFullscreen.delObserver( this );
58 void CtrlVideo::handleEvent( EvtGeneric &rEvent )
63 bool CtrlVideo::mouseOver( int x, int y ) const
69 void CtrlVideo::onResize()
71 const Position *pPos = getPosition();
72 if( pPos && m_pVoutWindow )
74 m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
75 m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
80 void CtrlVideo::onPositionChange()
82 // Compute the difference between layout size and video size
83 m_xShift = m_rLayout.getWidth() - getPosition()->getWidth();
84 m_yShift = m_rLayout.getHeight() - getPosition()->getHeight();
88 void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h)
90 const Position *pPos = getPosition();
91 rect region( pPos->getLeft(), pPos->getTop(),
92 pPos->getWidth(), pPos->getHeight() );
93 rect clip( xDest, yDest, w, h );
96 if( rect::intersect( region, clip, &inter ) )
98 // Draw a black rectangle under the video to avoid transparency
99 rImage.fillRect( inter.x, inter.y, inter.width, inter.height, 0 );
104 m_pVoutWindow->show();
109 void CtrlVideo::setLayout( GenericLayout *pLayout,
110 const Position &rPosition )
112 CtrlGeneric::setLayout( pLayout, rPosition );
113 m_pLayout->getActiveVar().addObserver( this );
115 m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get();
117 // register Video Control
118 VoutManager::instance( getIntf() )->registerCtrlVideo( this );
120 msg_Dbg( getIntf(),"New VideoControl detected(%p), useability=%s",
121 this, m_bIsUseable ? "true" : "false" );
125 void CtrlVideo::unsetLayout()
127 m_pLayout->getActiveVar().delObserver( this );
128 CtrlGeneric::unsetLayout();
132 void CtrlVideo::resizeControl( int width, int height )
137 WindowManager &rWindowManager =
138 getIntf()->p_sys->p_theme->getWindowManager();
140 const Position *pPos = getPosition();
142 if( width != pPos->getWidth() || height != pPos->getHeight() )
144 // new layout dimensions
145 int newWidth = width + m_xShift;
146 int newHeight = height + m_yShift;
149 rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
150 rWindowManager.resize( m_rLayout, newWidth, newHeight );
151 rWindowManager.stopResize();
155 m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
156 m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
162 void CtrlVideo::onUpdate( Subject<VarBool> &rVariable, void *arg )
164 // Visibility changed
165 if( &rVariable == m_pVisible )
167 msg_Dbg( getIntf(), "VideoCtrl : Visibility changed (visible=%d)",
172 // Active Layout changed
173 if( &rVariable == &m_pLayout->getActiveVar() )
175 msg_Dbg( getIntf(), "VideoCtrl : Active Layout changed (isActive=%d)",
176 m_pLayout->getActiveVar().get() );
179 VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
180 if( &rVariable == &rFullscreen )
182 msg_Dbg( getIntf(), "VideoCtrl : fullscreen toggled (fullscreen = %d)",
186 m_bIsUseable = isVisible() &&
187 m_pLayout->getActiveVar().get() &&
190 if( m_bIsUseable && !isUsed() )
192 VoutManager::instance( getIntf() )->requestVout( this );
194 else if( !m_bIsUseable && isUsed() )
196 VoutManager::instance( getIntf() )->discardVout( this );
200 void CtrlVideo::attachVoutWindow( VoutWindow* pVoutWindow, int width, int height )
202 width = ( width < 0 ) ? pVoutWindow->getOriginalWidth() : width;
203 height = ( height < 0 ) ? pVoutWindow->getOriginalHeight() : height;
205 WindowManager &rWindowManager =
206 getIntf()->p_sys->p_theme->getWindowManager();
207 TopWindow* pWin = getWindow();
208 rWindowManager.show( *pWin );
210 if( m_bAutoResize && width && height )
212 int newWidth = width + m_xShift;
213 int newHeight = height + m_yShift;
215 rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
216 rWindowManager.resize( m_rLayout, newWidth, newHeight );
217 rWindowManager.stopResize();
220 pVoutWindow->setCtrlVideo( this );
222 m_pVoutWindow = pVoutWindow;
226 void CtrlVideo::detachVoutWindow( )
228 m_pVoutWindow->setCtrlVideo( NULL );
229 m_pVoutWindow = NULL;