]> git.sesse.net Git - vlc/blob - modules/gui/skins2/src/vout_window.cpp
skins2 vout manager
[vlc] / modules / gui / skins2 / src / vout_window.cpp
1 /*****************************************************************************
2  * vout_window.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 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 "vout_window.hpp"
25 #include "vout_manager.hpp"
26 #include "vlcproc.hpp"
27 #include "theme.hpp"
28 #include "os_factory.hpp"
29 #include "os_graphics.hpp"
30 #include "os_window.hpp"
31
32 int VoutWindow::count = 0;
33
34 VoutWindow::VoutWindow( intf_thread_t *pIntf, vout_thread_t* pVout,
35                         int width, int height, GenericWindow* pParent ) :
36       GenericWindow( pIntf, 0, 0, false, false, pParent ),
37       m_pVout( pVout ), original_width( width ), original_height( height ),
38       m_pParentWindow( pParent ), m_pImage( NULL )
39 {
40     // counter for debug
41     count++;
42
43     if( m_pVout )
44         vlc_object_hold( m_pVout );
45
46     // needed on MS-Windows to prevent vlc hanging
47     show();
48 }
49
50
51 VoutWindow::~VoutWindow()
52 {
53     delete m_pImage;
54     if( m_pVout )
55         vlc_object_release( m_pVout );
56
57     count--;
58     msg_Dbg( getIntf(), "VoutWindow count = %d", count );
59 }
60
61
62 void VoutWindow::resize( int width, int height )
63 {
64     // don't try to resize with zero value
65     if( !width || !height )
66         return;
67
68     // Get the OSFactory
69     OSFactory *pOsFactory = OSFactory::instance( getIntf() );
70
71     // Recreate the image
72     delete m_pImage;
73     m_pImage = pOsFactory->createOSGraphics( width, height );
74     // Draw a black rectangle
75     m_pImage->fillRect( 0, 0, width, height, 0 );
76
77     // Resize the window
78     GenericWindow::resize( width, height );
79 }
80
81
82 void VoutWindow::refresh( int left, int top, int width, int height )
83 {
84     if( m_pImage )
85     {
86         if( !m_pCtrlVideo )
87         {
88             m_pImage->copyToWindow( *getOSWindow(), left, top,
89                                     width, height, left, top );
90         }
91     }
92 }
93
94 void VoutWindow::setCtrlVideo( CtrlVideo* pCtrlVideo )
95 {
96     if( pCtrlVideo )
97     {
98         const Position *pPos = pCtrlVideo->getPosition();
99         int x = pPos->getLeft();
100         int y = pPos->getTop();
101         int w = pPos->getWidth();
102         int h = pPos->getHeight();
103
104         setParent( pCtrlVideo->getWindow(), x, y, w, h );
105         m_pParentWindow = pCtrlVideo->getWindow();
106     }
107     else
108     {
109         setParent( VoutManager::instance( getIntf() )->getVoutMainWindow(),
110                    0, 0, 0, 0 );
111         m_pParentWindow =
112                   VoutManager::instance( getIntf() )->getVoutMainWindow();
113     }
114
115     m_pCtrlVideo = pCtrlVideo;
116 }
117