Commit 6b229b7e authored by Cyril Deguet's avatar Cyril Deguet

* 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.
parent f1ffafd6
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "cmd_resize.hpp" #include "cmd_resize.hpp"
#include "../src/generic_layout.hpp" #include "../src/generic_layout.hpp"
#include "../src/vlcproc.hpp"
CmdResize::CmdResize( intf_thread_t *pIntf, GenericLayout &rLayout, int width, CmdResize::CmdResize( intf_thread_t *pIntf, GenericLayout &rLayout, int width,
...@@ -51,8 +52,7 @@ CmdResizeVout::CmdResizeVout( intf_thread_t *pIntf, void *pWindow, int width, ...@@ -51,8 +52,7 @@ CmdResizeVout::CmdResizeVout( intf_thread_t *pIntf, void *pWindow, int width,
void CmdResizeVout::execute() void CmdResizeVout::execute()
{ {
// TODO VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
msg_Dbg( getIntf(), "New vout size requested: %d x %d", m_width, rVoutSize.setSize( m_width, m_height );
m_height );
} }
...@@ -163,24 +163,6 @@ void CtrlResize::CmdResizeResize::execute() ...@@ -163,24 +163,6 @@ void CtrlResize::CmdResizeResize::execute()
int newWidth = pEvtMotion->getXPos() - m_pParent->m_xPos + m_pParent->m_width; int newWidth = pEvtMotion->getXPos() - m_pParent->m_xPos + m_pParent->m_width;
int newHeight = pEvtMotion->getYPos() - m_pParent->m_yPos + m_pParent->m_height; 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 // Create a resize command
CmdGeneric *pCmd = new CmdResize( m_pParent->getIntf(), m_pParent->m_rLayout, CmdGeneric *pCmd = new CmdResize( m_pParent->getIntf(), m_pParent->m_rLayout,
newWidth, newHeight ); newWidth, newHeight );
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
#include "../commands/cmd_generic.hpp" #include "../commands/cmd_generic.hpp"
#include "../utils/fsm.hpp" #include "../utils/fsm.hpp"
class GenericLayout;
/// Control decorator for resizing windows /// Control decorator for resizing windows
class CtrlResize: public CtrlFlat class CtrlResize: public CtrlFlat
......
...@@ -25,17 +25,31 @@ ...@@ -25,17 +25,31 @@
#include "../src/theme.hpp" #include "../src/theme.hpp"
#include "../src/vout_window.hpp" #include "../src/vout_window.hpp"
#include "../src/os_graphics.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 ): 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() CtrlVideo::~CtrlVideo()
{ {
VarBox &rVoutSize = VlcProc::instance( getIntf() )->getVoutSizeVar();
rVoutSize.delObserver( this );
if( m_pVout ) if( m_pVout )
{ {
delete m_pVout; delete m_pVout;
...@@ -65,6 +79,14 @@ void CtrlVideo::onResize() ...@@ -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 ) void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest )
{ {
GenericWindow *pParent = getWindow(); GenericWindow *pParent = getWindow();
...@@ -85,3 +107,19 @@ void CtrlVideo::draw( OSGraphics &rImage, int xDest, int yDest ) ...@@ -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 ) );
}
...@@ -25,15 +25,16 @@ ...@@ -25,15 +25,16 @@
#define CTRL_VIDEO_HPP #define CTRL_VIDEO_HPP
#include "ctrl_generic.hpp" #include "ctrl_generic.hpp"
#include "../utils/position.hpp"
class VoutWindow; class VoutWindow;
/// Control video /// Control video
class CtrlVideo: public CtrlGeneric class CtrlVideo: public CtrlGeneric, public Observer<VarBox>
{ {
public: public:
CtrlVideo( intf_thread_t *pIntf, const UString &rHelp, CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout,
VarBool *pVisible ); bool autoResize, const UString &rHelp, VarBool *pVisible );
virtual ~CtrlVideo(); virtual ~CtrlVideo();
/// Handle an event on the control /// Handle an event on the control
...@@ -45,15 +46,25 @@ class CtrlVideo: public CtrlGeneric ...@@ -45,15 +46,25 @@ class CtrlVideo: public CtrlGeneric
/// Callback for layout resize /// Callback for layout resize
virtual void onResize(); virtual void onResize();
/// Called when the Position is set
virtual void onPositionChange();
/// Draw the control on the given graphics /// Draw the control on the given graphics
virtual void draw( OSGraphics &rImage, int xDest, int yDest ); virtual void draw( OSGraphics &rImage, int xDest, int yDest );
/// Get the type of control (custom RTTI) /// Get the type of control (custom RTTI)
virtual string getType() const { return "video"; } virtual string getType() const { return "video"; }
/// Method called when the vout size is updated
virtual void onUpdate( Subject<VarBox> &rVoutSize );
private: private:
/// Vout window /// Vout window
VoutWindow *m_pVout; VoutWindow *m_pVout;
/// Associated layout
GenericLayout &m_rLayout;
/// Difference between layout size and video size
int m_xShift, m_yShift;
}; };
#endif #endif
...@@ -702,8 +702,9 @@ void Builder::addVideo( const BuilderData::Video &rData ) ...@@ -702,8 +702,9 @@ void Builder::addVideo( const BuilderData::Video &rData )
Interpreter *pInterpreter = Interpreter::instance( getIntf() ); Interpreter *pInterpreter = Interpreter::instance( getIntf() );
VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme ); VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
CtrlVideo *pVideo = new CtrlVideo( getIntf(), CtrlVideo *pVideo = new CtrlVideo( getIntf(), *pLayout,
UString( getIntf(), rData.m_help.c_str() ), pVisible ); rData.m_autoResize, UString( getIntf(), rData.m_help.c_str() ),
pVisible );
// Compute the position of the control // Compute the position of the control
const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom, const Position pos = makePosition( rData.m_leftTop, rData.m_rightBottom,
......
...@@ -13,4 +13,4 @@ RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBott ...@@ -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 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 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 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
...@@ -364,8 +364,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width ...@@ -364,8 +364,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width
/// Type definition /// Type definition
struct Video 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 ): 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_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( 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; const string m_id;
int m_xPos; int m_xPos;
...@@ -375,6 +375,7 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_width( width ), m_height( height ) ...@@ -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_leftTop;
const string m_rightBottom; const string m_rightBottom;
const string m_visible; const string m_visible;
bool m_autoResize;
const string m_help; const string m_help;
int m_layer; int m_layer;
const string m_windowId; const string m_windowId;
......
...@@ -412,14 +412,15 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) ...@@ -412,14 +412,15 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
CheckDefault( "height", "0" ); CheckDefault( "height", "0" );
CheckDefault( "lefttop", "lefttop" ); CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" ); CheckDefault( "rightbottom", "lefttop" );
CheckDefault( "autoresize", "false" );
CheckDefault( "help", "" ); CheckDefault( "help", "" );
const BuilderData::Video videoData( uniqueId( attr["id"] ), const BuilderData::Video videoData( uniqueId( attr["id"] ),
atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset, atoi( attr["x"] ) + m_xOffset, atoi( attr["y"] ) + m_yOffset,
atoi( attr["width"] ), atoi( attr["height" ]), atoi( attr["width"] ), atoi( attr["height" ]),
attr["lefttop"], attr["rightbottom"], attr["lefttop"], attr["rightbottom"],
attr["visible"], attr["help"], m_curLayer, attr["visible"], convertBoolean( attr["autoresize"] ),
m_curWindowId, m_curLayoutId ); attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
m_curLayer++; m_curLayer++;
m_data.m_listVideo.push_back( videoData ); m_data.m_listVideo.push_back( videoData );
} }
......
...@@ -149,6 +149,24 @@ void GenericLayout::resize( int width, int height ) ...@@ -149,6 +149,24 @@ void GenericLayout::resize( int width, int height )
return; 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 // Update the window size
m_width = width; m_width = width;
m_height = height; m_height = height;
......
...@@ -85,7 +85,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -85,7 +85,7 @@ static int Open( vlc_object_t *p_this )
if( p_intf->p_sys->p_playlist == NULL ) if( p_intf->p_sys->p_playlist == NULL )
{ {
msg_Err( p_intf, "No playlist object found" ); 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; return VLC_EGENERIC;
} }
...@@ -110,36 +110,36 @@ static int Open( vlc_object_t *p_this ) ...@@ -110,36 +110,36 @@ static int Open( vlc_object_t *p_this )
if( OSFactory::instance( p_intf ) == NULL ) if( OSFactory::instance( p_intf ) == NULL )
{ {
msg_Err( p_intf, "Cannot initialize OSFactory" ); msg_Err( p_intf, "Cannot initialize OSFactory" );
vlc_object_release( p_intf->p_sys->p_playlist ); vlc_object_release( p_intf->p_sys->p_playlist );
msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
if( AsyncQueue::instance( p_intf ) == NULL ) if( AsyncQueue::instance( p_intf ) == NULL )
{ {
msg_Err( p_intf, "Cannot initialize AsyncQueue" ); msg_Err( p_intf, "Cannot initialize AsyncQueue" );
vlc_object_release( p_intf->p_sys->p_playlist ); vlc_object_release( p_intf->p_sys->p_playlist );
msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
if( Interpreter::instance( p_intf ) == NULL ) if( Interpreter::instance( p_intf ) == NULL )
{ {
msg_Err( p_intf, "Cannot instanciate Interpreter" ); msg_Err( p_intf, "Cannot instanciate Interpreter" );
vlc_object_release( p_intf->p_sys->p_playlist ); vlc_object_release( p_intf->p_sys->p_playlist );
msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
if( VarManager::instance( p_intf ) == NULL ) if( VarManager::instance( p_intf ) == NULL )
{ {
msg_Err( p_intf, "Cannot instanciate VarManager" ); msg_Err( p_intf, "Cannot instanciate VarManager" );
vlc_object_release( p_intf->p_sys->p_playlist ); vlc_object_release( p_intf->p_sys->p_playlist );
msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
if( VlcProc::instance( p_intf ) == NULL ) if( VlcProc::instance( p_intf ) == NULL )
{ {
msg_Err( p_intf, "Cannot initialize VLCProc" ); msg_Err( p_intf, "Cannot initialize VLCProc" );
vlc_object_release( p_intf->p_sys->p_playlist ); vlc_object_release( p_intf->p_sys->p_playlist );
msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
Dialogs::instance( p_intf ); Dialogs::instance( p_intf );
......
...@@ -62,7 +62,7 @@ void VlcProc::destroy( intf_thread_t *pIntf ) ...@@ -62,7 +62,7 @@ void VlcProc::destroy( intf_thread_t *pIntf )
VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ), m_pVout( NULL ), 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 // Create a timer to poll the status of the vlc
OSFactory *pOsFactory = OSFactory::instance( pIntf ); OSFactory *pOsFactory = OSFactory::instance( pIntf );
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "../vars/playtree.hpp" #include "../vars/playtree.hpp"
#include "../vars/time.hpp" #include "../vars/time.hpp"
#include "../vars/volume.hpp" #include "../vars/volume.hpp"
#include "../utils/position.hpp"
#include "../utils/var_text.hpp" #include "../utils/var_text.hpp"
#include "../commands/cmd_generic.hpp" #include "../commands/cmd_generic.hpp"
...@@ -69,6 +70,9 @@ class VlcProc: public SkinObject ...@@ -69,6 +70,9 @@ class VlcProc: public SkinObject
VarText &getStreamURIVar() VarText &getStreamURIVar()
{ return *((VarText*)(m_cVarStreamURI.get())); } { return *((VarText*)(m_cVarStreamURI.get())); }
/// Getter for the vout size variable
VarBox &getVoutSizeVar() { return m_varVoutSize; }
/// Set the vout window handle /// Set the vout window handle
void registerVoutWindow( void *pVoutWindow ); void registerVoutWindow( void *pVoutWindow );
...@@ -111,6 +115,8 @@ class VlcProc: public SkinObject ...@@ -111,6 +115,8 @@ class VlcProc: public SkinObject
VariablePtr m_cVarStopped; VariablePtr m_cVarStopped;
VariablePtr m_cVarPaused; VariablePtr m_cVarPaused;
VariablePtr m_cVarSeekable; VariablePtr m_cVarSeekable;
/// Variable for the vout
VarBox m_varVoutSize;
/// Set of handles of vout windows /// Set of handles of vout windows
/** /**
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#include "position.hpp" #include "position.hpp"
const string VarBox::m_type = "box";
Rect::Rect( int left, int top, int right, int bottom ): Rect::Rect( int left, int top, int right, int bottom ):
m_left( left ), m_top( top ), m_right( right ), m_bottom( bottom ) m_left( left ), m_top( top ), m_right( right ), m_bottom( bottom )
{ {
...@@ -123,3 +126,29 @@ int Position::getHeight() const ...@@ -123,3 +126,29 @@ int Position::getHeight() const
return getBottom() - getTop() + 1; 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();
}
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#ifndef POSITION_HPP #ifndef POSITION_HPP
#define POSITION_HPP #define POSITION_HPP
#include "variable.hpp"
#include "observer.hpp"
/// Interface for rectangular objects /// Interface for rectangular objects
class Box class Box
...@@ -105,4 +108,30 @@ class Position ...@@ -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 #endif
...@@ -222,5 +222,6 @@ ...@@ -222,5 +222,6 @@
height CDATA "0" height CDATA "0"
lefttop CDATA "lefttop" lefttop CDATA "lefttop"
rightbottom CDATA "lefttop" rightbottom CDATA "lefttop"
autoresize CDATA "false"
help CDATA "" help CDATA ""
> >
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment