4 #include "resolution.h"
5 #include "top5chosenscreen.h"
8 Top5ChosenScreen::Top5ChosenScreen(pqxx::connection &conn, unsigned tournament)
9 : conn(conn), tournament(tournament), scores_changed(conn, "scores"), valid(false)
13 Top5ChosenScreen::~Top5ChosenScreen()
17 bool Top5ChosenScreen::check_invalidated()
21 if (!scores_changed.get_flag())
24 // check that there are indeed changes, otherwise don't bother
25 std::vector<TopChosen> scores;
26 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
28 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
29 if (seen_topchosen.count(*i) == 0) {
37 void Top5ChosenScreen::draw(unsigned char *buf)
39 scores_changed.reset_flag();
40 memset(buf, 0, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
42 // fetch the top 5 chosen songs
43 std::vector<TopChosen> scores;
44 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
47 unsigned width = my_draw_text("Today's top 5 chosen songs", NULL, 40.0);
48 my_draw_text("Today's top 5 chosen songs", buf, 40.0, LOGICAL_SCREEN_WIDTH/2 - width/2, 60);
52 my_draw_text("Song", buf, 12.0, 70, 100);
53 my_draw_text("Frequency", buf, 12.0, 710, 100);
55 unsigned row = 1, y = 140;
56 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
58 unsigned r = 255, g = 255, b = 255;
60 // print new entries in red
61 if (seen_topchosen.count(*i) == 0 && seen_topchosen.size() > 0) {
65 std::sprintf(str, "%u", row++);
66 unsigned width = my_draw_text(str, NULL, 24.0);
67 my_draw_text(str, buf, 24.0, 30 - width/2, y);
69 if (my_draw_text(i->title, NULL, 24.0) > 610) {
70 my_draw_text(i->shorttitle, buf, 24.0, 70, y, r, g, b);
72 my_draw_text(i->title, buf, 24.0, 70, y, r, g, b);
75 std::sprintf(str, "%u", i->frequency);
76 width = my_draw_text(str, NULL, 24.0);
77 my_draw_text(str, buf, 24.0, 745 - width/2, y, r, g, b);
84 seen_topchosen.erase(seen_topchosen.begin(), seen_topchosen.end());
85 std::copy(scores.begin(), scores.end(), std::inserter(seen_topchosen, seen_topchosen.end()));