]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/src/generic_layout.cpp
Use pl_Locked and pl_Unlocked
[vlc] / modules / gui / skins2 / src / generic_layout.cpp
index 38b0be93309714d18da5912186de3108c5692e8d..68a16517535a20b2a479ea9c525809cac531195b 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "generic_layout.hpp"
 #include "top_window.hpp"
 #include "os_factory.hpp"
 #include "os_graphics.hpp"
+#include "var_manager.hpp"
+#include "anchor.hpp"
 #include "../controls/ctrl_generic.hpp"
+#include "../controls/ctrl_video.hpp"
+#include "../utils/var_bool.hpp"
 
 
 GenericLayout::GenericLayout( intf_thread_t *pIntf, int width, int height,
                               int minWidth, int maxWidth, int minHeight,
                               int maxHeight ):
-    SkinObject( pIntf ), m_pWindow( NULL ), m_width( width ),
-    m_height( height ), m_minWidth( minWidth ), m_maxWidth( maxWidth ),
-    m_minHeight( minHeight ), m_maxHeight( maxHeight )
+    SkinObject( pIntf ), m_pWindow( NULL ), m_rect( 0, 0, width, height ),
+    m_minWidth( minWidth ), m_maxWidth( maxWidth ),
+    m_minHeight( minHeight ), m_maxHeight( maxHeight ), m_pVideoControl( NULL ),
+    m_visible( false ), m_pVarActive( NULL )
 {
     // Get the OSFactory
     OSFactory *pOsFactory = OSFactory::instance( getIntf() );
     // Create the graphics buffer
     m_pImage = pOsFactory->createOSGraphics( width, height );
+
+    // Create the "active layout" variable and register it in the manager
+    m_pVarActive = new VarBoolImpl( pIntf );
+    VarManager::instance( pIntf )->registerVar( VariablePtr( m_pVarActive ) );
 }
 
 
@@ -49,6 +58,11 @@ GenericLayout::~GenericLayout()
     {
         delete m_pImage;
     }
+    list<Anchor*>::const_iterator it;
+    for( it = m_anchorList.begin(); it != m_anchorList.end(); it++ )
+    {
+        delete *it;
+    }
 }
 
 
@@ -92,7 +106,7 @@ void GenericLayout::addControl( CtrlGeneric *pControl,
         pControl->draw( *m_pImage, rPosition.getLeft(), rPosition.getTop() );
 
         // Add the control in the list.
-        // This list must remain sorted by layer order 
+        // This list must remain sorted by layer order
         list<LayeredControl>::iterator it;
         for( it = m_controlList.begin(); it != m_controlList.end(); it++ )
         {
@@ -107,10 +121,16 @@ void GenericLayout::addControl( CtrlGeneric *pControl,
         {
             m_controlList.push_back( LayeredControl( pControl, layer ) );
         }
+
+        // Check if it is a video control
+        if( pControl->getType() == "video" )
+        {
+            m_pVideoControl = (CtrlVideo*)pControl;
+        }
     }
     else
     {
-        msg_Dbg( getIntf(), "Adding NULL control in the layout" );
+        msg_Dbg( getIntf(), "adding NULL control in the layout" );
     }
 }
 
@@ -144,14 +164,8 @@ void GenericLayout::onControlUpdate( const CtrlGeneric &rCtrl,
 
 void GenericLayout::resize( int width, int height )
 {
-    if( width == m_width && height == m_height )
-    {
-        return;
-    }
-
     // Update the window size
-    m_width = width;
-    m_height = height;
+    m_rect = SkinsRect( 0, 0 , width, height );
 
     // Recreate a new image
     if( m_pImage )
@@ -165,13 +179,7 @@ void GenericLayout::resize( int width, int height )
     list<LayeredControl>::const_iterator iter;
     for( iter = m_controlList.begin(); iter != m_controlList.end(); iter++ )
     {
-        (*iter).m_pControl->onResize();
-        const Position *pPos = (*iter).m_pControl->getPosition();
-        if( pPos )
-        {
-            (*iter).m_pControl->draw( *m_pImage, pPos->getLeft(),
-                                      pPos->getTop() );
-        }
+        iter->m_pControl->onResize();
     }
 
     // Resize and refresh the associated window
@@ -179,25 +187,27 @@ void GenericLayout::resize( int width, int height )
     if( pWindow )
     {
         // Resize the window
-        pWindow->refresh( 0, 0, width, height );
         pWindow->resize( width, height );
-        pWindow->refresh( 0, 0, width, height );
-
+        refreshAll();
         // Change the shape of the window and redraw it
         pWindow->updateShape();
-        pWindow->refresh( 0, 0, width, height );
+        refreshAll();
     }
 }
 
 
 void GenericLayout::refreshAll()
 {
-    refreshRect( 0, 0, m_width, m_height );
+    refreshRect( 0, 0, m_rect.getWidth(), m_rect.getHeight() );
 }
 
 
 void GenericLayout::refreshRect( int x, int y, int width, int height )
 {
+    // Do nothing if the layout is hidden
+    if( !m_visible )
+        return;
+
     // Draw all the controls of the layout
     list<LayeredControl>::const_iterator iter;
     list<LayeredControl>::const_iterator iterVideo = m_controlList.end();
@@ -205,13 +215,9 @@ void GenericLayout::refreshRect( int x, int y, int width, int height )
     {
         CtrlGeneric *pCtrl = (*iter).m_pControl;
         const Position *pPos = pCtrl->getPosition();
-        if( pCtrl->isVisible() && pPos )
+        if( pPos && pCtrl->isVisible() )
         {
             pCtrl->draw( *m_pImage, pPos->getLeft(), pPos->getTop() );
-            // Remember the video control (we assume there is at most one video
-            // control per layout)
-            if( pCtrl->getType() == "video" && pCtrl->getPosition() )
-                iterVideo = iter;
         }
     }
 
@@ -224,13 +230,13 @@ void GenericLayout::refreshRect( int x, int y, int width, int height )
             x = 0;
         if( y < 0)
             y = 0;
-        if( x + width > m_width )
-            width = m_width - x;
-        if( y + height > m_height )
-            height = m_height - y;
+        if( x + width > m_rect.getWidth() )
+            width = m_rect.getWidth() - x;
+        if( y + height > m_rect.getHeight() )
+            height = m_rect.getHeight() - y;
 
-        // Refresh the window... but do not paint on a video control!
-        if( iterVideo == m_controlList.end() )
+        // Refresh the window... but do not paint on a visible video control!
+        if( !m_pVideoControl || !m_pVideoControl->isVisible() )
         {
             // No video control, we can safely repaint the rectangle
             pWindow->refresh( x, y, width, height );
@@ -245,10 +251,10 @@ void GenericLayout::refreshRect( int x, int y, int width, int height )
             // becomes a real mess :)
 
             // Use short variable names for convenience
-            int xx = iterVideo->m_pControl->getPosition()->getLeft();
-            int yy = iterVideo->m_pControl->getPosition()->getTop();
-            int ww = iterVideo->m_pControl->getPosition()->getWidth();
-            int hh = iterVideo->m_pControl->getPosition()->getHeight();
+            int xx = m_pVideoControl->getPosition()->getLeft();
+            int yy = m_pVideoControl->getPosition()->getTop();
+            int ww = m_pVideoControl->getPosition()->getWidth();
+            int hh = m_pVideoControl->getPosition()->getHeight();
 
             // Top part:
             if( y < yy )
@@ -278,3 +284,28 @@ void GenericLayout::addAnchor( Anchor *pAnchor )
     m_anchorList.push_back( pAnchor );
 }
 
+
+void GenericLayout::onShow()
+{
+    m_visible = true;
+
+    refreshAll();
+    // TODO find a better way to handle the vout ?
+    if( m_pVideoControl )
+    {
+        m_pVideoControl->setVisible( true );
+    }
+}
+
+
+void GenericLayout::onHide()
+{
+    m_visible = false;
+
+    // TODO find a better way to handle the vout ?
+    if( m_pVideoControl )
+    {
+        m_pVideoControl->setVisible( false );
+    }
+}
+