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 unsigned max_num_width = my_draw_text("88888", NULL, 22.0);
38 for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
39 width[0] = std::max(width[0], my_draw_text(i->nick, NULL, 18.0));
42 for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j, ++col) {
44 width[col] = std::max(width[col], my_draw_text(j->song.title, NULL, 12.0) +
47 width[col] = std::max(width[col], my_draw_text(j->song.title, NULL, 12.0));
48 width[col] = std::max(width[col], max_num_width);
53 // make column headings from the first player's songs
54 unsigned col = 1, x = 40 + width[0];
55 for (std::vector<Score>::const_iterator i = group.players[0].scores.begin(); i != group.players[0].scores.end(); ++i, ++col) {
57 unsigned this_width = my_draw_text(i->song.title, NULL, 12.0);
58 my_draw_text(i->song.title, buf, 12.0, x + width[col] / 2 - this_width / 2, 30);
63 // show all the players and the scores
65 for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
66 my_draw_text(i->nick, buf, 18.0, 20, y);
68 unsigned x = 40 + width[0];
71 for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j, ++col) {
73 sprintf(text, "%u", j->score);
75 unsigned this_width = my_draw_text(text, NULL, 22.0);
78 my_draw_text(text, buf, 22.0, x + max_num_width - this_width, y);
80 my_draw_text(j->song.title, buf, 12.0, x + max_num_width + 10, y);
83 my_draw_text(text, buf, 22.0, x + width[col] / 2 - this_width / 2, y);