X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Ftime.cpp;h=f9fae684fa5aa60543030d8eaab4a5be3b77c375;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=acc6bcf95f23b75c35c5232686dc3fd8917e26d4;hpb=716b28d513455e159096dff4777db6f60f9f3c8f;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/time.cpp b/synfig-core/trunk/src/synfig/time.cpp index acc6bcf..f9fae68 100644 --- a/synfig-core/trunk/src/synfig/time.cpp +++ b/synfig-core/trunk/src/synfig/time.cpp @@ -6,6 +6,9 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley +** Copyright (c) 2007, 2008 Chris Moore +** Copyright (c) 2008 Gerco Ballintijn +** Copyright (c) 2008 Carlos López ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -36,6 +39,7 @@ #include #include #include +#include #include #include @@ -100,7 +104,7 @@ Time::Time(const String &str_, float fps): int read; float amount; - // Now try to read it in the letter-abreviated format + // Now try to read it in the letter-abbreviated format while(pos1) { int frame; frame=round_to_int(time*fps); @@ -202,36 +208,86 @@ Time::get_string(float fps, Time::Format format)const return strprintf("%02d:%02d:%02d",hour,minute,second); } + if (format <= FORMAT_FRAMES) + { + if (fps && fps>0) + return strprintf("%df", round_to_int(time * fps)); + else + return strprintf("%ds", round_to_int(time * 1)); + } + String ret; + bool started = false; if(format<=FORMAT_FULL || hour) - ret+=strprintf(format<=FORMAT_NOSPACES?"%dh":"%dh ",hour); + { + ret+=strprintf("%dh",hour); + started = true; + } - if(format<=FORMAT_FULL || hour || minute) - ret+=strprintf(format<=FORMAT_NOSPACES?"%dm":"%dm ",minute); + if(format<=FORMAT_FULL || minute) + { + if (!(format<=FORMAT_NOSPACES) && started) + ret += " "; - if(fps) + ret += strprintf("%dm", minute); + started = true; + } + + if(fps && fps>1) { int second; float frame; second=time;time-=second; frame=time*fps; + if(format<=FORMAT_FULL || second) - ret+=strprintf(format<=FORMAT_NOSPACES?"%ds":"%ds ",(int)second); + { + if (!(format<=FORMAT_NOSPACES) && started) + ret += " "; - if(abs(frame-floor(frame)>=epsilon_())) - ret+=strprintf("%0.3ff",frame); - else - ret+=strprintf("%0.0ff",frame); + ret += strprintf("%ds", (int)second); + started = true; + } + + if(format<=FORMAT_FULL || abs(frame) > epsilon_() || !started) + { + if (!(format<=FORMAT_NOSPACES) && started) + ret += " "; + + if(abs(frame-floor(frame) >= epsilon_())) + ret += strprintf("%0.3ff", frame); + else + ret += strprintf("%0.0ff", frame); + } } else { float second; second=time; - if(abs(second-floor(second))>=epsilon_()) - ret+=strprintf("%0.8fs",second); - else - ret+=strprintf("%0.0fs",second); + if(format<=FORMAT_FULL || second || !started) + { + if (!(format<=FORMAT_NOSPACES) && started) + ret += " "; + + if(abs(second-floor(second))>=epsilon_()) + { + String seconds(strprintf("%0.8f",second)); + + // skip trailing zeros + int count = 0; + String::reverse_iterator i = seconds.rbegin(); + for ( ; (*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); + } } return ret; @@ -252,6 +308,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