]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_video.cpp
* all: new handling of vout controls to allow serveral layouts/windows
[vlc] / modules / gui / skins2 / controls / ctrl_video.cpp
1 /*****************************************************************************
2  * ctrl_video.cpp
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
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 "../commands/async_queue.hpp"
30 #include "../commands/cmd_resize.hpp"
31
32
33 CtrlVideo::CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout,
34                       bool autoResize, const UString &rHelp,
35                       VarBool *pVisible ):
36     CtrlGeneric( pIntf, rHelp, pVisible ), m_pVout( NULL ),
37     m_rLayout( rLayout ), m_xShift( 0 ), m_yShift( 0 )
38 {
39     // Observe the vout size variable if the control is auto-resizable
40     if( autoResize )
41     {
42         VarBox &rVoutSize = VlcProc::instance( pIntf )->getVoutSizeVar();
43         rVoutSize.addObserver( this );
44     }
45 }
46
47
48 CtrlVideo::~CtrlVideo()
49 {
50     VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
51     rVoutSize.delObserver( this );
52
53     if( m_pVout )
54     {
55         delete m_pVout;
56     }
57 }
58
59
60 void CtrlVideo::handleEvent( EvtGeneric &rEvent )
61 {
62 }
63
64
65 bool CtrlVideo::mouseOver( int x, int y ) const
66 {
67     return false;
68 }
69
70
71 void CtrlVideo::onResize()
72 {
73     const Position *pPos = getPosition();
74     if( pPos && m_pVout )
75     {
76         m_pVout->move( pPos->getLeft(), pPos->getTop() );
77         m_pVout->resize( pPos->getWidth(), pPos->getHeight() );
78     }
79 }
80
81
82 void CtrlVideo::onPositionChange()
83 {
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();
87 }
88
89
90 void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest )
91 {
92     GenericWindow *pParent = getWindow();
93     const Position *pPos = getPosition();
94     if( pParent && pPos )
95     {
96         // Draw a black rectangle under the video to avoid transparency
97         rImage.fillRect( pPos->getLeft(), pPos->getTop(), pPos->getWidth(),
98                          pPos->getHeight(), 0 );
99     }
100 }
101
102
103 void CtrlVideo::onUpdate( Subject<VarBox, void *> &rVoutSize, void *arg )
104 {
105     int newWidth = ((VarBox&)rVoutSize).getWidth() + m_xShift;
106     int newHeight = ((VarBox&)rVoutSize).getHeight() + m_yShift;
107
108     // Create a resize command
109     CmdGeneric *pCmd = new CmdResize( getIntf(), m_rLayout, newWidth,
110                                       newHeight );
111     // Push the command in the asynchronous command queue
112     AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
113     pQueue->push( CmdGenericPtr( pCmd ) );
114 }
115
116
117 void CtrlVideo::setVisible( bool visible )
118 {
119     if( visible )
120     {
121         GenericWindow *pParent = getWindow();
122         const Position *pPos = getPosition();
123         // Create a child window for the vout if it doesn't exist yet
124         if( !m_pVout && pParent && pPos )
125         {
126             m_pVout = new VoutWindow( getIntf(), pPos->getLeft(),
127                                       pPos->getTop(), false, false, *pParent );
128             m_pVout->resize( pPos->getWidth(), pPos->getHeight() );
129             m_pVout->show();
130         }
131     }
132     else
133     {
134         delete m_pVout;
135         m_pVout = NULL;
136     }
137 }
138