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 my_draw_text("Frequency", buf, 12.0, FREQUENCY_X - 35, 100);
63 unsigned row = 1, y = 140;
64 for (std::vector<TopChosen>::const_iterator i = scores.begin(); i != scores.end(); ++i) {
66 unsigned r = 255, g = 255, b = 255;
68 // print new entries in red
69 if (seen_topchosen.count(*i) == 0 && seen_topchosen.size() > 0) {
73 std::sprintf(str, "%u", row++);
74 unsigned width = my_draw_text(str, NULL, 24.0);
75 my_draw_text(str, buf, 24.0, RANK_X - width/2, y);
77 if (my_draw_text(i->title, NULL, 24.0) > SONG_MAX_WIDTH) {
78 my_draw_text(i->shorttitle, buf, 24.0, SONG_X, y, r, g, b);
80 my_draw_text(i->title, buf, 24.0, SONG_X, y, r, g, b);
83 std::sprintf(str, "%u", i->frequency);
84 width = my_draw_text(str, NULL, 24.0);
85 my_draw_text(str, buf, 24.0, FREQUENCY_X - width/2, y, r, g, b);
92 seen_topchosen.erase(seen_topchosen.begin(), seen_topchosen.end());
93 std::copy(scores.begin(), scores.end(), std::inserter(seen_topchosen, seen_topchosen.end()));