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 );
49 // observe visibility variable
51 m_pVisible->addObserver( this );
55 CtrlVideo::~CtrlVideo()
57 VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
58 rVoutSize.delObserver( this );
60 //m_pLayout->getActiveVar().delObserver( this );
63 m_pVisible->delObserver( this );
67 void CtrlVideo::handleEvent( EvtGeneric &rEvent )
72 bool CtrlVideo::mouseOver( int x, int y ) const
78 void CtrlVideo::onResize()
80 const Position *pPos = getPosition();
81 if( pPos && m_pVoutWindow )
83 m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
84 m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
89 void CtrlVideo::onPositionChange()
91 // Compute the difference between layout size and video size
92 m_xShift = m_rLayout.getWidth() - getPosition()->getWidth();
93 m_yShift = m_rLayout.getHeight() - getPosition()->getHeight();
97 void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest )
99 GenericWindow *pParent = getWindow();
100 const Position *pPos = getPosition();
101 if( pParent && pPos )
103 // Draw a black rectangle under the video to avoid transparency
104 rImage.fillRect( pPos->getLeft(), pPos->getTop(), pPos->getWidth(),
105 pPos->getHeight(), 0 );
110 void CtrlVideo::setLayout( GenericLayout *pLayout,
111 const Position &rPosition )
113 CtrlGeneric::setLayout( pLayout, rPosition );
114 m_pLayout->getActiveVar().addObserver( this );
116 m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get();
118 // register Video Control
119 VoutManager::instance( getIntf() )->registerCtrlVideo( this );
121 msg_Dbg( getIntf(),"New VideoControl detected(%x), useability=%s",
122 this, m_bIsUseable ? "true" : "false" );
126 void CtrlVideo::resizeControl( int width, int height )
128 int newWidth = width + m_xShift;
129 int newHeight = height + m_yShift;
131 // Create a resize command
132 // FIXME: this way of getting the window manager kind of sucks
133 WindowManager &rWindowManager =
134 getIntf()->p_sys->p_theme->getWindowManager();
135 rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
136 CmdGeneric *pCmd = new CmdResize( getIntf(), rWindowManager,
137 m_rLayout, newWidth, newHeight );
138 // Push the command in the asynchronous command queue
139 AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
140 pQueue->push( CmdGenericPtr( pCmd ), false );
142 // FIXME: this should be a command too
143 rWindowManager.stopResize();
145 pCmd = new CmdResizeInnerVout( getIntf(), this );
146 pQueue->push( CmdGenericPtr( pCmd ), false );
148 TopWindow* pWin = getWindow();
149 rWindowManager.show( *pWin );
153 void CtrlVideo::onUpdate( Subject<VarBox> &rVoutSize, void *arg )
155 int newWidth = ((VarBox&)rVoutSize).getWidth() + m_xShift;
156 int newHeight = ((VarBox&)rVoutSize).getHeight() + m_yShift;
158 resizeControl( newWidth, newHeight );
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)",
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 m_bIsUseable = isVisible() && m_pLayout->getActiveVar().get();
180 if( m_bIsUseable && !isUsed() )
182 VoutManager::instance( getIntf() )->requestVout( this );
184 else if( !m_bIsUseable && isUsed() )
186 VoutManager::instance( getIntf() )->discardVout( this );
190 void CtrlVideo::attachVoutWindow( VoutWindow* pVoutWindow )
192 int width = pVoutWindow->getOriginalWidth();
193 int height = pVoutWindow->getOriginalHeight();
195 WindowManager &rWindowManager =
196 getIntf()->p_sys->p_theme->getWindowManager();
197 TopWindow* pWin = getWindow();
198 rWindowManager.show( *pWin );
200 if( m_bAutoResize && width && height )
202 int newWidth = width + m_xShift;
203 int newHeight = height + m_yShift;
205 rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
206 rWindowManager.resize( m_rLayout, newWidth, newHeight );
207 rWindowManager.stopResize();
210 pVoutWindow->setCtrlVideo( this );
212 m_pVoutWindow = pVoutWindow;
216 void CtrlVideo::detachVoutWindow( )
218 m_pVoutWindow->setCtrlVideo( NULL );
219 m_pVoutWindow = NULL;
223 void CtrlVideo::resizeInnerVout( )
225 WindowManager &rWindowManager =
226 getIntf()->p_sys->p_theme->getWindowManager();
227 TopWindow* pWin = getWindow();
229 const Position *pPos = getPosition();
231 m_pVoutWindow->resize( pPos->getWidth(), pPos->getHeight() );
232 m_pVoutWindow->move( pPos->getLeft(), pPos->getTop() );
234 rWindowManager.show( *pWin );
235 m_pVoutWindow->show();