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 // Observe the vout size variable if the control is auto-resizable
45 VarBox &rVoutSize = VlcProc::instance( pIntf )->getVoutSizeVar();
46 rVoutSize.addObserver( this );
51 CtrlVideo::~CtrlVideo()
53 VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
54 rVoutSize.delObserver( this );
56 //m_pLayout->getActiveVar().delObserver( this );
60 void CtrlVideo::handleEvent( EvtGeneric &rEvent )
65 bool CtrlVideo::mouseOver( int x, int y ) const
71 void CtrlVideo::onResize()
73 const Position *pPos = getPosition();
74 if( pPos && m_pVoutWindow )
76 m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
77 m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
82 void CtrlVideo::onPositionChange()
84 // Compute the difference between layout size and video size
85 m_xShift = m_rLayout.getWidth() - getPosition()->getWidth();
86 m_yShift = m_rLayout.getHeight() - getPosition()->getHeight();
90 void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest )
92 GenericWindow *pParent = getWindow();
93 const Position *pPos = getPosition();
96 // Draw a black rectangle under the video to avoid transparency
97 rImage.fillRect( pPos->getLeft(), pPos->getTop(), pPos->getWidth(),
98 pPos->getHeight(), 0 );
103 void CtrlVideo::setLayout( GenericLayout *pLayout,
104 const Position &rPosition )
106 CtrlGeneric::setLayout( pLayout, rPosition );
107 m_pLayout->getActiveVar().addObserver( this );
109 m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get();
111 // register Video Control
112 VoutManager::instance( getIntf() )->registerCtrlVideo( this );
114 msg_Dbg( getIntf(),"New VideoControl detected(%p), useability=%s",
115 this, m_bIsUseable ? "true" : "false" );
119 void CtrlVideo::resizeControl( int width, int height )
121 int newWidth = width + m_xShift;
122 int newHeight = height + m_yShift;
124 // Create a resize command
125 // FIXME: this way of getting the window manager kind of sucks
126 WindowManager &rWindowManager =
127 getIntf()->p_sys->p_theme->getWindowManager();
128 rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
129 CmdGeneric *pCmd = new CmdResize( getIntf(), rWindowManager,
130 m_rLayout, newWidth, newHeight );
131 // Push the command in the asynchronous command queue
132 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
133 pQueue->push( CmdGenericPtr( pCmd ), false );
135 // FIXME: this should be a command too
136 rWindowManager.stopResize();
138 pCmd = new CmdResizeInnerVout( getIntf(), this );
139 pQueue->push( CmdGenericPtr( pCmd ), false );
141 TopWindow* pWin = getWindow();
142 rWindowManager.show( *pWin );
146 void CtrlVideo::onUpdate( Subject<VarBox> &rVoutSize, void *arg )
148 int newWidth = ((VarBox&)rVoutSize).getWidth() + m_xShift;
149 int newHeight = ((VarBox&)rVoutSize).getHeight() + m_yShift;
151 resizeControl( newWidth, newHeight );
155 void CtrlVideo::onUpdate( Subject<VarBool> &rVariable, void *arg )
157 // Visibility changed
158 if( &rVariable == m_pVisible )
160 msg_Dbg( getIntf(), "VideoCtrl : Visibility changed (visible=%d)",
164 // Active Layout changed
165 if( &rVariable == &m_pLayout->getActiveVar() )
167 msg_Dbg( getIntf(), "VideoCtrl : Active Layout changed (isActive=%d)",
168 m_pLayout->getActiveVar().get() );
171 m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get();
173 if( m_bIsUseable && !isUsed() )
175 VoutManager::instance( getIntf() )->requestVout( this );
177 else if( !m_bIsUseable && isUsed() )
179 VoutManager::instance( getIntf() )->discardVout( this );
183 void CtrlVideo::attachVoutWindow( VoutWindow* pVoutWindow, int width, int height )
185 width = ( width < 0 ) ? pVoutWindow->getOriginalWidth() : width;
186 height = ( height < 0 ) ? pVoutWindow->getOriginalHeight() : height;
188 WindowManager &rWindowManager =
189 getIntf()->p_sys->p_theme->getWindowManager();
190 TopWindow* pWin = getWindow();
191 rWindowManager.show( *pWin );
193 if( m_bAutoResize && width && height )
195 int newWidth = width + m_xShift;
196 int newHeight = height + m_yShift;
198 rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
199 rWindowManager.resize( m_rLayout, newWidth, newHeight );
200 rWindowManager.stopResize();
203 pVoutWindow->setCtrlVideo( this );
205 m_pVoutWindow = pVoutWindow;
209 void CtrlVideo::detachVoutWindow( )
211 m_pVoutWindow->setCtrlVideo( NULL );
212 m_pVoutWindow = NULL;
216 void CtrlVideo::resizeInnerVout( )
220 WindowManager &rWindowManager =
221 getIntf()->p_sys->p_theme->getWindowManager();
222 TopWindow* pWin = getWindow();
224 const Position *pPos = getPosition();
226 m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
227 m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
229 rWindowManager.show( *pWin );
230 m_pVoutWindow->show();