X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-core%2Ftrunk%2Fsrc%2Fsynfig%2Ftime.cpp;h=f9fae684fa5aa60543030d8eaab4a5be3b77c375;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=b751e8e0ba781b50f3ff238a0f4c0e716bfe8932;hpb=b786c4cafa872096fa3c3d24c4409e00a49dee88;p=synfig.git diff --git a/synfig-core/trunk/src/synfig/time.cpp b/synfig-core/trunk/src/synfig/time.cpp index b751e8e..f9fae68 100644 --- a/synfig-core/trunk/src/synfig/time.cpp +++ b/synfig-core/trunk/src/synfig/time.cpp @@ -6,7 +6,9 @@ ** ** \legal ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** Copyright (c) 2007 Chris Moore +** 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 @@ -37,6 +39,7 @@ #include #include #include +#include #include #include @@ -182,11 +185,12 @@ Time::get_string(float fps, Time::Format format)const if(ceil(time.value_)-time.value_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 || minute) { - ret+=strprintf(format<=FORMAT_NOSPACES?"%dm":"%dm ",minute); + if (!(format<=FORMAT_NOSPACES) && started) + ret += " "; + + ret += strprintf("%dm", minute); started = true; } @@ -225,18 +240,25 @@ Time::get_string(float fps, Time::Format format)const 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 += " "; + + ret += strprintf("%ds", (int)second); started = true; } - if(format<=FORMAT_FULL || frame || !started) + if(format<=FORMAT_FULL || abs(frame) > epsilon_() || !started) { - if(abs(frame-floor(frame)>=epsilon_())) - ret+=strprintf("%0.3ff",frame); + 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("%0.0ff", frame); } } else @@ -245,13 +267,17 @@ Time::get_string(float fps, Time::Format format)const second=time; 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; - for (String::reverse_iterator i = seconds.rbegin(); (*i) == '0'; i++) + String::reverse_iterator i = seconds.rbegin(); + for ( ; (*i) == '0'; i++) count++; // if we removed too many, go back one place, leaving one zero