Make queueMessage take a printf-style format string

This commit is contained in:
simon.kagstrom 2010-03-17 11:29:36 +00:00
parent f12c77463d
commit 17e2f4816c
2 changed files with 12 additions and 3 deletions

View File

@ -11,12 +11,21 @@ StatusBar::StatusBar() : Menu(Gui::gui->small_font), TimeoutHandler()
}
void StatusBar::queueMessage(const char *message)
void StatusBar::queueMessage(const char *fmt, ...)
{
char buf[255];
va_list ap;
int r;
memset(buf, 0, sizeof(buf));
va_start(ap, fmt);
r = vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
va_end(ap);
/* Free the existing message if we are overwriting it */
free((void*)this->messages[this->head]);
this->messages[this->head] = xstrdup(message);
this->messages[this->head] = xstrdup(buf);
/* If this is the first message, display it as soon as possible */
if (this->head == this->tail)

View File

@ -13,7 +13,7 @@ class StatusBar : public Menu, public TimeoutHandler
public:
StatusBar();
void queueMessage(const char *message);
void queueMessage(const char *message, ...);
virtual void draw(SDL_Surface *where);