]> git.sesse.net Git - vlc/commitdiff
* all: added an attribute "autoresize" to the Video control.
authorCyril Deguet <asmax@videolan.org>
Tue, 1 Nov 2005 15:53:07 +0000 (15:53 +0000)
committerCyril Deguet <asmax@videolan.org>
Tue, 1 Nov 2005 15:53:07 +0000 (15:53 +0000)
  When it is set to "true", the window is automatically resized
  when the vout size changes.

16 files changed:
modules/gui/skins2/commands/cmd_resize.cpp
modules/gui/skins2/controls/ctrl_resize.cpp
modules/gui/skins2/controls/ctrl_resize.hpp
modules/gui/skins2/controls/ctrl_video.cpp
modules/gui/skins2/controls/ctrl_video.hpp
modules/gui/skins2/parser/builder.cpp
modules/gui/skins2/parser/builder_data.def
modules/gui/skins2/parser/builder_data.hpp
modules/gui/skins2/parser/skin_parser.cpp
modules/gui/skins2/src/generic_layout.cpp
modules/gui/skins2/src/skin_main.cpp
modules/gui/skins2/src/vlcproc.cpp
modules/gui/skins2/src/vlcproc.hpp
modules/gui/skins2/utils/position.cpp
modules/gui/skins2/utils/position.hpp
share/skins2/skin.dtd

index b9dbe483004c650d8fa8a050616e15814f127c42..f04a95f5084bc994181fe4826d177226b282231a 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "cmd_resize.hpp"
 #include "../src/generic_layout.hpp"
+#include "../src/vlcproc.hpp"
 
 
 CmdResize::CmdResize( intf_thread_t *pIntf, GenericLayout &rLayout, int width,
@@ -51,8 +52,7 @@ CmdResizeVout::CmdResizeVout( intf_thread_t *pIntf, void *pWindow, int width,
 
 void CmdResizeVout::execute()
 {
-    // TODO
-    msg_Dbg( getIntf(), "New vout size requested: %d x %d", m_width,
-             m_height );
+    VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
+    rVoutSize.setSize( m_width, m_height );
 }
 
index 8408a01d6fe128f64a8e37d109bd7ec1d73c7d69..e7de6156f31f6775102e02c0823883b5bf6120f5 100644 (file)
@@ -163,24 +163,6 @@ void CtrlResize::CmdResizeResize::execute()
     int newWidth = pEvtMotion->getXPos() - m_pParent->m_xPos + m_pParent->m_width;
     int newHeight = pEvtMotion->getYPos() - m_pParent->m_yPos + m_pParent->m_height;
 
-    // Check boundaries
-    if( newWidth < m_pParent->m_rLayout.getMinWidth() )
-    {
-        newWidth = m_pParent->m_rLayout.getMinWidth();
-    }
-    if( newWidth > m_pParent->m_rLayout.getMaxWidth() )
-    {
-        newWidth = m_pParent->m_rLayout.getMaxWidth();
-    }
-    if( newHeight < m_pParent->m_rLayout.getMinHeight() )
-    {
-        newHeight = m_pParent->m_rLayout.getMinHeight();
-    }
-    if( newHeight > m_pParent->m_rLayout.getMaxHeight() )
-    {
-        newHeight = m_pParent->m_rLayout.getMaxHeight();
-    }
-
     // Create a resize command
     CmdGeneric *pCmd = new CmdResize( m_pParent->getIntf(), m_pParent->m_rLayout,
                                       newWidth, newHeight );
index 87780ac9d7054ce80f5ba28b872e100b3fd02d66..de4799ef77ef670227aef16e13aa75aa5b71f0da 100644 (file)
@@ -29,8 +29,6 @@
 #include "../commands/cmd_generic.hpp"
 #include "../utils/fsm.hpp"
 
-class GenericLayout;
-
 
 /// Control decorator for resizing windows
 class CtrlResize: public CtrlFlat
index 3e464bbbe3b04ad27942623433e1425d83dd842a..a8ea232d18b5cc5093d2b22d695e7508b8d1b6bc 100644 (file)
 #include "../src/theme.hpp"
 #include "../src/vout_window.hpp"
 #include "../src/os_graphics.hpp"
+#include "../src/vlcproc.hpp"
+#include "../commands/async_queue.hpp"
+#include "../commands/cmd_resize.hpp"
 
 
-CtrlVideo::CtrlVideo( intf_thread_t *pIntf, const UString &rHelp,
+CtrlVideo::CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout,
+                      bool autoResize, const UString &rHelp,
                       VarBool *pVisible ):
-    CtrlGeneric( pIntf, rHelp, pVisible ), m_pVout( NULL )
+    CtrlGeneric( pIntf, rHelp, pVisible ), m_pVout( NULL ),
+    m_rLayout( rLayout ), m_xShift( 0 ), m_yShift( 0 )
 {
+    // Observe the vout size variable if the control is auto-resizable
+    if( autoResize )
+    {
+        VarBox &rVoutSize = VlcProc::instance( pIntf )->getVoutSizeVar();
+        rVoutSize.addObserver( this );
+    }
 }
 
 
 CtrlVideo::~CtrlVideo()
 {
+    VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
+    rVoutSize.delObserver( this );
+
     if( m_pVout )
     {
         delete m_pVout;
@@ -65,6 +79,14 @@ void CtrlVideo::onResize()
 }
 
 
+void CtrlVideo::onPositionChange()
+{
+    // Compute the difference between layout size and video size
+    m_xShift = m_rLayout.getWidth() - getPosition()->getWidth();
+    m_yShift = m_rLayout.getHeight() - getPosition()->getHeight();
+}
+
+
 void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest )
 {
     GenericWindow *pParent = getWindow();
@@ -85,3 +107,19 @@ void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest )
         }
     }
 }
+
+
+void CtrlVideo::onUpdate( Subject<VarBox> &rVoutSize )
+{
+    int newWidth = ((VarBox&)rVoutSize).getWidth() + m_xShift;
+    int newHeight = ((VarBox&)rVoutSize).getHeight() + m_yShift;
+
+    // Create a resize command
+    CmdGeneric *pCmd = new CmdResize( getIntf(), m_rLayout, newWidth,
+                                      newHeight );
+    // Push the command in the asynchronous command queue
+    AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
+    pQueue->remove( "resize" );
+    pQueue->push( CmdGenericPtr( pCmd ) );
+}
+
index cbf2ad32a133c371ee687cee1c7d254613676784..a0303d819e1c104648c7c6023158f7011e3bca44 100644 (file)
 #define CTRL_VIDEO_HPP
 
 #include "ctrl_generic.hpp"
+#include "../utils/position.hpp"
 
 class VoutWindow;
 
 /// Control video
-class CtrlVideo: public CtrlGeneric
+class CtrlVideo: public CtrlGeneric, public Observer<VarBox>
 {
     public:
-        CtrlVideo( intf_thread_t *pIntf, const UString &rHelp,
-                   VarBool *pVisible );
+        CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout,
+                   bool autoResize, const UString &rHelp, VarBool *pVisible );
         virtual ~CtrlVideo();
 
         /// Handle an event on the control
@@ -45,15 +46,25 @@ class CtrlVideo: public CtrlGeneric
         /// Callback for layout resize
         virtual void onResize();
 
+        /// Called when the Position is set
+        virtual void onPositionChange();
+
         /// Draw the control on the given graphics
         virtual void draw( OSGraphics &rImage, int xDest, int yDest );
 
         /// Get the type of control (custom RTTI)
         virtual string getType() const { return "video"; }
 
+        /// Method called when the vout size is updated
+        virtual void onUpdate( Subject<VarBox> &rVoutSize );
+
     private:
         /// Vout window
         VoutWindow *m_pVout;
+        /// Associated layout
+        GenericLayout &m_rLayout;
+        /// Difference between layout size and video size
+        int m_xShift, m_yShift;
 };
 
 #endif
index 0ace39ddd40823dd8265541b8851e240e76741bc..d0ec71ad34ca4a4c788799672ccbcea4627babf3 100644 (file)
@@ -702,8 +702,9 @@ void Builder::addVideo( const BuilderData::Video &rData )
     Interpreter *pInterpreter = Interpreter::instance( getIntf() );
     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
 
-    CtrlVideo *pVideo = new CtrlVideo( getIntf(),
-        UString( getIntf(), rData.m_help.c_str() ), pVisible );
+    CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
+        rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
+        pVisible );
 
     // Compute the position of the control
     const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
index 146f5343c2571726d5492e65230d9c0d09e0ec0c..0bc358e23339ce6f50d4e2e506c3ba98f809db8f 100644 (file)
@@ -13,4 +13,4 @@ RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBott
 Slider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string upId:string downId:string overId:string points:string thickness:int value:string tooltip:string help:string layer:int windowId:string layoutId:string
 List id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string fgColor:uint32_t playColor:uint32_t bgColor1:uint32_t bgColor2:uint32_t selColor:uint32_t help:string layer:int windowId:string layoutId:string
 Tree id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string itemImageId:string openImageId:string closedImageId:string fgColor:uint32_t playColor:uint32_t bgColor1:uint32_t bgColor2:uint32_t selColor:uint32_t help:string layer:int windowId:string layoutId:string
-Video id:string xPos:int yPos:int width:int height:int leftTop:string rightBottom:string visible:string help:string layer:int windowId:string layoutId:string
+Video id:string xPos:int yPos:int width:int height:int leftTop:string rightBottom:string visible:string autoResize:bool help:string layer:int windowId:string layoutId:string
index 24706154c80c94ec7db1333ca1db32b0310424e7..33b22c863a80e9f1f95002fd9c93e6bbeb9d510d 100644 (file)
@@ -364,8 +364,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width
     /// Type definition
     struct Video
     {
-        Video( const string & id, int xPos, int yPos, int width, int height, const string & leftTop, const string & rightBottom, const string & visible, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_visible( visible ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+        Video( const string & id, int xPos, int yPos, int width, int height, const string & leftTop, const string & rightBottom, const string & visible, bool autoResize, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_visible( visible ), m_autoResize( autoResize ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         const string m_id;
         int m_xPos;
@@ -375,6 +375,7 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_width( width ), m_height( height )
         const string m_leftTop;
         const string m_rightBottom;
         const string m_visible;
+        bool m_autoResize;
         const string m_help;
         int m_layer;
         const string m_windowId;
index ad7502fe456bf0859f81874e04b5a1dd1ce8b107..4b510c985af3b74af30864d2ab233b26ab7073c7 100644 (file)
@@ -412,14 +412,15 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         CheckDefault( "height", "0" );
         CheckDefault( "lefttop", "lefttop" );
         CheckDefault( "rightbottom", "lefttop" );
+        CheckDefault( "autoresize", "false" );
         CheckDefault( "help", "" );
 
         const BuilderData::Video videoData( uniqueId( attr["id"] ),
                 atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
                 atoi( attr["width"] ), atoi( attr["height" ]),
                 attr["lefttop"], attr["rightbottom"],
-                attr["visible"], attr["help"], m_curLayer,
-                m_curWindowId, m_curLayoutId );
+                attr["visible"], convertBoolean( attr["autoresize"] ),
+                attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
         m_curLayer++;
         m_data.m_listVideo.push_back( videoData );
     }
index 38b0be93309714d18da5912186de3108c5692e8d..07522379002d0a6a4ee993f482acb36375d16820 100644 (file)
@@ -149,6 +149,24 @@ void GenericLayout::resize( int width, int height )
         return;
     }
 
+    // Check boundaries
+    if( width < m_minWidth )
+    {
+        width = m_minWidth;
+    }
+    if( width > m_maxWidth )
+    {
+        width = m_maxWidth;
+    }
+    if( height < m_minHeight )
+    {
+        height = m_minHeight;
+    }
+    if( height > m_maxHeight )
+    {
+        height = m_maxHeight;
+    }
+
     // Update the window size
     m_width = width;
     m_height = height;
index 520e16914e6454723baf47500c71614e4a757de4..91801ef391a0852e65a1eeb194006224b3285582 100644 (file)
@@ -85,7 +85,7 @@ static int Open( vlc_object_t *p_this )
     if( p_intf->p_sys->p_playlist == NULL )
     {
         msg_Err( p_intf, "No playlist object found" );
-       msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+        msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
         return VLC_EGENERIC;
     }
 
@@ -110,36 +110,36 @@ static int Open( vlc_object_t *p_this )
     if( OSFactory::instance( p_intf ) == NULL )
     {
         msg_Err( p_intf, "Cannot initialize OSFactory" );
-       vlc_object_release( p_intf->p_sys->p_playlist );
-       msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+        vlc_object_release( p_intf->p_sys->p_playlist );
+        msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
         return VLC_EGENERIC;
     }
     if( AsyncQueue::instance( p_intf ) == NULL )
     {
         msg_Err( p_intf, "Cannot initialize AsyncQueue" );
-       vlc_object_release( p_intf->p_sys->p_playlist );
-       msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+        vlc_object_release( p_intf->p_sys->p_playlist );
+        msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
         return VLC_EGENERIC;
     }
     if( Interpreter::instance( p_intf ) == NULL )
     {
         msg_Err( p_intf, "Cannot instanciate Interpreter" );
-       vlc_object_release( p_intf->p_sys->p_playlist );
-       msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+        vlc_object_release( p_intf->p_sys->p_playlist );
+        msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
         return VLC_EGENERIC;
     }
     if( VarManager::instance( p_intf ) == NULL )
     {
         msg_Err( p_intf, "Cannot instanciate VarManager" );
-       vlc_object_release( p_intf->p_sys->p_playlist );
-       msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+        vlc_object_release( p_intf->p_sys->p_playlist );
+        msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
         return VLC_EGENERIC;
     }
     if( VlcProc::instance( p_intf ) == NULL )
     {
         msg_Err( p_intf, "Cannot initialize VLCProc" );
-       vlc_object_release( p_intf->p_sys->p_playlist );
-       msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+        vlc_object_release( p_intf->p_sys->p_playlist );
+        msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
         return VLC_EGENERIC;
     }
     Dialogs::instance( p_intf );
index d73f0f6eebc8e19033207d588c23f08683b6d79b..16bdd036c0e03958da2afc1f31d79b5abb497c61 100644 (file)
@@ -62,7 +62,7 @@ void VlcProc::destroy( intf_thread_t *pIntf )
 
 
 VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ), m_pVout( NULL ),
-    m_cmdManage( this )
+    m_cmdManage( this ), m_varVoutSize( pIntf )
 {
     // Create a timer to poll the status of the vlc
     OSFactory *pOsFactory = OSFactory::instance( pIntf );
index 2ec1a1f801cf0bd570951dd4b6ce2df88514e81f..d56a59e1fe3114b853b50a87808848c28dc184ea 100644 (file)
@@ -31,6 +31,7 @@
 #include "../vars/playtree.hpp"
 #include "../vars/time.hpp"
 #include "../vars/volume.hpp"
+#include "../utils/position.hpp"
 #include "../utils/var_text.hpp"
 #include "../commands/cmd_generic.hpp"
 
@@ -69,6 +70,9 @@ class VlcProc: public SkinObject
         VarText &getStreamURIVar()
             { return *((VarText*)(m_cVarStreamURI.get())); }
 
+        /// Getter for the vout size variable
+        VarBox &getVoutSizeVar() { return m_varVoutSize; }
+
         /// Set the vout window handle
         void registerVoutWindow( void *pVoutWindow );
 
@@ -111,6 +115,8 @@ class VlcProc: public SkinObject
         VariablePtr m_cVarStopped;
         VariablePtr m_cVarPaused;
         VariablePtr m_cVarSeekable;
+        /// Variable for the vout
+        VarBox m_varVoutSize;
 
         /// Set of handles of vout windows
         /**
index f72a0de906335faa3877c83b441ceee31bf315b6..39474b990eed9dbf436eedd5bdb2df5b9fb37c54 100644 (file)
@@ -25,6 +25,9 @@
 #include "position.hpp"
 
 
+const string VarBox::m_type = "box";
+
+
 Rect::Rect( int left, int top, int right, int bottom ):
     m_left( left ), m_top( top ), m_right( right ), m_bottom( bottom )
 {
@@ -123,3 +126,29 @@ int Position::getHeight() const
     return getBottom() - getTop() + 1;
 }
 
+
+VarBox::VarBox( intf_thread_t *pIntf, int width, int height ):
+    Variable( pIntf ), m_width( width ), m_height( height )
+{
+}
+
+
+int VarBox::getWidth() const
+{
+    return m_width;
+}
+
+
+int VarBox::getHeight() const
+{
+    return m_height;
+}
+
+
+void VarBox::setSize( int width, int height )
+{
+    m_width = width;
+    m_height = height;
+    notify();
+}
+
index f529709663725d3b67f24ec5e81901ff9d00b0ce..b1584f98c09325a6437a400d3532cd6e67a1fbde 100644 (file)
@@ -25,6 +25,9 @@
 #ifndef POSITION_HPP
 #define POSITION_HPP
 
+#include "variable.hpp"
+#include "observer.hpp"
+
 
 /// Interface for rectangular objects
 class Box
@@ -105,4 +108,30 @@ class Position
 };
 
 
+/// Variable implementing the Box interface
+class VarBox: public Variable, public Box, public Subject<VarBox>
+{
+    public:
+        VarBox( intf_thread_t *pIntf, int width = 0, int height = 0 );
+
+        virtual ~VarBox() {}
+
+        /// Get the variable type
+        virtual const string &getType() const { return m_type; }
+
+        /// Get the size of the box
+        virtual int getWidth() const;
+        virtual int getHeight() const;
+
+        /// Change the size of the box
+        void setSize( int width, int height );
+
+    private:
+        /// Variable type
+        static const string m_type;
+        /// Size
+        int m_width, m_height;
+};
+
+
 #endif
index 6e4ed5690ff68357d1e5444ad5b267d265c25e63..ed09bc4dc255beb5355f6e45f3cee53a282b9c5a 100644 (file)
         height      CDATA   "0"
         lefttop     CDATA   "lefttop"
         rightbottom CDATA   "lefttop"
+        autoresize  CDATA   "false"
         help        CDATA   ""
     >