3 #include "groupscreen.h"
4 #include "fetch_group.h"
7 GroupScreen::GroupScreen(pqxx::connection &conn, unsigned tournament, unsigned round, unsigned parallel)
8 : tournament(tournament), round(round), parallel(parallel), scores_changed(conn, "scores"), conn(conn), valid(false)
12 GroupScreen::~GroupScreen()
16 bool GroupScreen::check_invalidated()
18 // we might want to do this slightly more sophisticated later, but for now this will do
19 return !valid || scores_changed.get_flag();
22 void GroupScreen::draw(unsigned char *buf)
24 scores_changed.reset_flag();
27 conn.perform(FetchGroup(tournament, round, parallel, &group));
29 memset(buf, 0, 800 * 600 * 4);
31 // find out how wide each column has to be
33 for (unsigned i = 0; i < 16; ++i)
36 for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
37 width[0] = std::max(width[0], my_draw_text(i->nick, NULL, 0, 0, false, 0, 0, 0));
40 for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j, ++col) {
42 width[col] = std::max(width[col], my_draw_text(j->song.title, NULL, 0, 0, false, 0, 0, 0) +
43 my_draw_text("8888", NULL, 0, 0, false, 0, 0, 0) + 10);
45 width[col] = std::max(width[col], my_draw_text(j->song.title, NULL, 0, 0, false, 0, 0, 0));
46 width[col] = std::max(width[col], my_draw_text("8888", NULL, 0, 0, false, 0, 0, 0));
51 // make column headings from the first player's songs
52 unsigned col = 1, x = 40 + width[0];
53 for (std::vector<Score>::const_iterator i = group.players[0].scores.begin(); i != group.players[0].scores.end(); ++i, ++col) {
54 my_draw_text(i->song.title, buf, x, 30, true, 255, 255, 255);
58 // show all the players and the scores
60 for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
61 my_draw_text(i->nick, buf, 20, y, true, 255, 255, 255);
63 unsigned x = 40 + width[0];
66 for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j, ++col) {
68 sprintf(text, "%u", j->score);
71 my_draw_text(text, buf, x, y, true, 255, 255, 255);