CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable,
const GenericFont &rFont, const UString &rHelp,
- uint32_t color, VarBool *pVisible ):
+ uint32_t color, VarBool *pVisible, Scrolling_t scrollMode,
+ Align_t alignment ):
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_color( color ), m_scrollMode( scrollMode ), m_alignment( alignment ),
+ m_pImg( NULL ), m_pImgDouble( NULL ),
m_pCurrImg( NULL ), m_xPos( 0 ), m_xOffset( 0 ),
m_cmdUpdateText( this )
{
m_fsm.addState( "outMoving" );
// Transitions
- m_fsm.addTransition( "still", "mouse:left:down", "manual1",
- &m_cmdToManual );
- m_fsm.addTransition( "manual1", "mouse:left:up", "moving",
- &m_cmdManualMoving );
- m_fsm.addTransition( "moving", "mouse:left:down", "manual2",
- &m_cmdToManual );
- m_fsm.addTransition( "manual2", "mouse:left:up", "still",
- &m_cmdManualStill );
- m_fsm.addTransition( "manual1", "motion", "manual1", &m_cmdMove );
- m_fsm.addTransition( "manual2", "motion", "manual2", &m_cmdMove );
m_fsm.addTransition( "still", "leave", "outStill" );
m_fsm.addTransition( "outStill", "enter", "still" );
- m_fsm.addTransition( "moving", "leave", "outMoving" );
- m_fsm.addTransition( "outMoving", "enter", "moving" );
+ if( m_scrollMode == kManual )
+ {
+ m_fsm.addTransition( "still", "mouse:left:down", "manual1",
+ &m_cmdToManual );
+ m_fsm.addTransition( "manual1", "mouse:left:up", "still",
+ &m_cmdManualStill );
+ m_fsm.addTransition( "manual1", "motion", "manual1", &m_cmdMove );
+ }
+ else if( m_scrollMode == kAutomatic )
+ {
+ m_fsm.addTransition( "still", "mouse:left:down", "manual1",
+ &m_cmdToManual );
+ m_fsm.addTransition( "manual1", "mouse:left:up", "moving",
+ &m_cmdManualMoving );
+ m_fsm.addTransition( "moving", "mouse:left:down", "manual2",
+ &m_cmdToManual );
+ m_fsm.addTransition( "manual2", "mouse:left:up", "still",
+ &m_cmdManualStill );
+ m_fsm.addTransition( "manual1", "motion", "manual1", &m_cmdMove );
+ m_fsm.addTransition( "manual2", "motion", "manual2", &m_cmdMove );
+ m_fsm.addTransition( "moving", "leave", "outMoving" );
+ m_fsm.addTransition( "outMoving", "enter", "moving" );
+ }
// Initial state
- m_fsm.setState( "moving" );
+ if( m_scrollMode == kAutomatic )
+ m_fsm.setState( "outMoving" );
+ else
+ m_fsm.setState( "outStill" );
// Observe the variable
m_rVariable.addObserver( this );
// Draw the current image
if( width > 0 && height > 0 )
{
- rImage.drawBitmap( *m_pCurrImg, -m_xPos, 0, xDest, yDest,
- width, height, true );
+ int offset = 0;
+ if( m_alignment == kLeft )
+ {
+ // We align to the left
+ offset = 0;
+ }
+ else if( m_alignment == kRight &&
+ width < getPosition()->getWidth() )
+
+ {
+ // The text is shorter than the width of the control, so we
+ // can align it to the right
+ offset = getPosition()->getWidth() - width;
+ }
+ else if( m_alignment == kCenter &&
+ width < getPosition()->getWidth() )
+ {
+ // The text is shorter than the width of the control, so we
+ // can center it
+ offset = (getPosition()->getWidth() - width) / 2;
+ }
+ rImage.drawBitmap( *m_pCurrImg, -m_xPos, 0, xDest + offset,
+ yDest, width, height, true );
}
}
}
// Update the current image used, as if the control size had changed
onChangePosition();
- m_xPos = 0;
+
+ if( m_alignment == kRight && getPosition() &&
+ getPosition()->getWidth() < m_pImg->getWidth() )
+ {
+ m_xPos = getPosition()->getWidth() - m_pImg->getWidth();
+ }
+ else if( m_alignment == kCenter && getPosition() &&
+ getPosition()->getWidth() < m_pImg->getWidth() )
+ {
+ m_xPos = (getPosition()->getWidth() - m_pImg->getWidth()) / 2;
+ }
+ else
+ {
+ m_xPos = 0;
+ }
if( getPosition() )
{
m_pParent->releaseMouse();
// Start the automatic movement, but only if the text is wider than the
- // control
+ // control and if the control can scroll (either in manual or automatic
+ // mode)
if( m_pParent->m_pImg &&
m_pParent->m_pImg->getWidth() >= m_pParent->getPosition()->getWidth() )
{
m_pParent->adjust( m_pParent->m_xPos );
m_pParent->notifyLayout( m_pParent->getPosition()->getWidth(),
- m_pParent->getPosition()->getHeight() );
+ m_pParent->getPosition()->getHeight() );
}
}
m_pParent->adjust( m_pParent->m_xPos );
m_pParent->notifyLayout( m_pParent->getPosition()->getWidth(),
- m_pParent->getPosition()->getHeight() );
+ m_pParent->getPosition()->getHeight() );
}
void CtrlText::adjust( int &position )
{
- // {m_pImgDouble->getWidth() - m_pImg->getWidth()} is the period of the
+ // {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
if( !m_pImg )
class CtrlText: public CtrlGeneric, public Observer<VarText>
{
public:
+ enum Align_t
+ {
+ kLeft,
+ kCenter,
+ kRight
+ };
+
+ enum Scrolling_t
+ {
+ // The text starts scrolling automatically if it is larger than the
+ // width of the control. The user can still stop it or make it
+ // scroll manually with the mouse.
+ kAutomatic,
+ // Only manual scrolling is allowed (with the mouse)
+ kManual,
+ // No scrolling of the text is allowed
+ kNone
+ };
+
/// Create a text control with the optional given color
CtrlText( intf_thread_t *pIntf, VarText &rVariable,
const GenericFont &rFont, const UString &rHelp,
- uint32_t color, VarBool *pVisible );
+ uint32_t color, VarBool *pVisible, Scrolling_t scrollMode,
+ Align_t alignment);
virtual ~CtrlText();
/// Handle an event
const GenericFont &m_rFont;
/// Color of the text
uint32_t m_color;
+ /// Scrolling mode
+ Scrolling_t m_scrollMode;
+ /// Type of alignment
+ Align_t m_alignment;
/// Image of the text
GenericBitmap *m_pImg;
/// Image of the text, repeated twice and with some blank between;
GenericBitmap *m_pImgDouble;
/// Current image (should always be equal to m_pImg or m_pImgDouble)
GenericBitmap *m_pCurrImg;
- /// Position of the left side of the moving text
+ /// Position of the left side of the moving text (always <= 0)
int m_xPos;
/// Offset between the mouse pointer and the left side of the
/// moving text
return;
}
+ // Convert the scrolling mode
+ CtrlText::Scrolling_t scrolling;
+ if( rData.m_scrolling == "auto" )
+ scrolling = CtrlText::kAutomatic;
+ else if( rData.m_scrolling == "manual" )
+ scrolling = CtrlText::kManual;
+ else if( rData.m_scrolling == "none" )
+ scrolling = CtrlText::kNone;
+ else
+ {
+ msg_Err( getIntf(), "Invalid scrolling mode: %s",
+ rData.m_scrolling.c_str() );
+ }
+
+ // Convert the alignment
+ CtrlText::Align_t alignment;
+ if( rData.m_alignment == "left" )
+ alignment = CtrlText::kLeft;
+ else if( rData.m_alignment == "center" || rData.m_alignment == "centre" )
+ alignment = CtrlText::kCenter;
+ else if( rData.m_alignment == "right" )
+ alignment = CtrlText::kRight;
+ else
+ {
+ msg_Err( getIntf(), "Invalid alignment: %s",
+ rData.m_alignment.c_str() );
+ return;
+ }
+
// Create a text variable
VarText *pVar = new VarText( getIntf() );
- UString msg( getIntf(), rData.m_text.c_str() );
- pVar->set( msg );
m_pTheme->m_vars.push_back( VariablePtr( pVar ) );
// Get the visibility variable
VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
CtrlText *pText = new CtrlText( getIntf(), *pVar, *pFont,
- UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible );
+ UString( getIntf(), rData.m_help.c_str() ), rData.m_color, pVisible,
+ scrolling, alignment );
int height = pFont->getSize();
pLayout->addControl( pText, pos, rData.m_layer );
+ // Set the text of the control
+ UString msg( getIntf(), rData.m_text.c_str() );
+ pVar->set( msg );
+
m_pTheme->m_controls[rData.m_id] = CtrlGenericPtr( pText );
}
Button id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string upId:string downId:string overId:string actionId:string tooltip:string help:string layer:int windowId:string layoutId:string
Checkbox id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string up1Id:string down1Id:string over1Id:string up2Id:string down2Id:string over2Id:string state:string action1:string action2:string tooltip1:string tooltip2:string help:string layer:int windowId:string layoutId:string
Image id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string bmpId:string actionId:string resize:string help:string layer:int windowId:string layoutId:string
-Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string color:uint32_t help:string layer:int windowId:string layoutId:string
+Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string color:uint32_t scrolling:string alignment:string help:string layer:int windowId:string layoutId:string
RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string sequence:string nbImages:int minAngle:float maxAngle:float 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 imageId:string nbHoriz:int nbVert:int padHoriz:int padVert:int 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
/// Type definition
struct Text
{
- Text( const string & id, int xPos, int yPos, const string & visible, const string & fontId, const string & text, int width, const string & leftTop, const string & rightBottom, uint32_t color, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( fontId ), m_text( text ), m_width( width ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_color( color ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+ Text( const string & id, int xPos, int yPos, const string & visible, const string & fontId, const string & text, int width, const string & leftTop, const string & rightBottom, uint32_t color, const string & scrolling, const string & alignment, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( fontId ), m_text( text ), m_width( width ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_color( color ), m_scrolling( scrolling ), m_alignment( alignment ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
string m_id;
int m_xPos;
string m_leftTop;
string m_rightBottom;
uint32_t m_color;
+ string m_scrolling;
+ string m_alignment;
string m_help;
int m_layer;
string m_windowId;
CheckDefault( "y", "0" );
CheckDefault( "text", "" );
CheckDefault( "color", "#000000" );
+ CheckDefault( "scrolling", "auto" );
+ CheckDefault( "alignment", "left" );
CheckDefault( "width", "0" );
CheckDefault( "lefttop", "lefttop" );
CheckDefault( "rightbottom", "lefttop" );
attr["visible"], attr["font"],
attr["text"], atoi( attr["width"] ),
attr["lefttop"], attr["rightbottom"],
- convertColor( attr["color"] ), attr["help"], m_curLayer,
- m_curWindowId, m_curLayoutId );
+ convertColor( attr["color"] ),
+ attr["scrolling"], attr["alignment"],
+ attr["help"], m_curLayer, m_curWindowId, m_curLayoutId );
m_curLayer++;
m_pData->m_listText.push_back( textData );
}
text CDATA ""
font CDATA #REQUIRED
color CDATA "#000000"
+ scrolling CDATA "auto"
+ alignment CDATA "left"
help CDATA ""
>
<!ELEMENT Playlist (Slider)?>