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_xShift( 0 ), m_yShift( 0 ), m_bAutoResize( autoResize ),
40 m_pVoutWindow( NULL ), m_bIsUseable( false )
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->move( pPos->getLeft(), pPos->getTop() );
105 m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
106 m_pVoutWindow->show();
111 void CtrlVideo::setLayout( GenericLayout *pLayout,
112 const Position &rPosition )
114 CtrlGeneric::setLayout( pLayout, rPosition );
115 m_pLayout->getActiveVar().addObserver( this );
117 m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get();
119 // register Video Control
120 VoutManager::instance( getIntf() )->registerCtrlVideo( this );
122 msg_Dbg( getIntf(),"New VideoControl detected(%p), useability=%s",
123 this, m_bIsUseable ? "true" : "false" );
127 void CtrlVideo::unsetLayout()
129 m_pLayout->getActiveVar().delObserver( this );
130 CtrlGeneric::unsetLayout();
134 void CtrlVideo::resizeControl( int width, int height )
136 WindowManager &rWindowManager =
137 getIntf()->p_sys->p_theme->getWindowManager();
139 const Position *pPos = getPosition();
141 if( width != pPos->getWidth() || height != pPos->getHeight() )
143 // new layout dimensions
144 int newWidth = width + m_xShift;
145 int newHeight = height + m_yShift;
148 rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
149 rWindowManager.resize( m_rLayout, newWidth, newHeight );
150 rWindowManager.stopResize();
154 m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
155 m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
161 void CtrlVideo::onUpdate( Subject<VarBool> &rVariable, void *arg )
163 // Visibility changed
164 if( &rVariable == m_pVisible )
166 msg_Dbg( getIntf(), "VideoCtrl : Visibility changed (visible=%d)",
171 // Active Layout changed
172 if( &rVariable == &m_pLayout->getActiveVar() )
174 msg_Dbg( getIntf(), "VideoCtrl : Active Layout changed (isActive=%d)",
175 m_pLayout->getActiveVar().get() );
178 VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar();
179 if( &rVariable == &rFullscreen )
181 msg_Dbg( getIntf(), "VideoCtrl : fullscreen toggled (fullscreen = %d)",
185 m_bIsUseable = isVisible() &&
186 m_pLayout->getActiveVar().get() &&
189 if( m_bIsUseable && !isUsed() )
191 VoutManager::instance( getIntf() )->requestVout( this );
193 else if( !m_bIsUseable && isUsed() )
195 VoutManager::instance( getIntf() )->discardVout( this );
199 void CtrlVideo::attachVoutWindow( VoutWindow* pVoutWindow, int width, int height )
201 width = ( width < 0 ) ? pVoutWindow->getOriginalWidth() : width;
202 height = ( height < 0 ) ? pVoutWindow->getOriginalHeight() : height;
204 WindowManager &rWindowManager =
205 getIntf()->p_sys->p_theme->getWindowManager();
206 TopWindow* pWin = getWindow();
207 rWindowManager.show( *pWin );
209 if( m_bAutoResize && width && height )
211 int newWidth = width + m_xShift;
212 int newHeight = height + m_yShift;
214 rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
215 rWindowManager.resize( m_rLayout, newWidth, newHeight );
216 rWindowManager.stopResize();
219 pVoutWindow->setCtrlVideo( this );
221 m_pVoutWindow = pVoutWindow;
225 void CtrlVideo::detachVoutWindow( )
227 m_pVoutWindow->setCtrlVideo( NULL );
228 m_pVoutWindow = NULL;