This is what I have to work with (job stuff)
by at 11:24 PM
Seriously.
Replaced with:
You probably don't want to see how he was formatting a percentage value.
char buffer[10];
int mins = m_timeLeft / 60;
int secs = m_timeLeft % 60;
int doubleMin;
int singleMin;
if(mins >= 10)
{
doubleMin = mins / 10;
singleMin = mins % 10;
}
else
{
doubleMin = 0;
singleMin = mins;
}
int doubleSec;
int singleSec;
if(secs >= 10)
{
doubleSec = secs / 10;
singleSec = secs % 10;
}
else
{
doubleSec = 0;
singleSec = secs;
}
short offset = 13;
short start = 255;
sprintf(buffer, "%d", singleSec);
ge->DrawText(buffer, 0, 0, 255, 0, GraphicsEngine::J_RIGHT);
start -= 2*offset;
sprintf(buffer, "%d", doubleSec);
ge->DrawText(buffer, 0, 0, start, 0, GraphicsEngine::J_RIGHT);
start -= offset;
sprintf(buffer, ":");
ge->DrawText(buffer, 0, 0, start, 0, GraphicsEngine::J_RIGHT);
start -= offset - 7;
sprintf(buffer, "%d", singleMin);
ge->DrawText(buffer, 0, 0, start, 0, GraphicsEngine::J_RIGHT);
start -= offset;
if(doubleMin)
{
sprintf(buffer, "%d", doubleMin);
ge->DrawText(buffer, 0, 0, start, 0, GraphicsEngine::J_RIGHT);
}
char buffer[10]; int mins = m_timeLeft / 60; int secs = m_timeLeft % 60; sprintf(buffer, "%d:%02d", mins, secs); ge->DrawText(buffer, 0, 0, 255, 0, GraphicsEngine::J_RIGHT);
Comments
If it's always going to be a monowidth font, I'll shoot him for you
char buf[2] = "\0";
buf[0] = time/600 + '0';
ge->DrawText(buf,...);
buf[1] = (time/60)%10 + '0';
ge->DrawText(buf,...);
// etc.
instead of calling fucking sprintf() for single digits. Also, DrawText() does allow you to draw a single character at a time from a longer string.
Tomorrow I'll change it to the less-retarded method which I'd originally suggested that he use to begin with, or maybe center the text within a box, or something. I just wanted to get rid of that ugly-ass eyesore, and maybe he'll stumble across the code and realize that, hey, the printf() family already knows how to deal with leading 0s and stuff...
And (OT) <div class="code"> matches with </div>, not </code>. (Now fixed. The gods of HTML thank you. My browser thanks you. And I thank you.)
This would certainly be a worthy candidate for The Daily WTF, though by the end of the day they'd probably have a dozen comments defending it.
-ajf