]> 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 2bc266994de3b978efe4ec55fa8c9072a69dd2f1..867c6612367d814e530e8bbb486b1d412325b6dd 100644 (file)
@@ -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,11 +202,30 @@ 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 )
 {
     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();
+        }
     }
 }
 
@@ -227,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 )
     {
@@ -238,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() )
@@ -279,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
         {
@@ -306,6 +311,12 @@ void CtrlText::onChangePosition()
 }
 
 
+void CtrlText::onResize()
+{
+    onPositionChange();
+}
+
+
 void CtrlText::CmdToManual::execute()
 {
     EvtMouse *pEvtMouse = (EvtMouse*)m_pParent->m_pEvt;