4 #include "top5chosenscreen.h"
7 Top5ChosenScreen::Top5ChosenScreen(pqxx::connection &conn, unsigned tournament)
8 : conn(conn), tournament(tournament), scores_changed(conn, "scores"), valid(false)
12 Top5ChosenScreen::~Top5ChosenScreen()
16 bool Top5ChosenScreen::check_invalidated()
20 if (!scores_changed.get_flag())
23 // check that there are indeed changes, otherwise don't bother
24 std::vector<TopChosen> scores;
25 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
27 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
28 if (seen_topchosen.count(*i) == 0) {
36 void Top5ChosenScreen::draw(unsigned char *buf)
38 scores_changed.reset_flag();
39 memset(buf, 0, 800 * 600 * 4);
41 // fetch the top 5 chosen songs
42 std::vector<TopChosen> scores;
43 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
46 unsigned width = my_draw_text("Today's top 5 chosen songs", NULL, 40.0);
47 my_draw_text("Today's top 5 chosen songs", buf, 40.0, 800/2 - width/2, 60);
51 my_draw_text("Song", buf, 12.0, 70, 100);
52 my_draw_text("Frequency", buf, 12.0, 710, 100);
54 unsigned row = 1, y = 140;
55 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
57 unsigned r = 255, g = 255, b = 255;
59 // print new entries in red
60 if (seen_topchosen.count(*i) == 0 && seen_topchosen.size() > 0) {
64 std::sprintf(str, "%u", row++);
65 unsigned width = my_draw_text(str, NULL, 24.0);
66 my_draw_text(str, buf, 24.0, 30 - width/2, y);
68 if (my_draw_text(i->title, NULL, 24.0) > 610) {
69 my_draw_text(i->shorttitle, buf, 24.0, 70, y, r, g, b);
71 my_draw_text(i->title, buf, 24.0, 70, y, r, g, b);
74 std::sprintf(str, "%u", i->frequency);
75 width = my_draw_text(str, NULL, 24.0);
76 my_draw_text(str, buf, 24.0, 745 - width/2, y, r, g, b);
83 seen_topchosen.erase(seen_topchosen.begin(), seen_topchosen.end());
84 std::copy(scores.begin(), scores.end(), std::inserter(seen_topchosen, seen_topchosen.end()));