]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins2/controls/ctrl_text.cpp
skins2: optimize refresh of text control
[vlc] / modules / gui / skins2 / controls / ctrl_text.cpp
index e71aa1ff8bf77ef7f606a0aa364b1d524903cec7..867c6612367d814e530e8bbb486b1d412325b6dd 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
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "ctrl_text.hpp"
@@ -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,31 @@ 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() );
+        notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() );
+    }
+}
+
+
+void CtrlText::onUpdate( Subject<VarBool> &rVariable, void *arg  )
+{
+    // Visibility changed
+    if( &rVariable == m_pVisible )
+    {
+        if( isVisible() )
+        {
+            displayText( m_rVariable.get() );
+            notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() );
+        }
+        else
+        {
+            notifyLayout();
+        }
+    }
 }
 
 
@@ -224,10 +234,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 +242,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() )
@@ -276,18 +280,22 @@ void CtrlText::displayText( const UString &rText )
                 m_pTimer->stop();
             }
         }
-        notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() );
     }
 }
 
 
-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 +311,12 @@ void CtrlText::onChangePosition()
 }
 
 
+void CtrlText::onResize()
+{
+    onPositionChange();
+}
+
+
 void CtrlText::CmdToManual::execute()
 {
     EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;