]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/controls/ctrl_text.cpp
skins2: fix #689 (text control refresh issue)
[vlc] / modules / gui / skins2 / controls / ctrl_text.cpp
index cf326476b630e51bb269bcec6296aac9757b716c..a6c90a03886824238f498f019d0dc5135eb0a7e1 100644 (file)
@@ -5,7 +5,7 @@
  * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
- *          Olivier Teulière <ipkiss@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -91,10 +91,7 @@ CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable,
     }
 
     // Initial state
-    if( m_scrollMode == kAutomatic )
-        m_fsm.setState( "outMoving" );
-    else
-        m_fsm.setState( "outStill" );
+    m_fsm.setState( "outStill" );
 
     // Observe the variable
     m_rVariable.addObserver( this );
@@ -107,18 +104,9 @@ CtrlText::CtrlText( intf_thread_t *pIntf, VarText &rVariable,
 CtrlText::~CtrlText()
 {
     m_rVariable.delObserver( this );
-    if( m_pTimer )
-    {
-        delete m_pTimer;
-    }
-    if( m_pImg )
-    {
-        delete m_pImg;
-    }
-    if( m_pImgDouble )
-    {
-        delete m_pImgDouble;
-    }
+    delete m_pTimer;
+    delete m_pImg;
+    delete m_pImgDouble;
 }
 
 
@@ -214,9 +202,29 @@ void CtrlText::setText( const UString &rText, uint32_t color )
 }
 
 
-void CtrlText::onUpdate( Subject<VarText, void*> &rVariable, void* arg )
+void CtrlText::onUpdate( Subject<VarText> &rVariable, void* arg )
 {
-    displayText( m_rVariable.get() );
+    if( isVisible() )
+    {
+        displayText( m_rVariable.get() );
+    }
+}
+
+
+void CtrlText::onUpdate( Subject<VarBool> &rVariable, void *arg  )
+{
+    // Visibility changed
+    if( &rVariable == m_pVisible )
+    {
+        if( isVisible() )
+        {
+            displayText( m_rVariable.get() );
+        }
+        else
+        {
+            notifyLayout();
+        }
+    }
 }
 
 
@@ -224,10 +232,7 @@ void CtrlText::displayText( const UString &rText )
 {
     // Create the images ('normal' and 'double') from the text
     // 'Normal' image
-    if( m_pImg )
-    {
-        delete m_pImg;
-    }
+    delete m_pImg;
     m_pImg = m_rFont.drawString( rText, m_color );
     if( !m_pImg )
     {
@@ -235,14 +240,11 @@ void CtrlText::displayText( const UString &rText )
     }
     // 'Double' image
     const UString doubleStringWithSep = rText + SEPARATOR_STRING + rText;
-    if( m_pImgDouble )
-    {
-        delete m_pImgDouble;
-    }
+    delete m_pImgDouble;
     m_pImgDouble = m_rFont.drawString( doubleStringWithSep, m_color );
 
     // Update the current image used, as if the control size had changed
-    onChangePosition();
+    onPositionChange();
 
     if( m_alignment == kRight && getPosition() &&
         getPosition()->getWidth() < m_pImg->getWidth() )
@@ -281,13 +283,18 @@ void CtrlText::displayText( const UString &rText )
 }
 
 
-void CtrlText::onChangePosition()
+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
         {
@@ -303,6 +310,12 @@ void CtrlText::onChangePosition()
 }
 
 
+void CtrlText::onResize()
+{
+    onPositionChange();
+}
+
+
 void CtrlText::CmdToManual::execute()
 {
     EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;