frodo-wii/Src/gui/network_server_messages.cpp

79 lines
1.7 KiB
C++
Raw Normal View History

2010-02-28 08:59:36 +01:00
#include "network_server_messages.hh"
#include "utils.hh"
NetworkServerMessages::NetworkServerMessages() : StatusBar()
{
unsigned i;
for (i = 0; i < ARRAY_SIZE(this->flowed_messages) - 1; i++)
this->flowed_messages[i] = (char *)xmalloc(28);
this->flowed_messages[i] = NULL;
}
NetworkServerMessages::~NetworkServerMessages()
{
for (unsigned i = 0; i < ARRAY_SIZE(this->flowed_messages) - 1; i++)
free(this->flowed_messages[i]);
}
void NetworkServerMessages::draw(SDL_Surface *where)
{
SDL_Rect dst;
int x = 350;
int y = 242;
int w = Gui::gui->network_message_box->w;
int h = Gui::gui->network_message_box->h;
2010-02-28 08:59:36 +01:00
dst = (SDL_Rect){x,y,0,0};
SDL_BlitSurface(Gui::gui->network_message_box, NULL, where, &dst);
2010-02-28 08:59:36 +01:00
Menu::draw(where, x+6, y+8, w-6, h-8);
}
void NetworkServerMessages::timeoutCallback()
{
const char *cur = this->messages[this->tail];
char *cpy = xstrdup(cur);
char *msgp;
char *p;
size_t line_len = 0;
size_t line = 0;
for (unsigned i = 0; i < ARRAY_SIZE(this->flowed_messages) - 1; i++)
this->flowed_messages[i][0] = '\0';
p = strtok_r(cpy, " ", &msgp);
while (p)
{
int word_len = strlen(p);
if (line_len + word_len > 24)
{
line++;
/* Too long! */
if (line >= ARRAY_SIZE(this->flowed_messages))
break;
line_len = 0;
}
strcat(this->flowed_messages[line], p);
strcat(this->flowed_messages[line], " ");
line_len += word_len + 1;
p = strtok_r(NULL, " ", &msgp);
}
for (line = line + 1; line < ARRAY_SIZE(this->flowed_messages) - 1; line++)
strcpy(this->flowed_messages[line], "#");
this->setText((const char **)this->flowed_messages);
while (1)
{
this->tail = (this->tail + 1) % N_STATUS_MESSAGES;
if (this->messages[this->tail])
break;
}
TimerController::controller->arm(this, 5000);
2010-02-28 08:59:36 +01:00
free(cpy);
}