Browse Source

StringStream means less recursive sprintf...

Adam Johnson 12 years ago
parent
commit
f27cf09cf5
  1. 29
      Sources/Plasma/PubUtilLib/plPipeline/plDTProgressMgr.cpp

29
Sources/Plasma/PubUtilLib/plPipeline/plDTProgressMgr.cpp

@ -203,25 +203,32 @@ bool plDTProgressMgr::IDrawTheStupidThing(plPipeline *p, plOperationProgress
if( drawWidth > 0 ) if( drawWidth > 0 )
text.DrawRect( drawX, y, rightX, y + height, color ); text.DrawRect( drawX, y, rightX, y + height, color );
int timeRemain = prog->fRemainingSecs; uint32_t timeRemain = prog->fRemainingSecs;
char remainStr[1024]; if (timeRemain > 0) {
strcpy(remainStr, "APPROXIMATELY "); plStringStream ss;
ss << "APPROXIMATELY ";
if (timeRemain > 3600) if (timeRemain > 3600)
{ {
const char* term = ((timeRemain / 3600) > 1) ? "HOURS" : "HOUR"; uint32_t hours = timeRemain / 3600;
sprintf(remainStr, "%s%d %s ", remainStr, (timeRemain / 3600), term); const char* plural = (hours > 1) ? "S" : "";
ss << hours << " HOUR" << plural << " ";
timeRemain %= 3600; timeRemain %= 3600;
} }
if (timeRemain > 60) if (timeRemain > 60)
{ {
const char* term = ((timeRemain / 60) > 1) ? "MINUTES" : "MINUTE"; uint32_t minutes = timeRemain / 60;
sprintf(remainStr, "%s%d %s ", remainStr, (timeRemain / 60), term); const char* plural = (minutes > 1) ? "S" : "";
ss << minutes << " MINUTE" << plural << " ";
timeRemain %= 60; timeRemain %= 60;
} }
const char* unitTerm = (timeRemain == 1) ? "SECOND" : "SECONDS"; if (timeRemain > 0)
sprintf(remainStr, "%s%d %s REMAINING", remainStr, timeRemain, unitTerm); {
const char* plural = (timeRemain > 1) ? "S" : "";
text.DrawString(x, y + height + 2, remainStr, (uint32_t)0xff635e6d ); ss << timeRemain << " SECOND" << plural << " ";
}
ss << "REMAINING";
text.DrawString(x, y + height + 2, ss.GetString().c_str(), (uint32_t)0xff635e6d);
}
x -= 2; x -= 2;
y -= 2; y -= 2;

Loading…
Cancel
Save