]> git.sesse.net Git - vlc/blob - modules/gui/skins2/controls/ctrl_video.cpp
* modules/gui/skins2/*:
[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 "../src/window_manager.hpp"
30 #include "../commands/async_queue.hpp"
31 #include "../commands/cmd_resize.hpp"
32
33
34 CtrlVideo::CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout,
35                       bool autoResize, const UString &rHelp,
36                       VarBool *pVisible ):
37     CtrlGeneric( pIntf, rHelp, pVisible ), m_pVout( NULL ),
38     m_rLayout( rLayout ), m_xShift( 0 ), m_yShift( 0 )
39 {
40     // Observe the vout size variable if the control is auto-resizable
41     if( autoResize )
42     {
43         VarBox &rVoutSize = VlcProc::instance( pIntf )->getVoutSizeVar();
44         rVoutSize.addObserver( this );
45     }
46 }
47
48
49 CtrlVideo::~CtrlVideo()
50 {
51     VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
52     rVoutSize.delObserver( this );
53
54     if( m_pVout )
55     {
56         delete m_pVout;
57     }
58 }
59
60
61 void CtrlVideo::handleEvent( EvtGeneric &rEvent )
62 {
63 }
64
65
66 bool CtrlVideo::mouseOver( int x, int y ) const
67 {
68     return false;
69 }
70
71
72 void CtrlVideo::onResize()
73 {
74     const Position *pPos = getPosition();
75     if( pPos && m_pVout )
76     {
77         m_pVout->move( pPos->getLeft(), pPos->getTop() );
78         m_pVout->resize( pPos->getWidth(), pPos->getHeight() );
79     }
80 }
81
82
83 void CtrlVideo::onPositionChange()
84 {
85     // Compute the difference between layout size and video size
86     m_xShift = m_rLayout.getWidth() - getPosition()->getWidth();
87     m_yShift = m_rLayout.getHeight() - getPosition()->getHeight();
88 }
89
90
91 void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest )
92 {
93     GenericWindow *pParent = getWindow();
94     const Position *pPos = getPosition();
95     if( pParent && pPos )
96     {
97         // Draw a black rectangle under the video to avoid transparency
98         rImage.fillRect( pPos->getLeft(), pPos->getTop(), pPos->getWidth(),
99                          pPos->getHeight(), 0 );
100     }
101 }
102
103
104 void CtrlVideo::onUpdate( Subject<VarBox, void *> &rVoutSize, void *arg )
105 {
106     int newWidth = ((VarBox&)rVoutSize).getWidth() + m_xShift;
107     int newHeight = ((VarBox&)rVoutSize).getHeight() + m_yShift;
108
109     // Create a resize command
110     // FIXME: this way of getting the window manager kind of sucks
111     WindowManager &rWindowManager =
112         getIntf()->p_sys->p_theme->getWindowManager();
113     rWindowManager.startResize( m_rLayout, WindowManager::kResizeSE );
114     CmdGeneric *pCmd = new CmdResize( getIntf(), rWindowManager,
115                                       m_rLayout, newWidth, newHeight );
116     // Push the command in the asynchronous command queue
117     AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
118     pQueue->push( CmdGenericPtr( pCmd ) );
119
120     // FIXME: this should be a command too
121     rWindowManager.stopResize();
122 }
123
124
125 void CtrlVideo::setVisible( bool visible )
126 {
127     if( visible )
128     {
129         GenericWindow *pParent = getWindow();
130         const Position *pPos = getPosition();
131         // Create a child window for the vout if it doesn't exist yet
132         if( !m_pVout && pParent && pPos )
133         {
134             m_pVout = new VoutWindow( getIntf(), pPos->getLeft(),
135                                       pPos->getTop(), false, false, *pParent );
136             m_pVout->resize( pPos->getWidth(), pPos->getHeight() );
137             m_pVout->show();
138         }
139     }
140     else
141     {
142         delete m_pVout;
143         m_pVout = NULL;
144     }
145 }
146