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())
28 scores_changed.reset_flag();
30 // check that there are indeed changes, otherwise don't bother
31 std::vector<TopChosen> scores;
32 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
34 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
35 if (seen_topchosen.count(*i) == 0) {
44 void Top5ChosenScreen::draw(unsigned char *buf, unsigned width, unsigned height)
46 scores_changed.reset_flag();
47 memset(buf, 0, width * height * 4);
48 set_screen_size(width, height);
50 // fetch the top 5 chosen songs
51 std::vector<TopChosen> scores;
52 conn.perform(FetchTopChosenSongsForTournament(tournament, 5, &scores));
55 unsigned width = my_draw_text("Today's top 5 chosen songs", NULL, 40.0);
56 my_draw_text("Today's top 5 chosen songs", buf, 40.0, LOGICAL_SCREEN_WIDTH/2 - width/2, 60);
60 my_draw_text("Song", buf, 12.0, SONG_X, 100);
61 width = my_draw_text("Frequency", NULL, 12.0);
62 my_draw_text("Frequency", buf, 12.0, FREQUENCY_X - width/2, 100);
64 unsigned row = 1, y = 140;
65 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
67 unsigned r = 255, g = 255, b = 255;
69 // print new entries in red
70 if (seen_topchosen.count(*i) == 0 && seen_topchosen.size() > 0) {
74 std::sprintf(str, "%u", row++);
75 unsigned width = my_draw_text(str, NULL, 24.0);
76 my_draw_text(str, buf, 24.0, RANK_X - width/2, y);
78 if (my_draw_text(i->title, NULL, 24.0) > SONG_MAX_WIDTH) {
79 my_draw_text(i->shorttitle, buf, 24.0, SONG_X, y, r, g, b);
81 my_draw_text(i->title, buf, 24.0, SONG_X, y, r, g, b);
84 std::sprintf(str, "%u", i->frequency);
85 width = my_draw_text(str, NULL, 24.0);
86 my_draw_text(str, buf, 24.0, FREQUENCY_X - width/2, y, r, g, b);
93 seen_topchosen.erase(seen_topchosen.begin(), seen_topchosen.end());
94 std::copy(scores.begin(), scores.end(), std::inserter(seen_topchosen, seen_topchosen.end()));