From 28bd3a4a6af005742657f8a0ea7fa92a4fef0618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= <ipkiss@videolan.org> Date: Sun, 14 May 2006 22:16:59 +0000 Subject: [PATCH] * skins2: new LayoutID.isActive boolean variable --- doc/skins/skins2-howto.xml | 12 ++++++++++-- modules/gui/skins2/parser/interpreter.cpp | 18 +++++++++++++++++- modules/gui/skins2/src/generic_layout.cpp | 8 +++++++- modules/gui/skins2/src/generic_layout.hpp | 12 ++++++++++++ modules/gui/skins2/src/top_window.cpp | 12 ++++++++++-- 5 files changed, 56 insertions(+), 6 deletions(-) diff --git a/doc/skins/skins2-howto.xml b/doc/skins/skins2-howto.xml index 3b4acd8e4ccb..37ce142d93bd 100644 --- a/doc/skins/skins2-howto.xml +++ b/doc/skins/skins2-howto.xml @@ -314,6 +314,11 @@ difficulty to understand how VLC skins work.</para> <sect3 id="Layout"> <title>Layout</title> <para>A layout is one aspect of a window, i.e. a set of controls and anchors. A window can have many layouts, but only one will be visible at any time.</para> + <sect4 id="layoutid"> + <title>id</title> + <para>Name of the layout (it may be used for actions). Two layouts cannot have the same id.</para> + <para>Default value: none</para> + </sect4> <sect4 id="layoutwidth"> <title>width</title> <para><!--TODO: calculate it in VLC :)-->Width of the layout. this value is required since VLC is not (yet?) able to calculate it using the sizes and positions of the controls.</para> @@ -921,7 +926,7 @@ difficulty to understand how VLC skins work.</para> <emphasis>WindowID.hide()</emphasis>: Hide the <link linkend="Window">Window</link> whose <link linkend="windowid">id</link> attribute is 'WindowID'. </para></listitem> <listitem><para> - <emphasis>WindowID.setLayout(LayoutID)</emphasis>: Change the layout of the <link linkend="Window">Window</link> whose <link linkend="windowid">id</link> attribute is 'WindowID', using the <link linkend="Layout">Layout</link> whose <link linkend="attrid">id</link> attribute is 'LayoutID'. + <emphasis>WindowID.setLayout(LayoutID)</emphasis>: Change the layout of the <link linkend="Window">Window</link> whose <link linkend="windowid">id</link> attribute is 'WindowID', using the <link linkend="Layout">Layout</link> whose <link linkend="layoutid">id</link> attribute is 'LayoutID'. </para></listitem> </itemizedlist> @@ -1023,7 +1028,10 @@ difficulty to understand how VLC skins work.</para> <emphasis>dvd.isActive</emphasis>: True when a DVD is currently playing. This variable can be used to display buttons associated to the <link linkend="dvdactions">dvd.* actions</link> only when needed (since VLC 0.8.5). </para></listitem> <listitem><para> - <emphasis>window_name.isVisible</emphasis>: True when the window whose <link linkend="windowid">id</link> is "window_name" is visible, false otherwise. + <emphasis>WindowID.isVisible</emphasis>: True when the window whose <link linkend="windowid">id</link> is "WindowID" is visible, false otherwise. + </para></listitem> + <listitem><para> + <emphasis>LayoutID.isVisible</emphasis>: True when the layout whose <link linkend="layoutid">id</link> is "LayoutID" is the active layout in its window (even if the window is hidden), false otherwise (since VLC 0.8.6). </para></listitem> </itemizedlist> diff --git a/modules/gui/skins2/parser/interpreter.cpp b/modules/gui/skins2/parser/interpreter.cpp index 2ba41f6139b2..8598cac9fe08 100644 --- a/modules/gui/skins2/parser/interpreter.cpp +++ b/modules/gui/skins2/parser/interpreter.cpp @@ -401,7 +401,7 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme ) TopWindow *pWin = pTheme->getWindowById( windowId ); if( pWin ) { - // Push the visibility variable on the stack + // Push the visibility variable onto the stack varStack.push_back( &pWin->getVisibleVar() ); } else @@ -410,6 +410,22 @@ VarBool *Interpreter::getVarBool( const string &rName, Theme *pTheme ) return NULL; } } + else if( token.find( ".isActive" ) != string::npos ) + { + int leftPos = token.find( ".isActive" ); + string layoutId = token.substr( 0, leftPos ); + GenericLayout *pLayout = pTheme->getLayoutById( layoutId ); + if( pLayout ) + { + // Push the isActive variable onto the stack + varStack.push_back( &pLayout->getActiveVar() ); + } + else + { + msg_Err( getIntf(), "unknown layout (%s)", layoutId.c_str() ); + return NULL; + } + } else { // Try to get the variable from the variable manager diff --git a/modules/gui/skins2/src/generic_layout.cpp b/modules/gui/skins2/src/generic_layout.cpp index a89348eba082..9884d06109d0 100644 --- a/modules/gui/skins2/src/generic_layout.cpp +++ b/modules/gui/skins2/src/generic_layout.cpp @@ -26,8 +26,10 @@ #include "top_window.hpp" #include "os_factory.hpp" #include "os_graphics.hpp" +#include "var_manager.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, @@ -36,12 +38,16 @@ GenericLayout::GenericLayout( intf_thread_t *pIntf, int width, int height, SkinObject( pIntf ), m_pWindow( NULL ), m_width( width ), m_height( height ), m_minWidth( minWidth ), m_maxWidth( maxWidth ), m_minHeight( minHeight ), m_maxHeight( maxHeight ), m_pVideoControl( NULL ), - m_visible( false ) + 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 ) ); } diff --git a/modules/gui/skins2/src/generic_layout.hpp b/modules/gui/skins2/src/generic_layout.hpp index 470f6710e03b..adf8a17d6b0e 100644 --- a/modules/gui/skins2/src/generic_layout.hpp +++ b/modules/gui/skins2/src/generic_layout.hpp @@ -36,6 +36,7 @@ class Anchor; class OSGraphics; class CtrlGeneric; class CtrlVideo; +class VarBoolImpl; /// Control and its associated layer @@ -128,6 +129,10 @@ class GenericLayout: public SkinObject, public Box /// Called when the layout is hidden virtual void onHide(); + /// Give access to the "active layout" variable + // FIXME: we give read/write access + VarBoolImpl &getActiveVar() { return *m_pVarActive; } + private: /// Parent window of the layout TopWindow *m_pWindow; @@ -145,6 +150,13 @@ class GenericLayout: public SkinObject, public Box list<Anchor*> m_anchorList; /// Flag to know if the layout is visible bool m_visible; + /// Variable for the "active state" of the layout + /** + * Note: the layout is not an observer on this variable, because it + * cannot be changed externally (i.e. without an explicit change of + * layout). This way, we avoid using a setActiveLayoutInner method. + */ + mutable VarBoolImpl *m_pVarActive; }; diff --git a/modules/gui/skins2/src/top_window.cpp b/modules/gui/skins2/src/top_window.cpp index 812d9daea068..92c859747476 100644 --- a/modules/gui/skins2/src/top_window.cpp +++ b/modules/gui/skins2/src/top_window.cpp @@ -323,9 +323,14 @@ void TopWindow::refresh( int left, int top, int width, int height ) void TopWindow::setActiveLayout( GenericLayout *pLayout ) { bool isVisible = getVisibleVar().get(); - if( m_pActiveLayout && isVisible ) + if( m_pActiveLayout ) { - m_pActiveLayout->onHide(); + if( isVisible ) + { + m_pActiveLayout->onHide(); + } + // The current layout becomes inactive + m_pActiveLayout->getActiveVar().set( false ); } pLayout->setWindow( this ); @@ -338,6 +343,9 @@ void TopWindow::setActiveLayout( GenericLayout *pLayout ) { pLayout->onShow(); } + + // The new layout is active + pLayout->getActiveVar().set( true ); } -- GitLab