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())
26 void Top5ChosenScreen::draw(unsigned char *buf)
28 scores_changed.reset_flag();
29 memset(buf, 0, 800 * 600 * 4);
31 // fetch the top 5 chosen songs
32 std::vector<TopChosen> scores;
33 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
36 unsigned width = my_draw_text("Today's top 5 chosen songs", NULL, 40.0);
37 my_draw_text("Today's top 5 chosen songs", buf, 40.0, 800/2 - width/2, 60);
41 my_draw_text("Song", buf, 12.0, 70, 100);
42 my_draw_text("Frequency", buf, 12.0, 710, 100);
44 unsigned row = 1, y = 140;
45 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
47 unsigned r = 255, g = 255, b = 255;
49 // print new entries in red
50 if (seen_topchosen.count(*i) == 0 && seen_topchosen.size() > 0) {
54 std::sprintf(str, "%u", row++);
55 unsigned width = my_draw_text(str, NULL, 24.0);
56 my_draw_text(str, buf, 24.0, 30 - width/2, y);
58 if (my_draw_text(i->title, NULL, 24.0) > 610) {
59 my_draw_text(i->shorttitle, buf, 24.0, 70, y, r, g, b);
61 my_draw_text(i->title, buf, 24.0, 70, y, r, g, b);
64 std::sprintf(str, "%u", i->frequency);
65 width = my_draw_text(str, NULL, 24.0);
66 my_draw_text(str, buf, 24.0, 745 - width/2, y, r, g, b);
73 seen_topchosen.erase(seen_topchosen.begin(), seen_topchosen.end());
74 std::copy(scores.begin(), scores.end(), std::inserter(seen_topchosen, seen_topchosen.end()));