4 #include "resolution.h"
5 #include "top5chosenscreen.h"
10 #define FREQUENCY_X (LOGICAL_SCREEN_WIDTH - 55)
11 #define SONG_MAX_WIDTH (LOGICAL_SCREEN_WIDTH - 190)
13 Top5ChosenScreen::Top5ChosenScreen(pqxx::connection &conn, unsigned tournament)
14 : conn(conn), tournament(tournament), scores_changed(conn, "scores"), valid(false)
18 Top5ChosenScreen::~Top5ChosenScreen()
22 bool Top5ChosenScreen::check_invalidated()
26 if (!scores_changed.get_flag())
29 // check that there are indeed changes, otherwise don't bother
30 std::vector<TopChosen> scores;
31 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
33 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
34 if (seen_topchosen.count(*i) == 0) {
42 void Top5ChosenScreen::draw(unsigned char *buf, unsigned width, unsigned height)
44 scores_changed.reset_flag();
45 memset(buf, 0, width * height * 4);
46 set_screen_size(width, height);
48 // fetch the top 5 chosen songs
49 std::vector<TopChosen> scores;
50 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
53 unsigned width = my_draw_text("Today's top 5 chosen songs", NULL, 40.0);
54 my_draw_text("Today's top 5 chosen songs", buf, 40.0, LOGICAL_SCREEN_WIDTH/2 - width/2, 60);
58 my_draw_text("Song", buf, 12.0, SONG_X, 100);
59 my_draw_text("Frequency", buf, 12.0, FREQUENCY_X - 35, 100);
61 unsigned row = 1, y = 140;
62 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
64 unsigned r = 255, g = 255, b = 255;
66 // print new entries in red
67 if (seen_topchosen.count(*i) == 0 && seen_topchosen.size() > 0) {
71 std::sprintf(str, "%u", row++);
72 unsigned width = my_draw_text(str, NULL, 24.0);
73 my_draw_text(str, buf, 24.0, RANK_X - width/2, y);
75 if (my_draw_text(i->title, NULL, 24.0) > SONG_MAX_WIDTH) {
76 my_draw_text(i->shorttitle, buf, 24.0, SONG_X, y, r, g, b);
78 my_draw_text(i->title, buf, 24.0, SONG_X, y, r, g, b);
81 std::sprintf(str, "%u", i->frequency);
82 width = my_draw_text(str, NULL, 24.0);
83 my_draw_text(str, buf, 24.0, FREQUENCY_X - width/2, y, r, g, b);
90 seen_topchosen.erase(seen_topchosen.begin(), seen_topchosen.end());
91 std::copy(scores.begin(), scores.end(), std::inserter(seen_topchosen, seen_topchosen.end()));