Don't break time into seconds and frames when the framerate is 1 or more.
[synfig.git] / synfig-core / trunk / src / synfig / time.cpp
index eb2eef7..98dbff5 100644 (file)
@@ -6,6 +6,7 @@
 **
 **     \legal
 **     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007 Chris Moore
 **
 **     This package is free software; you can redistribute it and/or
 **     modify it under the terms of the GNU General Public License as
@@ -192,7 +193,7 @@ Time::get_string(float fps, Time::Format format)const
                int second;
                second=time;time-=second;
 
-               if(fps)
+               if(fps && fps>1)
                {
                        int frame;
                        frame=round_to_int(time*fps);
@@ -218,7 +219,7 @@ Time::get_string(float fps, Time::Format format)const
                started = true;
        }
 
-       if(fps)
+       if(fps && fps>1)
        {
                int second;
                float frame;
@@ -245,7 +246,19 @@ Time::get_string(float fps, Time::Format format)const
                if(format<=FORMAT_FULL || second || !started)
                {
                        if(abs(second-floor(second))>=epsilon_())
-                               ret+=strprintf("%0.8fs",second);
+                       {
+                               String seconds(strprintf("%0.8f",second));
+
+                               // skip trailing zeros
+                               int count = 0;
+                               for (String::reverse_iterator i = seconds.rbegin(); (*i) == '0'; i++)
+                                       count++;
+
+                               // if we removed too many, go back one place, leaving one zero
+                               if (*i < '0' || *i > '9') count--;
+
+                               ret += seconds.substr(0, seconds.size()-count) + "s";
+                       }
                        else
                                ret+=strprintf("%0.0fs",second);
                }
@@ -269,6 +282,14 @@ Time::round(float fps)const
                return ceil(time)/fps;
 }
 
+#ifdef _DEBUG
+const char *
+Time::c_str()const
+{
+       return get_string().c_str();
+}
+#endif
+
 //! \writeme
 bool
 Time::is_valid()const