From: Olivier Teulière Date: Tue, 15 Nov 2005 20:00:04 +0000 (+0000) Subject: * skins2: the Text control now supports 2 additional attributes: X-Git-Tag: 0.9.0-test0~13295 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=e2cc1fabeeb51c046f8706d482a52502995ec0c0;p=vlc * skins2: the Text control now supports 2 additional attributes: - alignment: possible values are left/right/center (left is the default) The right and center alignments are computed using the width of the control (as given by the "width" attribute). - scrolling: possible values are auto/manual/none (auto is the default) * auto: same behaviour as before, the text automatically starts scrolling if it doesn't fit in the width of the control. The user can still drag it manually. * manual: only manual scrolling is possible * none: no scrolling possible --- diff --git a/modules/gui/skins2/controls/ctrl_text.cpp b/modules/gui/skins2/controls/ctrl_text.cpp index ec76b6a5ee..9e3a9df90d 100644 --- a/modules/gui/skins2/controls/ctrl_text.cpp +++ b/modules/gui/skins2/controls/ctrl_text.cpp @@ -42,12 +42,14 @@ 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 ) { @@ -62,23 +64,37 @@ CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable, 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 ); @@ -157,8 +173,29 @@ void CtrlText::draw( OSGraphics &rImage, int xDest, int yDest ) // 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 ); } } } @@ -206,7 +243,21 @@ void CtrlText::displayText( const UString &rText ) // 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() ) { @@ -269,7 +320,8 @@ void CtrlText::CmdManualMoving::execute() 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() ) { @@ -306,7 +358,7 @@ void CtrlText::CmdMove::execute() m_pParent->adjust( m_pParent->m_xPos ); m_pParent->notifyLayout( m_pParent->getPosition()->getWidth(), - m_pParent->getPosition()->getHeight() ); + m_pParent->getPosition()->getHeight() ); } } @@ -317,13 +369,13 @@ void CtrlText::CmdUpdateText::execute() 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 ) diff --git a/modules/gui/skins2/controls/ctrl_text.hpp b/modules/gui/skins2/controls/ctrl_text.hpp index 1de9744f26..490d4e501e 100644 --- a/modules/gui/skins2/controls/ctrl_text.hpp +++ b/modules/gui/skins2/controls/ctrl_text.hpp @@ -41,10 +41,30 @@ class VarText; class CtrlText: public CtrlGeneric, public Observer { 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 @@ -79,6 +99,10 @@ class CtrlText: public CtrlGeneric, public Observer 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; @@ -86,7 +110,7 @@ class CtrlText: public CtrlGeneric, public Observer 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 diff --git a/modules/gui/skins2/parser/builder.cpp b/modules/gui/skins2/parser/builder.cpp index fafaab89ad..b5da62e2e5 100644 --- a/modules/gui/skins2/parser/builder.cpp +++ b/modules/gui/skins2/parser/builder.cpp @@ -516,10 +516,37 @@ void Builder::addText( const BuilderData::Text &rData ) 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 @@ -528,7 +555,8 @@ void Builder::addText( const BuilderData::Text &rData ) 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(); @@ -540,6 +568,10 @@ void Builder::addText( const BuilderData::Text &rData ) 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 ); } diff --git a/modules/gui/skins2/parser/builder_data.def b/modules/gui/skins2/parser/builder_data.def index cd1b38b3d3..0f0cfe9c6e 100644 --- a/modules/gui/skins2/parser/builder_data.def +++ b/modules/gui/skins2/parser/builder_data.def @@ -9,7 +9,7 @@ Anchor xPos:int yPos:int range:int priority:int points:string layoutId:string 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 diff --git a/modules/gui/skins2/parser/builder_data.hpp b/modules/gui/skins2/parser/builder_data.hpp index 5a6876ab8b..c5cbe5c2d4 100644 --- a/modules/gui/skins2/parser/builder_data.hpp +++ b/modules/gui/skins2/parser/builder_data.hpp @@ -240,8 +240,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( /// 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; @@ -253,6 +253,8 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_fontId( font 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; diff --git a/modules/gui/skins2/parser/skin_parser.cpp b/modules/gui/skins2/parser/skin_parser.cpp index 815902ba3d..81038e972e 100644 --- a/modules/gui/skins2/parser/skin_parser.cpp +++ b/modules/gui/skins2/parser/skin_parser.cpp @@ -415,6 +415,8 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) CheckDefault( "y", "0" ); CheckDefault( "text", "" ); CheckDefault( "color", "#000000" ); + CheckDefault( "scrolling", "auto" ); + CheckDefault( "alignment", "left" ); CheckDefault( "width", "0" ); CheckDefault( "lefttop", "lefttop" ); CheckDefault( "rightbottom", "lefttop" ); @@ -425,8 +427,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) 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 ); } diff --git a/share/skins2/skin.dtd b/share/skins2/skin.dtd index cfa66e12ea..8480809d84 100644 --- a/share/skins2/skin.dtd +++ b/share/skins2/skin.dtd @@ -190,6 +190,8 @@ text CDATA "" font CDATA #REQUIRED color CDATA "#000000" + scrolling CDATA "auto" + alignment CDATA "left" help CDATA "" >