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);
34 sprintf(heading, "Round %u", round);
36 sprintf(heading, "Round %u, Group %u", round, parallel);
40 unsigned width = my_draw_text(heading, NULL, 48.0);
41 my_draw_text(heading, buf, 48.0, 800/2 - width/2, 60);
44 // find out how wide each column has to be
46 for (unsigned i = 0; i < 16; ++i)
49 unsigned max_num_width = my_draw_text("88888", NULL, 22.0);
50 for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
52 width[0] = std::max(width[0], my_draw_text(i->nick, NULL, 18.0));
54 for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j, ++col) {
56 width[col] = std::max(width[col], my_draw_text(j->song.title, NULL, 12.0) +
59 width[col] = std::max(width[col], my_draw_text(j->song.short_title, NULL, 12.0));
60 width[col] = std::max(width[col], max_num_width);
65 unsigned num_scores = group.players[0].scores.size();
67 width[num_scores + 1] = std::max(my_draw_text("Total", NULL, 12.0), max_num_width);
68 width[num_scores + 2] = my_draw_text("Rank", NULL, 12.0);
70 // make column headings from the first player's songs
72 unsigned x = 40 + width[0];
73 for (std::vector<Score>::const_iterator i = group.players[0].scores.begin(); i != group.players[0].scores.end(); ++i, ++col) {
75 unsigned this_width = my_draw_text(i->song.short_title, NULL, 12.0);
76 my_draw_text(i->song.short_title, buf, 12.0, x + width[col] / 2 - this_width / 2, 100);
81 my_draw_text("Total", buf, 12.0, x + width[num_scores + 1] / 2 - my_draw_text("Total", NULL, 12.0) / 2, 100);
82 x += width[num_scores + 1] + 20;
83 my_draw_text("Rank", buf, 12.0, x + width[num_scores + 2] / 2 - my_draw_text("Rank", NULL, 12.0) / 2, 100);
85 // show all the players and the scores
87 for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
88 my_draw_text(i->nick, buf, 18.0, 20, y);
90 unsigned x = 40 + width[0];
93 for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j, ++col) {
95 sprintf(text, "%u", j->score);
97 unsigned this_width = my_draw_text(text, NULL, 22.0);
100 my_draw_text(text, buf, 22.0, x + max_num_width - this_width, y);
102 my_draw_text(j->song.title, buf, 12.0, x + max_num_width + 10, y);
104 if (j->score != -1) {
105 my_draw_text(text, buf, 22.0, x + width[col] / 2 - this_width / 2, y);
108 x += width[col] + 20;