X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fskins2%2Fcontrols%2Fctrl_text.cpp;h=da48507ebce52fadd9b032a384417e522ea7c446;hb=465f11bc4273d4432995fa31888ca727f0f3aeaf;hp=e32da13683a8a0cfff3190cf1cd0a5f9ab1a5952;hpb=303113c7964055549f5335b9c8c6401567e0e515;p=vlc diff --git a/modules/gui/skins2/controls/ctrl_text.cpp b/modules/gui/skins2/controls/ctrl_text.cpp index e32da13683..da48507ebc 100644 --- a/modules/gui/skins2/controls/ctrl_text.cpp +++ b/modules/gui/skins2/controls/ctrl_text.cpp @@ -6,6 +6,7 @@ * * Authors: Cyril Deguet * Olivier Teulière + * Erwan Tulou get() ) + return false; + if( m_pCurrImg ) { // We have 3 different ways of deciding when to return true here: @@ -150,8 +154,10 @@ bool CtrlText::mouseOver( int x, int y ) const } -void CtrlText::draw( OSGraphics &rImage, int xDest, int yDest ) +void CtrlText::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h ) { + rect clip( xDest, yDest, w, h ); + const Position *pPos = getPosition(); if( m_pCurrImg ) { // Compute the dimensions to draw @@ -178,12 +184,18 @@ void CtrlText::draw( OSGraphics &rImage, int xDest, int yDest ) else if( m_alignment == kCenter && width < getPosition()->getWidth() ) { - // The text is shorter than the width of the control, so we - // can center it + // 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 ); + rect region( pPos->getLeft() + offset, + pPos->getTop(), width, height ); + rect inter; + if( rect::intersect( region, clip, &inter ) ) + rImage.drawBitmap( *m_pCurrImg, -m_xPos + inter.x - region.x, + inter.y - region.y, + inter.x, inter.y, + inter.width, inter.height, true ); } } } @@ -204,37 +216,89 @@ void CtrlText::setText( const UString &rText, uint32_t color ) void CtrlText::onUpdate( Subject &rVariable, void* arg ) { + (void)rVariable; (void)arg; if( isVisible() ) { - displayText( m_rVariable.get() ); + setPictures( m_rVariable.get() ); + updateContext(); + notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() ); } } -void CtrlText::displayText( const UString &rText ) +void CtrlText::onUpdate( Subject &rVariable, void *arg ) { - // Create the images ('normal' and 'double') from the text + (void)arg; + // Visibility changed + if( &rVariable == m_pVisible ) + { + if( isVisible() ) + { + setPictures( m_rVariable.get() ); + updateContext(); + notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() ); + } + } +} + + +void CtrlText::setPictures( const UString &rText ) +{ + // reset the images ('normal' and 'double') from the text // 'Normal' image delete m_pImg; m_pImg = m_rFont.drawString( rText, m_color ); if( !m_pImg ) - { return; - } + // 'Double' image const UString doubleStringWithSep = rText + SEPARATOR_STRING + rText; delete m_pImgDouble; m_pImgDouble = m_rFont.drawString( doubleStringWithSep, m_color ); +} + - // Update the current image used, as if the control size had changed - onPositionChange(); +void CtrlText::updateContext() +{ + if( !m_pImg || !getPosition() ) + return; + + if( m_pImg->getWidth() < getPosition()->getWidth() ) + { + m_pCurrImg = m_pImg; + + // When the control becomes wide enough for the text to display, + // make sure to stop any scrolling effect + m_pTimer->stop(); + m_xPos = 0; + } + else + { + m_pCurrImg = m_pImgDouble; + } + + // If the control is in the moving state, + // automatically start or stop the timer accordingly + const string &rState = m_fsm.getState(); + if( rState == "moving" || rState == "outMoving" ) + { + if( m_pCurrImg == m_pImgDouble ) + { + m_pTimer->start( MOVING_TEXT_DELAY, false ); + } + else + { + m_pTimer->stop(); + } + } - if( m_alignment == kRight && getPosition() && + // compute alignment + if( m_alignment == kRight && getPosition()->getWidth() < m_pImg->getWidth() ) { m_xPos = getPosition()->getWidth() - m_pImg->getWidth(); } - else if( m_alignment == kCenter && getPosition() && + else if( m_alignment == kCenter && getPosition()->getWidth() < m_pImg->getWidth() ) { m_xPos = (getPosition()->getWidth() - m_pImg->getWidth()) / 2; @@ -243,59 +307,18 @@ void CtrlText::displayText( const UString &rText ) { m_xPos = 0; } - - 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::onPositionChange() { - if( m_pImg && getPosition() ) - { - if( m_pImg->getWidth() < getPosition()->getWidth() ) - { - m_pCurrImg = m_pImg; - - // When the control becomes wide enough for the text to display, - // make sure to stop any scrolling effect - m_pTimer->stop(); - m_xPos = 0; - } - else - { - m_pCurrImg = m_pImgDouble; - } - } - else - { - // m_pImg is a better default value than m_pImgDouble, but anyway we - // don't care because the control is never drawn without position :) - m_pCurrImg = m_pImg; - } + updateContext(); } void CtrlText::onResize() { - onPositionChange(); + updateContext(); } @@ -318,13 +341,9 @@ void CtrlText::CmdManualMoving::execute() // Start the automatic movement, but only if the text is wider than the // 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() ) + if( m_pParent->m_pCurrImg && + m_pParent->m_pCurrImg == m_pParent->m_pImgDouble ) { - // The current image may have been set incorrectly in displayText(), so - // set the correct value - m_pParent->m_pCurrImg = m_pParent->m_pImgDouble; - m_pParent->m_pTimer->start( MOVING_TEXT_DELAY, false ); } } @@ -340,14 +359,10 @@ void CtrlText::CmdMove::execute() { EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt; - // Do nothing if the text fits in the control - if( m_pParent->m_pImg && - m_pParent->m_pImg->getWidth() >= m_pParent->getPosition()->getWidth() ) + // Move text only when it is larger than the control + if( m_pParent->m_pCurrImg && + m_pParent->m_pCurrImg == m_pParent->m_pImgDouble ) { - // The current image may have been set incorrectly in displayText(), so - // we set the correct value - 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 m_pParent->m_xPos = (pEvtMouse->getXPos() - m_pParent->m_xOffset); @@ -371,13 +386,12 @@ void CtrlText::CmdUpdateText::execute() void CtrlText::adjust( int &position ) { + if( !m_pImg || !m_pImgDouble ) + return; + // {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 ) - { - return; - } position %= m_pImgDouble->getWidth() - m_pImg->getWidth(); if( position > 0 ) {