]> git.sesse.net Git - vlc/commitdiff
* skins2: support $t, $d, and $l in text controls. They do the same as $T, $D
authorOlivier Teulière <ipkiss@videolan.org>
Sun, 13 Nov 2005 19:51:23 +0000 (19:51 +0000)
committerOlivier Teulière <ipkiss@videolan.org>
Sun, 13 Nov 2005 19:51:23 +0000 (19:51 +0000)
   and $L, except that the hour is not printed if it is 0.

modules/gui/skins2/src/bitmap_font.cpp
modules/gui/skins2/utils/var_text.cpp
modules/gui/skins2/vars/time.cpp
modules/gui/skins2/vars/time.hpp

index fb51e1dc6ee004da4495f5046a8e01ce95b6cdb5..0940a6706e66cbad27c1ff3643da47b47f2231e7 100644 (file)
@@ -43,6 +43,7 @@ BitmapFont::BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
         {
             m_table['0'+i].m_xPos = i * m_width;
         }
+        m_table[(size_t)' '].m_xPos = 10 * m_width;
         m_table[(size_t)'-'].m_xPos = 11 * m_width;
     }
     else if( rType == "text" )
index b851d798e421351fc9f4de0abd742e62da347fd8..9ede9fe9c24e75b8b1e7c4065fe44cd89310354c 100644 (file)
@@ -83,16 +83,31 @@ const UString VarText::get() const
         temp.replace( pos, 2,
                       pVlcProc->getTimeVar().getAsStringCurrTime().c_str() );
     }
+    while( (pos = temp.find( "$t" )) != UString::npos )
+    {
+        temp.replace( pos, 2,
+                      pVlcProc->getTimeVar().getAsStringCurrTime(true).c_str() );
+    }
     while( (pos = temp.find( "$L" )) != UString::npos )
     {
         temp.replace( pos, 2,
                       pVlcProc->getTimeVar().getAsStringTimeLeft().c_str() );
     }
+    while( (pos = temp.find( "$l" )) != UString::npos )
+    {
+        temp.replace( pos, 2,
+                      pVlcProc->getTimeVar().getAsStringTimeLeft(true).c_str() );
+    }
     while( (pos = temp.find( "$D" )) != UString::npos )
     {
         temp.replace( pos, 2,
                       pVlcProc->getTimeVar().getAsStringDuration().c_str() );
     }
+    while( (pos = temp.find( "$d" )) != UString::npos )
+    {
+        temp.replace( pos, 2,
+                      pVlcProc->getTimeVar().getAsStringDuration(true).c_str() );
+    }
     while( (pos = temp.find( "$V" )) != UString::npos )
     {
         temp.replace( pos, 2,
@@ -137,15 +152,18 @@ void VarText::set( const UString &rText )
         {
             pVarManager->getHelpText().addObserver( this );
         }
-        if( m_text.find( "$T" ) != UString::npos )
+        if( m_text.find( "$T" ) != UString::npos ||
+            m_text.find( "$t" ) != UString::npos )
         {
             pVlcProc->getTimeVar().addObserver( this );
         }
-        if( m_text.find( "$L" ) != UString::npos )
+        if( m_text.find( "$L" ) != UString::npos ||
+            m_text.find( "$l" ) != UString::npos )
         {
             pVlcProc->getTimeVar().addObserver( this );
         }
-        if( m_text.find( "$D" ) != UString::npos )
+        if( m_text.find( "$D" ) != UString::npos ||
+            m_text.find( "$d" ) != UString::npos )
         {
             pVlcProc->getTimeVar().addObserver( this );
         }
index 65633af03070e3cc2e0f6558551461879f27b657..4c081513873dda29fad90da815ae41a8f3a52092 100644 (file)
@@ -56,7 +56,7 @@ const string StreamTime::getAsStringPercent() const
 }
 
 
-const string StreamTime::getAsStringCurrTime() const
+const string StreamTime::getAsStringCurrTime( bool bShortFormat ) const
 {
     if( getIntf()->p_sys->p_input == NULL )
     {
@@ -73,11 +73,11 @@ const string StreamTime::getAsStringCurrTime() const
     vlc_value_t time;
     var_Get( getIntf()->p_sys->p_input, "time", &time );
 
-    return formatTime( time.i_time / 1000000 );
+    return formatTime( time.i_time / 1000000, bShortFormat );
 }
 
 
-const string StreamTime::getAsStringTimeLeft() const
+const string StreamTime::getAsStringTimeLeft( bool bShortFormat ) const
 {
     if( getIntf()->p_sys->p_input == NULL )
     {
@@ -95,11 +95,12 @@ const string StreamTime::getAsStringTimeLeft() const
     var_Get( getIntf()->p_sys->p_input, "time", &time );
     var_Get( getIntf()->p_sys->p_input, "length", &duration );
 
-    return formatTime( (duration.i_time - time.i_time) / 1000000 );
+    return formatTime( (duration.i_time - time.i_time) / 1000000,
+                       bShortFormat );
 }
 
 
-const string StreamTime::getAsStringDuration() const
+const string StreamTime::getAsStringDuration( bool bShortFormat ) const
 {
     if( getIntf()->p_sys->p_input == NULL )
     {
@@ -116,17 +117,26 @@ const string StreamTime::getAsStringDuration() const
     vlc_value_t time;
     var_Get( getIntf()->p_sys->p_input, "length", &time );
 
-    return formatTime( time.i_time / 1000000 );
+    return formatTime( time.i_time / 1000000, bShortFormat );
 }
 
 
-const string StreamTime::formatTime( int seconds ) const
+const string StreamTime::formatTime( int seconds, bool bShortFormat ) const
 {
     char *psz_time = new char[MSTRTIME_MAX_SIZE];
-    snprintf( psz_time, MSTRTIME_MAX_SIZE, "%d:%02d:%02d",
-              (int) (seconds / (60 * 60)),
-              (int) (seconds / 60 % 60),
-              (int) (seconds % 60) );
+    if( bShortFormat && (seconds < 60 * 60) )
+    {
+        snprintf( psz_time, MSTRTIME_MAX_SIZE, "  %02d:%02d",
+                  (int) (seconds / 60 % 60),
+                  (int) (seconds % 60) );
+    }
+    else
+    {
+        snprintf( psz_time, MSTRTIME_MAX_SIZE, "%d:%02d:%02d",
+                  (int) (seconds / (60 * 60)),
+                  (int) (seconds / 60 % 60),
+                  (int) (seconds % 60) );
+    }
 
     string ret = psz_time;
     delete[] psz_time;
index 082e1cd30c232a7f8773c3deb43a2f4a353393f9..0292c43cc85ff0dae3987cd98437876dc33ceb33 100644 (file)
@@ -42,15 +42,15 @@ class StreamTime: public VarPercent
         /// Return a string containing a value from 0 to 100
         virtual const string getAsStringPercent() const;
         /// Return the current time formatted as a time display (h:mm:ss)
-        virtual const string getAsStringCurrTime() const;
+        virtual const string getAsStringCurrTime( bool bShortFormat = false ) const;
         /// Return the time left formatted as a time display (h:mm:ss)
-        virtual const string getAsStringTimeLeft() const;
+        virtual const string getAsStringTimeLeft( bool bShortFormat = false ) const;
         /// Return the duration formatted as a time display (h:mm:ss)
-        virtual const string getAsStringDuration() const;
+        virtual const string getAsStringDuration( bool bShortFormat = false ) const;
 
     private:
         /// Convert a number of seconds into "h:mm:ss" format
-        const string formatTime( int seconds ) const;
+        const string formatTime( int seconds, bool bShortFormat ) const;
 };
 
 #endif