From 6b229b7e4d030f2ed1f19cc118d1312efb2488bf Mon Sep 17 00:00:00 2001 From: Cyril Deguet Date: Tue, 1 Nov 2005 15:53:07 +0000 Subject: [PATCH] * all: added an attribute "autoresize" to the Video control. When it is set to "true", the window is automatically resized when the vout size changes. --- modules/gui/skins2/commands/cmd_resize.cpp | 6 +-- modules/gui/skins2/controls/ctrl_resize.cpp | 18 --------- modules/gui/skins2/controls/ctrl_resize.hpp | 2 - modules/gui/skins2/controls/ctrl_video.cpp | 42 ++++++++++++++++++++- modules/gui/skins2/controls/ctrl_video.hpp | 17 +++++++-- modules/gui/skins2/parser/builder.cpp | 5 ++- modules/gui/skins2/parser/builder_data.def | 2 +- modules/gui/skins2/parser/builder_data.hpp | 5 ++- modules/gui/skins2/parser/skin_parser.cpp | 5 ++- modules/gui/skins2/src/generic_layout.cpp | 18 +++++++++ modules/gui/skins2/src/skin_main.cpp | 22 +++++------ modules/gui/skins2/src/vlcproc.cpp | 2 +- modules/gui/skins2/src/vlcproc.hpp | 6 +++ modules/gui/skins2/utils/position.cpp | 29 ++++++++++++++ modules/gui/skins2/utils/position.hpp | 29 ++++++++++++++ share/skins2/skin.dtd | 1 + 16 files changed, 162 insertions(+), 47 deletions(-) diff --git a/modules/gui/skins2/commands/cmd_resize.cpp b/modules/gui/skins2/commands/cmd_resize.cpp index b9dbe48300..f04a95f508 100644 --- a/modules/gui/skins2/commands/cmd_resize.cpp +++ b/modules/gui/skins2/commands/cmd_resize.cpp @@ -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 ); } diff --git a/modules/gui/skins2/controls/ctrl_resize.cpp b/modules/gui/skins2/controls/ctrl_resize.cpp index 8408a01d6f..e7de6156f3 100644 --- a/modules/gui/skins2/controls/ctrl_resize.cpp +++ b/modules/gui/skins2/controls/ctrl_resize.cpp @@ -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 ); diff --git a/modules/gui/skins2/controls/ctrl_resize.hpp b/modules/gui/skins2/controls/ctrl_resize.hpp index 87780ac9d7..de4799ef77 100644 --- a/modules/gui/skins2/controls/ctrl_resize.hpp +++ b/modules/gui/skins2/controls/ctrl_resize.hpp @@ -29,8 +29,6 @@ #include "../commands/cmd_generic.hpp" #include "../utils/fsm.hpp" -class GenericLayout; - /// Control decorator for resizing windows class CtrlResize: public CtrlFlat diff --git a/modules/gui/skins2/controls/ctrl_video.cpp b/modules/gui/skins2/controls/ctrl_video.cpp index 3e464bbbe3..a8ea232d18 100644 --- a/modules/gui/skins2/controls/ctrl_video.cpp +++ b/modules/gui/skins2/controls/ctrl_video.cpp @@ -25,17 +25,31 @@ #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 &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 ) ); +} + diff --git a/modules/gui/skins2/controls/ctrl_video.hpp b/modules/gui/skins2/controls/ctrl_video.hpp index cbf2ad32a1..a0303d819e 100644 --- a/modules/gui/skins2/controls/ctrl_video.hpp +++ b/modules/gui/skins2/controls/ctrl_video.hpp @@ -25,15 +25,16 @@ #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 { 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 &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 diff --git a/modules/gui/skins2/parser/builder.cpp b/modules/gui/skins2/parser/builder.cpp index 0ace39ddd4..d0ec71ad34 100644 --- a/modules/gui/skins2/parser/builder.cpp +++ b/modules/gui/skins2/parser/builder.cpp @@ -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, diff --git a/modules/gui/skins2/parser/builder_data.def b/modules/gui/skins2/parser/builder_data.def index 146f5343c2..0bc358e233 100644 --- a/modules/gui/skins2/parser/builder_data.def +++ b/modules/gui/skins2/parser/builder_data.def @@ -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 diff --git a/modules/gui/skins2/parser/builder_data.hpp b/modules/gui/skins2/parser/builder_data.hpp index 24706154c8..33b22c863a 100644 --- a/modules/gui/skins2/parser/builder_data.hpp +++ b/modules/gui/skins2/parser/builder_data.hpp @@ -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; diff --git a/modules/gui/skins2/parser/skin_parser.cpp b/modules/gui/skins2/parser/skin_parser.cpp index ad7502fe45..4b510c985a 100644 --- a/modules/gui/skins2/parser/skin_parser.cpp +++ b/modules/gui/skins2/parser/skin_parser.cpp @@ -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 ); } diff --git a/modules/gui/skins2/src/generic_layout.cpp b/modules/gui/skins2/src/generic_layout.cpp index 38b0be9330..0752237900 100644 --- a/modules/gui/skins2/src/generic_layout.cpp +++ b/modules/gui/skins2/src/generic_layout.cpp @@ -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; diff --git a/modules/gui/skins2/src/skin_main.cpp b/modules/gui/skins2/src/skin_main.cpp index 520e16914e..91801ef391 100644 --- a/modules/gui/skins2/src/skin_main.cpp +++ b/modules/gui/skins2/src/skin_main.cpp @@ -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 ); diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp index d73f0f6eeb..16bdd036c0 100644 --- a/modules/gui/skins2/src/vlcproc.cpp +++ b/modules/gui/skins2/src/vlcproc.cpp @@ -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 ); diff --git a/modules/gui/skins2/src/vlcproc.hpp b/modules/gui/skins2/src/vlcproc.hpp index 2ec1a1f801..d56a59e1fe 100644 --- a/modules/gui/skins2/src/vlcproc.hpp +++ b/modules/gui/skins2/src/vlcproc.hpp @@ -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 /** diff --git a/modules/gui/skins2/utils/position.cpp b/modules/gui/skins2/utils/position.cpp index f72a0de906..39474b990e 100644 --- a/modules/gui/skins2/utils/position.cpp +++ b/modules/gui/skins2/utils/position.cpp @@ -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(); +} + diff --git a/modules/gui/skins2/utils/position.hpp b/modules/gui/skins2/utils/position.hpp index f529709663..b1584f98c0 100644 --- a/modules/gui/skins2/utils/position.hpp +++ b/modules/gui/skins2/utils/position.hpp @@ -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 +{ + 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 diff --git a/share/skins2/skin.dtd b/share/skins2/skin.dtd index 6e4ed5690f..ed09bc4dc2 100644 --- a/share/skins2/skin.dtd +++ b/share/skins2/skin.dtd @@ -222,5 +222,6 @@ height CDATA "0" lefttop CDATA "lefttop" rightbottom CDATA "lefttop" + autoresize CDATA "false" help CDATA "" > -- 2.39.2