/*****************************************************************************
* ctrl_text.cpp
*****************************************************************************
- * Copyright (C) 2003 VideoLAN
- * $Id: ctrl_text.cpp,v 1.1 2004/01/03 23:31:33 asmax Exp $
+ * Copyright (C) 2003 the VideoLAN team
+ * $Id$
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr>
#include "../utils/var_text.hpp"
-#define MOVING_TEXT_STEP 3
-#define MOVING_TEXT_DELAY 200
+#define MOVING_TEXT_STEP 1
+#define MOVING_TEXT_DELAY 30
#define SEPARATOR_STRING " "
CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable,
const GenericFont &rFont, const UString &rHelp,
- uint32_t color ):
- CtrlGeneric( pIntf, rHelp ), m_fsm( pIntf ), m_rVariable( rVariable ),
- m_cmdToManual( this, &transToManual ),
- m_cmdManualMoving( this, &transManualMoving ),
- m_cmdManualStill( this, &transManualStill ),
- m_cmdMove( this, &transMove ),
- m_pEvt( NULL ), m_rFont( rFont ), m_color( color ),
- m_pImg( NULL ), m_pImgDouble( NULL ), m_pCurrImg( NULL ),
- m_xPos( 0 ), m_xOffset( 0 )
+ uint32_t color, VarBool *pVisible ):
+ CtrlGeneric( pIntf, rHelp, pVisible ), m_fsm( pIntf ),
+ m_rVariable( rVariable ), m_cmdToManual( this ),
+ m_cmdManualMoving( this ), m_cmdManualStill( this ),
+ m_cmdMove( this ), m_pEvt( NULL ), m_rFont( rFont ),
+ m_color( color ), m_pImg( NULL ), m_pImgDouble( NULL ),
+ m_pCurrImg( NULL ), m_xPos( 0 ), m_xOffset( 0 ),
+ m_cmdUpdateText( this )
{
- m_pTimer = OSFactory::instance( getIntf() )->createOSTimer(
- Callback( this, &updateText ) );
+ m_pTimer = OSFactory::instance( pIntf )->createOSTimer( m_cmdUpdateText );
// States
m_fsm.addState( "still" );
m_fsm.addTransition( "outMoving", "enter", "moving" );
// Initial state
- m_fsm.setState( "outStill" );
+ m_fsm.setState( "moving" );
// Observe the variable
m_rVariable.addObserver( this );
getPosition()->getWidth() );
int height = min( m_pCurrImg->getHeight(), getPosition()->getHeight() );
// Draw the current image
- rImage.drawBitmap( *m_pCurrImg, -m_xPos, 0, xDest, yDest,
- width, height );
+ if( width > 0 && height > 0 )
+ {
+ rImage.drawBitmap( *m_pCurrImg, -m_xPos, 0, xDest, yDest,
+ width, height, true );
+ }
}
}
void CtrlText::displayText( const UString &rText )
{
- m_pTimer->stop();
-
// Create the images ('normal' and 'double') from the text
// 'Normal' image
if( m_pImg )
delete m_pImg;
}
m_pImg = m_rFont.drawString( rText, m_color );
+ if( !m_pImg )
+ {
+ return;
+ }
// 'Double' image
const UString doubleStringWithSep = rText + SEPARATOR_STRING + rText;
if( m_pImgDouble )
// Update the current image used, as if the control size had changed
onChangePosition();
+ m_xPos = 0;
- // XXX: will this always work?
- m_fsm.setState( "outStill" );
- notifyLayout();
+ if( getPosition() )
+ {
+ // If the control was in the moving state, check if the scrolling is
+ // still necessary
+ const string &rState = m_fsm.getState();
+ if( rState == "moving" || rState == "outMoving" )
+ {
+ if( m_pImg && m_pImg->getWidth() >= getPosition()->getWidth() )
+ {
+ m_pCurrImg = m_pImgDouble;
+ m_pTimer->start( MOVING_TEXT_DELAY, false );
+ }
+ else
+ {
+ m_pTimer->stop();
+ }
+ }
+ notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() );
+ }
}
void CtrlText::onChangePosition()
{
- if( getPosition() )
+ if( m_pImg && getPosition() )
{
if( m_pImg->getWidth() < getPosition()->getWidth() )
{
}
-void CtrlText::transToManual( SkinObject *pCtrl )
+void CtrlText::CmdToManual::execute()
{
- CtrlText *pThis = (CtrlText*)pCtrl;
- EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
+ EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
// Compute the offset
- pThis->m_xOffset = pEvtMouse->getXPos() - pThis->m_xPos;
+ m_pParent->m_xOffset = pEvtMouse->getXPos() - m_pParent->m_xPos;
- pThis->m_pTimer->stop();
- pThis->captureMouse();
+ m_pParent->m_pTimer->stop();
+ m_pParent->captureMouse();
}
-void CtrlText::transManualMoving( SkinObject *pCtrl )
+void CtrlText::CmdManualMoving::execute()
{
- CtrlText *pThis = (CtrlText*)pCtrl;
- pThis->releaseMouse();
+ m_pParent->releaseMouse();
// Start the automatic movement, but only if the text is wider than the
// control
- if( pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
+ if( m_pParent->m_pImg &&
+ m_pParent->m_pImg->getWidth() >= m_pParent->getPosition()->getWidth() )
{
// The current image may have been set incorrectly in displayText(), so
// set the correct value
- pThis->m_pCurrImg = pThis->m_pImgDouble;
+ m_pParent->m_pCurrImg = m_pParent->m_pImgDouble;
- pThis->m_pTimer->start( MOVING_TEXT_DELAY, false );
+ m_pParent->m_pTimer->start( MOVING_TEXT_DELAY, false );
}
}
-void CtrlText::transManualStill( SkinObject *pCtrl )
+void CtrlText::CmdManualStill::execute()
{
- CtrlText *pThis = (CtrlText*)pCtrl;
- pThis->releaseMouse();
+ m_pParent->releaseMouse();
}
-void CtrlText::transMove( SkinObject *pCtrl )
+void CtrlText::CmdMove::execute()
{
- CtrlText *pThis = (CtrlText*)pCtrl;
- EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
+ EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;
// Do nothing if the text fits in the control
- if( pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
+ if( m_pParent->m_pImg &&
+ m_pParent->m_pImg->getWidth() >= m_pParent->getPosition()->getWidth() )
{
// The current image may have been set incorrectly in displayText(), so
// we set the correct value
- pThis->m_pCurrImg = pThis->m_pImgDouble;
+ m_pParent->m_pCurrImg = m_pParent->m_pImgDouble;
// Compute the new position of the left side, and make sure it is
// in the correct range
- pThis->m_xPos = (pEvtMouse->getXPos() - pThis->m_xOffset);
- pThis->adjust( pThis->m_xPos );
+ m_pParent->m_xPos = (pEvtMouse->getXPos() - m_pParent->m_xOffset);
+ m_pParent->adjust( m_pParent->m_xPos );
- pThis->notifyLayout();
+ m_pParent->notifyLayout( m_pParent->getPosition()->getWidth(),
+ m_pParent->getPosition()->getHeight() );
}
}
-void CtrlText::updateText( SkinObject *pCtrl )
+void CtrlText::CmdUpdateText::execute()
{
- CtrlText *pThis = (CtrlText*)pCtrl;
+ m_pParent->m_xPos -= MOVING_TEXT_STEP;
+ m_pParent->adjust( m_pParent->m_xPos );
- pThis->m_xPos -= MOVING_TEXT_STEP;
- pThis->adjust( pThis->m_xPos );
-
- pThis->notifyLayout();
+ m_pParent->notifyLayout( m_pParent->getPosition()->getWidth(),
+ m_pParent->getPosition()->getHeight() );
}
// {m_pImgDouble->getWidth() - m_pImg->getWidth()} is the period of the
// bitmap; remember that the string used to generate m_pImgDouble is of the
// form: "foo foo", the number of spaces being a parameter
- position %= m_pImgDouble->getWidth() - m_pImg->getWidth();
+ if( !m_pImg )
+ {
+ return;
+ }
+ position %= m_pImgDouble->getWidth() - m_pImg->getWidth();
if( position > 0 )
{
- position -= m_pImgDouble->getWidth() - m_pImg->getWidth();
+ position -= m_pImgDouble->getWidth() - m_pImg->getWidth();
}
}