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. First try unlimited width (ie.
45 // long titles for everything); if that gets too long, try again with short
46 // titles for chosen songs.
47 unsigned width[16], num_scores;
48 unsigned max_num_width = my_draw_text("8888", NULL, 22.0);
50 for (mode = 0; mode < 2; ++mode) {
51 for (unsigned i = 0; i < 16; ++i)
54 for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
56 width[0] = std::max(width[0], my_draw_text(i->nick, NULL, 18.0));
58 for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j, ++col) {
60 width[col] = std::max(width[col], my_draw_text((mode == 0) ? j->song.title : j->song.short_title, NULL, 12.0) +
63 width[col] = std::max(width[col], my_draw_text(j->song.short_title, NULL, 12.0));
64 width[col] = std::max(width[col], max_num_width);
69 num_scores = group.players[0].scores.size();
71 width[num_scores + 1] = std::max(my_draw_text("Total", NULL, 12.0), max_num_width);
72 width[num_scores + 2] = my_draw_text("Rank", NULL, 12.0);
74 // if we're at long titles and that works, don't try the short ones
76 unsigned sumwidth = 0;
77 for (unsigned i = 0; i <= num_scores + 2; ++i)
78 sumwidth += width[i] + 20;
85 // make column headings from the first player's songs
87 unsigned x = 40 + width[0];
88 for (std::vector<Score>::const_iterator i = group.players[0].scores.begin(); i != group.players[0].scores.end(); ++i, ++col) {
90 unsigned this_width = my_draw_text(i->song.short_title, NULL, 12.0);
91 my_draw_text(i->song.short_title, buf, 12.0, x + width[col] / 2 - this_width / 2, 100);
96 my_draw_text("Total", buf, 12.0, x + width[num_scores + 1] / 2 - my_draw_text("Total", NULL, 12.0) / 2, 100);
97 x += width[num_scores + 1] + 20;
98 my_draw_text("Rank", buf, 12.0, x + width[num_scores + 2] / 2 - my_draw_text("Rank", NULL, 12.0) / 2, 100);
100 // show all the players and the scores
102 for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
103 my_draw_text(i->nick, buf, 18.0, 20, y);
105 unsigned x = 40 + width[0];
108 for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j, ++col) {
110 sprintf(text, "%u", j->score);
112 unsigned this_width = my_draw_text(text, NULL, 22.0);
114 if (j->score != -1) {
115 my_draw_text(text, buf, 22.0, x + max_num_width - this_width, y);
117 my_draw_text((mode == 0) ? j->song.title : j->song.short_title, buf, 12.0, x + max_num_width + 10, y);
119 if (j->score != -1) {
120 my_draw_text(text, buf, 22.0, x + width[col] / 2 - this_width / 2, y);
123 x += width[col] + 20;